make-icon.swift (3490B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 // Generates the 1024×1024 icon (no transparency): swift tools/make-icon.swift path.png 3 // A grouper ("mérou" in French). 4 import CoreGraphics 5 import Foundation 6 import ImageIO 7 import UniformTypeIdentifiers 8 9 let size = 1024.0 10 let out = CommandLine.arguments[1] 11 let ctx = CGContext(data: nil, width: Int(size), height: Int(size), bitsPerComponent: 8, bytesPerRow: 0, 12 space: CGColorSpace(name: CGColorSpace.sRGB)!, 13 bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)! 14 15 func rgb(_ r: Double, _ g: Double, _ b: Double, _ a: Double = 1) -> CGColor { 16 CGColor(red: r / 255, green: g / 255, blue: b / 255, alpha: a) 17 } 18 19 // Background: deep blue to turquoise (light coming from above). 20 let bg = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), 21 colors: [rgb(8, 36, 84), rgb(10, 92, 140), rgb(40, 170, 190)] as CFArray, 22 locations: [0, 0.6, 1])! 23 ctx.drawLinearGradient(bg, start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: size), options: []) 24 25 // Light rays. 26 ctx.setFillColor(rgb(255, 255, 255, 0.06)) 27 for x in [180.0, 420.0, 700.0] { 28 ctx.move(to: CGPoint(x: x, y: size)); ctx.addLine(to: CGPoint(x: x + 120, y: size)) 29 ctx.addLine(to: CGPoint(x: x - 80, y: 0)); ctx.addLine(to: CGPoint(x: x - 260, y: 0)); ctx.fillPath() 30 } 31 32 // Grouper: stocky body, large mouth, rounded tail fin. 33 let body = rgb(150, 96, 62), belly = rgb(214, 170, 120), dark = rgb(92, 56, 36) 34 ctx.setFillColor(body) 35 ctx.move(to: CGPoint(x: 250, y: 520)) // tail 36 ctx.addCurve(to: CGPoint(x: 120, y: 360), control1: CGPoint(x: 190, y: 470), control2: CGPoint(x: 120, y: 420)) 37 ctx.addCurve(to: CGPoint(x: 120, y: 680), control1: CGPoint(x: 160, y: 520), control2: CGPoint(x: 160, y: 520)) 38 ctx.addCurve(to: CGPoint(x: 250, y: 520), control1: CGPoint(x: 120, y: 620), control2: CGPoint(x: 190, y: 570)) 39 ctx.fillPath() 40 ctx.fillEllipse(in: CGRect(x: 210, y: 330, width: 640, height: 380)) 41 // Dorsal fin. 42 ctx.move(to: CGPoint(x: 330, y: 680)); ctx.addCurve(to: CGPoint(x: 700, y: 690), control1: CGPoint(x: 420, y: 800), control2: CGPoint(x: 620, y: 800)) 43 ctx.fillPath() 44 // Belly. 45 ctx.setFillColor(belly) 46 ctx.fillEllipse(in: CGRect(x: 300, y: 340, width: 500, height: 150)) 47 // Spots. 48 ctx.setFillColor(dark) 49 for (x, y, r) in [(380.0, 600.0, 26.0), (470, 640, 20), (450, 540, 30), (560, 600, 24), (620, 540, 18), (340, 520, 18)] { 50 ctx.fillEllipse(in: CGRect(x: x - r, y: y - r, width: 2 * r, height: 2 * r)) 51 } 52 // Mouth (thick lips). 53 ctx.setFillColor(dark) 54 ctx.fillEllipse(in: CGRect(x: 790, y: 440, width: 110, height: 70)) 55 ctx.setFillColor(rgb(60, 30, 20)) 56 ctx.fillEllipse(in: CGRect(x: 830, y: 462, width: 60, height: 26)) 57 // Eye. 58 ctx.setFillColor(rgb(250, 240, 210)) 59 ctx.fillEllipse(in: CGRect(x: 690, y: 560, width: 80, height: 80)) 60 ctx.setFillColor(rgb(20, 20, 30)) 61 ctx.fillEllipse(in: CGRect(x: 718, y: 582, width: 40, height: 40)) 62 ctx.setFillColor(rgb(255, 255, 255)) 63 ctx.fillEllipse(in: CGRect(x: 738, y: 604, width: 12, height: 12)) 64 65 // Bubbles. 66 ctx.setStrokeColor(rgb(255, 255, 255, 0.85)); ctx.setLineWidth(10) 67 for (x, y, r) in [(880.0, 600.0, 22.0), (920, 700, 32), (870, 820, 44)] { 68 ctx.strokeEllipse(in: CGRect(x: x - r, y: y - r, width: 2 * r, height: 2 * r)) 69 } 70 71 let dest = CGImageDestinationCreateWithURL(URL(fileURLWithPath: out) as CFURL, UTType.png.identifier as CFString, 1, nil)! 72 CGImageDestinationAddImage(dest, ctx.makeImage()!, nil) 73 CGImageDestinationFinalize(dest)