An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(strip, shot): --query (tags on sheets); a swipe beat's empty first frame taken at 0.2 s
yzrcad1ee73c84e
diff --git a/.claude/skills/papermorph/scripts/shot.py b/.claude/skills/papermorph/scripts/shot.pyindex 7ef0212..fa6a9b5 100644--- a/.claude/skills/papermorph/scripts/shot.py+++ b/.claude/skills/papermorph/scripts/shot.py@@ -7,7 +7,7 @@uv run --with playwright --with pillow shot.py ch01 --out OUT --cuts # cut sheet of a picture bookuv run --with playwright --with pillow shot.py ch01 --out OUT --cuts scene3 # only the cuts into and out of scene3uv run --with playwright --with pillow shot.py ch01 --out books/<book>/review/stills 2:9 --webp 1400 --name still-ch01 # copy the .webp to site/<book>/img/- ... --url http://localhost:8765/<book>/+ ... --url http://localhost:8765/<book>/ [--query tags]A moment is BEAT:TIME. BEAT is the beat's index in BEATS counted from 0 (the player shows BEAT+1) or its id;TIME is seconds on the beat clock, open (1.2 s), mid (half the beat) or end (the beat's last frame, P.end - 0.05:@@ -22,7 +22,8 @@ the sheets first). --out is required: give each review its own folder (books/<bo--webp W also write each shot as a W-wide WebP of the stage's shape (implies --clean): a series-page still or a cover(stories.md: 1400 wide); --name NAME names it OUT/NAME.webp (one moment only)-Uses ?beat=N&t=0, then sets the beat clock to the moment, as playback would reach it. The page runs with reduced+--query adds to the page's query (tags: the source and AI tags an upright film's export shows). Uses ?beat=N&t=0,+then sets the beat clock to the moment, as playback would reach it. The page runs with reducedmotion, which stops the CSS-only motion that runs on the wall clock (page cross-fades, cards sliding in, the mascot):a shot is the same picture however busy the machine is, so several runs at once (parallel scene workers) are safe."""@@ -47,8 +48,8 @@ async def main(a):pg.on("pageerror", lambda e: errs.append(str(e)))# a desktop browser ($CHROME) also asks the server for /favicon.ico, which is not the book'spg.on("console", lambda m: m.type == "error" and not m.location.get("url", "").endswith("/favicon.ico") and errs.append(m.text))- base = f"{a.url}{a.chapter}/index.html"- await pg.goto(base + "?beat=0&t=0"); await pg.wait_for_timeout(500)+ base = f"{a.url}{a.chapter}/index.html?{a.query + '&' if a.query else ''}"+ await pg.goto(base + "beat=0&t=0"); await pg.wait_for_timeout(500)if errs:print("page errors:", errs); await b.close(); return 1ids = await pg.evaluate("BEATS.map(b => b.id)")@@ -57,7 +58,7 @@ async def main(a):async def grab(i, t, clean):"""The picture of beat i at t (seconds, open, mid, end) as an RGB image, and the time used."""- await pg.goto(f"{base}?beat={i}&t=0"); await pg.wait_for_timeout(300)+ await pg.goto(f"{base}beat={i}&t=0"); await pg.wait_for_timeout(300)end = await pg.evaluate("P.end")sec = {"open": 1.2, "end": end - .05, "mid": end / 2}.get(t)sec = float(t) if sec is None else sec@@ -137,6 +138,7 @@ if __name__ == "__main__":"with beats, only the cuts into and out of them")ap.add_argument("--webp", type=int, metavar="W", help="also save each shot as a W-wide WebP of the stage's shape (clean)")ap.add_argument("--name", help="file name (without .webp) for the one --webp still")+ ap.add_argument("--query", default="", help="extra page query, e.g. tags")a = ap.parse_args()a.url = a.url if a.url.endswith("/") else a.url + "/"sys.exit(asyncio.run(main(a)))diff --git a/.claude/skills/papermorph/scripts/strip.py b/.claude/skills/papermorph/scripts/strip.pyindex 99a895e..0a20364 100644--- a/.claude/skills/papermorph/scripts/strip.py+++ b/.claude/skills/papermorph/scripts/strip.py@@ -1,7 +1,7 @@#!/usr/bin/env python3"""Frames of a chapter's beats on contact sheets, rendered from the beat clock: storyboard sheets and motion strips.- uv run --with playwright --with pillow --with numpy strip.py ch12 OUT [specs ...] [--sheet NAME] [--url URL] [--browser chromium]+ uv run --with playwright --with pillow --with numpy strip.py ch12 OUT [specs ...] [--sheet NAME] [--url URL] [--browser chromium] [--query tags]push:2.3,dir,end chosen moments of beat 'push': seconds on the beat clock, a narration mark (dir, dir+0.5,s04.ba1 in a joined scene), mid or end of the whole beat@@ -16,8 +16,11 @@moves the background: a planted foot is one sharp ghost, a sliding foot a smear--sheet storyboard put every frame into one sheet OUT/storyboard.jpg (layout-first storyboard)+A whole-beat strip whose first frame is mostly one flat colour (a beat that swipes or fades its first shot in) takes that+frame at 0.2 s instead, labelled so, when its step is 0.2 s or more.Without --sheet each beat gets OUT/strip_<beat>.jpg (onion skins OUT/onion_<beat>.jpg). Frames are labelled "beat t" and shown at 1/3 size, four-a row. Firefox by default: it is the slowest common browser and the one to judge by. --url is where the book is served.+a row. Firefox by default: it is the slowest common browser and the one to judge by. --url is where the book is served;+--query adds to the page's query (tags: the source and AI tags an upright film's export shows)."""import argparse, asyncio, re, sys, tempfilefrom pathlib import Path@@ -42,6 +45,12 @@ def mean_diff(a, b):import numpy as npreturn float(np.abs(np.asarray(a.convert("L"), dtype=np.float32) - np.asarray(b.convert("L"), dtype=np.float32)).mean())+def blank(im):+ """Mostly one flat colour: 85 % of the pixels within 6 grey levels of the median (a clip's edge may peek in)."""+ import numpy as np+ g = np.asarray(im.convert("L"), dtype=np.float32)+ return float((np.abs(g - np.median(g)) <= 6).mean()) >= .85+def onion_skin(ims):"""Frames over a common background: what stays still is the per-pixel median; what moved is painted fromeach frame, earliest faintest."""@@ -61,7 +70,7 @@ async def main(a):b = await (p.firefox.launch(firefox_user_prefs={"media.autoplay.default": 0}) if a.browser == "firefox" else p.chromium.launch(**exe()))pg = await b.new_page(viewport={"width": 1600, "height": 960}, reduced_motion="reduce") # no wall-clock CSS motionerrs = []; pg.on("pageerror", lambda e: errs.append(str(e)))- await pg.goto(f"{a.url}{a.chapter}/?beat=0&t=0"); await pg.wait_for_timeout(800)+ await pg.goto(f"{a.url}{a.chapter}/?{a.query + '&' if a.query else ''}beat=0&t=0"); await pg.wait_for_timeout(800)sw, sh = await pg.evaluate("[SW, SH]") # the stage at scale 1, 1600 x 900 or 900 x 1600 uprightawait pg.set_viewport_size({"width": sw + 40, "height": sh + 100})at = {"i": -1, "t": 0.0}@@ -100,8 +109,11 @@ async def main(a):ts = ([when(x) for x in moments.split(",")] if moments and ".." not in momentselse [t0 + k * st for k in range(int((t1 - t0) / st + 1e-6) + 1)])ims, raw = [], []- for t in ts:- im = await shot(t, 3); raw.append(im.copy())+ for k, t in enumerate(ts):+ im = await shot(t, 3)+ if k == 0 and not moments and st >= .2 and blank(im): # empty until the first shot swipes or fades in+ t = ts[0] = .2; im = await shot(t, 3)+ raw.append(im.copy())ImageDraw.Draw(im).text((6, 4), f"{bid} t={t:.2f}", fill=(255, 230, 120)); ims.append(im)if onion:cuts = [f"{ts[k]:.2f}" for k in range(1, len(raw)) if mean_diff(raw[k - 1], raw[k]) > 30]@@ -128,5 +140,6 @@ if __name__ == "__main__":ap.add_argument("chapter"); ap.add_argument("out"); ap.add_argument("specs", nargs="+")ap.add_argument("--sheet"); ap.add_argument("--url", default="http://localhost:8765/")ap.add_argument("--browser", default="firefox", choices=["firefox", "chromium"])+ ap.add_argument("--query", default="", help="extra page query, e.g. tags")a = ap.parse_args(); a.url = a.url.rstrip("/") + "/"sys.exit(asyncio.run(main(a)))