Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Scripts/make-icon.swift3// Description: Draws the SP Mail icon (white envelope on a blue→indigo gradient) with CoreGraphics and writes a 1024 px PNG.4// Usage: swift Scripts/make-icon.swift <out.png> [mac|ios] (mac = rounded "squircle" with margins, ios = full-bleed square)5import AppKit6import CoreGraphics78let args = CommandLine.arguments9guard args.count >= 2 else { print("usage: make-icon <out.png> [mac|ios]"); exit(2) }10let mac = args.count < 3 || args[2] == "mac"11let size: CGFloat = 102412let space = CGColorSpaceCreateDeviceRGB()13guard let ctx = CGContext(data: nil, width: Int(size), height: Int(size), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { exit(1) }1415let plate = mac ? CGRect(x: 100, y: 100, width: 824, height: 824) : CGRect(x: 0, y: 0, width: size, height: size)16let platePath = mac ? CGPath(roundedRect: plate, cornerWidth: 186, cornerHeight: 186, transform: nil) : CGPath(rect: plate, transform: nil)17if mac { ctx.setShadow(offset: CGSize(width: 0, height: -10), blur: 24, color: CGColor(gray: 0, alpha: 0.28)); ctx.addPath(platePath); ctx.setFillColor(CGColor(gray: 0.2, alpha: 1)); ctx.fillPath(); ctx.setShadow(offset: .zero, blur: 0, color: nil) }18ctx.saveGState()19ctx.addPath(platePath); ctx.clip()20let colors = [CGColor(red: 0.20, green: 0.56, blue: 0.98, alpha: 1), CGColor(red: 0.16, green: 0.33, blue: 0.86, alpha: 1), CGColor(red: 0.30, green: 0.20, blue: 0.72, alpha: 1)] as CFArray21let gradient = CGGradient(colorsSpace: space, colors: colors, locations: [0, 0.55, 1])!22ctx.drawLinearGradient(gradient, start: CGPoint(x: plate.minX, y: plate.maxY), end: CGPoint(x: plate.maxX, y: plate.minY), options: [])23// soft highlight24let glow = CGGradient(colorsSpace: space, colors: [CGColor(gray: 1, alpha: 0.22), CGColor(gray: 1, alpha: 0)] as CFArray, locations: [0, 1])!25ctx.drawRadialGradient(glow, startCenter: CGPoint(x: plate.minX + plate.width * 0.3, y: plate.maxY - plate.height * 0.15), startRadius: 0, endCenter: CGPoint(x: plate.minX + plate.width * 0.3, y: plate.maxY - plate.height * 0.15), endRadius: plate.width * 0.75, options: [])26ctx.restoreGState()2728// envelope29let w = plate.width * 0.62, h = w * 0.6830let env = CGRect(x: plate.midX - w / 2, y: plate.midY - h / 2 - plate.height * 0.01, width: w, height: h)31let r = w * 0.08532ctx.setShadow(offset: CGSize(width: 0, height: -14), blur: 34, color: CGColor(red: 0.05, green: 0.08, blue: 0.35, alpha: 0.42))33ctx.addPath(CGPath(roundedRect: env, cornerWidth: r, cornerHeight: r, transform: nil))34ctx.setFillColor(CGColor(gray: 1, alpha: 1)); ctx.fillPath()35ctx.setShadow(offset: .zero, blur: 0, color: nil)36ctx.saveGState()37ctx.addPath(CGPath(roundedRect: env, cornerWidth: r, cornerHeight: r, transform: nil)); ctx.clip()38// lower folds39ctx.setStrokeColor(CGColor(red: 0.72, green: 0.78, blue: 0.93, alpha: 1)); ctx.setLineWidth(w * 0.022); ctx.setLineCap(.round)40ctx.move(to: CGPoint(x: env.minX, y: env.minY)); ctx.addLine(to: CGPoint(x: env.midX - w * 0.10, y: env.midY - h * 0.04))41ctx.move(to: CGPoint(x: env.maxX, y: env.minY)); ctx.addLine(to: CGPoint(x: env.midX + w * 0.10, y: env.midY - h * 0.04)); ctx.strokePath()42// flap43let flap = CGMutablePath()44flap.move(to: CGPoint(x: env.minX - 4, y: env.maxY + 4))45flap.addLine(to: CGPoint(x: env.midX - w * 0.06, y: env.midY - h * 0.10))46flap.addQuadCurve(to: CGPoint(x: env.midX + w * 0.06, y: env.midY - h * 0.10), control: CGPoint(x: env.midX, y: env.midY - h * 0.17))47flap.addLine(to: CGPoint(x: env.maxX + 4, y: env.maxY + 4)); flap.closeSubpath()48ctx.addPath(flap); ctx.setFillColor(CGColor(red: 0.90, green: 0.93, blue: 0.99, alpha: 1)); ctx.fillPath()49ctx.addPath(flap); ctx.setStrokeColor(CGColor(red: 0.62, green: 0.70, blue: 0.90, alpha: 1)); ctx.setLineWidth(w * 0.024); ctx.setLineJoin(.round); ctx.strokePath()50ctx.restoreGState()5152guard let image = ctx.makeImage(), let data = NSBitmapImageRep(cgImage: image).representation(using: .png, properties: [:]) else { exit(1) }53try! data.write(to: URL(fileURLWithPath: args[1]))54print("icon written: \(args[1])")55