Repository Public
1// Draws the SP Vault icon (ink ground, verdigris keyhole inside a brass-edged ring) with CoreGraphics.2// Usage: swift Scripts/make-icon.swift <out-dir> → ios-1024.png (full bleed, opaque) and mac-1024.png (rounded, with margin)3import AppKit4import CoreGraphics56func render(mac: Bool) -> Data {7 let S: CGFloat = 10248 let cs = CGColorSpace(name: CGColorSpace.sRGB)!9 let ctx = CGContext(data: nil, width: Int(S), height: Int(S), bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: (mac ? CGImageAlphaInfo.premultipliedLast : CGImageAlphaInfo.noneSkipLast).rawValue)!10 func c(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat = 1) -> CGColor { CGColor(colorSpace: cs, components: [r / 255, g / 255, b / 255, a])! }11 let inset: CGFloat = mac ? 100 : 0, side = S - 2 * inset12 let rect = CGRect(x: inset, y: inset, width: side, height: side)13 if mac {14 ctx.setShadow(offset: CGSize(width: 0, height: -10), blur: 24, color: c(0, 0, 0, 0.35))15 ctx.addPath(CGPath(roundedRect: rect, cornerWidth: side * 0.2237, cornerHeight: side * 0.2237, transform: nil)); ctx.setFillColor(c(12, 17, 19)); ctx.fillPath()16 ctx.setShadow(offset: .zero, blur: 0, color: nil)17 ctx.addPath(CGPath(roundedRect: rect, cornerWidth: side * 0.2237, cornerHeight: side * 0.2237, transform: nil)); ctx.clip()18 }19 // ground: deep ink with a soft verdigris glow from the top-left20 ctx.drawLinearGradient(CGGradient(colorsSpace: cs, colors: [c(22, 36, 40), c(9, 13, 15)] as CFArray, locations: [0, 1])!, start: CGPoint(x: rect.minX, y: rect.maxY), end: CGPoint(x: rect.maxX, y: rect.minY), options: [])21 ctx.drawRadialGradient(CGGradient(colorsSpace: cs, colors: [c(63, 208, 168, 0.30), c(63, 208, 168, 0)] as CFArray, locations: [0, 1])!, startCenter: CGPoint(x: rect.minX + side * 0.30, y: rect.minY + side * 0.78), startRadius: 0,22 endCenter: CGPoint(x: rect.minX + side * 0.30, y: rect.minY + side * 0.78), endRadius: side * 0.75, options: [])23 let cx = rect.midX, cy = rect.midY, u = side / 10024 // dial ring with tick marks (a vault door, abstracted)25 ctx.setStrokeColor(c(217, 180, 108)); ctx.setLineWidth(1.6 * u)26 ctx.strokeEllipse(in: CGRect(x: cx - 33 * u, y: cy - 33 * u, width: 66 * u, height: 66 * u))27 ctx.setStrokeColor(c(217, 180, 108, 0.55)); ctx.setLineWidth(0.9 * u); ctx.setLineCap(.round)28 for i in 0..<48 {29 let a = CGFloat(i) / 48 * 2 * .pi, long = i % 4 == 030 ctx.move(to: CGPoint(x: cx + cos(a) * 36.5 * u, y: cy + sin(a) * 36.5 * u)); ctx.addLine(to: CGPoint(x: cx + cos(a) * (long ? 40.5 : 38.5) * u, y: cy + sin(a) * (long ? 40.5 : 38.5) * u)); ctx.strokePath()31 }32 // inner plate33 ctx.setFillColor(c(19, 27, 30)); ctx.fillEllipse(in: CGRect(x: cx - 29 * u, y: cy - 29 * u, width: 58 * u, height: 58 * u))34 // keyhole: circle over a flared stem, verdigris gradient35 // two shapes filled separately with the same gradient (a single path would cancel where they overlap)36 let head = CGPath(ellipseIn: CGRect(x: cx - 9.5 * u, y: cy + 0.5 * u, width: 19 * u, height: 19 * u), transform: nil)37 let stem = CGMutablePath()38 stem.move(to: CGPoint(x: cx - 4.2 * u, y: cy + 5 * u)); stem.addLine(to: CGPoint(x: cx + 4.2 * u, y: cy + 5 * u)); stem.addLine(to: CGPoint(x: cx + 8.2 * u, y: cy - 17 * u))39 stem.addQuadCurve(to: CGPoint(x: cx - 8.2 * u, y: cy - 17 * u), control: CGPoint(x: cx, y: cy - 20 * u)); stem.closeSubpath()40 let grad = CGGradient(colorsSpace: cs, colors: [c(120, 236, 200), c(40, 170, 136)] as CFArray, locations: [0, 1])!41 for shape in [head, stem as CGPath] {42 ctx.saveGState(); ctx.addPath(shape); ctx.clip()43 ctx.drawLinearGradient(grad, start: CGPoint(x: cx, y: cy + 20 * u), end: CGPoint(x: cx, y: cy - 20 * u), options: [])44 ctx.restoreGState()45 }46 return NSBitmapImageRep(cgImage: ctx.makeImage()!).representation(using: .png, properties: [:])!47}48let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "."49try! render(mac: false).write(to: URL(fileURLWithPath: out + "/ios-1024.png"))50try! render(mac: true).write(to: URL(fileURLWithPath: out + "/mac-1024.png"))51print("icons written to", out)52