oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

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