Repository Public
1// ORIX DJ2// File: Scripts/icon.swift3// Description: Renders the five icon concepts, the concept sheet and the final ORIX DJ icon with Core Graphics, then4// writes the macOS icon set. Run: swift Scripts/icon.swift5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import AppKit9import CoreGraphics10import Foundation11import ImageIO12import UniformTypeIdentifiers1314let S: CGFloat = 102415let space = CGColorSpace(name: CGColorSpace.sRGB)!16func rgb(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor {17 CGColor(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: a)18}1920func canvas(_ size: CGFloat = S, _ draw: (CGContext) -> Void) -> CGImage {21 let ctx = CGContext(data: nil, width: Int(size), height: Int(size), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!22 ctx.scaleBy(x: size / S, y: size / S)23 draw(ctx)24 return ctx.makeImage()!25}2627func save(_ image: CGImage, _ path: String) {28 try? FileManager.default.createDirectory(atPath: (path as NSString).deletingLastPathComponent, withIntermediateDirectories: true)29 let dest = CGImageDestinationCreateWithURL(URL(fileURLWithPath: path) as CFURL, UTType.png.identifier as CFString, 1, nil)!30 CGImageDestinationAddImage(dest, image, nil)31 CGImageDestinationFinalize(dest)32}3334// macOS icon grid: 824 pt rounded square centred on a 1024 canvas, soft drop shadow.35let plate = CGRect(x: 100, y: 100, width: 824, height: 824)36let centre = CGPoint(x: 512, y: 512)37func platePath() -> CGPath { CGPath(roundedRect: plate, cornerWidth: 185.4, cornerHeight: 185.4, transform: nil) }3839func background(_ ctx: CGContext, top: UInt32 = 0x1A2142, bottom: UInt32 = 0x070A16) {40 ctx.saveGState()41 ctx.setShadow(offset: CGSize(width: 0, height: -10), blur: 22, color: CGColor(gray: 0, alpha: 0.35))42 ctx.addPath(platePath()); ctx.setFillColor(rgb(bottom)); ctx.fillPath()43 ctx.restoreGState()44 ctx.saveGState()45 ctx.addPath(platePath()); ctx.clip()46 let g = CGGradient(colorsSpace: space, colors: [rgb(top), rgb(bottom)] as CFArray, locations: [0, 1])!47 ctx.drawLinearGradient(g, start: CGPoint(x: 512, y: 924), end: CGPoint(x: 512, y: 100), options: [])48 // Faint glow behind the mark.49 let glow = CGGradient(colorsSpace: space, colors: [rgb(0x7C5CFC, 0.28), rgb(0x7C5CFC, 0)] as CFArray, locations: [0, 1])!50 ctx.drawRadialGradient(glow, startCenter: centre, startRadius: 0, endCenter: centre, endRadius: 430, options: [])51 ctx.restoreGState()52 // Inner highlight on the edge.53 ctx.saveGState()54 ctx.addPath(platePath()); ctx.setStrokeColor(rgb(0xFFFFFF, 0.07)); ctx.setLineWidth(3); ctx.strokePath()55 ctx.restoreGState()56}5758/// Colour along the ORIX DJ gradient: violet at the top-left, cyan at the bottom-right.59func gradientColor(_ t: CGFloat) -> CGColor {60 let a: (CGFloat, CGFloat, CGFloat) = (0x9B / 255.0, 0x7C / 255.0, 0xFF / 255.0), b: (CGFloat, CGFloat, CGFloat) = (0x22 / 255.0, 0xD3 / 255.0, 0xEE / 255.0)61 let x = min(1, max(0, t))62 return CGColor(srgbRed: a.0 + (b.0 - a.0) * x, green: a.1 + (b.1 - a.1) * x, blue: a.2 + (b.2 - a.2) * x, alpha: 1)63}6465func ring(_ ctx: CGContext, radius: CGFloat, width: CGFloat, color: CGColor) {66 ctx.setStrokeColor(color); ctx.setLineWidth(width)67 ctx.strokeEllipse(in: CGRect(x: centre.x - radius, y: centre.y - radius, width: radius * 2, height: radius * 2))68}6970/// Deterministic "audio" envelope around the circle: two beats per turn with detail, so the mark reads as a waveform.71func envelope(_ angle: CGFloat) -> CGFloat {72 let a = Double(angle)73 let v = 0.55 + 0.25 * sin(a * 2 + 0.6) + 0.14 * sin(a * 5 + 1.9) + 0.09 * sin(a * 11 + 0.3) + 0.06 * sin(a * 17 + 2.4)74 return CGFloat(min(1, max(0.16, v)))75}7677// Concept 1: the ORIX O as a turntable (platter, grooves, label, tonearm).78func concept1(_ ctx: CGContext) {79 background(ctx)80 ring(ctx, radius: 292, width: 84, color: rgb(0x9B7CFF))81 for r in stride(from: CGFloat(120), through: 228, by: 18) { ring(ctx, radius: r, width: 3, color: rgb(0xFFFFFF, 0.14)) }82 ctx.setFillColor(rgb(0x22D3EE)); ctx.fillEllipse(in: CGRect(x: 512 - 78, y: 512 - 78, width: 156, height: 156))83 ctx.setFillColor(rgb(0x070A16)); ctx.fillEllipse(in: CGRect(x: 512 - 20, y: 512 - 20, width: 40, height: 40))84 ctx.setStrokeColor(rgb(0xF2F4FB)); ctx.setLineWidth(22); ctx.setLineCap(.round)85 ctx.move(to: CGPoint(x: 790, y: 800)); ctx.addLine(to: CGPoint(x: 640, y: 600)); ctx.strokePath()86}8788// Concept 2: an O made of radial waveform bars.89func radialWave(_ ctx: CGContext, inner: CGFloat, maxLength: CGFloat, bars: Int, barWidth: CGFloat, gap: ClosedRange<CGFloat>? = nil) {90 ctx.setLineCap(.round)91 for i in 0 ..< bars {92 let angle = CGFloat(i) / CGFloat(bars) * 2 * .pi93 // Angle measured clockwise from the top.94 let deg = angle * 180 / .pi95 if let gap, gap.contains(deg) { continue }96 let len = maxLength * envelope(angle)97 let dx = sin(angle), dy = cos(angle)98 let mid = inner + maxLength / 299 let p0 = CGPoint(x: centre.x + dx * (mid - len / 2), y: centre.y + dy * (mid - len / 2))100 let p1 = CGPoint(x: centre.x + dx * (mid + len / 2), y: centre.y + dy * (mid + len / 2))101 // Gradient along the diagonal.102 let t = ((p0.x - 220) + (804 - p0.y)) / 1168103 ctx.setStrokeColor(gradientColor(t)); ctx.setLineWidth(barWidth)104 ctx.move(to: p0); ctx.addLine(to: p1); ctx.strokePath()105 }106}107108func concept2(_ ctx: CGContext) {109 background(ctx)110 radialWave(ctx, inner: 170, maxLength: 190, bars: 56, barWidth: 17)111}112113// Concept 3: dual-deck geometry, two interlocked rings and a crossfader line.114func concept3(_ ctx: CGContext) {115 background(ctx)116 ctx.setLineWidth(58)117 ctx.setStrokeColor(rgb(0x22D3EE)); ctx.strokeEllipse(in: CGRect(x: 512 - 150 - 190, y: 540 - 190, width: 380, height: 380))118 ctx.setStrokeColor(rgb(0xFF9F43)); ctx.strokeEllipse(in: CGRect(x: 512 + 150 - 190, y: 540 - 190, width: 380, height: 380))119 ctx.setStrokeColor(rgb(0xF2F4FB, 0.9)); ctx.setLineWidth(18); ctx.setLineCap(.round)120 ctx.move(to: CGPoint(x: 300, y: 250)); ctx.addLine(to: CGPoint(x: 724, y: 250)); ctx.strokePath()121 ctx.setFillColor(rgb(0xF2F4FB)); ctx.fill(CGRect(x: 480, y: 222, width: 64, height: 56).insetBy(dx: 0, dy: 0))122}123124// Concept 4: circular musical pulse, concentric arcs opening outwards.125func concept4(_ ctx: CGContext) {126 background(ctx)127 ctx.setLineCap(.round)128 for (i, r) in [110, 190, 270, 350].enumerated() {129 ctx.setStrokeColor(gradientColor(CGFloat(i) / 3)); ctx.setLineWidth(46 - CGFloat(i) * 6)130 let sweep = CGFloat.pi * (1.7 - CGFloat(i) * 0.28)131 ctx.addArc(center: centre, radius: CGFloat(r), startAngle: .pi / 2 - sweep / 2, endAngle: .pi / 2 + sweep / 2, clockwise: false); ctx.strokePath()132 }133 ctx.setFillColor(rgb(0xF2F4FB)); ctx.fillEllipse(in: CGRect(x: 512 - 34, y: 512 - 34, width: 68, height: 68))134}135136// Concept 5: minimal mixer emblem, an O holding three faders.137func concept5(_ ctx: CGContext) {138 background(ctx)139 ring(ctx, radius: 300, width: 64, color: rgb(0x9B7CFF))140 ctx.setLineCap(.round)141 for (i, y) in [CGFloat(600), 470, 560].enumerated() {142 let x = 512 + CGFloat(i - 1) * 120143 ctx.setStrokeColor(rgb(0xFFFFFF, 0.22)); ctx.setLineWidth(14)144 ctx.move(to: CGPoint(x: x, y: 370)); ctx.addLine(to: CGPoint(x: x, y: 654)); ctx.strokePath()145 ctx.setFillColor(rgb(0x22D3EE)); ctx.fill(CGRect(x: x - 40, y: y - 22, width: 80, height: 44))146 }147}148149// Final: the ORIX O drawn as a radial waveform, with a playhead entering from the top and a centre spindle.150// It keeps the family's ring monogram, reads as a record and as sound, and stays a clear ring at 16 px.151func finalIcon(_ ctx: CGContext) {152 background(ctx)153 // A solid inner ring keeps the O legible when the bars blur together at small sizes.154 ctx.saveGState()155 let ringRect = CGRect(x: 512 - 186, y: 512 - 186, width: 372, height: 372)156 ctx.setLineWidth(40)157 ctx.addEllipse(in: ringRect); ctx.replacePathWithStrokedPath(); ctx.clip()158 let g = CGGradient(colorsSpace: space, colors: [gradientColor(0), gradientColor(1)] as CFArray, locations: [0, 1])!159 ctx.drawLinearGradient(g, start: CGPoint(x: 300, y: 760), end: CGPoint(x: 724, y: 264), options: [])160 ctx.restoreGState()161 // Radial waveform, with a gap at the top for the playhead.162 radialWave(ctx, inner: 226, maxLength: 150, bars: 60, barWidth: 15, gap: nil)163 // Mask the gap, then draw the playhead through it.164 ctx.saveGState()165 ctx.addPath(platePath()); ctx.clip()166 ctx.setBlendMode(.clear)167 ctx.fill(CGRect(x: 512 - 34, y: 512 + 150, width: 68, height: 300))168 ctx.restoreGState()169 ctx.saveGState()170 ctx.addPath(platePath()); ctx.clip()171 let top = CGGradient(colorsSpace: space, colors: [rgb(0x1A2142), rgb(0x141A36)] as CFArray, locations: [0, 1])!172 ctx.clip(to: CGRect(x: 512 - 34, y: 512 + 150, width: 68, height: 300))173 ctx.drawLinearGradient(top, start: CGPoint(x: 512, y: 924), end: CGPoint(x: 512, y: 600), options: [])174 ctx.restoreGState()175 ctx.setStrokeColor(rgb(0xF2F4FB)); ctx.setLineWidth(20); ctx.setLineCap(.round)176 ctx.move(to: CGPoint(x: 512, y: 512 + 150)); ctx.addLine(to: CGPoint(x: 512, y: 512 + 392)); ctx.strokePath()177 // Spindle.178 ctx.setFillColor(rgb(0xF2F4FB)); ctx.fillEllipse(in: CGRect(x: 512 - 30, y: 512 - 30, width: 60, height: 60))179}180181let out = "design/icon"182let concepts: [(String, (CGContext) -> Void)] = [183 ("concept-1-turntable-o", concept1), ("concept-2-waveform-monogram", concept2), ("concept-3-dual-deck", concept3),184 ("concept-4-circular-pulse", concept4), ("concept-5-mixer-emblem", concept5),185]186var rendered: [CGImage] = []187for (name, draw) in concepts { let image = canvas(S, draw); rendered.append(image); save(image, "\(out)/\(name).png") }188let master = canvas(S, finalIcon)189save(master, "\(out)/orix-dj-icon-1024.png")190save(master, "docs/assets/icon.png")191192// Concept sheet: the five concepts and the final, at 16 / 32 / 128 px underneath to judge small sizes.193let sheet = canvas(S) { _ in }194let sheetCtx = CGContext(data: nil, width: 2160, height: 620, bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!195_ = sheet196sheetCtx.setFillColor(rgb(0x0A0D18)); sheetCtx.fill(CGRect(x: 0, y: 0, width: 2160, height: 620))197for (i, image) in (rendered + [master]).enumerated() {198 let x = CGFloat(20 + i * 356)199 sheetCtx.draw(image, in: CGRect(x: x, y: 250, width: 340, height: 340))200 sheetCtx.draw(image, in: CGRect(x: x + 20, y: 90, width: 128, height: 128))201 sheetCtx.draw(image, in: CGRect(x: x + 170, y: 138, width: 32, height: 32))202 sheetCtx.draw(image, in: CGRect(x: x + 220, y: 146, width: 16, height: 16))203}204save(sheetCtx.makeImage()!, "\(out)/concepts-sheet.png")205save(sheetCtx.makeImage()!, "docs/assets/icon-concepts.png")206207// macOS icon set.208let setDir = "App/Resources/Assets.xcassets/AppIcon.appiconset"209var entries: [String] = []210for (points, scale) in [(16, 1), (16, 2), (32, 1), (32, 2), (128, 1), (128, 2), (256, 1), (256, 2), (512, 1), (512, 2)] {211 let pixels = points * scale212 let file = "icon_\(points)x\(points)\(scale == 2 ? "@2x" : "").png"213 save(canvas(CGFloat(pixels), finalIcon), "\(setDir)/\(file)")214 entries.append(" { \"filename\" : \"\(file)\", \"idiom\" : \"mac\", \"scale\" : \"\(scale)x\", \"size\" : \"\(points)x\(points)\" }")215}216let contents = "{\n \"images\" : [\n" + entries.joined(separator: ",\n") + "\n ],\n \"info\" : { \"author\" : \"xcode\", \"version\" : 1 }\n}\n"217try! contents.write(toFile: "\(setDir)/Contents.json", atomically: true, encoding: .utf8)218print("icon written: \(out)/orix-dj-icon-1024.png, \(entries.count) sizes in the asset catalog")219