-
Notifications
You must be signed in to change notification settings - Fork 0
/
close.swift
executable file
·33 lines (28 loc) · 999 Bytes
/
close.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env swift
import AppKit
let width = 128
let height = 128
let path = CommandLine.arguments[0] as NSString
let output = (path.deletingPathExtension as NSString).appendingPathExtension("pdf")!
var box = CGRect(x: 0, y: 0, width: width, height: height)
guard let context = CGContext(NSURL(fileURLWithPath: output, isDirectory: false), mediaBox: &box, nil) else {exit(EXIT_FAILURE)}
context.beginPDFPage(nil)
context.setFillColor(NSColor(white: 0.0, alpha: 1.0).cgColor)
context.setStrokeColor(NSColor(white: 0.0, alpha: 1.0).cgColor)
context.setLineWidth(10)
context.setLineJoin(.round)
context.setLineCap(.round)
// uncomment for flipped
context.scaleBy(x: 1, y: -1)
context.translateBy(x: 0, y: -CGFloat(height))
// START DRAWING
context.translateBy(x: box.midX, y: box.midY)
context.rotate(by: .pi / 4)
for _ in 1...2 {
context.move(to: CGPoint(x: -56, y: 0))
context.addLine(to: CGPoint(x: 56, y: 0))
context.rotate(by: .pi / 2)
}
context.strokePath()
// END
context.endPDFPage()