Repository Public License
1// ORIX Alarm2// File: Scripts/make-icon.swift3// Description: Draws the 1024 px app icon with Core Graphics: a sun rising as a clock dial over a midnight sky (run: swift Scripts/make-icon.swift <output.png>).4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AppKit8import CoreGraphics910let side = 102411let space = CGColorSpaceCreateDeviceRGB()12let ctx = CGContext(data: nil, width: side, height: side, bitsPerComponent: 8, bytesPerRow: 0, space: space,13 bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)!14func color(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor {15 CGColor(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: a)16}17let s = CGFloat(side)18// Sky: midnight at the top, violet, then ember at the horizon.19let sky = CGGradient(colorsSpace: space, colors: [color(0x070916), color(0x1B1650), color(0x5B2D8C), color(0xE8553F)] as CFArray, locations: [0, 0.38, 0.62, 0.80])!20ctx.drawLinearGradient(sky, start: CGPoint(x: 0, y: s), end: CGPoint(x: 0, y: s * 0.20), options: [.drawsAfterEndLocation])21func glow(_ hex: UInt32, _ x: CGFloat, _ y: CGFloat, _ r: CGFloat, _ a: CGFloat) {22 let g = CGGradient(colorsSpace: space, colors: [color(hex, a), color(hex, 0)] as CFArray, locations: [0, 1])!23 ctx.drawRadialGradient(g, startCenter: CGPoint(x: x, y: y), startRadius: 0, endCenter: CGPoint(x: x, y: y), endRadius: r, options: [])24}25glow(0x7A5CFA, s * 0.18, s * 0.88, s * 0.55, 0.45)26glow(0x548FFF, s * 0.86, s * 0.80, s * 0.45, 0.35)27let horizon = s * 0.3428let center = CGPoint(x: s / 2, y: horizon)29glow(0xFFC96B, center.x, center.y, s * 0.62, 0.75)30// Sun disc (upper half visible above the horizon).31let radius = s * 0.3032ctx.saveGState()33ctx.clip(to: CGRect(x: 0, y: horizon, width: s, height: s))34let sun = CGGradient(colorsSpace: space, colors: [color(0xFFF1C9), color(0xFFC96B), color(0xFF8F42)] as CFArray, locations: [0, 0.55, 1])!35ctx.addEllipse(in: CGRect(x: center.x - radius, y: center.y - radius, width: radius * 2, height: radius * 2)); ctx.clip()36ctx.drawRadialGradient(sun, startCenter: CGPoint(x: center.x, y: center.y + radius * 0.3), startRadius: 0, endCenter: center, endRadius: radius, options: [.drawsAfterEndLocation])37ctx.restoreGState()38// Dial ticks around the visible half.39ctx.setLineCap(.round)40for i in 0...12 {41 let angle = CGFloat.pi * CGFloat(i) / 1242 let major = i % 3 == 043 let r0 = radius + s * 0.050, r1 = radius + s * (major ? 0.115 : 0.085)44 ctx.setStrokeColor(color(0xFFE2B0, major ? 0.95 : 0.55)); ctx.setLineWidth(s * (major ? 0.020 : 0.012))45 ctx.move(to: CGPoint(x: center.x + cos(angle) * r0, y: center.y + sin(angle) * r0))46 ctx.addLine(to: CGPoint(x: center.x + cos(angle) * r1, y: center.y + sin(angle) * r1)); ctx.strokePath()47}48// Clock hands on the sun (about seven o'clock rotated into the visible half: pointing up-left and up-right).49ctx.setStrokeColor(color(0x1B1650, 0.92))50ctx.setLineWidth(s * 0.030)51ctx.move(to: center); ctx.addLine(to: CGPoint(x: center.x - radius * 0.34, y: center.y + radius * 0.46)); ctx.strokePath()52ctx.setLineWidth(s * 0.022)53ctx.move(to: center); ctx.addLine(to: CGPoint(x: center.x + radius * 0.50, y: center.y + radius * 0.62)); ctx.strokePath()54// Foreground: dark land below the horizon with a thin bright rim.55let land = CGGradient(colorsSpace: space, colors: [color(0x120F33), color(0x05060D)] as CFArray, locations: [0, 1])!56ctx.saveGState(); ctx.clip(to: CGRect(x: 0, y: 0, width: s, height: horizon))57ctx.drawLinearGradient(land, start: CGPoint(x: 0, y: horizon), end: .zero, options: [])58glow(0xFF8F42, center.x, horizon, s * 0.42, 0.35)59ctx.restoreGState()60ctx.setStrokeColor(color(0xFFE2B0, 0.9)); ctx.setLineWidth(s * 0.008)61ctx.move(to: CGPoint(x: s * 0.10, y: horizon)); ctx.addLine(to: CGPoint(x: s * 0.90, y: horizon)); ctx.strokePath()6263let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "icon-1024.png"64let rep = NSBitmapImageRep(cgImage: ctx.makeImage()!)65try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: out))66print("wrote \(out)")67