SPB Git

Repository Public License

icon.swift 8.2 KB 141 lines swift

1// ORIX Clean — Scripts/icon.swift2// Description: Renders the five icon concepts and the final ORIX Clean icon with Core Graphics (run: swift Scripts/icon.swift <outdir>).3// Author: Simon-Pierre Boucher — contact@spboucher.ai4import AppKit5import CoreGraphics6import Foundation7import ImageIO8import UniformTypeIdentifiers910let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "design/icon"11let S: CGFloat = 102412func rgb(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor {13    CGColor(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: a)14}15let space = CGColorSpace(name: CGColorSpace.sRGB)!1617func canvas(_ draw: (CGContext) -> Void) -> CGImage {18    let ctx = CGContext(data: nil, width: Int(S), height: Int(S), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!19    draw(ctx)20    return ctx.makeImage()!21}2223func save(_ image: CGImage, _ name: String) {24    let url = URL(fileURLWithPath: out + "/" + name)25    let dest = CGImageDestinationCreateWithURL(url as CFURL, UTType.png.identifier as CFString, 1, nil)!26    CGImageDestinationAddImage(dest, image, nil)27    CGImageDestinationFinalize(dest)28}2930/// macOS icon grid: 824 pt rounded square centred on a 1024 canvas, continuous corners, soft drop shadow.31let plate = CGRect(x: 100, y: 100, width: 824, height: 824)32func platePath() -> CGPath { NSBezierPath(roundedRect: plate, xRadius: 185.4, yRadius: 185.4).cgPath }3334func background(_ ctx: CGContext, top: UInt32 = 0x1B2340, bottom: UInt32 = 0x070A16) {35    ctx.saveGState()36    ctx.setShadow(offset: CGSize(width: 0, height: -10), blur: 22, color: CGColor(gray: 0, alpha: 0.35))37    ctx.addPath(platePath()); ctx.setFillColor(rgb(bottom)); ctx.fillPath()38    ctx.restoreGState()39    ctx.saveGState()40    ctx.addPath(platePath()); ctx.clip()41    let g = CGGradient(colorsSpace: space, colors: [rgb(top), rgb(bottom)] as CFArray, locations: [0, 1])!42    ctx.drawLinearGradient(g, start: CGPoint(x: 512, y: 924), end: CGPoint(x: 512, y: 100), options: [])43    // Soft glow behind the mark.44    let glow = CGGradient(colorsSpace: space, colors: [rgb(0x2DD4BF, 0.28), rgb(0x2DD4BF, 0)] as CFArray, locations: [0, 1])!45    ctx.drawRadialGradient(glow, startCenter: CGPoint(x: 512, y: 540), startRadius: 0, endCenter: CGPoint(x: 512, y: 540), endRadius: 430, options: [])46    // Top inner highlight.47    ctx.addPath(platePath()); ctx.setStrokeColor(CGColor(gray: 1, alpha: 0.10)); ctx.setLineWidth(3); ctx.strokePath()48    ctx.restoreGState()49}5051func arc(_ ctx: CGContext, r: CGFloat, w: CGFloat, from: CGFloat, to: CGFloat, colors: [UInt32], cap: CGLineCap = .round, alpha: CGFloat = 1) {52    // Angles in degrees, clockwise from 12 o'clock.53    let c = CGPoint(x: 512, y: 512)54    let a0 = (90 - from) * .pi / 180, a1 = (90 - to) * .pi / 18055    let path = CGMutablePath()56    path.addArc(center: c, radius: r, startAngle: a0, endAngle: a1, clockwise: true)57    let stroked = path.copy(strokingWithWidth: w, lineCap: cap, lineJoin: .round, miterLimit: 1)58    ctx.saveGState()59    ctx.addPath(stroked); ctx.clip()60    let g = CGGradient(colorsSpace: space, colors: colors.map { rgb($0, alpha) } as CFArray, locations: nil)!61    ctx.drawLinearGradient(g, start: CGPoint(x: 512 - r, y: 512 + r), end: CGPoint(x: 512 + r, y: 512 - r), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])62    ctx.restoreGState()63}6465func sparkle(_ ctx: CGContext, at p: CGPoint, size: CGFloat, color: CGColor) {66    let path = CGMutablePath()67    let k = size * 0.2268    path.move(to: CGPoint(x: p.x, y: p.y + size))69    path.addQuadCurve(to: CGPoint(x: p.x + size, y: p.y), control: CGPoint(x: p.x + k, y: p.y + k))70    path.addQuadCurve(to: CGPoint(x: p.x, y: p.y - size), control: CGPoint(x: p.x + k, y: p.y - k))71    path.addQuadCurve(to: CGPoint(x: p.x - size, y: p.y), control: CGPoint(x: p.x - k, y: p.y - k))72    path.addQuadCurve(to: CGPoint(x: p.x, y: p.y + size), control: CGPoint(x: p.x - k, y: p.y + k))73    ctx.addPath(path); ctx.setFillColor(color); ctx.fillPath()74}7576// Concept 1 (chosen): the ORIX "O" as a storage ring. Three quarters hold data as segments of decreasing weight;77// the last quarter has been swept clean and is only a faint track, with a single spark where the sweep ended.78func concept1(_ ctx: CGContext) {79    background(ctx)80    arc(ctx, r: 250, w: 20, from: 0, to: 360, colors: [0xFFFFFF, 0xFFFFFF], cap: .butt, alpha: 0.07)81    arc(ctx, r: 250, w: 118, from: 14, to: 112, colors: [0x5EEAD4, 0x14B8A6])82    arc(ctx, r: 250, w: 118, from: 142, to: 206, colors: [0x22D3EE, 0x0891B2])83    arc(ctx, r: 250, w: 118, from: 236, to: 268, colors: [0x818CF8, 0x5B5BF0])84    // The swept quarter: a thin bright trail fading out.85    for i in 0 ..< 10 {86        let a = 290 + CGFloat(i) * 6.287        arc(ctx, r: 250, w: 20, from: a, to: a + 3.4, colors: [0xCCFBF1, 0xCCFBF1], cap: .round, alpha: 0.16 + CGFloat(i) * 0.075)88    }89    let tip = CGFloat(-6.0 * Double.pi / 180.0)90    sparkle(ctx, at: CGPoint(x: 512 + 250 * sin(tip), y: 512 + 250 * cos(tip)), size: 62, color: rgb(0xFFFFFF))91    sparkle(ctx, at: CGPoint(x: 512, y: 512), size: 30, color: rgb(0x5EEAD4, 0.9))92}9394// Concept 2: geometric treemap.95func concept2(_ ctx: CGContext) {96    background(ctx)97    let rects: [(CGRect, UInt32)] = [(CGRect(x: 250, y: 430, width: 300, height: 344), 0x14B8A6), (CGRect(x: 574, y: 560, width: 200, height: 214), 0x0891B2),98                                     (CGRect(x: 574, y: 430, width: 200, height: 106), 0x5B5BF0), (CGRect(x: 250, y: 250, width: 170, height: 156), 0x6366F1),99                                     (CGRect(x: 444, y: 250, width: 150, height: 156), 0x22D3EE)]100    for (r, c) in rects { ctx.addPath(CGPath(roundedRect: r, cornerWidth: 26, cornerHeight: 26, transform: nil)); ctx.setFillColor(rgb(c)); ctx.fillPath() }101    ctx.addPath(CGPath(roundedRect: CGRect(x: 618, y: 250, width: 156, height: 156), cornerWidth: 26, cornerHeight: 26, transform: nil))102    ctx.setStrokeColor(rgb(0xCCFBF1, 0.5)); ctx.setLineWidth(8); ctx.setLineDash(phase: 0, lengths: [22, 16]); ctx.strokePath()103    sparkle(ctx, at: CGPoint(x: 696, y: 328), size: 46, color: rgb(0xFFFFFF))104}105106// Concept 3: minimal disk with a cleared sector.107func concept3(_ ctx: CGContext) {108    background(ctx)109    ctx.setFillColor(rgb(0x0891B2)); ctx.fillEllipse(in: CGRect(x: 232, y: 232, width: 560, height: 560))110    ctx.move(to: CGPoint(x: 512, y: 512)); ctx.addArc(center: CGPoint(x: 512, y: 512), radius: 280, startAngle: .pi / 2, endAngle: .pi * 0.05, clockwise: true)111    ctx.closePath(); ctx.setFillColor(rgb(0x0B1020)); ctx.fillPath()112    ctx.setFillColor(rgb(0x0B1020)); ctx.fillEllipse(in: CGRect(x: 442, y: 442, width: 140, height: 140))113    ctx.setStrokeColor(rgb(0x5EEAD4)); ctx.setLineWidth(18); ctx.strokeEllipse(in: CGRect(x: 232, y: 232, width: 560, height: 560))114}115116// Concept 4: layered storage sheets.117func concept4(_ ctx: CGContext) {118    background(ctx)119    for (i, c) in [0x5B5BF0, 0x0891B2, 0x14B8A6].enumerated() {120        let y = 300 + CGFloat(i) * 130121        let p = CGMutablePath()122        p.move(to: CGPoint(x: 512, y: y + 150)); p.addLine(to: CGPoint(x: 800, y: y + 40)); p.addLine(to: CGPoint(x: 512, y: y - 70)); p.addLine(to: CGPoint(x: 224, y: y + 40)); p.closeSubpath()123        ctx.addPath(p); ctx.setFillColor(rgb(UInt32(c), i == 2 ? 1 : 0.75)); ctx.fillPath()124    }125    sparkle(ctx, at: CGPoint(x: 512, y: 600), size: 50, color: rgb(0xFFFFFF))126}127128// Concept 5: ORIX monogram ring with a clean notch.129func concept5(_ ctx: CGContext) {130    background(ctx)131    arc(ctx, r: 240, w: 130, from: 40, to: 360, colors: [0x5EEAD4, 0x5B5BF0], cap: .butt)132    ctx.setFillColor(rgb(0xFFFFFF)); ctx.fillEllipse(in: CGRect(x: 592, y: 700, width: 70, height: 70))133}134135try? FileManager.default.createDirectory(atPath: out, withIntermediateDirectories: true)136let concepts: [(String, (CGContext) -> Void)] = [("concept-1-storage-ring-sweep", concept1), ("concept-2-treemap", concept2), ("concept-3-disk-sector", concept3),137                                                 ("concept-4-layers", concept4), ("concept-5-monogram-notch", concept5)]138for (name, draw) in concepts { save(canvas(draw), name + ".png") }139save(canvas(concept1), "ORIXClean-1024.png")140print("icons written to \(out)")141
Files main
Menu

Theme