Files
OrbitTv/design/channels/build-backdrops.py
T
pauljdandClaude Opus 5.5 201c79bf96
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m32s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m28s
Redraw the ToonZ, Evidence, Orbit X and Rewind backdrops, and tidy Orbit 1's (0.56.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-02 09:46:53 +00:00

131 lines
10 KiB
Python

#!/usr/bin/env python3
"""Replacement channel backdrops: each a scene that says what the channel is. Originals in Orbit-Channel-Designs stay untouched.
The app puts the logo top left, the number top right and Tuning bottom left, so each scene keeps those corners quiet."""
import math, os, random, subprocess, sys
from pathlib import Path
from PIL import Image
OUT = Path(__file__).parent / 'backdrops'
RES = Path(__file__).parents[2] / 'android/app/src/main/res/drawable-nodpi'
W, H = 1920, 1080
FONT = "Barlow"
def svg(body, defs=''):
return f'<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{H}" viewBox="0 0 {W} {H}"><defs>{defs}</defs>{body}</svg>'
def lin(i, *stops, x2=0, y2=1):
return f'<linearGradient id="{i}" x1="0" y1="0" x2="{x2}" y2="{y2}">' + ''.join(f'<stop offset="{o}" stop-color="{c}"/>' for o, c in stops) + '</linearGradient>'
def rad(i, *stops):
return f'<radialGradient id="{i}">' + ''.join(f'<stop offset="{o}" stop-color="{c}" stop-opacity="{a}"/>' for o, c, a in stops) + '</radialGradient>'
def rect(x, y, w, h, fill, extra=''):
return f'<rect x="{x}" y="{y}" width="{w}" height="{h}" fill="{fill}" {extra}/>'
def toonz():
"""Saturday morning: a cartoon hillside under a big sun, drawn with thick ink lines."""
ink = '#10203F'
defs = lin('sky', (0, '#123C8C'), (.55, '#2AA8E8'), (1, '#8FE3F5'))
b = rect(0, 0, W, H, 'url(#sky)')
cx, cy = 1400, 330
for i in range(16):
a0, a1 = i * math.pi / 8, (i + .5) * math.pi / 8
b += f'<polygon points="{cx},{cy} {cx+1500*math.cos(a0):.0f},{cy+1500*math.sin(a0):.0f} {cx+1500*math.cos(a1):.0f},{cy+1500*math.sin(a1):.0f}" fill="#FFFFFF" opacity=".07"/>'
b += f'<circle cx="{cx}" cy="{cy}" r="150" fill="#FFDE59" stroke="{ink}" stroke-width="10"/>'
def cloud(x, y, s):
p = f'M{x} {y} q{-60*s} 0 {-60*s} {-45*s} q0 {-45*s} {55*s} {-45*s} q{15*s} {-55*s} {80*s} {-50*s} q{50*s} {-45*s} {105*s} {-5*s} q{70*s} {-15*s} {85*s} {50*s} q{50*s} {5*s} {45*s} {50*s} q{-5*s} {45*s} {-55*s} {45*s} Z'
return f'<path d="{p}" fill="#FFFFFF" stroke="{ink}" stroke-width="9" stroke-linejoin="round"/>'
b += cloud(820, 300, 1.25) + cloud(1660, 590, .9) + cloud(960, 520, .7)
b += f'<path d="M0 760 C300 610 620 640 900 740 S1500 640 1920 700 L1920 1080 L0 1080 Z" fill="#58C84E" stroke="{ink}" stroke-width="10"/>'
b += f'<path d="M0 900 C400 780 800 800 1180 900 S1700 880 1920 830 L1920 1080 L0 1080 Z" fill="#35A63E" stroke="{ink}" stroke-width="10"/>'
# A winding road and two cartoon trees, then a pink Z painted on the hill.
b += f'<path d="M1120 1080 C1060 980 1400 930 1290 840 C1250 800 1330 770 1400 745 C1360 790 1440 830 1460 880 C1500 960 1340 1000 1400 1080 Z" fill="#FFE9A8" stroke="{ink}" stroke-width="8"/>'
for x, y, s in ((560, 760, 1.2), (1680, 780, 1.0), (300, 800, .85)):
b += rect(x-16*s, y-40*s, 32*s, 110*s, '#8A5A2B', f'stroke="{ink}" stroke-width="8"')
b += f'<circle cx="{x}" cy="{y-110*s}" r="{95*s}" fill="#1F8F3F" stroke="{ink}" stroke-width="9"/><circle cx="{x-60*s}" cy="{y-60*s}" r="{62*s}" fill="#27A34A" stroke="{ink}" stroke-width="9"/><circle cx="{x+62*s}" cy="{y-62*s}" r="{60*s}" fill="#27A34A" stroke="{ink}" stroke-width="9"/>'
return svg(b, defs)
def evidence():
"""A crime scene at night: a torch beam over numbered markers, with police tape across the corner."""
defs = lin('wall', (0, '#050C1C'), (1, '#0A1C3A')) + lin('floor', (0, '#0B1E3E'), (1, '#050C1C')) + rad('torch', (0, '#7FE9FF', .55), (.6, '#37C8E8', .16), (1, '#37C8E8', 0)) + lin('tape', (0, '#FFDE59'), (1, '#E8C030'))
b = rect(0, 0, W, 620, 'url(#wall)') + rect(0, 620, W, 460, 'url(#floor)')
for i in range(1, 15):
x = i * W / 15
b += f'<line x1="{x:.0f}" y1="620" x2="{(x-960)*2.6+960:.0f}" y2="1080" stroke="#1B3A68" stroke-width="2" opacity=".5"/>'
for y in (660, 720, 800, 910, 1040):
b += f'<line x1="0" y1="{y}" x2="{W}" y2="{y}" stroke="#1B3A68" stroke-width="2" opacity=".5"/>'
# Blinds on a window in the wall, the only light from outside.
for i in range(12):
b += rect(1190, 110 + i * 34, 470, 20, '#16365F', 'opacity=".9"')
b += '<rect x="1178" y="96" width="494" height="420" fill="none" stroke="#2C5688" stroke-width="10"/>'
b += '<polygon points="1560,-40 1800,-40 1180,860 640,860" fill="#7FE9FF" opacity=".10"/>'
b += '<ellipse cx="900" cy="850" rx="620" ry="170" fill="url(#torch)"/>'
for n, x, y, s in (('1', 560, 880, 1.0), ('2', 880, 790, .78), ('3', 1190, 860, .95)):
w, h = 120*s, 110*s
b += f'<polygon points="{x-w/2:.0f},{y} {x+w/2:.0f},{y} {x+w/2-16*s:.0f},{y-h:.0f} {x-w/2+16*s:.0f},{y-h:.0f}" fill="url(#tape)"/>'
b += f'<polygon points="{x-w/2:.0f},{y} {x+w/2:.0f},{y} {x+w/2+6*s:.0f},{y+16*s:.0f} {x-w/2-6*s:.0f},{y+16*s:.0f}" fill="#A9891F"/>'
b += f'<text x="{x}" y="{y-24*s:.0f}" font-family="{FONT}" font-weight="700" font-size="{78*s:.0f}" text-anchor="middle" fill="#071632">{n}</text>'
b += '<g transform="translate(1500,930) rotate(-24)"><rect x="-1100" y="-44" width="2400" height="88" fill="url(#tape)"/>'
for i in range(-5, 7):
b += f'<text x="{i*360}" y="24" font-family="{FONT}" font-weight="800" font-size="60" letter-spacing="6" text-anchor="middle" fill="#071632">EVIDENCE</text>'
return svg(b + '</g>', defs)
def orbit_x():
"""A chrome X bursting out of red speed lines, like the title card of an 80s action cartoon."""
defs = lin('bg', (0, '#040408'), (1, '#16060C')) + lin('chrome', (0, '#FFFFFF'), (.45, '#C8D0DC'), (.5, '#5E6A7C'), (.62, '#E8EDF5'), (1, '#8A95A8'), x2=1, y2=1) + rad('glow', (0, '#FF2B44', .6), (.55, '#C8102E', .22), (1, '#C8102E', 0))
b = rect(0, 0, W, H, 'url(#bg)')
cx, cy = 1180, 570
random.seed(7)
for i in range(72):
a = i * 2 * math.pi / 72 + random.uniform(-.015, .015)
r0, r1 = random.uniform(420, 560), random.uniform(1000, 1700)
b += f'<line x1="{cx+r0*math.cos(a):.0f}" y1="{cy+r0*math.sin(a):.0f}" x2="{cx+r1*math.cos(a):.0f}" y2="{cy+r1*math.sin(a):.0f}" stroke="#E5273A" stroke-width="{random.choice((3,5,8))}" opacity="{random.uniform(.25,.8):.2f}"/>'
b += f'<ellipse cx="{cx}" cy="{cy}" rx="620" ry="620" fill="url(#glow)"/>'
s = 400
pts = [(-1,-1),(-.42,-1),(0,-.36),(.42,-1),(1,-1),(.3,0),(1,1),(.42,1),(0,.36),(-.42,1),(-1,1),(-.3,0)]
poly = lambda dx, dy: ' '.join(f'{cx+dx+x*s+y*-.12*s:.0f},{cy+dy+y*s:.0f}' for x, y in pts)
b += f'<polygon points="{poly(26,30)}" fill="#7A0A1C"/><polygon points="{poly(0,0)}" fill="url(#chrome)" stroke="#FFFFFF" stroke-width="6"/>'
return svg(b, defs)
def rewind():
"""A 90s bedroom after school: a CRT on, colour bars and all, on a VCR, against a loud patterned wall."""
defs = lin('wall', (0, '#3B1468'), (1, '#6B1F8F')) + lin('floor', (0, '#F07A1E'), (1, '#B84A10')) + lin('shell', (0, '#3A3F4E'), (1, '#1D2029'))
b = rect(0, 0, W, 800, 'url(#wall)') + rect(0, 800, W, 280, 'url(#floor)')
random.seed(11)
for i in range(46):
x, y, k = random.uniform(420, 1920), random.uniform(20, 760), random.choice('tzc')
c = random.choice(('#FFDE59', '#23D5D5', '#FF5FA8', '#FF9A2E'))
if k == 't': b += f'<polygon points="{x:.0f},{y:.0f} {x+46:.0f},{y+14:.0f} {x+12:.0f},{y+50:.0f}" fill="{c}" opacity=".55"/>'
elif k == 'c': b += f'<circle cx="{x:.0f}" cy="{y:.0f}" r="20" fill="none" stroke="{c}" stroke-width="8" opacity=".55"/>'
else: b += f'<path d="M{x:.0f} {y:.0f} l28 -24 l28 24 l28 -24" fill="none" stroke="{c}" stroke-width="8" opacity=".55"/>'
b += rect(0, 800, W, 12, '#7A2E08')
tx, ty, tw, th = 800, 190, 880, 620
b += f'<rect x="{tx-30}" y="{ty+th+96}" width="{tw+60}" height="60" fill="#5A2A10"/>'
b += f'<rect x="{tx+90}" y="{ty+th+6}" width="{tw-180}" height="90" rx="8" fill="#14161D"/><rect x="{tx+150}" y="{ty+th+36}" width="330" height="20" fill="#000"/><text x="{tx+tw-250}" y="{ty+th+64}" font-family="{FONT}" font-weight="700" font-size="34" fill="#5CFF6A">12:00</text>'
b += f'<rect x="{tx}" y="{ty}" width="{tw}" height="{th}" rx="44" fill="url(#shell)" stroke="#0B0C12" stroke-width="8"/>'
sx, sy, sw, sh = tx+50, ty+50, tw-210, th-100
bars = ['#E8E8E8', '#E8D820', '#20D8D8', '#20D020', '#D820C8', '#D82020', '#2030D8']
b += f'<clipPath id="screen"><rect x="{sx}" y="{sy}" width="{sw}" height="{sh}" rx="50"/></clipPath><g clip-path="url(#screen)">'
for i, c in enumerate(bars): b += rect(sx + i*sw/7, sy, sw/7+1, sh*.72, c)
for i, c in enumerate(['#2030D8', '#14161D', '#D820C8', '#14161D', '#20D8D8', '#14161D', '#E8E8E8']): b += rect(sx + i*sw/7, sy+sh*.72, sw/7+1, sh*.08, c)
b += rect(sx, sy+sh*.8, sw, sh*.2, '#101218')
for y in range(int(sy), int(sy+sh), 8): b += rect(sx, y, sw, 2, '#000000', 'opacity=".16"')
b += '</g>' + f'<text x="{sx+50}" y="{sy+70}" font-family="{FONT}" font-weight="700" font-size="54" fill="#FFFFFF">◄◄ REW</text>'
for i in (0, 1): b += f'<circle cx="{tx+tw-85}" cy="{ty+130+i*130}" r="36" fill="#50566A" stroke="#0B0C12" stroke-width="6"/>'
for i in range(6): b += rect(tx+tw-130, ty+350+i*26, 90, 12, '#0B0C12')
b += f'<line x1="{tx+230}" y1="{ty+6}" x2="{tx+110}" y2="{ty-170}" stroke="#AEB6C6" stroke-width="10"/><line x1="{tx+250}" y1="{ty+6}" x2="{tx+430}" y2="{ty-160}" stroke="#AEB6C6" stroke-width="10"/>'
# A stack of tapes on the floor to the left.
for i, c in enumerate(('#FFDE59', '#23D5D5', '#FF5FA8')):
y = 960 - i*54
b += rect(300 + i*14, y, 360, 52, '#14161D', 'rx="5"') + rect(330 + i*14, y+10, 300, 28, c)
return svg(b, defs)
SCENES = {'toonz': toonz, 'evidence': evidence, 'orbit_x': orbit_x, 'rewind': rewind}
OUT.mkdir(exist_ok=True)
env = dict(os.environ)
fonts = os.environ.get('ORBIT_FONT_HOME')
if fonts: env['XDG_DATA_HOME'] = fonts
for name, scene in SCENES.items():
path = OUT / f'{name}_background_v2.svg'
path.write_text(scene())
png = OUT / f'{name}_background_v2.png'
subprocess.run(['vectorcraft-cli', 'convert', str(path), str(png)], env=env, check=True, stdout=subprocess.DEVNULL)
Image.open(png).convert('RGB').resize((W, H), Image.LANCZOS).save(RES / f'{name}_background.webp', quality=86, method=6)
png.unlink()
print(name, (RES / f'{name}_background.webp').stat().st_size)