mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
His notes: the hero moment needed to be exciting, and the legend needed visuals. The hero clip is now one entire session that loops. The sea comes up with the work and settles, subagents arrive as kittens and swim off when they report back, stars light as the plan gets done, the moon wanes and sinks as the context window fills, the companion asks for permission and later reports it is finished, and then the context is compacted and the list starts over, which is what puts the scene back where it opened. The day turns underneath the whole thing. The agent's own transcript scrolls above it, printed from the same events. Sixteen seconds, a hundred and sixty frames, no cuts. Making that possible took three things. A clip can now run its session on its own clock while the waves keep real time, so a whole arc fits in seconds without the water looking sped up. A clip can ramp the time of day across its length. And a long clip is captured across several pages, because one page of every frame outgrew what a headless screenshot takes. The legend section, now How to read it, has nine dissected clips, one per row: the same renderer cropped to the one part of the scene that carries that fact. The moon and the stars run at night because the scene washes both out at midday on purpose, which is why the first cut of those two came back empty. Everything below the hero loads lazily. The page is six megabytes of animation and a phone should not fetch all of it at once. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCZwNPxGTvpCSRLXPzGSam
90 lines
4.0 KiB
Python
90 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Encode the site's animated clips from the frame pages the engine writes.
|
|
|
|
go run . -gifs site/anim # one HTML page per clip, frames stacked
|
|
python3 site/make-gifs.py # captures each page once, slices, encodes
|
|
|
|
Each page holds every frame of a clip under a magenta separator (site/anim/
|
|
manifest.json says how many). One headless Chrome screenshot per page, sliced
|
|
on the separators, quantised to one 256-colour palette per clip without
|
|
dithering (the frames are flat cells), written as GIF, then gifsicle -O3.
|
|
Needs Pillow and gifsicle; Chrome at the usual path.
|
|
"""
|
|
import json, os, subprocess, sys
|
|
from PIL import Image
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ANIM = os.path.join(HERE, 'anim')
|
|
CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
|
MAGENTA = (255, 0, 255)
|
|
|
|
def capture(page, png, width, height):
|
|
subprocess.run([CHROME, '--headless=new', '--disable-gpu', '--use-mock-keychain',
|
|
'--password-store=basic', '--hide-scrollbars', '--force-device-scale-factor=1',
|
|
f'--window-size={width},{height}', f'--screenshot={png}', f'file://{page}'],
|
|
check=True, capture_output=True)
|
|
|
|
def slices(im):
|
|
"""Frame boxes between magenta separators: (x0, x1) from the separator's run, y ranges between."""
|
|
w, h = im.size
|
|
px = im.load()
|
|
seps = []
|
|
y = 0
|
|
while y < h:
|
|
if px[2, y] == MAGENTA:
|
|
y0 = y
|
|
while y < h and px[2, y] == MAGENTA:
|
|
y += 1
|
|
seps.append((y0, y))
|
|
else:
|
|
y += 1
|
|
if len(seps) < 2:
|
|
sys.exit('no separators found; is the page rendered?')
|
|
# The frame's own width: each frame box ends in a magenta right border,
|
|
# so the art is everything left of the first magenta pixel on a row
|
|
# inside the box (the sand's black rows carry no magenta).
|
|
boxes = []
|
|
for i in range(len(seps) - 1):
|
|
top, bottom = seps[i][1], seps[i + 1][0]
|
|
ym = (top + bottom) // 2
|
|
x1 = 0
|
|
while x1 < w and px[x1, ym] != MAGENTA:
|
|
x1 += 1
|
|
boxes.append((0, top, x1, bottom))
|
|
return boxes
|
|
|
|
def main():
|
|
manifest = json.load(open(os.path.join(ANIM, 'manifest.json')))
|
|
for clip in manifest:
|
|
name, n, fps, px_ = clip['name'], clip['frames'], clip['fps'], clip.get('px', 12)
|
|
# Each clip carries its own geometry: the window clip is wider than the
|
|
# design size and taller, because it shows the agent's rows too.
|
|
rows, cols = clip.get('rows', 24), clip.get('cols', 80)
|
|
# A long clip is split over several pages, each captured and sliced on
|
|
# its own, because one page of every frame outgrows what a headless
|
|
# screenshot will take.
|
|
width = max(900, int(cols * px_ * 0.6) + 80)
|
|
frames = []
|
|
for p in range(clip.get('pages', 1)):
|
|
page = os.path.join(ANIM, f'{name}.{p}.html')
|
|
png = os.path.join(ANIM, f'{name}.{p}.png')
|
|
here = min(n - len(frames), (15000 // (rows * px_ + 4)) or 1)
|
|
capture(page, png, width, here * (rows * px_ + 4) + 8)
|
|
im = Image.open(png).convert('RGB')
|
|
frames += [im.crop(b) for b in slices(im)]
|
|
os.remove(png)
|
|
if len(frames) != n:
|
|
sys.exit(f'{name}: sliced {len(frames)} frames, manifest says {n}')
|
|
pal = frames[0].quantize(colors=255, method=Image.Quantize.MEDIANCUT, dither=Image.Dither.NONE)
|
|
q = [f.quantize(palette=pal, dither=Image.Dither.NONE) for f in frames]
|
|
raw = os.path.join(ANIM, name + '.raw.gif')
|
|
q[0].save(raw, save_all=True, append_images=q[1:], duration=int(1000 / fps), loop=0,
|
|
optimize=False, disposal=1)
|
|
out = os.path.join(ANIM, name + '.gif')
|
|
subprocess.run(['gifsicle', '-O3', '--no-warnings', '-o', out, raw], check=True)
|
|
os.remove(raw)
|
|
print(f'{name}.gif {n} frames {frames[0].size[0]}x{frames[0].size[1]} {os.path.getsize(out)//1024} KB')
|
|
|
|
if __name__ == '__main__':
|
|
main()
|