icon.swift (2259B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 // Draws the icon (1024 px, opaque): `swift tools/icon.swift output.png` on chunga. 3 import CoreGraphics 4 import Foundation 5 import ImageIO 6 import UniformTypeIdentifiers 7 8 let size = 1024 9 let space = CGColorSpaceCreateDeviceRGB() 10 let ctx = CGContext(data: nil, width: size, height: size, bitsPerComponent: 8, bytesPerRow: 0, space: space, 11 bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)! 12 func color(_ r: Double, _ g: Double, _ b: Double, _ a: Double = 1) -> CGColor { CGColor(red: r, green: g, blue: b, alpha: a) } 13 14 // Water: light at the surface (top), dark at the bottom. 15 let gradient = CGGradient(colorsSpace: space, colors: [color(0.02, 0.10, 0.25), color(0.03, 0.33, 0.60), color(0.20, 0.72, 0.90)] as CFArray, 16 locations: [0, 0.6, 1])! 17 ctx.drawLinearGradient(gradient, start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: size), options: []) 18 19 // Dive profile: descent, bottom, ascent with one stop. 20 let pts: [(Double, Double)] = [(130, 830), (300, 330), (560, 330), (700, 640), (820, 640), (894, 830)] 21 let profile = CGMutablePath() 22 profile.move(to: CGPoint(x: pts[0].0, y: pts[0].1)) 23 for p in pts.dropFirst() { profile.addLine(to: CGPoint(x: p.0, y: p.1)) } 24 let fill = profile.mutableCopy()! 25 fill.closeSubpath() 26 ctx.addPath(fill); ctx.setFillColor(color(1, 1, 1, 0.14)); ctx.fillPath() 27 ctx.addPath(profile); ctx.setStrokeColor(color(1, 1, 1)); ctx.setLineWidth(44) 28 ctx.setLineJoin(.round); ctx.setLineCap(.round); ctx.strokePath() 29 30 // The remora: a small fish following the profile, at the bottom. 31 ctx.setFillColor(color(1.0, 0.72, 0.20)) 32 ctx.fillEllipse(in: CGRect(x: 360, y: 180, width: 230, height: 96)) 33 let tail = CGMutablePath() 34 tail.move(to: CGPoint(x: 380, y: 228)); tail.addLine(to: CGPoint(x: 290, y: 290)); tail.addLine(to: CGPoint(x: 290, y: 166)) 35 tail.closeSubpath() 36 ctx.addPath(tail); ctx.fillPath() 37 ctx.setFillColor(color(0.02, 0.10, 0.25)) 38 ctx.fillEllipse(in: CGRect(x: 528, y: 232, width: 24, height: 24)) 39 40 let url = URL(fileURLWithPath: CommandLine.arguments[1]) 41 let dest = CGImageDestinationCreateWithURL(url as CFURL, UTType.png.identifier as CFString, 1, nil)! 42 CGImageDestinationAddImage(dest, ctx.makeImage()!, nil) 43 CGImageDestinationFinalize(dest)