An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
fix(skill): film-aware still.py, BGM follows speed in the kit
yzr668fbcfbc5b1
diff --git a/.claude/skills/papermorph/assets/templates/picture-book/lib/shared.js b/.claude/skills/papermorph/assets/templates/picture-book/lib/shared.jsindex e90e053..ea7675a 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/lib/shared.js+++ b/.claude/skills/papermorph/assets/templates/picture-book/lib/shared.js@@ -43,6 +43,8 @@ function sfxTick() {if (e.at <= from || e.at > P.t) a.addEventListener('loadedmetadata', () => { a.currentTime = P.t - e.at; }, { once: true }); // a long bed joined mid-way}for (const a of sfxOn) { a.playbackRate = P.rate || 1; if (on === a.paused && !a.ended) on ? a.play().catch(() => {}) : a.pause(); } // a pause holds them, play resumes+ // the music follows the playback speed too (BGM is the chapter's own list, when it has one)+ if (typeof BGM !== 'undefined') for (const m of BGM) if (m.a.playbackRate !== (P.rate || 1)) m.a.playbackRate = P.rate || 1;sfxLast = { i: P.i, t: on ? P.t : from, pend: !on && (!same || !!sfxLast.pend) };requestAnimationFrame(sfxTick);}diff --git a/.claude/skills/papermorph/scripts/still.py b/.claude/skills/papermorph/scripts/still.pyindex 9d67223..d73886b 100644--- a/.claude/skills/papermorph/scripts/still.py+++ b/.claude/skills/papermorph/scripts/still.py@@ -4,18 +4,19 @@uv run --with playwright --with pillow still.py ch15 --url http://localhost:8765/science/ [beat ...] [--min 3]Prints, per lesson beat, the stretches of at least --min seconds whose consecutive frames differ by less than---thr (mean absolute pixel difference, 0-255, on a small grey copy of the stage). Strips and onion skins cannot+--thr (mean absolute pixel difference, 0-255, on a small grey copy of the stage; default 0.03 for a lesson, 2 for a+picture book, whose puppets jitter and flicker on every frame even when nothing acts). Strips and onion skins cannotshow that nothing moves; this can. A stretch is worth a look, not automatically wrong: a held moment can be right."""import argparse, asyncio, iofrom playwright.async_api import async_playwrightfrom PIL import Image, ImageChops, ImageStat-ap = argparse.ArgumentParser()+ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)ap.add_argument("chapter"); ap.add_argument("beats", nargs="*")ap.add_argument("--url", default="http://localhost:8765/")ap.add_argument("--step", type=float, default=1); ap.add_argument("--min", type=float, default=3)-ap.add_argument("--thr", type=float, default=.03)+ap.add_argument("--thr", type=float)a = ap.parse_args()URL = a.url.rstrip("/") + f"/{a.chapter}/"@@ -25,6 +26,7 @@ async def main():pg = await b.new_page(viewport={"width": 1600, "height": 960})await pg.goto(URL + "?beat=0&t=0"); await pg.wait_for_timeout(800)ids = await pg.evaluate("BEATS.map(b => b.id)"); asks = await pg.evaluate("BEATS.map(b => !!b.ask)")+ thr = a.thr if a.thr is not None else (2 if await pg.evaluate("typeof jit === 'function'") else .03) # paper.js jittersr = await pg.evaluate("(() => { const r = document.getElementById('stage').getBoundingClientRect(); return {x: r.x, y: r.y, width: r.width, height: r.height}; })()")for i, bid in enumerate(ids):if asks[i] or (a.beats and bid not in a.beats): continue@@ -38,8 +40,8 @@ async def main():prev = im; t += a.stepruns, start = [], Nonefor t1, d in diffs + [(t, 99)]:- if d < a.thr and start is None: start = t1 - a.step- if d >= a.thr and start is not None:+ if d < thr and start is None: start = t1 - a.step+ if d >= thr and start is not None:if min(t1 - a.step, dur) - start >= a.min: runs.append((start, min(t1 - a.step, dur)))start = Noneprint(f"{bid:11s} dur {dur:5.1f} still: " + (", ".join(f"{s:.0f}-{e:.0f}s" for s, e in runs) or "-"), flush=True)diff --git a/site/joke-collection/lib/paper.js b/site/joke-collection/lib/paper.jsindex 48619f9..d8a50e0 100644--- a/site/joke-collection/lib/paper.js+++ b/site/joke-collection/lib/paper.js@@ -1,5 +1,5 @@/* paper.js — a paper-cutout stop-motion kit on top of the engine.- Sets are baked bitmaps (img/sets/, from tools/breakfast/bake.py); puppets are live SVG pieces with the+ Sets are baked bitmaps (img/sets/, from the Skill's scripts/bake_sets.py or painted.py); puppets are live SVG pieces with thesame paper filter. Everything moves on a 12 fps clock (on twos), each frame with its own small hand jitter, sopause, seek and ?beat=N&t=S show exactly the frame a viewer would see. */'use strict';@@ -132,7 +132,7 @@ const blinking = (q, times) => times.some(b => q >= b && q < b + 2 / FPS);piece is drawn once to a bitmap (at RES px per unit) and replaced by that image. Parts that change (eyes, mouths,brows, pieces with data-p) stay live; a filtered live part is baked on its own. Identical pieces share one bitmap. */const RES = 4, bakedReady = new Map(), bakedJobs = new Map(), PAPER_EXTRA = []; // extra defs (patterns) other files add-// Pieces baked ahead of time (tools/breakfast/bake_puppets.py): img/puppets/<hash>.webp, listed in+// Pieces baked ahead of time (the Skill's scripts/bake_puppets.py): img/puppets/<hash>.webp, listed in// window.BAKED. A piece missing from it (just edited) is baked here in the browser; ?bake ignores the list.const BAKED = new URLSearchParams(location.search).has('bake') ? {} : (window.BAKED || {});const keyHash = k => { let h = 2166136261; for (let i = 0; i < k.length; i++) h = Math.imul(h ^ k.charCodeAt(i), 16777619); return (h >>> 0).toString(16).padStart(8, '0'); };diff --git a/site/joke-collection/lib/shared.js b/site/joke-collection/lib/shared.jsindex ff5cd3a..88c50ea 100644--- a/site/joke-collection/lib/shared.js+++ b/site/joke-collection/lib/shared.js@@ -14,7 +14,7 @@ const lips = (q, scene, pre, ...clips) => { for (const c of clips) { const m = mconst chew = q => onTwos(q) > 0 ? 'chew' : 'A';/* ---------- props (puppet pieces, baked like them) ---------- */-// Painted props (img/props, from tools/breakfast/painted.py): a picture at (x, y), w by h.+// Painted props (img/props, from the Skill's scripts/painted.py): a picture at (x, y), w by h.const artSVG = (name, x, y, w, h) => `<image href="../img/props/${name}.webp" x="${x}" y="${y}" width="${w}" height="${h}"/>`;// A steamed bun, centred on (0, 0), about 48 wide; `bite`: with a bite out of its right side.const bunSVG = (bite = false) => bite ? artSVG('bun-bite', -24, -36, 48, 44) : artSVG('bun', -24, -34, 48, 42);@@ -34,7 +34,7 @@ const deskSVG = (cx, top, s) => artSVG('desk', cx - 240 * s, top - 10 * s, 480 *const STALL = { ground: 800, s: .95, me: 480, bo: 760, aunt: { x: 1300, y: 780, s: 1 } };// the stall's locked framing: the boys and the seller, a little closer than the whole setconst STALL_VIEW = { x: 860, y: 560, z: 1.3 };-// The stall is painted (tools/breakfast/painted.py): three weathers of the street, and the cart as its own cut-out so+// The stall is painted (the Skill's scripts/painted.py): three weathers of the street, and the cart as its own cut-out so// the seller stands behind it. weather('sun'|'rain'|'snow').function stallSet(p, holds = {}) {const cam = paperCam(p, 'stall', {}, { after: 'cart', stages: ['snow'] });diff --git a/site/little-red-riding-hood/ch01/index.html b/site/little-red-riding-hood/ch01/index.htmlindex 321f341..9c42595 100644--- a/site/little-red-riding-hood/ch01/index.html+++ b/site/little-red-riding-hood/ch01/index.html@@ -119,7 +119,7 @@ function scene1(p, D) {/* ---------- sound effects ----------sfx(beat, at, name, vol): play audio/sfx/<name>.mp3 when the clock of beat `beat` passes `at` in normal playback- (seeking past it does not fire it). Pausing stops them. Made by tools/little-red-riding-hood/sfx.py. */+ (seeking past it does not fire it). Pausing stops them. Synthesized like the recipes of the Skill's scripts/sfx.py. */const SFX = [], sfxOn = [];const sfx = (beat, at, name, vol = 1) => SFX.push({ beat, at, name, vol });let sfxLast = { i: -1, t: 0 };diff --git a/site/little-red-riding-hood/lib/paper.js b/site/little-red-riding-hood/lib/paper.jsindex 9de6ad5..779f39f 100644--- a/site/little-red-riding-hood/lib/paper.js+++ b/site/little-red-riding-hood/lib/paper.js@@ -1,5 +1,5 @@/* paper.js — a paper-cutout stop-motion kit on top of the engine.- Sets are baked bitmaps (img/sets/, from tools/little-red-riding-hood/bake.py); puppets are live SVG pieces with the+ Sets are baked bitmaps (img/sets/, baked from SVG set sketches); puppets are live SVG pieces with thesame paper filter. Everything moves on a 12 fps clock (on twos), each frame with its own small hand jitter, sopause, seek and ?beat=N&t=S show exactly the frame a viewer would see. */'use strict';@@ -287,7 +287,7 @@ function motherPuppet(parent) {piece is drawn once to a bitmap (at RES px per unit) and replaced by that image. Parts that change (eyes, mouths,brows, pieces with data-p) stay live; a filtered live part is baked on its own. Identical pieces share one bitmap. */const RES = 4, bakedReady = new Map(), bakedJobs = new Map(), PAPER_EXTRA = []; // extra defs (patterns) other files add-// Pieces baked ahead of time (tools/little-red-riding-hood/bake_puppets.py): img/puppets/<hash>.webp, listed in+// Pieces baked ahead of time (the Skill's scripts/bake_puppets.py): img/puppets/<hash>.webp, listed in// window.BAKED. A piece missing from it (just edited) is baked here in the browser; ?bake ignores the list.const BAKED = new URLSearchParams(location.search).has('bake') ? {} : (window.BAKED || {});const keyHash = k => { let h = 2166136261; for (let i = 0; i < k.length; i++) h = Math.imul(h ^ k.charCodeAt(i), 16777619); return (h >>> 0).toString(16).padStart(8, '0'); };