"""Render the original Studio launch projects with Python, Pillow and FFmpeg.""" from functools import lru_cache import argparse import math import random import subprocess from pathlib import Path from PIL import Image, ImageDraw, ImageFont W, H = 960, 600 TAU = math.tau def background(top, bottom): image = Image.new("RGB", (W, H)) draw = ImageDraw.Draw(image) for y in range(H): f = y / H draw.line((0, y, W, y), fill=tuple(round(a + (b - a) * f) for a, b in zip(top, bottom))) return image, draw def font(size, mono=False): # Pillow's built-in DejaVu lookup works on machines with the font installed. name = "DejaVuSansMono.ttf" if mono else "DejaVuSans-Bold.ttf" try: return ImageFont.truetype(name, size) except OSError: path = "/System/Library/Fonts/Menlo.ttc" if mono else "/System/Library/Fonts/Avenir Next.ttc" return ImageFont.truetype(path, size, index=0 if mono else 2) def after_hours(t): # Apply a depth-weighted horizontal drift, anchoring the horizon behind the road. from PIL import ImageOps with Image.open(Path(__file__).with_name("desert-drive.webp")) as plate: scale = 1 + .035 * (1 - math.cos(TAU * t)) / 2 wide = ImageOps.fit(plate, (round(W * scale), round(H * scale))) left, top = (wide.width-W)//2, (wide.height-H)//2 image = wide.crop((left, top, left+W, top+H)).convert("RGB") # Sample inside the overscan. Distant sky holds, near road travels faster. plate=image.resize((W+20,H),Image.Resampling.LANCZOS) for y in range(0,H,3): depth=max(0,(y-H*.54)/(H*.46)) dx=10+round(8*depth*math.sin(TAU*t)) image.paste(plate.crop((dx,y,dx+W,min(y+3,H))),(0,y)) draw = ImageDraw.Draw(image) draw.text((39, 40), "AFTER HOURS", font=font(67), fill="#fff0d7", stroke_width=1, stroke_fill="#302b3b") return image OUTPOST_TERRACES = [ (-170, -180, -44, 365, 352, 43, ("#7bae91", "#345e60", "#4b7770")), (-151, -160, -1, 322, 299, 25, ("#a0bea0", "#426b61", "#709080")), (-112, -124, 24, 222, 222, 20, ("#c5ca9e", "#5a8270", "#8da382")), ] OUTPOST_TOWER = (-65, -98, 44, 124, 104, 76, ("#e5d7ae", "#a0a484", "#eee3be")) @lru_cache(maxsize=1) def outpost_source(): import runpy source = Path(__file__).with_name("outpost-scene.txt") return runpy.run_path(str(source)) def observatory(t): return outpost_source()["frame"](t) SPRITE = [ ".......ccccc....", ".....ccrrrrcc...", "....crrrrrrrrc..", "....crrrrrrrrc..", "...ccyyyyyyycc..", "...cyybyybyyc...", "....cyyyyyyc....", ".....cccccc.....", "....cgccggc.....", "...cggcggggc....", "...cggcggggcc...", "....cccccccc....", ".....cgc.cgc....", ".....cgc.cgc....", "....ccc..ccc....", ] PALETTE = {"c": "#201a38", "r": "#f17368", "y": "#ffd798", "b": "#3b2843", "g": "#76d3bd"} def paint_sprite(d, x, y, scale, phase): for j, line in enumerate(SPRITE): for i, color in enumerate(line): if color == ".": continue stride = int(phase * (1 if i < 8 else -1)) if j >= 12 else 0 d.rectangle((x + i*scale, y + (j+stride)*scale, x + (i+1)*scale-1, y + (j+stride+1)*scale-1), fill=PALETTE[color]) def courier_pose(index): frame=Image.new("RGBA",(32,32)) d=ImageDraw.Draw(frame) ink="#282234" lift=(0,0,-1,-1,0,0,-1,-1)[index] stride=(0,2,4,2,0,-2,-4,-2)[index] def shape(points,color): d.polygon([(x,y+lift) for x,y in points],fill=color,outline=ink) for side in (-1,1): knee=(16+side*stride,24+lift) foot=(15+side*stride*1.5,29-(1 if side*stride<0 else 0)) d.line([(16+side*2,21+lift),knee,foot],fill=ink,width=4) d.line([(16+side*2,21+lift),knee,(foot[0],foot[1]-1)],fill="#525264" if side<0 else "#718288",width=2) d.line([foot,(foot[0]+3,foot[1])],fill="#513a38",width=2) # Brass clasp and cream envelope against a dark leather mail satchel. shape([(8,13),(14,12),(16,18),(13,23),(6,21),(6,15)],"#996343") d.rectangle((7,14+lift,12,16+lift),fill="#f2cea1") shape([(14,12),(18,12),(22,16),(20,23),(11,23),(12,17)],"#4b897a") d.line([(16,13+lift),(13,21+lift)],fill="#e5ae73",width=2) shape([(14,6),(20,5),(22,8),(22,10),(24,11),(21,13),(17,13),(14,11)],"#e3a274") d.point((20,9+lift),fill=ink) d.line((15,10+lift,15,12+lift),fill="#69483e",width=2) shape([(11,6),(13,3),(19,2),(22,4),(21,6),(25,6),(25,7),(13,8)],"#c75d55") d.line((14,4+lift,19,3+lift),fill="#f5aa75") d.point((20,5+lift),fill="#ffe1a1") tail=round(math.sin(index*TAU/8)*2) shape([(17,12),(15,15),(10,14),(5,15+tail),(4,13+tail),(10,12)],"#db735b") d.line([(19,15+lift),(21+stride//2,18+lift),(23+stride//2,18+lift)],fill="#30484c",width=3) d.point((23+stride//2,18+lift),fill="#ffca91") return frame def courier(t): scene=Image.new("RGB",(192,120),"#293448") d=ImageDraw.Draw(scene) for x in range(-16,210,26): d.polygon([(x,52),(x+13,38),(x+26,52),(x+26,76),(x,76)],fill="#41485a") d.line((x,53,x+26,53),fill="#767182") for k in (5,15): d.rectangle((x+k,57,x+k+3,62),fill="#d8a778") d.rectangle((0,76,191,119),fill="#424859") for row in range(4): y=82+row*10 for x in range(-20,200,25): u=x+10*(row%2);d.line((u,y,u+17,y),fill="#656575") # Platform canopy, cast-iron brackets, station clock and amber lanterns. for x in (12,159): d.rectangle((x,4,x+4,88),fill="#252e40") d.line((x+5,27,x+24,11),fill="#3c4552",width=3) d.rectangle((x-2,84,x+7,89),fill="#252e40") d.rectangle((0,5,191,12),fill="#222b3b") for x in (30,85,139): d.line((x,12,x,17),fill="#394657") d.polygon([(x-5,19),(x,16),(x+5,19),(x+3,25),(x-3,25)],fill="#efd19c",outline="#635958") d.ellipse((163,23,182,42),fill="#cdb48b",outline="#252e40",width=2) d.line([(172,26),(172,32),(177,34)],fill="#524853") d.ellipse((66,99,124,105),fill="#343b4d") sprite=courier_pose(int(t*8)%8).resize((70,70),Image.Resampling.NEAREST) scene.paste(sprite,(60,36),sprite) return scene.resize((W,H),Image.Resampling.NEAREST) def make_study(name, frame, motion, output): """Create a contact sheet for motion or a two-panel composition study.""" image = Image.new("RGB", (W, H), "#181b25") draw = ImageDraw.Draw(image) label = name.replace("-", " ").upper() draw.text((34, 26), label, font=font(27), fill="#f8ecd9") draw.text((36, 67), "KEY FRAMES" if motion else "COMPOSITION STUDY", font=font(14, True), fill="#e9b982") if motion: for index, phase in enumerate((0, .25, .5, .75)): x, y = 77 + index % 2 * 451, 101 + index // 2 * 245 image.paste(frame(phase).resize((352, 220), Image.Resampling.LANCZOS), (x, y)) draw.text((x,y+225), f"{phase*3:.2f} s", font=font(16, True), fill="#e0d9d4") else: original = frame(0) image.paste(original.resize((554, 346), Image.Resampling.LANCZOS), (34, 128)) crop = original.crop((360, 215, 635, 490)).resize((262, 262), Image.Resampling.LANCZOS) image.paste(crop, (625, 128)) draw.text((34, 490), "FULL FRAME", font=font(15, True), fill="#e0d9d4") draw.text((625, 405), "CENTER DETAIL", font=font(15, True), fill="#e0d9d4") image.save(output / (name + "-study.webp"), quality=85, method=6) def save_workflow_asset(name, out): if name == "copper-hopper": sheet = Image.new("RGBA", (HOPPER_FRAMES*HOPPER_CELL,HOPPER_CELL)) for i in range(HOPPER_FRAMES): sheet.paste(hopper_frame(i),(i*HOPPER_CELL,0)) sheet.save(out / "copper-hopper-sheet.png") if name == "cinder-courier": sheet=Image.new("RGBA",(256,32)) for i in range(8): sheet.paste(courier_pose(i),(i*32,0)) sheet.save(out/"cinder-courier-walk.png") def point(cx, cy, rx, ry, angle): return cx + rx * math.cos(angle), cy + ry * math.sin(angle) HOPPER_FRAMES = 8 HOPPER_CELL = 48 def hopper_frame(frame): """Side-on clockwork frog. All poses share a fixed ground contact at y=45.""" image=Image.new("RGBA",(HOPPER_CELL,HOPPER_CELL)) d=ImageDraw.Draw(image) y=(0,2,0,-5,-8,-6,-2,1)[frame] toe=(0,-2,1,5,6,4,2,0)[frame] ink="#292630" def face(points,color): d.polygon([(x,h+y) for x,h in points],fill=color,outline=ink) def joint(x,h,r): d.ellipse((x-r,h+y-r,x+r,h+y+r),fill="#a46348",outline=ink) d.point((x-1,h+y-1),fill="#ffe5a2") # Far leg, rear oil reservoir, riveted shell and protective brow. face([(11,31),(20,32),(22,38),(15,40),(9,38)],"#614650") face([(6,32),(6,27),(10,23),(17,22),(20,28),(17,34),(10,36)],"#996044") face([(11,25),(17,19),(25,16),(31,17),(34,24),(29,32),(18,35),(11,31)],"#be784b") d.line([(12,27+y),(18,21+y),(26,18+y),(30,19+y)],fill="#f6cc82",width=2) for x in (17,21,25): d.line((x,25+y,x-2,30+y),fill="#75444a",width=2) face([(24,24),(25,16),(30,12),(36,12),(39,17),(43,20),(42,25),(35,28),(29,28)],"#d69a67") d.line([(31,13+y),(36,13+y),(39,17+y)],fill="#ffe6a0") d.rectangle((29,17+y,39,22+y),fill=ink) d.rectangle((32,18+y,38,20+y),fill="#93ebc8") d.point((38,18+y),fill="#f0ffe1") d.line((36,25+y,41,24+y),fill=ink) # Two hinged limbs with a polished piston rod between the larger knuckles. hip=(17,30+y); knee=(8,36+y); ankle=(17-toe//2,40+y//2); foot=(24+toe,44+min(y,0)) d.line([hip,knee,ankle,foot],fill=ink,width=5) d.line([hip,knee],fill="#d89559",width=3) d.line([knee,ankle],fill="#aac5b2",width=2) d.line([ankle,foot],fill="#bb7954",width=3) d.line([foot,(foot[0]+5,foot[1])],fill=ink,width=2) joint(17,30,3); joint(8,36,2) d.line([(33,28+y),(29,34+y),(35,40+y//2),(40,40+y//2)],fill=ink,width=3) d.line([(30,34+y),(35,39+y//2)],fill="#d19763") return image def copper_hopper(t): small=Image.new("RGB",(160,100),"#293c40") d=ImageDraw.Draw(small) # Old pump gallery: window ribs, water pipes, floor grating, reflected light. for x in range(-8,170,32): d.rectangle((x,10,x+26,52),fill="#47605b") d.rectangle((x+3,14,x+23,45),fill="#799284") d.polygon([(x+4,16),(x+16,16),(x+4,39)],fill="#afba96") d.line((x+13,14,x+13,46),fill="#475e59",width=2) d.rectangle((x,54,x+29,56),fill="#152f38") for y in (61,67): d.line((0,y,159,y),fill="#182c35",width=4) d.line((0,y-1,159,y-1),fill="#876955") for x in range(6,160,23): d.rectangle((x,y-2,x+2,y+1),fill="#a57f63") d.rectangle((0,77,160,99),fill="#465456") for x in range(-32,180,8): d.line((x,78,x-12,100),fill="#283e45",width=2) d.line((0,77,159,77),fill="#c6af82",width=2) d.ellipse((45,78,117,85),fill="#233339") frog=hopper_frame(int(t*HOPPER_FRAMES)%HOPPER_FRAMES).resize((80,80),Image.Resampling.NEAREST) small.paste(frog,(40,8),frog) return small.resize((W,H),Image.Resampling.NEAREST) @lru_cache(maxsize=8) def studio_plate(name): with Image.open(Path(__file__).with_name(name+".webp")) as source: return source.convert("RGB").resize((W,H),Image.Resampling.LANCZOS) def type_foundry(t): im=studio_plate("press-bed").copy() d=ImageDraw.Draw(im) cue=min(2,int(t*3)) phase=t*3-cue ink=("#303636","#a44836","#293e47")[cue] # Registration marks stay fixed while individual letters strike the paper. for x,y in ((92,97),(615,97),(92,435),(615,435)): d.line((x-7,y,x+7,y),fill="#846e54");d.line((x,y-7,x,y+7),fill="#846e54") d.text((101,118),"TYPE FOUNDRY",font=font(18,True),fill="#6c5949") word=("CAST","PRESS","PRINT")[cue] x=98 for j,char in enumerate(word): y=213-round(15*min(1,max(0,1-phase*7+j*.18))**2) d.text((x,y),char,font=font(112),fill=ink,stroke_width=1,stroke_fill=ink) x+=round(d.textlength(char,font=font(112)))+1 d.line((103,380,592,380),fill=ink,width=2) d.text((103,394),("01 FORM THE LETTER","02 SET THE IMPRESSION","03 PULL THE PROOF")[cue],font=font(16,True),fill=ink) return im def tidal_engine(t): # A side-on engineering plate keeps the piston and crank in the same plane. im,d=background((234,223,193),(204,196,169)) ink="#35494a";metal="#538680";shadow="#375952";brass="#bc8452";light="#e2bd80" d.text((52,40),"TIDAL ENGINE",font=font(43),fill=ink) d.text((54,99),"SINGLE-ACTING PUMP",font=font(17,True),fill=ink) base=445 for x,w in ((145,221),(458,348)): d.rounded_rectangle((x,base-18,x+w,base+12),radius=6,fill=shadow,outline=ink,width=3) d.rectangle((x-12,base+13,x+w+12,base+25),fill="#887768",outline=ink,width=2) cx,cy=284,300 # Crank and slider share a rigid rod of length 276 pixels. a=TAU*t px,py=cx+65*math.cos(a),cy+65*math.sin(a) slide=px+math.sqrt(276**2-(py-cy)**2) d.polygon([(cx-67,base-19),(cx-22,cy-12),(cx+23,cy-12),(cx+69,base-19)],fill=metal,outline=ink,width=4) for x in (596,660,735): d.polygon([(x-15,base-19),(x-9,342),(x+9,342),(x+15,base-19)],fill=metal,outline=ink,width=3) d.rounded_rectangle((558,249,781,352),radius=17,fill=metal,outline=ink,width=4) d.rectangle((570,265,769,329),fill="#2e4346",outline=light,width=3) d.rectangle((slide,288,slide+100,310),fill="#d5bf96",outline=ink,width=2) d.rectangle((slide+80,268,slide+103,326),fill=brass,outline=ink,width=3) for i in range(8): b=a+TAU*i/8 d.line([(cx,cy),point(cx,cy,123,123,b)],fill=ink,width=16) d.line([(cx,cy),point(cx,cy,122,122,b)],fill=metal,width=9) for r,col,width in ((130,ink,16),(125,brass,10),(117,light,3)): d.ellipse((cx-r,cy-r,cx+r,cy+r),outline=col,width=width) d.ellipse((cx-21,cy-21,cx+21,cy+21),fill=brass,outline=ink,width=3) d.line([(px,py),(slide,cy)],fill=ink,width=19);d.line([(px,py),(slide,cy)],fill=light,width=11) for x,y in ((px,py),(slide,cy)): d.ellipse((x-11,y-11,x+11,y+11),fill=brass,outline=ink,width=3) for x in (570,766): for y in (258,342):d.ellipse((x-4,y-4,x+4,y+4),fill=light,outline=ink) d.line((78,509,884,509),fill="#9e9882") d.text((78,525),"CRANK 65 px",font=font(17,True),fill=ink) d.text((367,525),"ROD 276 px",font=font(17,True),fill=ink) d.text((662,525),"STROKE 130 px",font=font(17,True),fill=ink) return im def phase_loom(t): image=Image.new("RGB",(W,H),"#092a36") d=ImageDraw.Draw(image) count=18 for i in range(count): o=i/(count-1) pts=[] for x in range(-4,W+5,3): a=TAU*(x/W+t) pts.append((x,H*(.40+.15*math.sin(a+o*2.4)+.07*math.cos(2*a+o)+o*.24))) d.line(pts,fill="#f7d799" if i%5==0 else "#95e5d0" if i