Files
OrbitTv/design/channels/build-batch3-blocks.py
T
pauljdandClaude Opus 5.5 c7bd97d6bc
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m21s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m31s
Batch 3 block idents: Paul's 5% notes (softer Sunday glow, richer tartan, Spooky contrast, subtler tracking line, Movie Night as a feature presentation)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-03 19:30:20 +00:00

700 lines
36 KiB
Python

#!/usr/bin/env python3
"""Batch 3 block idents, previews for Paul's review (3 November 2026 brief): Sunday Gold, Scottish Comedy Night,
Vortex Movie Night, Retro Action and Friday Spooky Teatime.
The 3D comes from blender/build_block_ident.py (each channel's own scene, with the block's additions). This lays the
sharp 2D on top as the other batches do: the channel logo, the Sunday script, the Orbit Three tartan and tiles, the
letterbox and chrome, the Retro chrome, the steam ghost and bats, and an original quiet sting. The channel logos and
scenes are read only. Writes orbit-gold-blocks/, orbit-three-blocks/, vortex-blocks/ and orbit-2-blocks/.
build-batch3-blocks.py <blender-blocks folder> [sundaygold|scottish|movienight|retro|spooky] ...
"""
from pathlib import Path
import importlib.util, json, math, random, shutil, subprocess, sys
from PIL import Image, ImageChops, ImageDraw, ImageFilter, ImageFont
HERE = Path(__file__).resolve().parent
def load(name, file):
spec = importlib.util.spec_from_file_location(name, HERE / file)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
riot, dark = load('riot', 'build-riot-blocks.py'), load('dark', 'build-dark-blocks.py')
kf, ease_out, ease_in, ease_io, glow, fade = riot.kf, riot.ease_out, riot.ease_in, riot.ease_io, riot.glow, riot.fade
text_layer, place, scaled, font, fade_in = dark.text_layer, dark.place, dark.scaled, dark.font, dark.fade_in
DESIGNS, W, H, FPS, LENGTH, MOVE = dark.DESIGNS, dark.W, dark.H, dark.FPS, dark.LENGTH, dark.MOVE
SCRIPT = '/usr/share/fonts/opentype/urw-base35/Z003-MediumItalic.otf' # URW's calligraphic italic, for the Sunday script
INK, WHITE = (12, 10, 18), (255, 255, 255)
BLOCKS = {
'sundaygold': dict(title='Sunday Gold', folder='orbit-gold-blocks/sunday-gold', channel='orbit-gold'),
'scottish': dict(title='Scottish Comedy Night', folder='orbit-three-blocks/scottish-comedy-night', channel='orbit-three'),
'movienight': dict(title='Vortex Movie Night', folder='vortex-blocks/movie-night', channel='vortex'),
'retro': dict(title='Retro Action', folder='orbit-2-blocks/retro-action', channel='orbit-2'),
'spooky': dict(title='Friday Spooky Teatime', folder='orbit-2-blocks/spooky-teatime', channel='orbit-2'),
}
def gradient_fill(mask, stops):
"""Fill a mask's shape with a vertical gradient: stops are (0..1, (r, g, b))."""
w, h = mask.size
column = Image.new('RGB', (1, h))
for y in range(h):
u = y / max(1, h - 1)
for (a, ca), (b, cb) in zip(stops, stops[1:]):
if a <= u <= b:
k = (u - a) / (b - a) if b > a else 0
column.putpixel((0, y), tuple(round(x + (z - x) * k) for x, z in zip(ca, cb)))
break
out = column.resize((w, h)).convert('RGBA')
out.putalpha(mask)
return out
def joined(words, face, fill):
"""Words drawn in one go, so a script font keeps its own joins and spacing."""
left, top, right, bottom = face.getbbox(words)
layer = Image.new('RGBA', (right - left + 20, bottom - top + 20))
ImageDraw.Draw(layer).text((10 - left, 10 - top), words, font=face, fill=fill)
return layer.crop(layer.getbbox())
def chrome(words, face, spacing, stops, edge=(10, 16, 34), shear=.18, outline=5):
"""Chrome lettering: a banded metal gradient inside a dark edge, leaning forward like the channel's own chrome."""
letters = text_layer(words, face, WHITE + (255,), spacing)
pad = outline + 4
mask = Image.new('L', (letters.width + 2 * pad, letters.height + 2 * pad))
mask.paste(letters.getchannel('A'), (pad, pad))
lean = round(mask.height * shear)
mask = mask.transform((mask.width + lean, mask.height), Image.AFFINE, (1, shear, -lean, 0, 1, 0), resample=Image.BICUBIC)
border = mask.filter(ImageFilter.MaxFilter(outline * 2 + 1))
out = Image.new('RGBA', mask.size, edge + (0,))
out.putalpha(border)
out.alpha_composite(gradient_fill(mask, stops))
return out
def glint(layer, u, width=46):
"""One bright diagonal band crossing a layer once, clipped to its letters; gone when u reaches 1."""
if not 0 < u < 1:
return layer
band = Image.new('L', layer.size, 0)
x = -width + (layer.width + 2 * width) * u
ImageDraw.Draw(band).polygon([(x, 0), (x + width, 0), (x + width - layer.height * .4, layer.height), (x - layer.height * .4, layer.height)], fill=210)
band = band.filter(ImageFilter.GaussianBlur(8))
shine = Image.new('RGBA', layer.size, WHITE + (0,))
shine.putalpha(ImageChops.multiply(band, layer.getchannel('A')))
out = layer.copy()
out.alpha_composite(shine)
return out
class Block:
def __init__(self, key, frames):
self.key, self.cfg, self.frames = key, BLOCKS[key], Path(frames) / key
self.points = json.loads((self.frames / 'points.json').read_text())
logo = Image.open(DESIGNS / self.cfg['channel'] / 'exports' / f"{self.cfg['channel'].replace('-', '_')}_primary.png").convert('RGBA')
self.logo = logo.crop(logo.getbbox())
self.cache = {}
def scene(self, t):
n = min(MOVE, max(1, int(t * FPS) + 1))
if self.cache.get('scene_n') != n:
self.cache['scene_n'], self.cache['scene'] = n, Image.open(self.frames / f'frame_{n:04d}.png').convert('RGBA')
return self.cache['scene'].copy(), self.points[str(n)]
def logo_at(self, width):
key = ('logo', width)
if key not in self.cache:
self.cache[key] = scaled(self.logo, width / self.logo.width)
return self.cache[key]
def channel_logo(self, canvas, t, start, width=700, at=(44, 44)):
place(canvas, self.logo_at(width), at[0], at[1], kf(t, [(start, 0), (start + .5, 1)], ease_io))
def frame(self, t):
canvas, pts = self.scene(t)
getattr(self, f'draw_{self.key}')(canvas, pts, t)
out = Image.new('RGBA', (W, H), (0, 0, 0, 255))
out.alpha_composite(canvas)
return fade_in(out, t)
# ---- Sunday Gold: a ribbon of gold dust writes Sunday --------------------------------------------------------
def draw_sundaygold(self, canvas, pts, t):
self.channel_logo(canvas, t, .3)
word = self.cache.get('sunday')
if word is None:
face = ImageFont.truetype(SCRIPT, 132)
ink = joined('Sunday', face, WHITE + (255,))
word = gradient_fill(ink.getchannel('A'), [(0, (255, 236, 176)), (.5, (240, 192, 80)), (1, (176, 120, 32))])
halo = glow(word, 5, .55) # Paul's 5% note: keep the glow soft and understated
halo.alpha_composite(word)
word = halo.rotate(5, Image.BICUBIC, expand=True)
self.cache['sunday'] = word
x0, y0 = 150, 262
u = kf(t, [(.95, 0), (2.15, 1)], ease_io)
# Before writing, the ribbon's head sweeps in from the planet to where the S begins.
head = None
if .45 < t <= .95:
v = ease_io((t - .45) / .5)
p = pts['planet'] if 'x' in pts['planet'] else {'x': (pts['planet']['left'] + pts['planet']['right']) / 2, 'y': (pts['planet']['top'] + pts['planet']['bottom']) / 2}
sx, sy = p['x'], p['y']
ex, ey = x0 + 30, y0 + word.height * .55
head = (sx + (ex - sx) * v, sy + (ey - sy) * v - 120 * math.sin(math.pi * v))
if u > 0:
edge = round(word.width * u)
mask = Image.new('L', word.size, 0)
ImageDraw.Draw(mask).rectangle((0, 0, edge, word.height), fill=255)
cut = word.copy(); cut.putalpha(ImageChops.multiply(word.getchannel('A'), mask))
place(canvas, cut, x0, y0)
if u < 1:
column = word.getchannel('A').crop((max(0, edge - 3), 0, min(word.width, edge + 3), word.height))
ys = [y for y in range(column.height) for x in range(column.width) if column.getpixel((x, y)) > 180]
head = (x0 + edge, y0 + (sum(ys) / len(ys) if ys else word.height * .6))
if head:
self.sparkle(canvas, head, t)
def sparkle(self, canvas, head, t):
"""The ribbon's head: a soft gold light with a short trail of specks."""
dot = Image.new('RGBA', (90, 90))
d = ImageDraw.Draw(dot)
d.ellipse((33, 33, 57, 57), fill=(255, 240, 196, 255))
dot = glow(dot, 10, 2.2)
d = ImageDraw.Draw(dot); d.ellipse((40, 40, 50, 50), fill=(255, 252, 240, 255))
place(canvas, dot, head[0] - 45, head[1] - 45)
rng = random.Random(int(t * FPS))
d = ImageDraw.Draw(canvas)
for _ in range(10):
dx, dy = -rng.uniform(4, 60), rng.uniform(-18, 18)
r = rng.choice((1, 1.5, 2))
d.ellipse((head[0] + dx - r, head[1] + dy - r, head[0] + dx + r, head[1] + dy + r), fill=(255, 206, 110, rng.choice((90, 140, 200))))
# ---- Scottish Comedy Night: tartan unrolls, tiles drop in, one lands squint and is nudged straight ------------
def draw_scottish(self, canvas, pts, t):
self.channel_logo(canvas, t, .3)
band = self.cache.get('tartan') or self.cache.setdefault('tartan', tartan(1180, 104))
u = kf(t, [(.8, 0), (1.45, 1)], ease_out)
if u > 0:
edge = round(band.width * u)
mask = Image.new('L', band.size, 0)
ImageDraw.Draw(mask).rectangle((0, 0, edge, band.height), fill=255)
cut = band.copy(); cut.putalpha(ImageChops.multiply(band.getchannel('A'), mask))
if u < 1: # the roll still to unfurl, as a darker rounded edge
ImageDraw.Draw(cut).rounded_rectangle((edge - 16, -2, edge + 4, band.height + 2), 9, fill=(40, 12, 54, 255))
turned = cut.rotate(-2, Image.BICUBIC, expand=True)
shadow = Image.new('RGBA', turned.size, (0, 0, 0, 0)); shadow.putalpha(turned.getchannel('A').point(lambda v: v * 150 // 255))
place(canvas, shadow.filter(ImageFilter.GaussianBlur(6)), 54, 488)
place(canvas, turned, 50, 480)
tiles = self.cache.get('tiles') or self.cache.setdefault('tiles', tile_row('SCOTTISH COMEDY NIGHT'))
squint = next(i for i, (c, *_) in enumerate(tiles) if c == 'Y')
for i, (c, tile, x, base_rot) in enumerate(tiles):
at = 1.35 + i * .06
if t < at:
continue
drop = kf(t, [(at, -70), (at + .14, 6), (at + .22, 0)], ease_in)
rot = base_rot
shove = 0
if i == squint:
fix = 1.35 + (i + 1) * .06 + .12 # the next tile lands, and it bumps this one straight
rot = kf(t, [(at, 22), (at + .14, 28), (fix, 28), (fix + .1, -7), (fix + .2, 3), (fix + .3, base_rot)], ease_out)
shove = kf(t, [(fix, 0), (fix + .08, -5), (fix + .2, 0)], ease_out)
turned = tile.rotate(rot, Image.BICUBIC, expand=True)
place(canvas, turned, 140 + x + shove - (turned.width - tile.width) / 2, 508 + drop - (turned.height - tile.height) / 2, kf(t, [(at, 0), (at + .08, 1)]))
# ---- Vortex Movie Night: the rush slows, letterbox bars slide in with sprocket strips, chrome title ----------
def draw_movienight(self, canvas, pts, t):
bar = 92
slide = kf(t, [(1.0, 0), (1.45, 1)], ease_out)
if slide > 0:
d = ImageDraw.Draw(canvas)
top, bottom = -bar + bar * slide, H - bar * slide
d.rectangle((0, 0, W, top + bar), fill=(0, 0, 0, 255))
d.rectangle((0, bottom, W, H), fill=(0, 0, 0, 255))
# The sprocket strips: the tunnel's hoops, flattened into film edge, slowing to a stop.
travel = kf(t, [(1.0, 0), (2.3, 1)], ease_out) * 260
for y in (top + bar * .5, bottom + bar * .5):
d.line((0, y - 14, W, y - 14), fill=(55, 223, 255, 140), width=1)
d.line((0, y + 14, W, y + 14), fill=(55, 223, 255, 140), width=1)
for k in range(-1, 42):
x = k * 34 - travel % 34
d.rounded_rectangle((x, y - 7, x + 18, y + 7), 3, fill=(26, 38, 56, 255))
# Paul's 5% note, more of a feature presentation: the house lights go down (the tunnel dims into a vignette
# inside the frame), the logo sits centred like a studio card, and a presentation line introduces the title.
dim = kf(t, [(1.2, 0), (1.9, 1)], ease_io)
if dim > 0:
vignette = self.cache.get('vignette')
if vignette is None:
vignette = Image.new('L', (W, H), 0)
ImageDraw.Draw(vignette).ellipse((-160, 40, W + 160, H - 40), fill=255)
vignette = ImageChops.invert(vignette.filter(ImageFilter.GaussianBlur(120)))
vignette = vignette.point(lambda v: 90 + v * 165 // 255)
self.cache['vignette'] = vignette
shade = Image.new('RGBA', (W, H), (0, 0, 0, 0)); shade.putalpha(vignette.point(lambda v: round(v * dim * .78)))
inside = canvas.crop((0, bar, W, H - bar)); inside.alpha_composite(shade.crop((0, bar, W, H - bar))); canvas.paste(inside, (0, bar))
logo = self.logo_at(500)
place(canvas, logo, (W - logo.width) / 2 - 20, 112, kf(t, [(1.2, 0), (1.7, 1)], ease_io))
line = self.cache.get('feature') or self.cache.setdefault('feature', text_layer("TONIGHT'S FEATURE PRESENTATION", font('barlow-regular.ttf', 24), (226, 236, 250, 255), 9))
la = kf(t, [(1.6, 0), (2.0, 1)], ease_io)
place(canvas, line, W / 2, 388, la, 'mt')
reach = kf(t, [(1.7, 0), (2.2, 1)], ease_io) * 150
if reach > 0:
d = ImageDraw.Draw(canvas)
for side in (-1, 1):
x = W / 2 + side * (line.width / 2 + 22)
d.line((x, 401, x + side * reach, 401), fill=(55, 223, 255, 200), width=2)
title = self.cache.get('movie_title')
if title is None:
title = chrome('MOVIE NIGHT', font('anton-regular.ttf', 112), 8, [(0, (255, 255, 255)), (.42, (205, 220, 242)), (.5, (70, 92, 132)), (.56, (36, 52, 88)), (1, (196, 214, 240))])
self.cache['movie_title'] = title
a = kf(t, [(1.85, 0), (2.25, 1)], ease_io)
place(canvas, glint(title, kf(t, [(2.5, 0), (2.95, 1)], ease_io)), (W - title.width) / 2, 430 + kf(t, [(1.85, 18), (2.25, 0)], ease_out), a)
# ---- Retro Action: chrome title, a star glint, one VHS tracking line ----------------------------------------
def draw_retro(self, canvas, pts, t):
self.channel_logo(canvas, t, 1.0, 620, (44, 30))
title = self.cache.get('retro_title')
if title is None:
title = chrome('RETRO ACTION', font('anton-regular.ttf', 104), 6, [(0, (155, 231, 255)), (.4, (255, 255, 255)), (.5, (58, 26, 90)), (.56, (255, 95, 176)), (1, (255, 192, 106))], edge=(20, 6, 30))
self.cache['retro_title'] = title
a = kf(t, [(1.4, 0), (1.75, 1)], ease_io)
x, y = 70, 300 + kf(t, [(1.4, -24), (1.75, 0)], ease_out)
place(canvas, title, x, y, a)
# A four-point star twinkles on the last letter, and stays small and still for the hold.
s = kf(t, [(2.0, 0), (2.2, 1.4), (2.5, .8)], ease_out)
if s > 0:
star = self.cache.get('star') or self.cache.setdefault('star', make_star())
st = scaled(star, s)
place(canvas, st, x + title.width - 70 - st.width / 2, y + 18 - st.height / 2)
# One tracking line rolls down through the picture, then it's gone.
u = kf(t, [(2.55, 0), (2.95, 1)], lambda v: v)
if 0 < u < 1:
band_y = round(-30 + (H + 60) * u)
strip = canvas.crop((0, max(0, band_y), W, min(H, band_y + 10)))
if strip.height > 0:
rng = random.Random(int(t * FPS))
shifted = Image.new('RGBA', strip.size)
for row in range(strip.height):
line = strip.crop((0, row, W, row + 1))
shifted.paste(line, (rng.randint(-5, 5), row))
bright = Image.new('RGBA', strip.size, (255, 255, 255, 16)) # Paul's 5% note: subtle, so the road stays the star
shifted.alpha_composite(bright)
canvas.paste(shifted, (0, max(0, band_y)))
# ---- Friday Spooky Teatime: steam becomes a friendly ghost, bats, wobbly title -------------------------------
def draw_spooky(self, canvas, pts, t):
self.channel_logo(canvas, t, .4, 620, (44, 30))
cup = pts['cup']
cx, top = (cup['left'] + cup['right']) / 2, cup['top']
# Steam wisps rise from the tea, then gather into the ghost.
wisps = kf(t, [(1.0, 0), (1.3, 1), (1.85, 1), (2.1, 0)], ease_io)
if wisps > 0:
layer = Image.new('RGBA', (W, H))
d = ImageDraw.Draw(layer)
for k in (-1, 0, 1):
points = []
for j in range(26):
v = j / 25
rise = v * 150 * kf(t, [(1.0, .3), (1.8, 1)], ease_out)
points.append((cx + k * 22 + 12 * math.sin(v * 7 + t * 5 + k) * v, top - rise))
d.line(points, fill=(255, 255, 255, round(150 * wisps)), width=6, joint='curve')
canvas.alpha_composite(layer.filter(ImageFilter.GaussianBlur(3)))
g = kf(t, [(1.75, 0), (2.15, 1)], ease_out)
if g > 0:
ghost = self.cache.get('ghost') or self.cache.setdefault('ghost', make_ghost())
bob = 6 * math.sin((t - 1.75) * 7) * kf(t, [(2.0, 1), (3.0, 0)], ease_io)
wob = 7 * math.sin((t - 1.75) * 11) * kf(t, [(2.0, 1), (2.9, 0)], ease_io)
gs = scaled(ghost, .35 + .65 * g, rot=wob)
place(canvas, gs, cx - gs.width / 2, top - 40 - gs.height + bob, min(1, g * 1.4))
boo = kf(t, [(2.2, 0), (2.3, 1), (2.65, 1), (2.85, 0)], ease_io)
if boo > 0:
word = self.cache.get('boo') or self.cache.setdefault('boo', text_layer('boo!', font('comfortaa.ttf', 40), WHITE + (255,), 2, 3, (60, 30, 90)))
place(canvas, scaled(word, .8 + .2 * boo, rot=-8), cx + gs.width / 2 - 10, top - 40 - gs.height - 10 + bob, boo)
# Bats flap round the planet's ring and come to rest on the title.
title = self.cache.get('spooky_title') or self.cache.setdefault('spooky_title', wobbly('SPOOKY TEATIME'))
tx, ty = 80, 318
for i, (layer, x, y, rot) in enumerate(title):
at = 1.5 + i * .055
a = kf(t, [(at, 0), (at + .1, 1)])
if a <= 0:
continue
w = rot + 9 * math.sin((t - at) * 16) * kf(t, [(at, 1), (at + .6, 0)], ease_io)
hop = kf(t, [(at, 26), (at + .16, -6), (at + .26, 0)], ease_out)
turned = layer.rotate(w, Image.BICUBIC, expand=True)
place(canvas, turned, tx + x - (turned.width - layer.width) / 2, ty + y + hop - (turned.height - layer.height) / 2, a)
perches = [(tx + title[1][1] + 28, ty + title[1][2] + 6), (tx + title[6][1] + 38, ty + title[6][2] + 8), (tx + title[11][1] + 26, ty + title[11][2] + 6)] # on the letters' tops (they carry an 8 px shadow margin)
p = pts['planet']
px, py = (p['left'] + p['right']) / 2, (p['top'] + p['bottom']) / 2
for i, (lx, ly) in enumerate(perches):
start, land = .9 + i * .18, 2.6 + i * .12
if t < start:
continue
if t < land:
v = (t - start) / (land - start)
angle = v * math.tau * .9 + i * 2.1
orbit = (px + 260 * math.cos(angle), py + 90 * math.sin(angle) - 30)
k = ease_in(max(0, (v - .55) / .45))
bx, by = orbit[0] + (lx - orbit[0]) * k, orbit[1] + (ly - orbit[1]) * k
flap = math.sin((t - start) * 30 + i)
place(canvas, make_bat(flap), bx - 24, by - 14)
else:
place(canvas, make_bat(None), lx - 24, ly - 26)
def tartan(w, h, scale=3):
"""The original Orbit Three sett: deep purple ground, the channel's pink, yellow and cyan, woven as a 2/2 twill."""
sett = [((42, 14, 62), 14), ((238, 76, 184), 6), ((42, 14, 62), 3), ((255, 194, 30), 2), ((42, 14, 62), 3), ((56, 216, 255), 5), ((70, 22, 96), 9), ((238, 76, 184), 2)]
sett = sett + sett[-2:0:-1]
stripes = [c for c, n in sett for _ in range(n * scale)]
L = len(stripes)
warp = Image.new('RGB', (L, 1)); weft = Image.new('RGB', (1, L))
for i, c in enumerate(stripes):
warp.putpixel((i, 0), c); weft.putpixel((0, i), c)
warp = warp.resize((L, L)); weft = weft.resize((L, L))
twill = Image.new('L', (L, L))
for y in range(L):
for x in range(L):
twill.putpixel((x, y), 255 if ((x + y) // 2) % 2 else 0)
tile = Image.composite(warp, weft, twill)
cloth = Image.new('RGB', (w, h))
for x in range(0, w, L):
for y in range(0, h, L):
cloth.paste(tile, (x, y))
# Paul's 5% note, more depth: a woven grain, light catching the top fold and shade under it, like real cloth.
rng = random.Random(9)
grain = Image.new('L', (w, h))
gd = ImageDraw.Draw(grain)
for y in range(h):
for x in range(0, w, 2):
gd.point((x + (y % 2), y), fill=rng.randint(0, 255))
grain = grain.filter(ImageFilter.GaussianBlur(.6))
cloth = Image.blend(cloth, ImageChops.overlay(cloth, Image.merge('RGB', (grain, grain, grain))), .35)
shade = Image.new('L', (1, h))
for y in range(h):
v = y / (h - 1)
shade.putpixel((0, y), round(255 * (1.12 - .32 * v + .1 * math.sin(v * math.pi * 3))) if v < 1 else 200)
cloth = ImageChops.multiply(cloth, Image.merge('RGB', [shade.resize((w, h))] * 3).point(lambda q: min(255, q)))
highlight = Image.new('RGBA', (w, h))
hd = ImageDraw.Draw(highlight)
hd.rectangle((0, 4, w, 10), fill=(255, 255, 255, 46)); hd.rectangle((0, h - 12, w, h - 4), fill=(0, 0, 0, 70))
cloth = cloth.convert('RGBA')
cloth.alpha_composite(highlight)
mask = Image.new('L', (w, h), 0)
d = ImageDraw.Draw(mask)
d.rectangle((0, 4, w, h - 4), fill=235)
for x in range(0, w, 7): # a little fringe at the top and bottom edges
d.line((x, 0, x, 6), fill=200); d.line((x + 3, h - 6, x + 3, h), fill=200)
cloth.putalpha(mask)
return cloth
def tile_row(words):
"""THREE's tiles: pink cards with a light edge and white letters, each at its own small tilt."""
rng = random.Random(3)
face = font('barlow-semibold.ttf', 40)
out, x = [], 0
for c in words:
if c == ' ':
x += 20
continue
tile = Image.new('RGBA', (48, 54))
d = ImageDraw.Draw(tile)
d.rectangle((0, 0, 47, 53), fill=(238, 76, 184, 255), outline=(255, 160, 220, 255), width=2)
letter = text_layer(c, face, WHITE + (255,))
tile.alpha_composite(letter, (round((48 - letter.width) / 2), round((54 - letter.height) / 2)))
out.append((c, tile, x, rng.uniform(-4, 4)))
x += 52
return out
def make_star():
star = Image.new('RGBA', (90, 90))
d = ImageDraw.Draw(star)
d.polygon([(45, 0), (51, 39), (90, 45), (51, 51), (45, 90), (39, 51), (0, 45), (39, 39)], fill=(255, 255, 255, 255))
out = glow(star, 6, 1.4)
out.alpha_composite(star)
return out
def make_ghost():
"""A small friendly ghost: a soft white sheet with a wavy hem, two dark eyes and a little o of a mouth."""
w, h = 120, 140
g = Image.new('RGBA', (w, h))
d = ImageDraw.Draw(g)
d.ellipse((10, 0, 110, 100), fill=(250, 248, 255, 255))
d.rectangle((10, 50, 110, 118), fill=(250, 248, 255, 255))
for i in range(4):
x = 10 + i * 25
d.ellipse((x, 106, x + 25, 134), fill=(250, 248, 255, 255) if i % 2 == 0 else (0, 0, 0, 0))
if i % 2:
d.rectangle((x, 106, x + 25, 120), fill=(250, 248, 255, 255))
d.ellipse((x, 112, x + 25, 134), fill=(0, 0, 0, 0))
d.ellipse((38, 40, 52, 60), fill=(30, 18, 50, 255)); d.ellipse((68, 40, 82, 60), fill=(30, 18, 50, 255))
d.ellipse((54, 68, 66, 82), outline=(30, 18, 50, 255), width=3)
soft = glow(g, 8, .9)
soft.alpha_composite(g)
return soft
def make_bat(flap):
"""A tiny bat with a thin lilac rim so it reads against the night: wings beating (flap from -1 to 1), or folded when resting (None)."""
shape = draw_bat(flap)
rim = Image.new('RGBA', shape.size, (170, 130, 230, 0))
rim.putalpha(shape.getchannel('A').filter(ImageFilter.MaxFilter(3)))
rim.alpha_composite(shape)
return rim
def draw_bat(flap):
b = Image.new('RGBA', (48, 40))
d = ImageDraw.Draw(b)
body = (18, 10, 32)
d.ellipse((19, 14, 29, 30), fill=body)
d.polygon([(20, 15), (21, 9), (24, 14)], fill=body); d.polygon([(28, 15), (27, 9), (24, 14)], fill=body)
if flap is None:
d.polygon([(19, 16), (14, 30), (20, 28)], fill=body); d.polygon([(29, 16), (34, 30), (28, 28)], fill=body)
return b
lift = 12 * flap
for side in (-1, 1):
cx = 24 + side * 5
d.polygon([(cx, 18), (24 + side * 23, 18 - lift), (24 + side * 17, 24 - lift * .5), (24 + side * 11, 22), (cx, 26)], fill=body)
return b
def wobbly(words):
"""SPOOKY TEATIME in hand-drawn letters: each one its own size, tilt and height, orange with a purple outline."""
rng = random.Random(31)
out, x = [], 0
for c in words:
if c == ' ':
x += 26
continue
face = font('comfortaa.ttf', rng.choice((70, 74, 78)))
letter = text_layer(c, face, (255, 154, 60, 255), 0, 6, (36, 12, 58))
# Paul's 5% note: enough contrast on any screen, so a soft dark shadow sits behind each letter.
pad = 8
backed = Image.new('RGBA', (letter.width + 2 * pad, letter.height + 2 * pad))
under = Image.new('RGBA', letter.size, (10, 4, 20, 0)); under.putalpha(letter.getchannel('A').point(lambda v: v * 200 // 255))
backed.alpha_composite(under, (pad + 3, pad + 4)); backed = backed.filter(ImageFilter.GaussianBlur(4))
backed.alpha_composite(letter, (pad, pad))
letter = backed
out.append((letter, x - pad, rng.uniform(-8, 8) - pad, rng.uniform(-7, 7)))
x += letter.width - 4 - 2 * pad
return out
# ---- Sound ----------------------------------------------------------------------------------------------------
RATE = riot.RATE
def bell(f, n_sec=1.8):
"""A warm chime: a few slightly inharmonic partials, each dying away at its own rate."""
n, out = int(n_sec * RATE), []
partials = [(1, 1, 2.2), (2.01, .45, 3.5), (2.76, .25, 5), (4.07, .12, 7)]
for i in range(n):
t = i / RATE
out.append(sum(a * math.sin(2 * math.pi * f * m * t) * math.exp(-d * t) for m, a, d in partials) * min(1, t / .004))
return out
def shimmer(n_sec, seed=31):
rng, n = random.Random(seed), int(n_sec * RATE)
noise = [rng.uniform(-1, 1) for _ in range(n)]
high = [a - b for a, b in zip(noise, riot.onepole(noise, .3))]
return [s * .5 * riot.env(i, n, .3, .5) for i, s in enumerate(high)]
def reedy(f, n_sec):
"""A small reed-like note: odd harmonics, a little vibrato, quick attack."""
n, ph, out = int(n_sec * RATE), 0.0, []
for i in range(n):
t = i / RATE
ph += 2 * math.pi * f * (1 + .006 * math.sin(2 * math.pi * 6 * t)) / RATE
out.append((math.sin(ph) + .33 * math.sin(3 * ph) + .2 * math.sin(5 * ph)) * riot.env(i, n, .008, .04))
return out
def pop(n_sec=.14):
n, ph, out = int(n_sec * RATE), 0.0, []
for i in range(n):
t = i / RATE
ph += 2 * math.pi * (900 * math.exp(-28 * t) + 180) / RATE
out.append(math.sin(ph) * math.exp(-22 * t) * min(1, t / .002))
return out
def falling_whoosh(n_sec=1.3, seed=32):
rng, n = random.Random(seed), int(n_sec * RATE)
raw, out, y = [rng.uniform(-1, 1) for _ in range(n)], [], 0.0
for i in range(n):
u = i / n
y += (.25 * (1 - u) ** 2 + .01) * (raw[i] - y)
out.append(y * 2.5 * riot.env(i, n, .05, .4))
return out
def stab(f=55, n_sec=.5):
"""A synth-bass stab: a saw built from harmonics, its brightness closing quickly."""
n, out = int(n_sec * RATE), []
for i in range(n):
t = i / RATE
bright = 2 + 14 * math.exp(-9 * t)
s = sum(math.sin(2 * math.pi * f * k * t) / k * math.exp(-k / bright) for k in range(1, 18))
out.append(s * math.exp(-3 * t) * riot.env(i, n, .004, .08))
return out
def gated_drum(seed=33):
"""A big drum with a big room, cut off sharply: the 80s gated sound, made here from noise and a pitched thump."""
hit = riot.thump(.3, 140, 55, .9, seed)
rng = random.Random(seed)
room = riot.onepole([rng.uniform(-1, 1) * math.exp(-4 * i / RATE) for i in range(int(.26 * RATE))], .25)
out = [0.0] * int(.3 * RATE)
for i, s in enumerate(hit[:len(out)]):
out[i] += s
for i, s in enumerate(room):
out[i] += s * 1.6 * (1 if i < int(.22 * RATE) else max(0, 1 - (i - int(.22 * RATE)) / (.04 * RATE)))
return out
def clink():
n, out = int(.5 * RATE), []
for i in range(n):
t = i / RATE
out.append((math.sin(2 * math.pi * 2650 * t) + .6 * math.sin(2 * math.pi * 3980 * t) + .3 * math.sin(2 * math.pi * 5310 * t)) * math.exp(-11 * t) * min(1, t / .001))
return out
def wooo(n_sec=.9):
"""A soft, silly ghost: a sine sliding up and back down, with a wide wobble and a breath of noise."""
rng, n, ph, out = random.Random(34), int(n_sec * RATE), 0.0, []
for i in range(n):
t = i / RATE
f = (420 + 220 * math.sin(math.pi * t / n_sec)) * (1 + .04 * math.sin(2 * math.pi * 5 * t))
ph += 2 * math.pi * f / RATE
out.append((math.sin(ph) + .08 * rng.uniform(-1, 1)) * riot.env(i, n, .12, .3))
return out
JIG = [587.3, 659.3, 784.0, 880.0, 784.0, 987.8] # a little rising pentatonic run
SOUNDS = {
'sundaygold': lambda: riot.mix(LENGTH, [(.95, shimmer(1.2), .25), (1.0, bell(659.3), .5), (1.6, bell(523.3), .45)]),
'scottish': lambda: riot.mix(LENGTH, [(1.35 + i * .1, reedy(f, .12), .4) for i, f in enumerate(JIG)] + [(1.35 + 14 * .06 + .12, pop(), .6)]),
'movienight': lambda: riot.mix(LENGTH, [(0, falling_whoosh(), .6), (1.4, riot.thump(.5, 70, 32, .3, 35), .8)]),
'retro': lambda: riot.mix(LENGTH, [(1.4, stab(), .5), (1.4, gated_drum(), .7)]),
'spooky': lambda: riot.mix(LENGTH, [(.95, clink(), .35), (1.85, wooo(), .45)]),
}
# ---- Guide cards ----------------------------------------------------------------------------------------------
def guide_lines(key):
if key == 'sundaygold':
face = ImageFont.truetype(SCRIPT, 64)
ink = joined('Sunday', face, WHITE + (255,))
return [gradient_fill(ink.getchannel('A'), [(0, (255, 236, 176)), (1, (200, 140, 40))])]
if key == 'scottish':
return [text_layer('SCOTTISH', font('barlow-semibold.ttf', 30), (255, 194, 30, 255), 3), text_layer('COMEDY NIGHT', font('barlow-semibold.ttf', 24), (255, 160, 220, 255), 2)]
if key == 'movienight':
return [chrome('MOVIE', font('anton-regular.ttf', 40), 2, [(0, (255, 255, 255)), (.45, (205, 220, 242)), (.5, (70, 92, 132)), (1, (196, 214, 240))], outline=3), chrome('NIGHT', font('anton-regular.ttf', 40), 2, [(0, (255, 255, 255)), (.45, (205, 220, 242)), (.5, (70, 92, 132)), (1, (196, 214, 240))], outline=3)]
if key == 'retro':
stops = [(0, (155, 231, 255)), (.4, (255, 255, 255)), (.5, (58, 26, 90)), (.56, (255, 95, 176)), (1, (255, 192, 106))]
return [chrome('RETRO', font('anton-regular.ttf', 40), 2, stops, (20, 6, 30), outline=3), chrome('ACTION', font('anton-regular.ttf', 40), 2, stops, (20, 6, 30), outline=3)]
if key == 'spooky':
return [text_layer('SPOOKY', font('comfortaa.ttf', 32), (255, 154, 60, 255), 0, 2, (44, 16, 70)), text_layer('TEATIME', font('comfortaa.ttf', 32), (255, 154, 60, 255), 0, 2, (44, 16, 70))]
def guide_card(key, d, stem):
channel = BLOCKS[key]['channel']
epg = Image.open(DESIGNS / channel / 'exports' / f"{channel.replace('-', '_')}_epg.png").convert('RGBA')
epg = scaled(epg.crop(epg.getbbox()), .74)
card = Image.new('RGBA', (512, 160))
card.alpha_composite(epg, (10, round((160 - epg.height) / 2)))
lines = guide_lines(key)
total = sum(l.height for l in lines) + 6 * (len(lines) - 1)
y = (160 - total) / 2
for layer in lines:
layer = scaled(layer, min(1, 170 / layer.width))
card.alpha_composite(layer, (318, round(y)))
y += layer.height + 6
card.save(d / 'exports' / f'{stem}_guide.png')
card.resize((256, 80), Image.LANCZOS).save(d / 'exports' / f'{stem}_guide_app.webp', quality=90)
def build(key, frames):
cfg = BLOCKS[key]
d = HERE / cfg['folder']
for sub in ('exports', 'review'):
(d / sub).mkdir(parents=True, exist_ok=True)
stem = Path(cfg['folder']).name.replace('-', '_')
block = Block(key, frames)
tmp = d / 'review' / '.frames'
if tmp.exists():
shutil.rmtree(tmp)
tmp.mkdir()
rendered = []
for i in range(int(LENGTH * FPS)):
f = block.frame(i / FPS).convert('RGB')
f.save(tmp / f'{i:04d}.png')
rendered.append(f)
rendered[-1].save(d / 'review' / f'{stem}_final_still.png')
silent = d / 'exports' / f'{stem}_ident.mp4'
encode = ['-an', '-vf', 'fps=30', '-c:v', 'libx264', '-profile:v', 'main', '-pix_fmt', 'yuv420p', '-preset', 'veryslow', '-tune', 'animation', '-crf', riot.CRF, '-maxrate', '1400k', '-bufsize', '2800k', '-movflags', '+faststart']
subprocess.run(['ffmpeg', '-y', '-v', 'error', '-framerate', str(FPS), '-i', str(tmp / '%04d.png'), *encode, str(silent)], check=True)
sting = d / 'exports' / f'{stem}_sting.wav'
samples = SOUNDS[key]()
riot.write_wav(sting, samples)
measured = riot.loudness(sting)
riot.write_wav(sting, samples, -14.0 + min(riot.STING_LUFS - measured['integratedLufs'], riot.STING_PEAK - measured['truePeakDbfs']))
with_sound = d / 'review' / f'{stem}_preview_with_sound.mp4'
subprocess.run(['ffmpeg', '-y', '-v', 'error', '-i', str(silent), '-i', str(sting), '-map', '0:v', '-map', '1:a', '-c:v', 'copy', '-c:a', 'aac', '-b:a', '96k', '-shortest', '-movflags', '+faststart', str(with_sound)], check=True)
shutil.copy(silent, d / 'review' / f'{stem}_preview_silent.mp4')
guide_card(key, d, stem)
picks = [0, .5, 1.0, 1.4, 1.8, 2.2, 2.6, 3.0, LENGTH - 1 / FPS]
sheet = Image.new('RGB', (1920, 1080 + 70), (7, 22, 50))
ImageDraw.Draw(sheet).text((20, 16), f"{cfg['title']} / block ident preview, {LENGTH:.0f} s", font=font('barlow-semibold.ttf', 32), fill='white')
for n, t in enumerate(picks):
tile = rendered[min(len(rendered) - 1, round(t * FPS))].resize((640, 360), Image.LANCZOS)
riot.label(tile, f'{t:.1f} s' if n < 8 else 'final hold', 22)
sheet.paste(tile, ((n % 3) * 640, 70 + (n // 3) * 360))
sheet.save(d / 'review' / f'{stem}_contact_sheet.png')
report = dict(status='preview-not-integrated', block=cfg['title'], seconds=LENGTH, fps=FPS, size=[W, H], crf=riot.CRF,
identBytes=silent.stat().st_size, ssim=riot.ssim(silent, tmp), guideAppBytes=(d / 'exports' / f'{stem}_guide_app.webp').stat().st_size,
finalHoldStillForHalfSecond=riot.hold_check(rendered), flash=riot.flash_check(silent), sting=riot.loudness(sting))
(d / 'review' / 'checks.json').write_text(json.dumps(report, indent=1))
shutil.rmtree(tmp)
print(json.dumps(report))
def review_board():
"""One page for Paul: each block's final hold frame and its guide card at app size and at 2x."""
small, big = font('barlow-semibold.ttf', 22), font('barlow-semibold.ttf', 30)
board = Image.new('RGB', (1920, 100 + len(BLOCKS) * 400), (7, 22, 50))
d = ImageDraw.Draw(board)
d.text((40, 30), 'Batch 3 block idents, previews: final hold frames and guide cards', font=font('barlow-semibold.ttf', 36), fill='white')
for i, (key, cfg) in enumerate(BLOCKS.items()):
folder, stem, y = HERE / cfg['folder'], Path(cfg['folder']).name.replace('-', '_'), 100 + i * 400
still = folder / 'review' / f'{stem}_final_still.png'
if not still.exists():
continue
board.paste(Image.open(still).resize((640, 360), Image.LANCZOS), (40, y))
d.text((720, y), cfg['title'], font=big, fill='white')
d.text((720, y + 46), 'Guide card at app size (256x80) on the guide panel, then at 2x', font=small, fill=(183, 203, 232))
card = Image.open(folder / 'exports' / f'{stem}_guide_app.webp').convert('RGBA')
for (x, w, h, size, at) in [(720, 300, 110, (256, 80), (22, 15)), (1060, 560, 200, (512, 160), (24, 20))]:
panel = Image.new('RGBA', (w, h), (18, 53, 107, 255))
panel.alpha_composite(card.resize(size, Image.LANCZOS), at)
board.paste(panel.convert('RGB'), (x, y + 96))
board.save(HERE / 'batch3_review.png')
if __name__ == '__main__':
frames = sys.argv[1]
for key in sys.argv[2:] or list(BLOCKS):
build(key, frames)
review_board()