SPB Git

Repository Public License

icon.swift 15.0 KB 303 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Convert9// File             : Scripts/icon.swift10// Description      : Renders the five icon concepts and the final ORIX Convert11//                    icon with Core Graphics. Run: swift Scripts/icon.swift12//                    design/icon13// Module           : Scripts14// Repository       : https://git.spboucher.ai/orix-convert15// Created          : 2026-11-2116// Last Modified    : 2026-11-2117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : Proprietary, all rights reserved (see license file)83// License File     : LICENSE84// Maintainer       : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import AppKit92import CoreGraphics93import Foundation94import ImageIO95import UniformTypeIdentifiers9697let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "design/icon"98try? FileManager.default.createDirectory(atPath: out, withIntermediateDirectories: true)99let S: CGFloat = 1024100func rgb(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor {101    CGColor(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: a)102}103let space = CGColorSpace(name: CGColorSpace.sRGB)!104let C = CGPoint(x: 512, y: 512)105106// ORIX Convert accent: warm "source" amber → magenta → violet → cool "destination" cyan.107let warm: [UInt32] = [0xFDBA4D, 0xFB7A5C, 0xE8509E]108let cool: [UInt32] = [0x8B5CF6, 0x5B8DF8, 0x22D3EE]109110func canvas(_ draw: (CGContext) -> Void) -> CGImage {111    let ctx = CGContext(data: nil, width: Int(S), height: Int(S), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!112    draw(ctx)113    return ctx.makeImage()!114}115116func save(_ image: CGImage, _ name: String) {117    let url = URL(fileURLWithPath: out + "/" + name)118    let dest = CGImageDestinationCreateWithURL(url as CFURL, UTType.png.identifier as CFString, 1, nil)!119    CGImageDestinationAddImage(dest, image, nil)120    CGImageDestinationFinalize(dest)121}122123/// macOS icon grid: 824 pt rounded square centred on a 1024 canvas, soft drop shadow (same plate as the ORIX family).124let plate = CGRect(x: 100, y: 100, width: 824, height: 824)125func platePath() -> CGPath { NSBezierPath(roundedRect: plate, xRadius: 185.4, yRadius: 185.4).cgPath }126127func background(_ ctx: CGContext, top: UInt32 = 0x1D2145, bottom: UInt32 = 0x070A16, glow: UInt32 = 0x8B5CF6) {128    ctx.saveGState()129    ctx.setShadow(offset: CGSize(width: 0, height: -10), blur: 22, color: CGColor(gray: 0, alpha: 0.35))130    ctx.addPath(platePath()); ctx.setFillColor(rgb(bottom)); ctx.fillPath()131    ctx.restoreGState()132    ctx.saveGState()133    ctx.addPath(platePath()); ctx.clip()134    let g = CGGradient(colorsSpace: space, colors: [rgb(top), rgb(bottom)] as CFArray, locations: [0, 1])!135    ctx.drawLinearGradient(g, start: CGPoint(x: 512, y: 924), end: CGPoint(x: 512, y: 100), options: [])136    let halo = CGGradient(colorsSpace: space, colors: [rgb(glow, 0.30), rgb(glow, 0)] as CFArray, locations: [0, 1])!137    ctx.drawRadialGradient(halo, startCenter: CGPoint(x: 512, y: 540), startRadius: 0, endCenter: CGPoint(x: 512, y: 540), endRadius: 440, options: [])138    ctx.addPath(platePath()); ctx.setStrokeColor(CGColor(gray: 1, alpha: 0.10)); ctx.setLineWidth(3); ctx.strokePath()139    ctx.restoreGState()140}141142func fill(_ ctx: CGContext, _ path: CGPath, colors: [UInt32], from: CGPoint, to: CGPoint, alpha: CGFloat = 1, glow: UInt32? = nil) {143    if let glow {144        ctx.saveGState()145        ctx.setShadow(offset: .zero, blur: 46, color: rgb(glow, 0.55))146        ctx.addPath(path); ctx.setFillColor(rgb(glow, 0.9)); ctx.fillPath()147        ctx.restoreGState()148    }149    ctx.saveGState()150    ctx.addPath(path); ctx.clip()151    let g = CGGradient(colorsSpace: space, colors: colors.map { rgb($0, alpha) } as CFArray, locations: nil)!152    ctx.drawLinearGradient(g, start: from, end: to, options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])153    ctx.restoreGState()154}155156func stroked(_ path: CGPath, _ w: CGFloat, cap: CGLineCap = .round, join: CGLineJoin = .round) -> CGPath {157    path.copy(strokingWithWidth: w, lineCap: cap, lineJoin: join, miterLimit: 4)158}159160/// Superellipse |x/a|^n + |y/b|^n = 1 between two angles (degrees, counter-clockwise from +x).161func superArc(center: CGPoint, radius: CGFloat, n: CGFloat, from: CGFloat, to: CGFloat, steps: Int = 240) -> CGPath {162    let p = CGMutablePath()163    for i in 0...steps {164        let t = (from + (to - from) * CGFloat(i) / CGFloat(steps)) * .pi / 180165        let c = cos(t), s = sin(t)166        let x = center.x + radius * (c < 0 ? -1 : 1) * pow(abs(c), 2 / n)167        let y = center.y + radius * (s < 0 ? -1 : 1) * pow(abs(s), 2 / n)168        if i == 0 { p.move(to: CGPoint(x: x, y: y)) } else { p.addLine(to: CGPoint(x: x, y: y)) }169    }170    return p171}172173func arrowHead(at tip: CGPoint, direction: CGFloat, size: CGFloat) -> CGPath {174    // direction in degrees (counter-clockwise from +x): where the arrow points.175    let d = direction * .pi / 180176    let back = CGPoint(x: tip.x - cos(d) * size, y: tip.y - sin(d) * size)177    let n = CGPoint(x: -sin(d), y: cos(d))178    let p = CGMutablePath()179    p.move(to: tip)180    p.addLine(to: CGPoint(x: back.x + n.x * size * 0.72, y: back.y + n.y * size * 0.72))181    p.addLine(to: CGPoint(x: back.x - n.x * size * 0.72, y: back.y - n.y * size * 0.72))182    p.closeSubpath()183    return p184}185186// Concept 1 (chosen): the ORIX "O" is drawn as one shape becoming another. Its left half is the half-outline of a187// square (n = 6 superellipse: "a format with corners"), its right half a true circle arc ("another format"). The188// two halves chase each other like a conversion cycle and stay a single readable O at 16 px.189func concept1(_ ctx: CGContext) {190    background(ctx)191    let r: CGFloat = 250, w: CGFloat = 86, gap: CGFloat = 16, head: CGFloat = 23192    // Left half: squared (warm), running counter-clockwise from the top, down the left side, to the bottom.193    let left = stroked(superArc(center: C, radius: r, n: 4.6, from: 90 + gap, to: 270 - head), w, cap: .butt)194    // Right half: circular (cool), from the bottom, up the right side, to the top.195    let right = stroked(superArc(center: C, radius: r, n: 2, from: -90 + gap, to: 90 - head), w, cap: .butt)196    fill(ctx, left, colors: warm, from: CGPoint(x: 300, y: 800), to: CGPoint(x: 380, y: 220), glow: 0xFB7A5C)197    fill(ctx, right, colors: cool, from: CGPoint(x: 640, y: 220), to: CGPoint(x: 720, y: 800), glow: 0x5B8DF8)198    // Each half ends in an arrow head that points into the start of the other.199    func tip(_ deg: CGFloat, _ n: CGFloat) -> CGPoint {200        let t = deg * .pi / 180, c = cos(t), s = sin(t)201        return CGPoint(x: C.x + r * (c < 0 ? -1 : 1) * pow(abs(c), 2 / n), y: C.y + r * (s < 0 ? -1 : 1) * pow(abs(s), 2 / n))202    }203    func headPath(_ deg: CGFloat, _ n: CGFloat) -> CGPath {204        let e = tip(deg, n), f = tip(deg + 1.5, n)205        let len = hypot(f.x - e.x, f.y - e.y)206        let d = CGPoint(x: (f.x - e.x) / len, y: (f.y - e.y) / len)207        let size: CGFloat = 104208        return arrowHead(at: CGPoint(x: e.x + d.x * (size - 6), y: e.y + d.y * (size - 6)), direction: atan2(d.y, d.x) * 180 / .pi, size: size)209    }210    let a1 = headPath(270 - 23, 4.6), a2 = headPath(90 - 23, 2)211    fill(ctx, a1, colors: [0xE8509E, 0xE8509E], from: .zero, to: CGPoint(x: 1, y: 1), glow: 0xE8509E)212    fill(ctx, a2, colors: [0x22D3EE, 0x22D3EE], from: .zero, to: CGPoint(x: 1, y: 1), glow: 0x22D3EE)213}214215// Concept 2: a square morphing into a circle through three intermediate outlines.216func concept2(_ ctx: CGContext) {217    background(ctx)218    let ns: [CGFloat] = [12, 5, 3.2, 2.4, 2]219    for (i, n) in ns.enumerated() {220        let t = CGFloat(i) / CGFloat(ns.count - 1)221        let c = CGPoint(x: 330 + t * 364, y: 512)222        let path = stroked(superArc(center: c, radius: 150 + t * 20, n: n, from: 0, to: 360), 22, cap: .butt)223        let all = warm + cool224        let col = all[min(all.count - 1, Int(t * CGFloat(all.count - 1) + 0.5))]225        fill(ctx, path, colors: [col, col], from: .zero, to: CGPoint(x: 1, y: 1), alpha: 0.35 + 0.65 * (i == 0 || i == ns.count - 1 ? 1 : 0.5))226    }227}228229// Concept 3: two opposing arrows inside a document outline.230func concept3(_ ctx: CGContext) {231    background(ctx)232    let doc = CGMutablePath()233    doc.addRoundedRect(in: CGRect(x: 312, y: 250, width: 400, height: 524), cornerWidth: 54, cornerHeight: 54)234    ctx.addPath(stroked(doc, 26)); ctx.setFillColor(CGColor(gray: 1, alpha: 0.16)); ctx.fillPath()235    func bar(_ y: CGFloat, _ right: Bool, _ colors: [UInt32]) {236        let p = CGMutablePath(); p.move(to: CGPoint(x: 380, y: y)); p.addLine(to: CGPoint(x: 644, y: y))237        fill(ctx, stroked(p, 56), colors: colors, from: CGPoint(x: 380, y: y), to: CGPoint(x: 644, y: y))238        let tip = CGPoint(x: right ? 700 : 324, y: y)239        fill(ctx, arrowHead(at: tip, direction: right ? 0 : 180, size: 96), colors: [right ? colors[2] : colors[0], right ? colors[2] : colors[0]], from: .zero, to: CGPoint(x: 1, y: 1))240    }241    bar(596, true, warm); bar(428, false, cool)242}243244// Concept 4: a precision dial. Tick ring, a square at the centre resolving into a circle.245func concept4(_ ctx: CGContext) {246    background(ctx)247    for i in 0..<60 {248        let a = CGFloat(i) * 6 * .pi / 180249        let long = i % 5 == 0250        let r0: CGFloat = long ? 286 : 300, r1: CGFloat = 326251        let p = CGMutablePath()252        p.move(to: CGPoint(x: 512 + cos(a) * r0, y: 512 + sin(a) * r0)); p.addLine(to: CGPoint(x: 512 + cos(a) * r1, y: 512 + sin(a) * r1))253        ctx.addPath(stroked(p, long ? 10 : 5)); ctx.setFillColor(CGColor(gray: 1, alpha: long ? 0.55 : 0.22)); ctx.fillPath()254    }255    fill(ctx, stroked(superArc(center: C, radius: 200, n: 2, from: -60, to: 200), 44), colors: cool, from: CGPoint(x: 312, y: 312), to: CGPoint(x: 712, y: 712))256    let sq = CGMutablePath(); sq.addRoundedRect(in: CGRect(x: 432, y: 432, width: 160, height: 160), cornerWidth: 30, cornerHeight: 30)257    fill(ctx, sq, colors: warm, from: CGPoint(x: 432, y: 592), to: CGPoint(x: 592, y: 432))258}259260// Concept 5: an O monogram cut diagonally, the two halves offset along the cut like a slide.261func concept5(_ ctx: CGContext) {262    background(ctx)263    let ring = stroked(superArc(center: C, radius: 250, n: 2, from: 0, to: 360), 96, cap: .butt)264    func half(_ dx: CGFloat, _ cols: [UInt32], _ sign: CGFloat) {265        ctx.saveGState()266        let clip = CGMutablePath()267        let edge: CGFloat = sign > 0 ? 0 : 1024268        clip.move(to: CGPoint(x: 512 - 388 * sign, y: 0)); clip.addLine(to: CGPoint(x: 512 + 412 * sign, y: 1024))269        clip.addLine(to: CGPoint(x: edge, y: 1024)); clip.addLine(to: CGPoint(x: edge, y: 0)); clip.closeSubpath()270        ctx.addPath(clip); ctx.clip()271        ctx.translateBy(x: dx * 0.6, y: -dx * 1.4 * sign)272        fill(ctx, ring, colors: cols, from: CGPoint(x: 262, y: 762), to: CGPoint(x: 762, y: 262))273        ctx.restoreGState()274    }275    half(-26, warm, 1)276    half(26, cool, -1)277}278279typealias Draw = (CGContext) -> Void280let concepts: [(String, Draw)] = [281    ("concept-1-shape-shifting-o", concept1), ("concept-2-square-to-circle", concept2), ("concept-3-document-arrows", concept3),282    ("concept-4-precision-dial", concept4), ("concept-5-sliced-monogram", concept5),283]284for (name, draw) in concepts { save(canvas(draw), name + ".png") }285let final = canvas(concept1)286save(final, "ORIXConvert-1024.png")287288// Small-size check sheet: the chosen icon at 16, 32, 64, 128, 256 px on light and dark.289func sheet() -> CGImage {290    let sizes: [CGFloat] = [16, 32, 64, 128, 256]291    let w = 760, h = 620292    let ctx = CGContext(data: nil, width: w, height: h, bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!293    ctx.interpolationQuality = .high294    for (row, bg) in [UInt32(0xF4F5FA), 0x0A0D18].enumerated() {295        ctx.setFillColor(rgb(bg)); ctx.fill(CGRect(x: 0, y: row * 310, width: w, height: 310))296        var x: CGFloat = 30297        for s in sizes { ctx.draw(final, in: CGRect(x: x, y: CGFloat(row * 310) + 155 - s / 2, width: s, height: s)); x += s + 40 }298    }299    return ctx.makeImage()!300}301save(sheet(), "small-sizes.png")302print("icons written to \(out)")303
Files main
Menu

Theme