SPB Git

Repository Public MIT

make-icon.swift 8.2 KB 163 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Astra9// File             : Scripts/make-icon.swift10// Module           : Scripts11// Repository       : https://git.spboucher.ai/orix-astra12// Created          : 2026-11-2113// Last Modified    : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : Proprietary, all rights reserved (see license file)80// License File     : LICENSE81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788// Renders the ORIX Astra app icon (1024 px, opaque) with Core Graphics. Usage: swift Scripts/make-icon.swift <out.png> [dark|tinted]89import AppKit90import CoreGraphics9192let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "icon.png"93let variant = CommandLine.arguments.count > 2 ? CommandLine.arguments[2] : "default"94let S: CGFloat = 102495let cs = CGColorSpace(name: CGColorSpace.sRGB)!96let ctx = CGContext(data: nil, width: Int(S), height: Int(S), bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!97func rgb(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor { CGColor(colorSpace: cs, components: [CGFloat(hex >> 16 & 0xFF) / 255, CGFloat(hex >> 8 & 0xFF) / 255, CGFloat(hex & 0xFF) / 255, a])! }98let tinted = variant == "tinted"99100// background: obsidian with two soft nebula washes101ctx.setFillColor(rgb(tinted ? 0x000000 : 0x06060B)); ctx.fill(CGRect(x: 0, y: 0, width: S, height: S))102if !tinted {103    func wash(_ c: UInt32, _ a: CGFloat, _ p: CGPoint, _ r: CGFloat) {104        let g = CGGradient(colorsSpace: cs, colors: [rgb(c, a), rgb(c, 0)] as CFArray, locations: [0, 1])!105        ctx.drawRadialGradient(g, startCenter: p, startRadius: 0, endCenter: p, endRadius: r, options: [])106    }107    wash(0x6B3BEA, 0.55, CGPoint(x: 180, y: 900), 760)108    wash(0x1FA8C9, 0.34, CGPoint(x: 940, y: 200), 640)109    wash(0x4338CA, 0.30, CGPoint(x: 512, y: 512), 520)110}111// stars112var seed: UInt64 = 42113func rnd() -> CGFloat { seed = seed &* 6364136223846793005 &+ 1442695040888963407; return CGFloat((seed >> 33) % 100000) / 100000 }114for _ in 0..<90 {115    let x = rnd() * S, y = rnd() * S, m = rnd(), r = 1.2 + m * m * 3.4116    ctx.setFillColor(rgb(0xFFFFFF, tinted ? 0.10 + m * 0.2 : 0.12 + m * 0.5)); ctx.fillEllipse(in: CGRect(x: x - r, y: y - r, width: r * 2, height: r * 2))117}118let c = CGPoint(x: S / 2, y: S / 2)119let grad = CGGradient(colorsSpace: cs, colors: (tinted ? [rgb(0xFFFFFF), rgb(0xBBBBBB)] : [rgb(0xB79BFF), rgb(0x7C83FF), rgb(0x3FD8F2)]) as CFArray, locations: tinted ? [0, 1] : [0, 0.5, 1])!120func strokeGradient(_ path: CGPath, width: CGFloat, alpha: CGFloat) {121    ctx.saveGState(); ctx.setAlpha(alpha)122    ctx.addPath(path); ctx.setLineWidth(width); ctx.setLineCap(.round); ctx.replacePathWithStrokedPath(); ctx.clip()123    ctx.drawLinearGradient(grad, start: CGPoint(x: 160, y: 880), end: CGPoint(x: 880, y: 160), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])124    ctx.restoreGState()125}126func orbit(tilt: CGFloat, flatten: CGFloat, size: CGFloat) -> CGPath {127    var t = CGAffineTransform(translationX: c.x, y: c.y).rotated(by: tilt * .pi / 180)128    return CGPath(ellipseIn: CGRect(x: -size / 2, y: -size * flatten / 2, width: size, height: size * flatten), transform: &t)129}130strokeGradient(orbit(tilt: 28, flatten: 0.42, size: 760), width: 30, alpha: 0.95)131strokeGradient(orbit(tilt: -34, flatten: 0.36, size: 760), width: 22, alpha: 0.6)132// four-point star133let R: CGFloat = 196, inner = R * 0.22134let star = CGMutablePath()135for i in 0..<4 {136    let a = CGFloat(i) * .pi / 2 + .pi / 2137    let tip = CGPoint(x: c.x + cos(a) * R, y: c.y + sin(a) * R)138    if i == 0 { star.move(to: tip) }139    let next = CGPoint(x: c.x + cos(a + .pi / 2) * R, y: c.y + sin(a + .pi / 2) * R)140    let valley = CGPoint(x: c.x + cos(a + .pi / 4) * inner, y: c.y + sin(a + .pi / 4) * inner)141    star.addQuadCurve(to: next, control: valley)142}143star.closeSubpath()144if !tinted { // soft glow behind the star145    let g = CGGradient(colorsSpace: cs, colors: [rgb(0x9B7BFF, 0.55), rgb(0x9B7BFF, 0)] as CFArray, locations: [0, 1])!146    ctx.drawRadialGradient(g, startCenter: c, startRadius: 0, endCenter: c, endRadius: 330, options: [])147}148ctx.saveGState(); ctx.addPath(star); ctx.clip()149let sg = CGGradient(colorsSpace: cs, colors: [rgb(0xFFFFFF), rgb(tinted ? 0xDDDDDD : 0xD9CCFF)] as CFArray, locations: [0, 1])!150ctx.drawLinearGradient(sg, start: CGPoint(x: c.x, y: c.y + R), end: CGPoint(x: c.x, y: c.y - R), options: [])151ctx.restoreGState()152// the satellite on the first orbit153let sa: CGFloat = 28 * .pi / 180154let sp = CGPoint(x: c.x + cos(sa) * 380 * cos(0.55) - sin(sa) * 380 * 0.42 * sin(0.55), y: c.y + sin(sa) * 380 * cos(0.55) + cos(sa) * 380 * 0.42 * sin(0.55))155ctx.setFillColor(rgb(tinted ? 0xFFFFFF : 0x7BE8FA)); ctx.fillEllipse(in: CGRect(x: sp.x - 30, y: sp.y - 30, width: 60, height: 60))156157let image = ctx.makeImage()!158// App Store icons must be opaque: flatten to RGB without alpha159let flat = CGContext(data: nil, width: Int(S), height: Int(S), bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)!160flat.draw(image, in: CGRect(x: 0, y: 0, width: S, height: S))161let rep = NSBitmapImageRep(cgImage: flat.makeImage()!)162try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: out))163
Files main
Menu

Theme