// Run from the repository root: swift docs/design/generate-brand-icons.swift // B1 geometry is shared by SVG masters and raster assets; no external dependencies. import AppKit struct Outline { let path = CGMutablePath() var svg = "" mutating func move(_ x: Double, _ y: Double) { path.move(to: CGPoint(x: x, y: y)); svg += "M\(x) \(y) " } mutating func line(_ x: Double, _ y: Double) { path.addLine(to: CGPoint(x: x, y: y)); svg += "L\(x) \(y) " } mutating func curve(_ x1: Double, _ y1: Double, _ x2: Double, _ y2: Double, _ x: Double, _ y: Double) { path.addCurve(to: CGPoint(x: x, y: y), control1: CGPoint(x: x1, y: y1), control2: CGPoint(x: x2, y: y2)) svg += "C\(x1) \(y1) \(x2) \(y2) \(x) \(y) " } } var orbit = Outline() orbit.move(536, 194) orbit.curve(349, 164, 184, 312, 184, 508) orbit.curve(184, 697, 326, 840, 514, 840) orbit.curve(702, 840, 844, 697, 844, 508) orbit.curve(844, 478, 840, 455, 832, 433) var wave = Outline() wave.move(300, 555) wave.line(344, 555) wave.curve(362, 555, 365, 503, 387, 503) wave.line(431, 503) wave.curve(453, 503, 455, 555, 479, 555) wave.line(522, 555) wave.curve(547, 555, 564, 412, 594, 412) wave.line(643, 412) wave.curve(672, 412, 677, 478, 704, 478) let dot = CGRect(x: 730, y: 122, width: 116, height: 116) let root = URL(fileURLWithPath: FileManager.default.currentDirectoryPath) let assets = root.appendingPathComponent("kymo/Assets.xcassets") func write(_ text: String, _ relative: String) throws { try text.write(to: root.appendingPathComponent(relative), atomically: true, encoding: .utf8) } func symbolSVG(color: String, dotColor: String) -> String { """ """ } let logoSVG = """ \(symbolSVG(color: "url(#graphite)", dotColor: "url(#blue)")) """ try write(logoSVG, "kymo/Assets.xcassets/BrandLogo.imageset/BrandLogo.svg") try write(""" \(symbolSVG(color: "#000000", dotColor: "#000000")) """, "docs/design/kymo-b1-mark.svg") func gradient(_ context: CGContext, _ colors: [UInt32], from: CGPoint, to: CGPoint) { let values = colors.map { value in CGColor(srgbRed: Double((value >> 16) & 255) / 255, green: Double((value >> 8) & 255) / 255, blue: Double(value & 255) / 255, alpha: 1) } let gradient = CGGradient(colorsSpace: CGColorSpace(name: CGColorSpace.sRGB)!, colors: values as CFArray, locations: nil)! context.drawLinearGradient(gradient, start: from, end: to, options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) } func render(size: Int, template: Bool) throws -> NSBitmapImageRep { // Supersample to preserve smooth curves at 18px, including fractional optical spacing. let scale = 4 let pixels = size * scale let context = CGContext(data: nil, width: pixels, height: pixels, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)! context.scaleBy(x: Double(pixels) / 1024, y: Double(pixels) / 1024) context.translateBy(x: 0, y: 1024) context.scaleBy(x: 1, y: -1) if !template { gradient(context, [0xffffff, 0xeeeae4], from: .zero, to: CGPoint(x: 307, y: 1024)) } for (outline, width) in [(orbit, 84.0), (wave, 46.0)] { context.saveGState() context.addPath(outline.path) context.setLineWidth(width) context.setLineCap(.round) context.setLineJoin(.round) context.replacePathWithStrokedPath() context.clip() if template { context.setFillColor(CGColor(gray: 0, alpha: 1)) context.fill(CGRect(x: 0, y: 0, width: 1024, height: 1024)) } else { // Each SVG path's default object bounding box defines its gradient. let bounds = outline.path.boundingBoxOfPath gradient(context, [0x383936, 0x232421], from: CGPoint(x: 0, y: bounds.minY), to: CGPoint(x: 0, y: bounds.maxY)) } context.restoreGState() } context.saveGState() context.addEllipse(in: dot); context.clip() if template { context.setFillColor(CGColor(gray: 0, alpha: 1)); context.fill(dot) } else { gradient(context, [0x369dff, 0x0877ff, 0x0753df], from: CGPoint(x: 730, y: 122), to: CGPoint(x: 753.2, y: 238)) } context.restoreGState() let small = CGContext(data: nil, width: size, height: size, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)! small.interpolationQuality = .high small.draw(context.makeImage()!, in: CGRect(x: 0, y: 0, width: size, height: size)) return NSBitmapImageRep(cgImage: small.makeImage()!) } for scale in 1...3 { let suffix = scale == 1 ? "" : "@\(scale)x" try render(size: 18 * scale, template: true).representation(using: .png, properties: [:])! .write(to: assets.appendingPathComponent("BrandMark.imageset/BrandMark\(suffix).png")) } for size in [16, 32, 128, 256, 512] { for scale in 1...2 { try render(size: size * scale, template: false).representation(using: .png, properties: [:])! .write(to: assets.appendingPathComponent("AppIcon.appiconset/AppIcon-\(size)@\(scale)x.png")) } } print("Generated B1 SVG masters, 3 template scales and 10 AppIcon slots.")