Files
OrbitTv/design/interface/build-new-icons.py
T
pauljdandClaude Opus 5.5 20bac5f95e
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m38s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m28s
Give Orbit 1, 2 and Three 101 to 103, make Orbit 1 smart, fix Drive-In boards and centre the icon (0.68.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-02 12:22:35 +00:00

49 lines
4.2 KiB
Python

#!/usr/bin/env python3
"""New category icons and the app's launcher art. The first icon set in icons/ stays as it was."""
import os, subprocess
from pathlib import Path
from PIL import Image
HERE = Path(__file__).parent
ICONS = HERE / 'icons'
RES = HERE.parents[1] / 'android/app/src/main/res/drawable-nodpi'
C, A = '#E8EDF5', '#7FB2FF'
S = f'fill="none" stroke="{C}" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"'
T = f'fill="none" stroke="{A}" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"'
CRESCENT = 'M335 132C141 114 66 384 257 475C143 363 185 207 335 132Z'
ICON = {
# The TV now carries the Orbit crescent and ring.
'all': f'<rect x="10" y="26" width="76" height="56" rx="9" {S}/><path d="M34 26L24 10M62 26L72 10" {S}/><g transform="translate(20,25) scale(.095)"><path d="{CRESCENT}" fill="{C}"/></g>'
f'<path d="M32 60C30 63 31 65 36 65.5C46 66 62 57 63.5 52.5C64.5 49 60 49 56.5 50" fill="none" stroke="{A}" stroke-width="3" stroke-linecap="round"/>',
# A camera on a tripod: someone out filming the real world.
'documentaries': f'<rect x="14" y="36" width="46" height="26" rx="4" {S}/><path d="M60 44L82 34V64L60 54" {S}/><circle cx="26" cy="23" r="9" {T}/><circle cx="48" cy="23" r="9" {T}/><path d="M37 62V72M37 72L22 90M37 72L52 90M37 72V90" {S}/>',
# A comic burst, so Cartoons can't be confused with the Kids rocket.
'cartoons': f'<path d="M48 6L56 26L74 12L70 34L92 32L76 48L92 64L70 62L74 84L56 70L48 90L40 70L22 84L26 62L4 64L20 48L4 32L26 34L22 12L40 26Z" {S}/><path d="M48 32V52" {T}/><circle cx="48" cy="62" r="3.5" fill="{A}"/>',
}
def render(svg, out):
path = ICONS / out
path.write_text(svg)
png = path.with_suffix('.png')
subprocess.run(['vectorcraft-cli', 'convert', str(path), str(png)], check=True, stdout=subprocess.DEVNULL)
return png
for name, body in ICON.items():
png = render(f'<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" viewBox="0 0 96 96">{body}</svg>', f'orbit_icon_{name}_v2.svg')
Image.open(png).convert('RGBA').resize((96, 96), Image.LANCZOS).save(RES / f'orbit_icon_{name}.webp', lossless=True)
SILVER = '<linearGradient id="s" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#FFFFFF"/><stop offset=".44" stop-color="#E8EDF5"/><stop offset=".5" stop-color="#B7CBE8"/><stop offset="1" stop-color="#F5F7FF"/></linearGradient>'
BG = '<linearGradient id="n" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#12356B"/><stop offset="1" stop-color="#071632"/></linearGradient>'
MARK = f'<path d="{CRESCENT}" fill="url(#s)"/><path d="M129 369C102 399 111 425 161 428C267 432 431 340 445 289C455 250 405 250 369 261" fill="none" stroke="#36BFFF" stroke-width="13"/><circle cx="430" cy="282" r="10" fill="#36BFFF"/>'
def centred(name, w, h, background, art, fill):
"""Lays art on the background with its visible edges centred, as launchers show the picture exactly as drawn."""
back = Image.open(render(f'<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="{h}" viewBox="0 0 {w} {h}"><defs>{BG}</defs>{background}</svg>', f'{name}_back.svg')).convert('RGBA')
front = Image.open(render(f'<svg xmlns="http://www.w3.org/2000/svg" width="2048" height="1024" viewBox="0 0 2048 1024"><defs>{SILVER}</defs>{art}</svg>', f'{name}.svg')).convert('RGBA')
front = front.crop(front.getbbox())
scale = min(w * fill / front.width, h * fill / front.height)
front = front.resize((round(front.width * scale), round(front.height * scale)), Image.LANCZOS)
back.paste(front, ((w - front.width) // 2, (h - front.height) // 2), front)
(ICONS / f'{name}_back.svg').unlink(); (ICONS / f'{name}_back.png').unlink()
return back.convert('RGB')
NIGHT = '<rect width="100%" height="100%" fill="url(#n)"/>'
centred('orbit_app_icon', 512, 512, NIGHT, f'<g transform="scale(2)">{MARK}</g>', .72).save(RES / 'orbit_app_icon.webp', quality=92)
centred('orbit_banner', 640, 360, NIGHT, f'<g transform="scale(1.5)">{MARK}</g><text x="810" y="520" font-family="Barlow" font-weight="600" font-size="210" letter-spacing="52" fill="#F5F7FF">ORBIT</text>', .78).save(RES / 'orbit_banner.png')
for f in ICONS.glob('*_v2.png'): f.unlink()
for n in ('orbit_app_icon', 'orbit_banner'): (ICONS / f'{n}.png').unlink(missing_ok=True)