make-icon.swift (5743B)
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 scorpionfish ("rascasse" in French) just below the surface. 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 let space = CGColorSpaceCreateDeviceRGB() 19 20 // Water: from deep blue (bottom) to turquoise (top). 21 let water = CGGradient(colorsSpace: space, colors: [rgb(6, 40, 92), rgb(8, 104, 150), rgb(64, 190, 205)] as CFArray, locations: [0, 0.6, 1])! 22 ctx.drawLinearGradient(water, start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: size), options: []) 23 24 // Surface: a light wave at the top. 25 ctx.setFillColor(rgb(214, 244, 250)) 26 ctx.move(to: CGPoint(x: 0, y: size)) 27 ctx.addLine(to: CGPoint(x: 0, y: 850)) 28 ctx.addCurve(to: CGPoint(x: 512, y: 850), control1: CGPoint(x: 170, y: 910), control2: CGPoint(x: 340, y: 790)) 29 ctx.addCurve(to: CGPoint(x: 1024, y: 850), control1: CGPoint(x: 684, y: 910), control2: CGPoint(x: 854, y: 790)) 30 ctx.addLine(to: CGPoint(x: 1024, y: size)) 31 ctx.fillPath() 32 33 // Sand at the bottom. 34 ctx.setFillColor(rgb(232, 204, 150)) 35 ctx.move(to: CGPoint(x: 0, y: 0)) 36 ctx.addLine(to: CGPoint(x: 0, y: 170)) 37 ctx.addCurve(to: CGPoint(x: 1024, y: 150), control1: CGPoint(x: 340, y: 240), control2: CGPoint(x: 700, y: 110)) 38 ctx.addLine(to: CGPoint(x: 1024, y: 0)) 39 ctx.fillPath() 40 41 // Scorpionfish: stocky orange-red body, big head, spiny dorsal fin, grumpy but likeable. 42 let red = rgb(226, 78, 52), deep = rgb(150, 40, 36), light = rgb(255, 170, 110), belly = rgb(255, 214, 170) 43 // Tail. 44 ctx.setFillColor(red) 45 ctx.move(to: CGPoint(x: 300, y: 450)) 46 ctx.addCurve(to: CGPoint(x: 120, y: 610), control1: CGPoint(x: 230, y: 500), control2: CGPoint(x: 150, y: 560)) 47 ctx.addCurve(to: CGPoint(x: 130, y: 300), control1: CGPoint(x: 190, y: 500), control2: CGPoint(x: 190, y: 410)) 48 ctx.addCurve(to: CGPoint(x: 300, y: 450), control1: CGPoint(x: 170, y: 350), control2: CGPoint(x: 240, y: 410)) 49 ctx.fillPath() 50 // Spiny dorsal fin: a row of spines joined by a membrane. 51 let spines: [(Double, Double)] = [(330, 640), (390, 760), (450, 650), (520, 790), (585, 660), (650, 770), (705, 640), (760, 700)] 52 ctx.setFillColor(light) 53 ctx.move(to: CGPoint(x: 300, y: 560)) 54 for (x, y) in spines { ctx.addLine(to: CGPoint(x: x, y: y)) } 55 ctx.addLine(to: CGPoint(x: 800, y: 560)) 56 ctx.fillPath() 57 ctx.setStrokeColor(deep) 58 ctx.setLineWidth(12) 59 ctx.setLineCap(.round) 60 for (x, y) in spines where y > 690 { 61 ctx.move(to: CGPoint(x: x, y: y)); ctx.addLine(to: CGPoint(x: x - 10, y: 580)); ctx.strokePath() 62 } 63 // Body. 64 ctx.saveGState() 65 let bodyRect = CGRect(x: 240, y: 280, width: 640, height: 400) 66 ctx.addEllipse(in: bodyRect) 67 ctx.clip() 68 let scales = CGGradient(colorsSpace: space, colors: [belly, light, red, deep] as CFArray, locations: [0, 0.25, 0.6, 1])! 69 ctx.drawLinearGradient(scales, start: CGPoint(x: 0, y: 280), end: CGPoint(x: 0, y: 700), options: []) 70 // Mottling. 71 ctx.setFillColor(rgb(150, 40, 36, 0.45)) 72 for (x, y, r) in [(380.0, 560.0, 34.0), (470, 610, 26), (460, 500, 30), (560, 570, 28), (350, 470, 22), (620, 620, 20), (540, 470, 18)] { 73 ctx.fillEllipse(in: CGRect(x: x - r, y: y - r * 0.8, width: 2 * r, height: 1.6 * r)) 74 } 75 ctx.restoreGState() 76 ctx.setStrokeColor(deep) 77 ctx.setLineWidth(14) 78 ctx.strokeEllipse(in: bodyRect) 79 // Fan-shaped pectoral fin. 80 ctx.setFillColor(light) 81 ctx.move(to: CGPoint(x: 560, y: 430)) 82 ctx.addCurve(to: CGPoint(x: 430, y: 300), control1: CGPoint(x: 500, y: 410), control2: CGPoint(x: 440, y: 360)) 83 ctx.addCurve(to: CGPoint(x: 600, y: 330), control1: CGPoint(x: 480, y: 270), control2: CGPoint(x: 560, y: 280)) 84 ctx.closePath() 85 ctx.fillPath() 86 ctx.setStrokeColor(deep) 87 ctx.setLineWidth(10) 88 for (x, y) in [(450.0, 310.0), (500, 300), (550, 310)] { 89 ctx.move(to: CGPoint(x: 560, y: 420)); ctx.addLine(to: CGPoint(x: x, y: y)); ctx.strokePath() 90 } 91 // Big eye, spiny eyebrow, pink cheek. 92 ctx.setFillColor(rgb(255, 255, 255)) 93 ctx.fillEllipse(in: CGRect(x: 690, y: 500, width: 120, height: 130)) 94 ctx.setFillColor(rgb(30, 30, 50)) 95 ctx.fillEllipse(in: CGRect(x: 730, y: 522, width: 66, height: 78)) 96 ctx.setFillColor(rgb(255, 255, 255)) 97 ctx.fillEllipse(in: CGRect(x: 764, y: 566, width: 24, height: 24)) 98 ctx.setStrokeColor(deep) 99 ctx.setLineWidth(16) 100 ctx.move(to: CGPoint(x: 680, y: 640)); ctx.addLine(to: CGPoint(x: 820, y: 622)); ctx.strokePath() 101 ctx.setFillColor(rgb(255, 150, 160, 0.7)) 102 ctx.fillEllipse(in: CGRect(x: 690, y: 420, width: 70, height: 40)) 103 // Wide mouth, slightly sulky. 104 ctx.setStrokeColor(deep) 105 ctx.setLineWidth(16) 106 ctx.move(to: CGPoint(x: 800, y: 420)) 107 ctx.addQuadCurve(to: CGPoint(x: 878, y: 440), control: CGPoint(x: 840, y: 450)) 108 ctx.strokePath() 109 110 // Bubbles rising to the surface. 111 ctx.setStrokeColor(rgb(255, 255, 255, 0.85)) 112 ctx.setLineWidth(8) 113 for (x, y, r) in [(900.0, 560.0, 26.0), (930, 670, 18), (905, 760, 12), (200, 700, 20), (160, 780, 13)] { 114 ctx.setFillColor(rgb(255, 255, 255, 0.18)) 115 ctx.fillEllipse(in: CGRect(x: x - r, y: y - r, width: 2 * r, height: 2 * r)) 116 ctx.strokeEllipse(in: CGRect(x: x - r, y: y - r, width: 2 * r, height: 2 * r)) 117 } 118 119 let image = ctx.makeImage()! 120 let dest = CGImageDestinationCreateWithURL(URL(fileURLWithPath: out) as CFURL, UTType.png.identifier as CFString, 1, nil)! 121 CGImageDestinationAddImage(dest, image, nil) 122 CGImageDestinationFinalize(dest)