Files
sfhorizont/assets/branding/make_icons.py
T
2026-10-24 13:20:55 +02:00

92 lines
4.5 KiB
Python

"""Regenerate every app icon / splash asset from one definition.
Source: the "A · Skyline" concept on the claude.ai design canvas (Icons.dc.html).
After changing the shapes below, run (from the repo root):
python3 assets/branding/make_icons.py
dart run flutter_launcher_icons
dart run flutter_native_splash:create
The web UI draws the same icon in wasm/frontend/src/components/AppIcon.jsx;
keep EDGE / WINDOW there in sync.
"""
import os
import re
import subprocess
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(os.path.dirname(HERE))
CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
# Horizon line between the left run-in (y = 70) and the right run-out (y = 63):
# house roof with chimney, then a tall and a small fir tree.
EDGE = ('L8 70 L8 56 L21 44 L27 49.5 L27 43 L30.5 43 L30.5 52.8 L34 56 L34 70 L46 70 '
'L50 66 L59 56 L54 56 L62 44 L58 44 L66 28 L74 44 L70 44 L78 56 L73 56 L82 66 '
'L85 66 L89 58 L87 58 L92 48 L97 58 L95 58')
LEFT_Y, RIGHT_Y = 70, 63
STARS = ('<circle cx="48" cy="30" r="2.6" fill="#E8ECF2"/><circle cx="24" cy="22" r="1.5" fill="#C9D2DE"/>'
'<circle cx="74" cy="20" r="1.3" fill="#C9D2DE"/><circle cx="88" cy="30" r="1.1" fill="#93A0B4"/>')
WINDOW = '<rect x="16" y="58" width="6" height="6" fill="#F5B544" fill-opacity="0.9"/>'
LINE = 'fill="none" stroke="#F5B544" stroke-width="4" stroke-linejoin="round" stroke-linecap="round"'
def rounded():
"""Rounded tile: web favicon, splash, in-app icon."""
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">\n'
f' <rect width="100" height="100" rx="22.5" fill="#0E1424"/>\n {STARS}\n'
f' <path d="M0 77.5 L0 {LEFT_Y} {EDGE} L100 {RIGHT_Y} L100 77.5 A22.5 22.5 0 0 1 77.5 100 '
f'L22.5 100 A22.5 22.5 0 0 1 0 77.5 Z" fill="#070A12"/>\n {WINDOW}\n'
f' <path d="M2 {LEFT_Y} {EDGE} L98 {RIGHT_Y}" {LINE}/>\n</svg>\n')
def square():
"""Full-bleed square for iOS / store icons (the OS applies the corner mask)."""
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">\n'
f' <rect width="100" height="100" fill="#0E1424"/>\n {STARS}\n'
f' <path d="M0 100 L0 {LEFT_Y} {EDGE} L100 {RIGHT_Y} L100 100 Z" fill="#070A12"/>\n {WINDOW}\n'
f' <path d="M-4 {LEFT_Y} L0 {LEFT_Y} {EDGE} L100 {RIGHT_Y} L104 {RIGHT_Y}" {LINE}/>\n</svg>\n')
def foreground():
"""Android adaptive foreground (background #0E1424): artwork in the middle 2/3 so
round launcher masks keep the house; ground and line run out to the border."""
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="-25 -25 150 150">\n {STARS}\n'
f' <path d="M-26 126 L-26 {LEFT_Y} L0 {LEFT_Y} {EDGE} L100 {RIGHT_Y} L126 {RIGHT_Y} L126 126 Z" fill="#070A12"/>\n'
f' {WINDOW}\n <path d="M-26 {LEFT_Y} L0 {LEFT_Y} {EDGE} L100 {RIGHT_Y} L126 {RIGHT_Y}" {LINE}/>\n</svg>\n')
def splash12(size=1152, icon=520):
"""Android 12+ splash: the rounded icon inside the 768 px safe circle."""
inner = re.search(r'<svg[^>]*>(.*)</svg>', rounded(), re.S).group(1)
off = (size - icon) / 2
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {size} {size}">\n'
f' <svg x="{off}" y="{off}" width="{icon}" height="{icon}" viewBox="0 0 100 100">{inner}</svg>\n</svg>\n')
def write(name, text):
with open(os.path.join(HERE, name), 'w') as f:
f.write(text)
def render(svg, px, png):
subprocess.run([CHROME, '--headless=new', '--disable-gpu', '--hide-scrollbars',
'--default-background-color=00000000', f'--window-size={px},{px}',
f'--screenshot={os.path.join(HERE, png)}', 'file://' + os.path.join(HERE, svg)],
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
write('icon.svg', rounded())
write('icon-square.svg', square())
write('icon-foreground.svg', foreground())
write('splash-android12.svg', splash12())
render('icon-square.svg', 1024, 'icon-1024.png')
render('icon-foreground.svg', 1024, 'icon-foreground-1024.png')
render('icon.svg', 384, 'splash-logo.png')
render('splash-android12.svg', 1152, 'splash-android12.png')
public = os.path.join(ROOT, 'wasm', 'frontend', 'public')
write(os.path.join(public, 'favicon.svg'), rounded())
subprocess.run(['sips', '-Z', '180', os.path.join(HERE, 'icon-1024.png'),
'--out', os.path.join(public, 'apple-touch-icon.png')], check=True, stdout=subprocess.DEVNULL)
print('icons written to', HERE, 'and', public)