SPB Git

Repository Public

make-icon.swift 2.3 KB 34 lines swift

1// VQuant iOS2// File: Scripts/make-icon.swift3// Description: Draws the app icon (the VQuant sparkle of shared/vqLogo.ts on the Onyx background) as a 1024 px PNG.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AppKit8import CoreGraphics910let size = 102411let cs = CGColorSpace(name: CGColorSpace.sRGB)!12let ctx = CGContext(data: nil, width: size, height: size, bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)!13func rgb(_ hex: UInt32) -> CGColor { CGColor(colorSpace: cs, components: [CGFloat((hex >> 16) & 0xFF) / 255, CGFloat((hex >> 8) & 0xFF) / 255, CGFloat(hex & 0xFF) / 255, 1])! }14// background15let bg = CGGradient(colorsSpace: cs, colors: [rgb(0x15151C), rgb(0x08080C)] as CFArray, locations: [0, 1])!16ctx.drawLinearGradient(bg, start: CGPoint(x: 0, y: size), end: CGPoint(x: size, y: 0), options: [])17// sparkle, viewBox 64 → centred at 68 % of the canvas, y flipped18let scale = CGFloat(size) * 0.68 / 6419ctx.translateBy(x: CGFloat(size) * 0.16 + 2 * scale, y: CGFloat(size) * 0.84 + 2 * scale)20ctx.scaleBy(x: scale, y: -scale)21func star(_ p: [(CGFloat, CGFloat)]) -> CGPath {22    let path = CGMutablePath(); path.move(to: CGPoint(x: p[0].0, y: p[0].1))23    var i = 124    while i + 2 < p.count { path.addCurve(to: CGPoint(x: p[i + 2].0, y: p[i + 2].1), control1: CGPoint(x: p[i].0, y: p[i].1), control2: CGPoint(x: p[i + 1].0, y: p[i + 1].1)); i += 3 }25    path.closeSubpath(); return path26}27let main = star([(27, 9), (28.9, 23.6), (33.4, 30.1), (51, 35), (33.4, 39.9), (28.9, 46.4), (27, 61), (25.1, 46.4), (20.6, 39.9), (3, 35), (20.6, 30.1), (25.1, 23.6), (27, 9)])28let small = star([(50, 3), (50.8, 9.1), (52.9, 11.9), (60, 14), (52.9, 16.1), (50.8, 18.9), (50, 25), (49.2, 18.9), (47.1, 16.1), (40, 14), (47.1, 11.9), (49.2, 9.1), (50, 3)])29ctx.addPath(main); ctx.addPath(small); ctx.clip()30let g = CGGradient(colorsSpace: cs, colors: [rgb(0xFF8A2A), rgb(0xFF3D6E), rgb(0xA855F7)] as CFArray, locations: [0, 0.55, 1])!31ctx.drawLinearGradient(g, start: CGPoint(x: 6, y: 8), end: CGPoint(x: 58, y: 58), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])32let rep = NSBitmapImageRep(cgImage: ctx.makeImage()!)33try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))34
Files main
Menu

Theme