Launchers on Android 8+ and Android Auto put the old icon, a rounded square with a transparent margin, inside their own shape and filled the margin with white. Both apps now have an adaptive icon (the gradient behind a wave layer, which also serves as the themed monochrome icon), and the legacy PNGs are opaque full-bleed squares, so nothing is left to frame. make_icon.py draws both with --foreground and --square. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
3.8 KiB
Python
Executable File
107 lines
3.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Draws the Musyx app icon (1024x1024 PNG) with no dependencies.
|
|
|
|
Aubergine squircle with amber wave lines, matching the My Wave hero.
|
|
Usage: python3 tool/make_icon.py assets/icon/musyx.png
|
|
|
|
With --foreground it draws the adaptive icon's foreground instead: the waves
|
|
alone on a transparent, full-bleed 108dp canvas, laid out so the launcher's
|
|
mask (the middle 72dp) shows what the squircle does. The background layer is
|
|
the gradient in res/drawable/ic_launcher_background.xml.
|
|
|
|
With --square it draws the legacy res/mipmap-*/ic_launcher.png: the artwork as
|
|
an opaque, full-bleed square. Anything that still loads the legacy icon on a
|
|
newer Android (Android Auto's media header does) wraps it in a shape, and any
|
|
transparent margin left in it shows there as a white frame.
|
|
"""
|
|
import math
|
|
import struct
|
|
import sys
|
|
import zlib
|
|
|
|
SIZE = 1024
|
|
# macOS icon grid: the body is 824px, centred, with a ~185px corner radius.
|
|
BODY, RADIUS = 824, 185
|
|
FOREGROUND = "--foreground" in sys.argv
|
|
SQUARE = "--square" in sys.argv
|
|
if FOREGROUND:
|
|
BODY = SIZE * 72 / 108
|
|
if SQUARE:
|
|
BODY = SIZE
|
|
OFF = (SIZE - BODY) / 2
|
|
TOP, BOTTOM = (0x35, 0x30, 0x42), (0x1C, 0x1A, 0x22)
|
|
AMBER = (0xF0, 0xB2, 0x3E)
|
|
LINES = 11
|
|
|
|
|
|
def rounded_alpha(x, y):
|
|
"""Coverage of the rounded square at pixel centre (x, y), anti-aliased."""
|
|
px, py = x + 0.5 - OFF, y + 0.5 - OFF
|
|
cx = min(max(px, RADIUS), BODY - RADIUS)
|
|
cy = min(max(py, RADIUS), BODY - RADIUS)
|
|
d = math.hypot(px - cx, py - cy) - RADIUS
|
|
if px < 0 or py < 0 or px > BODY or py > BODY:
|
|
d = max(d, 1.0)
|
|
return min(max(0.5 - d, 0.0), 1.0)
|
|
|
|
|
|
def wave(k, x):
|
|
"""Height of line k at x, and its slope, in pixels."""
|
|
u = (x - OFF) / BODY
|
|
base = OFF + BODY * (0.34 + k * 0.034)
|
|
amp = BODY * (0.045 + k * 0.006)
|
|
f = 1.5 + k * 0.08
|
|
ph = k * 0.55 + 1.1
|
|
a = u * math.pi * f + ph
|
|
b = u * math.pi * 4.2 - ph * 0.7
|
|
y = base + math.sin(a) * amp + math.sin(b) * amp * 0.35
|
|
dy = (math.cos(a) * amp * math.pi * f + math.cos(b) * amp * 0.35 * math.pi * 4.2) / BODY
|
|
return y, dy
|
|
|
|
|
|
def main(out):
|
|
rows = []
|
|
curves = [[wave(k, x + 0.5) for x in range(SIZE)] for k in range(LINES)]
|
|
for y in range(SIZE):
|
|
row = bytearray([0]) # filter: none
|
|
t = y / SIZE
|
|
bg = tuple(round(TOP[i] + (BOTTOM[i] - TOP[i]) * t) for i in range(3))
|
|
for x in range(SIZE):
|
|
cover = 1.0 if FOREGROUND or SQUARE else rounded_alpha(x, y)
|
|
if cover == 0.0:
|
|
row += b"\x00\x00\x00\x00"
|
|
continue
|
|
r, g, b = bg
|
|
clear = 1.0 # how much of the background the lines leave showing
|
|
for k in range(LINES):
|
|
cy, slope = curves[k][x]
|
|
dist = abs(y + 0.5 - cy) / math.sqrt(1 + slope * slope)
|
|
width = (4.0 + k * 0.9) * BODY / 824
|
|
a = min(max(width / 2 - dist + 0.5, 0.0), 1.0)
|
|
if a:
|
|
a *= 0.18 + 0.82 * (k / (LINES - 1))
|
|
clear *= 1 - a
|
|
r = r + (AMBER[0] - r) * a
|
|
g = g + (AMBER[1] - g) * a
|
|
b = b + (AMBER[2] - b) * a
|
|
if FOREGROUND:
|
|
row += bytes((*AMBER, round((1 - clear) * 255)))
|
|
else:
|
|
row += bytes((round(r), round(g), round(b), round(cover * 255)))
|
|
rows.append(bytes(row))
|
|
|
|
def chunk(kind, data):
|
|
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data) & 0xFFFFFFFF)
|
|
|
|
png = b"\x89PNG\r\n\x1a\n"
|
|
png += chunk(b"IHDR", struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0))
|
|
png += chunk(b"IDAT", zlib.compress(b"".join(rows), 9))
|
|
png += chunk(b"IEND", b"")
|
|
with open(out, "wb") as f:
|
|
f.write(png)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = [a for a in sys.argv[1:] if not a.startswith("--")]
|
|
main(args[0] if args else "musyx.png")
|