SPB Git

Repository Public License

make-icon.swift 3.5 KB 71 lines swift

1// ORIX Arcade2// File: Scripts/make-icon.swift3// Description: Draws the 1024 px app icon with Core Graphics (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// Background: midnight gradient with three soft accent glows (one per game).19let bg = CGGradient(colorsSpace: space, colors: [color(0x1A1740), color(0x05060D)] as CFArray, locations: [0, 1])!20ctx.drawLinearGradient(bg, start: CGPoint(x: 0, y: s), end: CGPoint(x: s, y: 0), options: [])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(0x8B7BFF, s * 0.2, s * 0.85, s * 0.7, 0.55)26glow(0x3DE8C5, s * 0.9, s * 0.2, s * 0.6, 0.35)27glow(0xFF5E7E, s * 0.1, s * 0.1, s * 0.5, 0.28)2829// Orbit ring drawn as short arc segments so the colour sweeps around it.30let center = CGPoint(x: s / 2, y: s / 2)31let radius = s * 0.30, width = s * 0.08532let stops: [UInt32] = [0x8B7BFF, 0x4DD8FF, 0x3DE8C5, 0xFFB341, 0xFF5E7E, 0x8B7BFF]33func mix(_ t: CGFloat) -> CGColor {34    let x = t * CGFloat(stops.count - 1), i = min(Int(x), stops.count - 2), f = x - CGFloat(i)35    func ch(_ h: UInt32, _ shift: UInt32) -> CGFloat { CGFloat((h >> shift) & 0xFF) / 255 }36    let a = stops[i], b = stops[i + 1]37    return CGColor(red: ch(a, 16) + (ch(b, 16) - ch(a, 16)) * f, green: ch(a, 8) + (ch(b, 8) - ch(a, 8)) * f, blue: ch(a, 0) + (ch(b, 0) - ch(a, 0)) * f, alpha: 1)38}39let startAngle = CGFloat.pi * 0.36, sweep = CGFloat.pi * 2 * 0.8640ctx.setLineWidth(width)41ctx.setShadow(offset: .zero, blur: 50, color: color(0x4DD8FF, 0.55))42let segments = 22043for i in 0..<segments {44    let t0 = CGFloat(i) / CGFloat(segments), t1 = CGFloat(i + 1) / CGFloat(segments) + 0.00445    ctx.setStrokeColor(mix(t0))46    ctx.setLineCap(i == 0 || i == segments - 1 ? .round : .butt)47    ctx.addArc(center: center, radius: radius, startAngle: startAngle - sweep * t0, endAngle: startAngle - sweep * t1, clockwise: true)48    ctx.strokePath()49}50// Four-point spark.51ctx.setShadow(offset: .zero, blur: 60, color: color(0x4DD8FF, 0.9))52let r = s * 0.1553ctx.beginPath()54for i in 0..<8 {55    let a = CGFloat(i) * .pi / 4 + .pi / 2, rr = i % 2 == 0 ? r : r * 0.2656    let p = CGPoint(x: center.x + cos(a) * rr, y: center.y + sin(a) * rr)57    if i == 0 { ctx.move(to: p) } else { ctx.addLine(to: p) }58}59ctx.closePath()60ctx.setFillColor(color(0xFFFFFF))61ctx.fillPath()62// Gold satellite dot in the ring gap.63ctx.setShadow(offset: .zero, blur: 40, color: color(0xFFC94D, 0.9))64ctx.setFillColor(color(0xFFC94D))65let d = s * 0.07566ctx.fillEllipse(in: CGRect(x: center.x + radius * 0.74 - d / 2, y: center.y + radius * 0.74 - d / 2, width: d, height: d))6768let image = ctx.makeImage()!69let rep = NSBitmapImageRep(cgImage: image)70try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))71
Files main
Menu

Theme