// Draws Base's app icon, ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png: // Base's mark (the wordmark's rounded square, --mark-1 into --mark-2, with // its bright edge) on the dark sky (--sky-1 to --sky-3 at 165°), lit as the // web is: the warm beam from above and the teal and violet fog below. A // square 1024 px master; bundle-mac.py derives the Mac's padded icon. // // swift native/scripts/make-icon.swift native/ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png import AppKit let size: CGFloat = 1024 let out = URL(fileURLWithPath: CommandLine.arguments[1]) func rgba(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat = 1) -> CGColor { CGColor(srgbRed: r / 255, green: g / 255, blue: b / 255, alpha: a) } let space = CGColorSpace(name: CGColorSpace.sRGB)! guard let ctx = CGContext(data: nil, width: Int(size), height: Int(size), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { fatalError("no context") } // CoreGraphics' origin is the bottom left: y runs up. // The sky: 165° (towards the bottom, a little left), --sky-1 0%, --sky-2 62%, --sky-3 100%. let sky = CGGradient(colorsSpace: space, colors: [rgba(44, 52, 112), rgba(26, 31, 69), rgba(22, 25, 58)] as CFArray, locations: [0, 0.62, 1])! let angle = 165.0 * Double.pi / 180 let dx = CGFloat(sin(angle)), dy = CGFloat(-cos(angle)) let half = (abs(dx) + abs(dy)) * size / 2 let mid = CGPoint(x: size / 2, y: size / 2) ctx.drawLinearGradient(sky, start: CGPoint(x: mid.x - dx * half, y: mid.y + dy * half), end: CGPoint(x: mid.x + dx * half, y: mid.y - dy * half), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) // Fog: soft radial glows of --lagoon and --orchid low down, and the warm beam from above. func glow(_ color: CGColor, at center: CGPoint, radius: CGFloat) { let g = CGGradient(colorsSpace: space, colors: [color, color.copy(alpha: 0)!] as CFArray, locations: [0, 1])! ctx.drawRadialGradient(g, startCenter: center, startRadius: 0, endCenter: center, endRadius: radius, options: []) } glow(rgba(47, 198, 192, 0.42), at: CGPoint(x: size * 0.18, y: size * 0.12), radius: size * 0.62) glow(rgba(139, 92, 246, 0.42), at: CGPoint(x: size * 0.86, y: size * 0.22), radius: size * 0.6) glow(rgba(244, 114, 182, 0.18), at: CGPoint(x: size * 0.6, y: size * 0.02), radius: size * 0.36) glow(rgba(255, 214, 170, 0.30), at: CGPoint(x: size * 0.42, y: size * 1.02), radius: size * 0.62) // The mark: a rounded square (16 px with 5 px corners on the web), 40% of the icon. let side = size * 0.40 let rect = CGRect(x: (size - side) / 2, y: (size - side) / 2, width: side, height: side) let path = CGPath(roundedRect: rect, cornerWidth: side * 5 / 16, cornerHeight: side * 5 / 16, transform: nil) ctx.saveGState() ctx.setShadow(offset: CGSize(width: 0, height: -side * 0.06), blur: side * 0.22, color: rgba(8, 12, 22, 0.55)) ctx.addPath(path); ctx.setFillColor(rgba(238, 242, 248, 0.5)); ctx.fillPath() ctx.restoreGState() ctx.saveGState() ctx.addPath(path); ctx.clip() // 160°: from the top, a little left, to the bottom: #FFFFFF into rgba(238,242,248,.35) over the sky. let markAngle = 160.0 * Double.pi / 180 let mdx = CGFloat(sin(markAngle)), mdy = CGFloat(-cos(markAngle)) let mhalf = (abs(mdx) + abs(mdy)) * side / 2 let mc = CGPoint(x: rect.midX, y: rect.midY) let mark = CGGradient(colorsSpace: space, colors: [rgba(255, 255, 255), rgba(238, 242, 248, 0.35)] as CFArray, locations: [0, 1])! ctx.drawLinearGradient(mark, start: CGPoint(x: mc.x - mdx * mhalf, y: mc.y + mdy * mhalf), end: CGPoint(x: mc.x + mdx * mhalf, y: mc.y - mdy * mhalf), options: []) // Its edge: inset 0 0 0 1px rgba(255,255,255,.5), scaled. ctx.addPath(path); ctx.setStrokeColor(rgba(255, 255, 255, 0.5)); ctx.setLineWidth(side / 24); ctx.strokePath() ctx.restoreGState() guard let image = ctx.makeImage(), let png = NSBitmapImageRep(cgImage: image).representation(using: .png, properties: [:]) else { fatalError("no png") } try png.write(to: out)