An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(skill): the picture-book kit carries what the two reference books needed
yzr1336f84d8a37
diff --git a/.claude/skills/papermorph/assets/templates/picture-book/chapter.html b/.claude/skills/papermorph/assets/templates/picture-book/chapter.htmlindex 19da7b5..72ee5f2 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/chapter.html+++ b/.claude/skills/papermorph/assets/templates/picture-book/chapter.html@@ -23,16 +23,23 @@<script src="scene1.js"></script><script>'use strict';-const CHAPTER = { number: 1, title: 'PICTURE BOOK TITLE', minutes: 2, language: 'en' }; // next: '../ch02/' once it exists+// film: true plays music and effects; questionKeys: false leaves the question keys out of the help, since the only+// question is the listen-and-find stop. A film for older readers without a stop can drop both and the ask.+const CHAPTER = { number: 1, title: 'PICTURE BOOK TITLE', minutes: 2, language: 'en', film: true, questionKeys: false }; // next: '../ch02/' once it existstry { if (localStorage.getItem('captions') === null) setCaptions(true, false); } catch {} // captions on at the first visit; the reader's own choice is kept/* ---------- beats: one per scene ----------[id, title, run, { lead: false, pre }]: id names audio/en/<id>.mp3 (the joined scene clip) and its TIMINGS entry;`pre` is the seconds of picture before the speech starts (the scene's PRE constant).- A point-and-read stop for young readers (references/picture-books/stories.md, "Point and read") is one more scene whose- beat ends { …, ask: done => tapWords(THINGS, done) }, with film: true and questionKeys: false in CHAPTER. */+ A listen-and-find stop for young readers (references/picture-books/stories.md) is a beat's `ask`: after the scene,+ the picture stays alive and the engine's findWords(things, asks, done) asks for one thing at a time. The scene fills+ its things ({ g, word }: THINGS1 in scene1.js); each thing says audio/en/w-<word>.mp3 when tapped, each ask plays+ its clip, then r-<word> ("Where's the cat?") when it asks again; q-done praises at the end and q-there helps a+ child who never taps. Those lines are in the narration, the chime in audio/sfx/chime.mp3 (sfx.py chime), and+ lint.py names any clip that is missing. Write words and clips as literals so lint can check them. */+const FIND1 = [{ word: 'cat', clip: 'q-cat' }, { word: 'dad', clip: 'q-dad' }];const BEATS = [- ['scene1', 'The visit', (m, D) => scene1(panel(0), D), { lead: false, pre: PRE1 }],+ ['scene1', 'The visit', (m, D) => scene1(panel(0), D), { lead: false, pre: PRE1, ask: done => findWords(THINGS1, FIND1, done) }],].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));/* ---------- background music ----------@@ -42,7 +49,7 @@ const BEATS = [window.MUSIC_OFF = { sceneId: t => boolean }. */// music('audio/bgm/theme.mp3', ['scene1', 'scene2'], .3);// Build every puppet and prop once at load, off screen, so their bitmaps are ready before the first beat needs them.-paperWarm(g => { kidPuppet(g); });+paperWarm(g => { kidPuppet(g); catPuppet(g); });boot();</script></body>diff --git a/.claude/skills/papermorph/assets/templates/picture-book/lib/cast.js b/.claude/skills/papermorph/assets/templates/picture-book/lib/cast.jsindex c41a4aa..4e4b2ba 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/lib/cast.js+++ b/.claude/skills/papermorph/assets/templates/picture-book/lib/cast.js@@ -1,6 +1,16 @@-/* cast.js — the puppets, in the flat cut-paper style of South Park: a big round head straight on the body, two- touching eyes, a mouth low on the face, mitten hands. Built at the feet (0, 0) facing us. They turn by sliding the- face to one side (look -1 … 1), as that show does; the paper pieces never deform, except that a sleeve stretches with+/* cast.js — the puppets, on paper.js. Three kinds, each with a working example to copy; a book keeps the kind (or kinds)+ its story needs, adds its characters and deletes the rest:+ 1. round-headed figures that face us, in the flat cut-paper style of South Park (spKid, kidPuppet; Joke Collection);+ 2. storybook figures seen mostly in profile, with a side set and a front set of pieces (puppet, common, figurePuppet;+ Little Red Riding Hood);+ 3. four-legged animals in profile on a two-bone leg rig with distance-driven gaits (beast, catPuppet; The Little Horse+ Crosses the River).+ Moving along the ground: spStep / spWalk (kind 1), walk() in paper.js with hipOn, walker and bigStep (kind 2), route+ (kinds 2 and 3); flipTurn turns a profile puppet over like a card. Each section's header lists its pose keys.++ ---------- 1. round-headed figures ----------+ A big round head straight on the body, two touching eyes, a mouth low on the face, mitten hands. Built at the feet+ (0, 0) facing us. They turn by sliding the face to one side (look -1 … 1), as that show does; the paper pieces never deform, except that a sleeve stretches withreach and a seated shin with the seat's height.pose(o, f): x, y, s; look (face slide), eyeX/eyeY (pupils, -1 … 1), lids (0 open … 1 shut; .55 is deadpan), shut(blink), mouth (a Rhubarb shape or an expression below), brow (0 none, <0 angry, >0 worried), headR, bob, squash,@@ -23,9 +33,10 @@hip, body and head outlines, eyes [x, y, rx, ry], mouth [x, y], slide how far the face moves, hair [colour, path],optional glasses/hat/extra/legH/armH/browUp/cheeks/chin), then a one-line builder like kidPuppet below. A grown-up is a tallerbody (legH 96, sy and the head moved up) with longer arms (armH 100 reaches a table). Colours (coat, stripe, pants, skin, cuff) are options of the builder, so one shape- serves many characters. An animal or anything not built like a kid gets its own builder with the same contract- (build in g, bakeAll(g), return { g, aim, point, pose(o, f) }) — see spKid for the pattern; aimArm and rotPt below do- the geometry for any shoulder and head. */+ serves many characters. A four-legged animal goes on the rig of section 3 (it stands in profile beside these figures+ well enough: the template's scene1 has the cat walk in with the kid); anything else not built like a kid gets its own+ builder with the same contract (build in g, bakeAll(g), return { g, aim, point, pose(o, f) }) — see spKid for the+ pattern; aimArm and rotPt below do the geometry for any shoulder and head. */'use strict';const SP_INK = '#1d1a1a';// How far a shut eye's lid comes down: .9 leaves the lid line showing (a full lid, 1, leaves two blank skin ovals).@@ -191,3 +202,336 @@ function spStep(tau, { L = 52, A = 20, period = 2 / 3 } = {}) {const a = Math.asin(D * Math.min(u, 1 - u) / L) * 180 / Math.PI;return { legL: a, legR: a, d: D * (n + u), drop: L * (1 - Math.cos(a * Math.PI / 180)), u };}+++/* ---------- 2. storybook figures: a side set and a front set ----------+ A figure is drawn at its hip (0, 0) facing right, its feet at y 170 (hipOn(gy, s) puts them on ground y gy), as two+ sets of paper pieces: a profile set (data-p "body", holding "headP") and a front set ("bodyF", "headF"). The front+ set shows whenever head is 'F' or |turn| < .55, so a figure always faces us as a whole: turn tweened from 1 to -1+ squashes the side figure, shows the whole front figure through the thin middle and comes out mirrored.+ puppet(parent, svg, rest, pose) builds one from its SVG; common(P, o, j, g, rig) does what every figure does with+ its pose (place and jitter, turn, the profile legs and near arm, the two front arms, the head, eyes and mouth):+ rig = { neck, sh, el (the near shoulder and elbow pins), fsh (the front right shoulder), fup (its upper arm length),+ knee (the knee pin's y in legPiece), waist (the y that lean bends about, default 0) }. The common keys (REST_FIG):+ x y s turn; near, far (the profile legs, degrees, + forward) and kNear, kFar (knee bends); ua, fa (the near arm's+ shoulder and elbow); rua, rfa, lua, lfa (the front figure's screen-right and screen-left arms; 0 hangs down); head+ ('P' | 'F'), headR (degrees), nod (+ lowers the head); mouth, shut (blink: blinking(q, times) in paper.js); hop+ (+ moves the whole figure down, - up; the arc of a hop is yours); lean; brow.+ A face's live parts are found by class: .eyeO (open eyes) / .eyeC (shut) and a <use class="mouth" href="#mX">.++ figurePuppet(parent, colours) is the example, a child in a coat and a hat; one builder serves many characters+ through its colours: { skin, coat, coatFar, legs, legsFar, shoe, hair, hat (null: no hat), band, cheek, skirt+ (true: a long coat over the thighs, false: a short one over trousers), holds: { key: svg } }. Its keys besides+ the common ones:+ look the pupils, -1 … 1 (profile: + towards the way it faces; front: + to screen right)+ brow 0 none (the brows are hidden: earlier shots keep their faces), > 0 worried (inner ends up), < 0 cross+ lean bends it at the waist, degrees forward (profile only): 60–80 reaches the ground+ crouch 0 … 1: knees up and hip down, the feet kept on the ground (a duck, a bend to pick something up, the squash+ before and after a hop)+ fua, ffa the far arm (profile), shoulder and elbow like ua / fa; null hides it (it hangs behind the body at rest).+ To pick something off the ground: { lean: 60, crouch: .7, fua: -50, ffa: 10 } puts the far hand there+ hat true / false: the hat on its head. The hair is drawn under the hat on both heads, so a hat that comes off+ leaves hair, never a bald head (the hat on its own is hatSVG, for a hand or the ground)+ hold a key of holds, shown in the near hand (profile) and the screen-right hand (front), kept upright; each+ svg is drawn around the hand's centre (0, 0)+ To add a character with another build, copy figurePuppet, change its paths and pins, and keep its pose to common()+ plus the keys the character needs. */+// A profile leg: a thigh and a shin on a knee pin (y thigh - 8), with its shoe.+function legPiece(id, sock, shoe, thigh = 94, shin = 82, w = 18) {+ const k = thigh - 8, f = k + shin - 10;+ return `<g data-p="${id}"><g filter="url(#paper)"><rect x="${-w / 2}" y="-4" width="${w}" height="${thigh}" rx="8" fill="${sock}"/></g>+ <g data-p="${id}k"><g filter="url(#paper)"><rect x="${-w / 2 + 1}" y="${k - 6}" width="${w - 2}" height="${shin}" rx="7" fill="${sock}"/><path d="M-10,${f} h22 q13,0 13,10 v4 h-37 z" fill="${shoe}"/></g>${pinAt(0, k)}</g></g>`;+}+// A front arm hanging from its shoulder (x, y): sleeve, forearm, hand; extra goes in the hand's group.+const frontArm = (id, x, y, sleeve, skin, up = 60, fore = 56, extra = '') => `<g data-p="${id}"><g filter="url(#paper)"><rect x="${x - 8.5}" y="${y - 6}" width="17" height="${up + 6}" rx="8" fill="${sleeve}"/></g>+ <g data-p="${id}f"><g filter="url(#paper)"><rect x="${x - 6.5}" y="${y + up - 6}" width="13" height="${fore}" rx="6" fill="${skin}"/><circle cx="${x}" cy="${y + up + fore - 4}" r="9.5" fill="${skin}"/>${extra}</g>+ ${pinAt(x, y + up - 2)}</g>${pinAt(x, y)}</g>`;+function armsF(P, o, j, sx, sy, up) { // the two front arms: r = screen right, l = screen left; 0 hangs down+ tf(P.rArm, `rotate(${(o.rua + j(21) * .6).toFixed(2)},${sx},${sy})`); tf(P.rArmf, `rotate(${(o.rfa + j(22) * .6).toFixed(2)},${sx},${sy + up - 2})`);+ tf(P.lArm, `rotate(${(o.lua + j(23) * .6).toFixed(2)},${-sx},${sy})`); tf(P.lArmf, `rotate(${(o.lfa + j(24) * .6).toFixed(2)},${-sx},${sy + up - 2})`);+}+// How far a jaw opens for each mouth shape of the cues (a jaw on a pin: the four-legged rig, a snout).+const JAW = { X: 0, A: 0, B: .25, C: .45, D: .85, E: .6, F: .3, G: .2, H: .35 };++function puppet(parent, svg, rest, pose) {+ const g = mk('g', {}, parent);+ g.innerHTML = svg;+ bakeAll(g);+ const P = pieces(g);+ return { g, P, pose(o, f) { o = { ...rest, ...o }; pose(P, o, k => jit(f, k), g); } };+}+function common(P, o, j, g, { neck, sh, el, fsh, fup, knee, waist = 0 }) {+ const front = o.head === 'F' || Math.abs(o.turn) < .55;+ tf(g, `translate(${(o.x + j(1) * .8).toFixed(1)},${(o.y + o.hop + j(2) * .6).toFixed(1)}) scale(${o.s}) rotate(${(j(3) * .5).toFixed(2)})`);+ tf(P.body, `scale(${o.turn.toFixed(3)},1)`); vis(P.body, !front); vis(P.bodyF, front);+ if (P.upper) tf(P.upper, `rotate(${o.lean.toFixed(2)},0,${waist})`);+ if (P.legN) {+ tf(P.legN, `rotate(${(o.near + j(4) * .6).toFixed(2)})`); tf(P.legNk, `rotate(${o.kNear.toFixed(2)},0,${knee})`);+ tf(P.legF, `rotate(${(o.far + j(5) * .6).toFixed(2)})`); tf(P.legFk, `rotate(${o.kFar.toFixed(2)},0,${knee})`);+ }+ const ua = o.ua + j(7) * .6, fa = o.fa + j(8) * .6;+ tf(P.arm, `rotate(${ua.toFixed(2)},${sh[0]},${sh[1]})`); tf(P.fore, `rotate(${fa.toFixed(2)},${el[0]},${el[1]})`);+ armsF(P, o, j, fsh[0], fsh[1], fup);+ const hr = `translate(0,${o.nod.toFixed(1)}) rotate(${(o.headR + j(9) * .7).toFixed(2)},${neck[0]},${neck[1]})`;+ tf(P.headP, hr); tf(P.headF, hr);+ vis(P.headP, !front); vis(P.headF, front);+ face(front ? P.headF : P.headP, o);+ return { front, ua, fa };+}+// Show or hide a piece on both sets at once: both(P, 'hat', on) for data-p "hatP" and "hatF".+const both = (P, k, on) => { if (P[k + 'P']) vis(P[k + 'P'], on); if (P[k + 'F']) vis(P[k + 'F'], on); };+const REST_FIG = { x: 0, y: 0, s: 1, turn: 1, near: 0, far: 0, kNear: 0, kFar: 0, lean: 0, ua: 6, fa: -6, rua: 6, rfa: -4, lua: -6, lfa: 4,+ head: 'P', headR: 0, nod: 0, mouth: 'X', shut: false, hop: 0, brow: 0 };++// Where a figure's hip goes for its feet on ground y gy at scale s (feet: the feet's y in the figure, 170 here).+const hipOn = (gy, s, feet = 170) => gy - feet * s;+// A walk from x0 to the right (dir -1: to the left) that stops cleanly after `steps` steps: walker(x0, s)(tau) gives+// walk()'s keys and x; pose({ ...w, y: hipOn(gy, s) + w.drop * s }). It stops where both legs pass the vertical and+// sets the lifted foot down beside the other over a quarter second, so the figure ends standing, not mid-stride.+function walker(x0, s, opts = {}, dir = 1, steps = Infinity) {+ const half = (opts.period || 1) / 2, end = steps * half;+ return tau => { const w = walk(Math.min(tau, end), opts), k = tau > end ? 1 - ease((tau - end) / .25) : 1;+ return { ...w, kNear: w.kNear * k, kFar: w.kFar * k, x: x0 + dir * w.d * s }; };+}+// One big, deliberate step forward (off a path onto the grass), u 0 … 1 over the step: the near knee lifts high, the+// foot comes down ahead and the hip follows, sinking into the stride (drop) while the back knee bends so the back foot+// stays on the ground; at u 1 both feet are down. Like walk(): const b = bigStep(u);+// fig.pose({ ...b, x: x0 + b.d * s, y: hipOn(gy, s) + b.drop * s, … }).+function bigStep(u, L = 166, reach = 30) {+ const e = ease(u), lift = Math.sin(Math.PI * Math.min(1, u * 1.25)), r = Math.PI / 180;+ const near = -reach * Math.sin(Math.PI * e / 2) - 40 * lift * (1 - e), far = reach * e * .7;+ // hip height h·L: down to the stride's (cos reach) as the step lands; the back leg (thigh ≈ shin ≈ L/2) bends to reach it+ const h = Math.cos(reach * e * r), kFar = Math.max(0, Math.acos(Math.min(1, 2 * h - Math.cos(far * r))) / r - far);+ return { near, far, kNear: 75 * lift, kFar, d: 2 * L * Math.sin(reach * Math.PI / 360) * e * 1.6, drop: L * (1 - h) };+}++// A hat on its own, drawn where it sits on the profile head at puppet scale 1 (for a hand, a peg or the ground).+const hatSVG = (hat = '#c8322f', band = '#8a2420') => `<g filter="url(#paper)"><path d="M-30,-222 C-28,-262 40,-268 50,-222 Z" fill="${hat}"/><rect x="-40" y="-228" width="102" height="11" rx="5" fill="${band}"/></g>`;+const REST_FIGURE = { ...REST_FIG, look: 0, fua: null, ffa: -10, crouch: 0, hat: true, hold: null };+function figurePuppet(parent, { skin = '#f6d2b5', coat = '#3d6fa8', coatFar = '#335d8d', legs = '#f2ede1', legsFar = '#d8d1c2', shoe = '#3a2418',+ hair = '#6b3b22', hat = '#c8322f', band = '#8a2420', cheek = '#ef9a8a', skirt = true, holds = {} } = {}) {+ const ink = '#22150e', held = (side, x, y) => Object.entries(holds).map(([k, s]) => `<g data-p="hold${side}_${k}" transform="translate(${x},${y})">${s}</g>`).join('');+ const lower = skirt ? 'M-38,-46 L38,-46 C48,0 58,30 64,56 Q0,70 -64,56 C-58,30 -48,0 -38,-46 Z' : 'M-36,-46 L36,-46 L40,10 Q0,18 -40,10 Z';+ const lowerF = skirt ? 'M-40,-46 L40,-46 C52,0 62,30 68,56 Q0,70 -68,56 C-62,30 -52,0 -40,-46 Z' : 'M-38,-46 L38,-46 L42,10 Q0,18 -42,10 Z';+ const fig = puppet(parent, `<g data-p="body">+ ${legPiece('legF', legsFar, shoe)}${legPiece('legN', legs, shoe)}+ <g filter="url(#paper)"><path d="${lower}" fill="${coat}"/></g>+ <g data-p="upper">+ <g data-p="armF"><g filter="url(#paper)"><rect x="-4.5" y="-134" width="17" height="62" rx="8" fill="${coatFar}"/></g>+ <g data-p="foreF"><g filter="url(#paper)"><rect x="-2" y="-80" width="12" height="54" rx="6" fill="${skin}"/><circle cx="4" cy="-26" r="9" fill="${skin}"/></g>${pinAt(4, -76)}</g>${pinAt(4, -128)}</g>+ <g filter="url(#paper)"><path d="M-28,-128 L26,-128 L34,-42 L-34,-42 Z" fill="${coat}"/><rect x="-8" y="-150" width="16" height="28" fill="${skin}"/>+ <path d="M-30,-132 Q0,-142 30,-130 L28,-118 Q0,-126 -30,-118 Z" fill="${coatFar}"/></g>+ <g data-p="headP"><g filter="url(#paper)">+ <path d="M-44,-186 C-48,-244 34,-256 52,-212 L30,-204 L-6,-206 L-10,-160 L-34,-152 C-46,-162 -44,-176 -44,-186 Z" fill="${hair}"/>+ <circle cx="14" cy="-192" r="40" fill="${skin}"/><circle cx="53" cy="-189" r="7" fill="${skin}"/>+ <path d="M-28,-200 C-30,-238 20,-250 54,-210 Q32,-222 12,-206 Q-4,-216 -14,-198 Q-20,-186 -16,-172 L-28,-176 Z" fill="${hair}"/>+ <circle cx="31" cy="-176" r="8.5" fill="${cheek}" opacity=".8"/></g>+ <g data-p="lookP"><g class="eyeO"><ellipse cx="34" cy="-198" rx="4.5" ry="6.2" fill="${ink}"/></g></g>+ <g class="eyeC"><path d="M29,-197 Q34,-193 39,-197" fill="none" stroke="${ink}" stroke-width="2.4" stroke-linecap="round"/></g>+ <path data-p="browP" d="M26,-209 L41,-208" stroke="${ink}" stroke-width="3.6" stroke-linecap="round"/>+ <use class="mouth" href="#mX" transform="translate(41,-172) scale(.85)"/>+ ${hat ? `<g data-p="hatP">${hatSVG(hat, band)}</g>` : ''}${pinAt(0, -146)}</g>+ <g data-p="arm"><g filter="url(#paper)"><rect x="6" y="-134" width="17" height="64" rx="8" fill="${coat}"/></g>+ <g data-p="fore"><g filter="url(#paper)"><rect x="8.5" y="-80" width="12" height="54" rx="6" fill="${skin}"/><circle cx="14.5" cy="-26" r="9" fill="${skin}"/></g>+ ${held('N', 14.5, -26)}${pinAt(14.5, -76)}</g>${pinAt(14.5, -128)}</g></g></g>+ <g data-p="bodyF">+ <g filter="url(#paper)"><rect x="-21" y="${skirt ? 46 : 0}" width="16" height="${skirt ? 114 : 160}" rx="7" fill="${legs}"/><rect x="5" y="${skirt ? 46 : 0}" width="16" height="${skirt ? 114 : 160}" rx="7" fill="${legs}"/>+ <ellipse cx="-13" cy="164" rx="12" ry="7" fill="${shoe}"/><ellipse cx="13" cy="164" rx="12" ry="7" fill="${shoe}"/></g>+ <g filter="url(#paper)"><path d="${lowerF}" fill="${coat}"/></g>+ <g filter="url(#paper)"><path d="M-30,-128 L30,-128 L38,-42 L-38,-42 Z" fill="${coat}"/><rect x="-8" y="-150" width="16" height="28" fill="${skin}"/>+ <path d="M-32,-132 Q0,-144 32,-132 L30,-120 Q0,-130 -30,-120 Z" fill="${coatFar}"/></g>+ ${frontArm('lArm', -30, -126, coat, skin, 54, 50)}+ ${frontArm('rArm', 30, -126, coat, skin, 54, 50, held('F', 30, -26))}+ </g>+ <g data-p="headF"><g filter="url(#paper)">+ <path d="M-52,-168 C-62,-238 62,-238 52,-168 Q40,-160 30,-168 L-30,-168 Q-40,-160 -52,-168 Z" fill="${hair}"/><circle cx="0" cy="-188" r="42" fill="${skin}"/>+ <path d="M-44,-196 C-46,-250 46,-250 44,-196 Q24,-222 0,-216 Q-24,-222 -44,-196 Z" fill="${hair}"/>+ <circle cx="-23" cy="-176" r="8" fill="${cheek}" opacity=".8"/><circle cx="23" cy="-176" r="8" fill="${cheek}" opacity=".8"/></g>+ <g data-p="lookF"><g class="eyeO"><ellipse cx="-14" cy="-196" rx="4.5" ry="6.2" fill="${ink}"/><ellipse cx="14" cy="-196" rx="4.5" ry="6.2" fill="${ink}"/></g></g>+ <g class="eyeC"><path d="M-19,-195 Q-14,-191 -9,-195 M9,-195 Q14,-191 19,-195" fill="none" stroke="${ink}" stroke-width="2.4" stroke-linecap="round"/></g>+ <path data-p="browL" d="M-22,-208 L-7,-207" stroke="${ink}" stroke-width="3.4" stroke-linecap="round"/><path data-p="browR" d="M7,-207 L22,-208" stroke="${ink}" stroke-width="3.4" stroke-linecap="round"/>+ <use class="mouth" href="#mX" transform="translate(0,-166)"/>+ ${hat ? `<g data-p="hatF"><g filter="url(#paper)"><path d="M-46,-224 C-44,-276 44,-276 46,-224 Z" fill="${hat}"/><ellipse cx="0" cy="-224" rx="62" ry="9" fill="${band}"/></g></g>` : ''}</g>`,+ REST_FIGURE, (P, o, j, g) => {+ if (o.crouch) { // the hip sinks as far as the folded legs shorten, so the feet stay on the ground+ const c = o.crouch, r = Math.PI / 180, n = { near: o.near - 62 * c, far: o.far - 50 * c, kNear: o.kNear + 104 * c, kFar: o.kFar + 100 * c };+ const reach = (a, k) => 86 * Math.cos(a * r) + 86 * Math.cos((a + k) * r), drop = 172 - Math.max(reach(n.near, n.kNear), reach(n.far, n.kFar));+ o = { ...o, ...n, hop: o.hop + Math.max(0, drop) * o.s };+ }+ const { front, ua, fa } = common(P, o, j, g, { neck: [0, -146], sh: [14.5, -128], el: [14.5, -76], fsh: [30, -126], fup: 54, knee: 86, waist: -44 });+ tf(P.lookP, `translate(${(3 * o.look).toFixed(1)},0)`); tf(P.lookF, `translate(${(4 * o.look).toFixed(1)},0)`);+ for (const k of ['browP', 'browL', 'browR']) vis(P[k], o.brow !== 0);+ tf(P.browP, `rotate(${(-16 * o.brow).toFixed(1)},26,-209)`);+ tf(P.browL, `rotate(${(-16 * o.brow).toFixed(1)},-22,-208)`); tf(P.browR, `rotate(${(16 * o.brow).toFixed(1)},22,-208)`);+ both(P, 'hat', o.hat);+ vis(P.armF, o.fua !== null && !front);+ if (o.fua !== null) { tf(P.armF, `rotate(${(o.fua + j(10) * .6).toFixed(2)},4,-128)`); tf(P.foreF, `rotate(${(o.ffa + j(11) * .6).toFixed(2)},4,-76)`); }+ for (const k of Object.keys(holds)) { // a held thing stays upright whatever the arm and the bend do+ vis(P[`holdN_${k}`], o.hold === k); vis(P[`holdF_${k}`], o.hold === k);+ tf(P[`holdN_${k}`], `translate(14.5,-26) rotate(${(-(o.lean + ua + fa)).toFixed(2)})`);+ tf(P[`holdF_${k}`], `translate(30,-26) rotate(${(-(o.rua + o.rfa)).toFixed(2)})`);+ }+ });+ return fig;+}++/* ---------- moving along the ground (kinds 2 and 3) ---------- */+// keys [[t, x], …] on the scene clock, eased between keys. Returns x, the distance travelled in the puppet's own units+// (d: a four-legged puppet's pose({ d }) plants its feet with it) and stand (1 at rest, blending to 0 within a quarter+// second of setting off and back to 1 after stopping).+function route(q, keys, s = 1) {+ let x = keys[0][1], d = 0, moving = false, since = 1e9;+ for (let i = 1; i < keys.length; i++) {+ const [t0, a] = keys[i - 1], [t1, b] = keys[i];+ if (q >= t1) { d += Math.abs(b - a) / s; x = b; if (a !== b) since = q - t1; continue; }+ if (q > t0 && a !== b) { const u = ease((q - t0) / (t1 - t0)); x = a + (b - a) * u; d += Math.abs(b - a) * u / s; moving = true; since = 0; }+ break;+ }+ const start = keys.find((k, i) => i && keys[i - 1][1] !== k[1] && q >= keys[i - 1][0] && q < k[0]);+ const into = start ? q - keys[keys.indexOf(start) - 1][0] : 1e9;+ const stand = moving ? Math.max(0, 1 - into / .25) : Math.min(1, since / .25);+ return { x, d, stand };+}+// A cut-out turned over in the shot: the turn key from face a to face b (1 right, -1 left) over four frames on twos,+// never quite flat. Turning on a cut (the next shot simply has the other turn) read best of all; use this when the+// turn has to happen on screen, in a wide shot.+const flipTurn = (q, t0, a, b) => { const k = Math.floor((q - t0) * FPS + 1e-6); return k < 0 ? a : k >= 4 ? b : [.5 * a, .12 * a, .12 * b, .5 * b][k]; };++/* ---------- 3. four-legged animals ----------+ Drawn in profile facing right, at the point on the ground under the body (0, 0); turn -1 faces left, and a turn+ tweened through 0 squashes the whole figure (never thinner than a third) and out mirrored, as a cut-out turned over+ on the table (flipTurn above does it in four frames).+ beast(parent, svg, geo, rest) is the rig: each leg is two pieces on pins solved to put its foot on a point, so a+ foot planted on the ground stays exactly there while the body rides over it. Walking and trotting come from the+ distance covered, not the clock: pose({ d }) with d in the puppet's own units, and the scene moves x by d·s in the+ facing direction (x = x0 + turn·s·d; route() above gives x and d together), so the feet never slide.+ Pose keys (REST_BEAST): x y s turn; d, gait ('walk': one foot at a time; 'trot': diagonal pairs), stand (0 … 1:+ blends every leg back to its rest place for a stop; route's stand); bob (+ down), tilt (the body about its centre,+ degrees); neck, nod (degrees about the neck and head pins); mouth (a cue shape: the jaw opens by JAW) or jaw (0 … 1,+ overrides it), chew (a number that grows with time works the jaw); shut (blink), lid (0 … 1, a sleepy lid), look+ (the pupil, -1 … 1 along the face), brow (> 0 tips it down to the nose: cross, determined; < 0 lifts it: worried,+ surprised); ear, tail (degrees: ear × 22, tail as given); legs: { nf: [dx, lift], … } moves a foot from where the+ gait puts it (a paw raised, a hoof testing the water). Any other true / false key shows or hides the piece of the+ same data-p name (a saddle cloth, a sack on the back, a tear): give its default in the rest.+ at(name) gives a named point of the drawn pose in the puppet's parent's coordinates: a leg's hip 'nf' 'ff' 'nh'+ 'fh', its knee or hock 'nfk' …, its foot 'nfHoof' …, and every mark the drawing places (mark('at_<name>', x, y) in+ the svg: the cat has 'mouth', 'eye', 'head', 'back'), so a thing in its mouth or water at a knee lands where the+ picture is.+ geo: { hips: { nf: [x, y], ff, nh, fh }, up, low (the two leg pieces' lengths), L (stride), H (foot lift), body:+ [x, y] tilt centre, neck, head, jaw: [x, y] pins, jawOpen (degrees at jaw 1), ear, tail: [x, y] pins, rest: { nf: dx,+ … } each foot's rest place from under its hip, eye: [x, y], lidH (the lid's travel), lookX (the pupil's) }.+ Legs: nf near fore, ff far fore, nh near hind, fh far hind; a fore knee folds forward, a hind hock backward. The svg+ names its pieces: trunk (holding tail, neckG > headG > jaw, ear, eyeO, eyeC, pupil, optional lid and brow), and the+ four legs from legSVG, far legs before the trunk and near legs after it. catPuppet below is the example: copy it and+ its CAT_GEO for another animal (Little Horse's horses and water buffalo are built this way). */+const pf = (body, id = '') => `<g${id ? ` data-p="${id}"` : ''} filter="url(#paper)">${body}</g>`;+const mark = (id, x, y) => `<g data-p="${id}" transform="translate(${x} ${y})"></g>`;+// One leg: the upper piece (data-p id) and the lower one (id + 'k', on the knee pin at y up) with its hoof or paw, and+// the foot's mark (id + 'Hoof'). sock colours the lower leg's foot end.+function legSVG(id, up, low, wUp, wLow, col, hoof, sock = null) {+ const u = `<path d="M${-wUp / 2},-6 C${-wUp / 2},${up * .5} ${-wLow / 2 - 1},${up * .8} ${-wLow / 2},${up + 4} L${wLow / 2},${up + 4} C${wLow / 2 + 1},${up * .8} ${wUp / 2},${up * .5} ${wUp / 2},-6 Z" fill="${col}"/>`;+ const l = `<path d="M${-wLow / 2},-3 L${-wLow / 2 + 1},${low - 14} L${wLow / 2 - 1},${low - 14} L${wLow / 2},-3 Z" fill="${col}"/>`+ + (sock ? `<path d="M${-wLow / 2 + 1},${low - 34} L${-wLow / 2 + 1},${low - 12} L${wLow / 2 - 1},${low - 12} L${wLow / 2 - 1},${low - 34} Z" fill="${sock}"/>` : '')+ + `<path d="M${-wLow / 2 - 2},${low - 15} L${wLow / 2 + 4},${low - 15} L${wLow / 2 + 7},${low} L${-wLow / 2 - 3},${low} Z" fill="${hoof}"/>`;+ return `<g data-p="${id}">${pf(u)}<g data-p="${id}k" transform="translate(0 ${up})">${pf(l)}${pinAt(0, 0)}${mark(id + 'Hoof', 1, low)}</g>${pinAt(0, 0)}</g>`;+}+// Two-bone reach from a hip to a foot point (dx, dy from the hip, y down): the upper and lower piece angles in degrees+// (SVG rotate, 0 = straight down). bend +1 puts the joint forward (a fore knee), -1 backward (a hind hock).+function reach2(dx, dy, up, low, bend) {+ let D = Math.hypot(dx, dy); D = Math.min(up + low - .5, Math.max(Math.abs(up - low) + 1, D));+ const phi0 = Math.atan2(dx, dy), b = Math.acos(Math.max(-1, Math.min(1, (up * up + D * D - low * low) / (2 * up * D))));+ const p1 = phi0 + bend * b, kx = up * Math.sin(p1), ky = up * Math.cos(p1);+ const p2 = Math.atan2(dx - kx, dy - ky);+ return [-p1 * 180 / Math.PI, -(p2 - p1) * 180 / Math.PI];+}+// Where each foot is, relative to its rest place, at walk distance d: [dx, lift]. Walk: one foot at a time (lateral+// sequence); trot: diagonal pairs.+const GAITS = {+ walk: { phase: { nh: 0, nf: .25, fh: .5, ff: .75 }, beta: .64, bob: 2.5 },+ trot: { phase: { nh: 0, ff: 0, fh: .5, nf: .5 }, beta: .5, bob: 6 },+};+function gait(d, kind, L, H) {+ const G = GAITS[kind], out = {}, u0 = d / L;+ for (const k of ['nf', 'ff', 'nh', 'fh']) {+ const r = u0 + G.phase[k] - Math.floor(u0 + G.phase[k]), b = G.beta, s = L * b;+ if (r < b) out[k] = [s / 2 - s * (r / b), 0];+ else { const w = (r - b) / (1 - b); out[k] = [-s / 2 + s * ease(w), H * Math.sin(Math.PI * w)]; }+ }+ out.bob = kind === 'trot' ? -G.bob * Math.abs(Math.sin(2 * Math.PI * u0)) : -G.bob * (1 - Math.cos(4 * Math.PI * u0)) / 2;+ return out;+}+const REST_BEAST = { x: 0, y: 0, s: 1, turn: 1, d: 0, gait: 'walk', stand: 1, bob: 0, tilt: 0, neck: 0, nod: 0, mouth: 'X',+ jaw: null, chew: 0, shut: false, lid: 0, look: 0, brow: 0, ear: 0, tail: 0, legs: {} };+function beast(parent, svg, geo, rest) {+ const g = mk('g', {}, parent);+ g.innerHTML = svg;+ bakeAll(g);+ const P = pieces(g), R = { ...REST_BEAST, ...rest };+ const legs = ['nf', 'ff', 'nh', 'fh'], toggles = Object.keys(R).filter(k => typeof R[k] === 'boolean' && k !== 'shut' && P[k]);+ return { g, P,+ pose(o, f) {+ o = { ...R, ...o };+ const j = k => jit(f, k);+ const gt = gait(o.d, o.gait, geo.L, geo.H), st = Math.max(0, Math.min(1, o.stand));+ const bob = o.bob + gt.bob * (1 - st);+ const tn = Math.sign(o.turn || 1) * Math.max(.34, Math.abs(o.turn)); // flips through, never a sliver+ tf(g, `translate(${(o.x + j(1) * .7).toFixed(1)},${(o.y + j(2) * .5).toFixed(1)}) scale(${(o.s * tn).toFixed(4)},${o.s.toFixed(4)})`);+ // the body (with neck, head, tail) tilts about its centre and rides the bob; legs hang from the tilted hips+ const [cx, cy] = geo.body, a = o.tilt * Math.PI / 180, ca = Math.cos(a), sa = Math.sin(a);+ tf(P.trunk, `translate(0,${bob.toFixed(1)}) rotate(${(o.tilt + j(3) * .3).toFixed(2)},${cx},${cy})`);+ for (const k of legs) {+ const [hx0, hy0] = geo.hips[k], hx = cx + (hx0 - cx) * ca - (hy0 - cy) * sa, hy = cy + (hx0 - cx) * sa + (hy0 - cy) * ca + bob;+ const [gx, gl] = gt[k], extra = o.legs[k] || [0, 0];+ const fx = hx0 + geo.rest[k] + gx * (1 - st) + extra[0], fy = -(gl * (1 - st)) - extra[1];+ const [a1, a2] = reach2(fx - hx, fy - hy, geo.up, geo.low, k[1] === 'f' ? 1 : -1);+ tf(P[k], `translate(${hx.toFixed(1)},${hy.toFixed(1)}) rotate(${(a1 + j(4) * .4).toFixed(2)})`);+ tf(P[k + 'k'], `translate(0,${geo.up}) rotate(${a2.toFixed(2)})`);+ }+ tf(P.neckG, `rotate(${(o.neck + j(5) * .4).toFixed(2)},${geo.neck[0]},${geo.neck[1]})`);+ tf(P.headG, `rotate(${(o.nod + j(6) * .5).toFixed(2)},${geo.head[0]},${geo.head[1]})`);+ const jaw = o.jaw ?? (o.chew ? .25 + .25 * Math.sin(o.chew * Math.PI * 2) : JAW[o.mouth || 'X'] ?? 0);+ tf(P.jaw, `rotate(${(jaw * geo.jawOpen).toFixed(1)},${geo.jaw[0]},${geo.jaw[1]})`);+ tf(P.ear, `rotate(${(o.ear * 22 + j(7)).toFixed(1)},${geo.ear[0]},${geo.ear[1]})`);+ tf(P.tail, `rotate(${(o.tail + j(8) * 1.5).toFixed(1)},${geo.tail[0]},${geo.tail[1]})`);+ vis(P.eyeO, !o.shut); vis(P.eyeC, !!o.shut);+ if (P.lid) { vis(P.lid, !o.shut && o.lid > 0); tf(P.lid, `translate(0,${(-geo.lidH * (1 - o.lid)).toFixed(1)})`); }+ tf(P.pupil, `translate(${(o.look * geo.lookX).toFixed(1)},0)`);+ if (P.brow) tf(P.brow, `rotate(${(o.brow * 14).toFixed(1)},${geo.eye[0]},${geo.eye[1] - 12}) translate(0,${(-4 * Math.max(0, o.brow)).toFixed(1)})`);+ for (const k of toggles) vis(P[k], !!o[k]);+ },+ at(name) { const m = P[name] || P['at_' + name]; const M = g.parentNode.getCTM().inverse().multiply(m.getCTM()); return [M.e, M.f]; },+ };+}++// The example: a tabby cat, about 150 units long and 130 tall to the ear tips; s 1.4 stands it beside the kid.+const CAT_GEO = { hips: { nf: [44, -60], ff: [52, -60], nh: [-44, -62], fh: [-36, -62] }, up: 30, low: 34, L: 46, H: 10,+ body: [0, -72], neck: [44, -82], head: [66, -104], jaw: [82, -92], jawOpen: 18, ear: [64, -124], tail: [-56, -80],+ rest: { nf: 2, ff: 0, nh: -2, fh: 0 }, eye: [80, -110], lidH: 9, lookX: 2 };+function catSVG({ coat = '#d98a3d', far = '#b8722f', stripe = '#a35a22', belly = '#f3e2c4', nose = '#d9646a', paw = '#f3e2c4' } = {}) {+ return `${legSVG('fh', 30, 34, 22, 11, far, paw)}${legSVG('ff', 30, 34, 15, 10, far, paw)}+ <g data-p="trunk">+ <g data-p="tail">${pf(`<path d="M-54,-84 C-82,-92 -96,-120 -88,-148 C-86,-156 -76,-156 -78,-146 C-84,-122 -72,-100 -50,-94 Z" fill="${coat}"/><path d="M-84,-126 l9,-2 M-80,-110 l9,-4 M-70,-98 l7,-6" stroke="${stripe}" stroke-width="4"/>`)}</g>+ ${pf(`<path d="M-62,-78 C-64,-98 -40,-104 0,-102 C34,-102 58,-98 60,-80 C62,-62 48,-52 30,-52 L-36,-52 C-54,-54 -62,-62 -62,-78 Z" fill="${coat}"/>+ <path d="M-30,-102 q4,12 -2,20 M-8,-103 q4,12 -2,20 M14,-103 q4,12 -2,20" stroke="${stripe}" stroke-width="5" fill="none" stroke-linecap="round"/>+ <path d="M-40,-56 C-20,-50 20,-50 40,-56 C34,-52 30,-52 26,-52 L-30,-52 Z" fill="${belly}"/>`)}${mark('at_back', 0, -104)}+ <g data-p="neckG">+ ${pf(`<path d="M30,-98 C40,-110 54,-116 64,-114 L76,-96 C68,-82 56,-70 44,-66 C34,-70 28,-84 30,-98 Z" fill="${coat}"/><path d="M50,-72 C58,-78 66,-86 72,-94 L76,-90 C70,-80 60,-70 48,-66 Z" fill="${belly}"/>`)}+ <g data-p="headG">+ <g data-p="ear">${pf(`<path d="M56,-118 L60,-142 L74,-122 Z" fill="${coat}"/><path d="M60,-122 L62,-136 L70,-123 Z" fill="${nose}" opacity=".7"/>`)}</g>+ ${pf(`<path d="M50,-112 C50,-130 74,-136 86,-124 C94,-116 100,-106 100,-98 C100,-88 90,-84 80,-86 L64,-90 C54,-94 50,-102 50,-112 Z" fill="${coat}"/>+ <path d="M74,-130 L80,-142 L88,-124 Z" fill="${coat}"/><path d="M58,-128 q6,6 14,4" stroke="${stripe}" stroke-width="3" fill="none"/>+ <ellipse cx="90" cy="-96" rx="10" ry="7" fill="${belly}"/><path d="M97,-102 l4,3 l-5,2 Z" fill="${nose}"/>+ <path d="M92,-98 l18,-3 M92,-96 l18,2" stroke="#3a2a20" stroke-width="1.2" opacity=".6"/>`)}+ <g data-p="jaw">${pf(`<path d="M80,-90 C88,-86 96,-86 100,-90 C99,-82 90,-79 82,-84 Z" fill="${belly}"/>`)}${mark('at_mouth', 96, -88)}</g>+ <g data-p="eyeO"><ellipse cx="80" cy="-110" rx="5.5" ry="6" fill="#e9d36a"/><g data-p="pupil"><ellipse cx="81" cy="-110" rx="2" ry="4.6" fill="#1e1610"/><circle cx="82.5" cy="-112" r="1.2" fill="#fff"/></g>+ <g data-p="lid"><rect x="73.5" y="-118" width="13" height="8" fill="${coat}"/><path d="M74,-110 h12" stroke="#1e1610" stroke-width="1.8"/></g></g>+ <g data-p="eyeC"><path d="M75,-109 Q80,-105 85,-109" stroke="#1e1610" stroke-width="2.2" fill="none"/></g>+ <path data-p="brow" d="M74,-120 Q80,-123 87,-120" stroke="${stripe}" stroke-width="3" fill="none" stroke-linecap="round"/>+ ${mark('at_eye', 80, -110)}${mark('at_head', 72, -138)}${pinAt(66, -104)}+ </g>${pinAt(44, -82)}+ </g>+ </g>+ ${legSVG('nh', 30, 34, 24, 12, coat, paw)}${legSVG('nf', 30, 34, 16, 11, coat, paw)}`;+}+// catPuppet(parent, colours, rest): colours as catSVG's; rest overrides REST_BEAST (gait, lid …).+const catPuppet = (parent, colours = {}, rest = {}) => beast(parent, catSVG(colours), CAT_GEO, rest);diff --git a/.claude/skills/papermorph/assets/templates/picture-book/lib/paper.js b/.claude/skills/papermorph/assets/templates/picture-book/lib/paper.jsindex 83d11af..f16b2e8 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/lib/paper.js+++ b/.claude/skills/papermorph/assets/templates/picture-book/lib/paper.js@@ -48,18 +48,28 @@ function stopClock(D, draw) { let last = null; clockRun(t => { const f = Math.flA view {x, y, z} is the world point at the frame's centre and the zoom. Moves: to(view, t0, dur) eases each givenkey from where the camera is at t0 (zooms keep one world point still, as the engine's camera does); cut(view, t0).Layers slide by their parallax factor k against the base view. soft(t0, on) swaps the far layers (k < 1) for their- blurred copies: shallow focus on close shots (on = 'all' blurs the puppets' plane too, for a set seen behind a close-up). Puppets go in cam.stage, on the k = 1 plane in front of `after`. */+ blurred copies: shallow focus on close shots (on = 'all' blurs the puppets' plane too, for a set seen behind a close-up).+ Puppets go in cam.stage, a k = 1 plane drawn just after the layer named `after`. Without one it is the set's layer+ marked stage: true in sets.js (bake_sets.py and painted.py keep the mark), else the first layer with k 1, so a set+ that always needs the same place for its puppets says so once (a river's tree in front of the bank, a house whose+ front hides whoever is inside). stages: [layer names] adds a plane after each of those layers too, cam.stageAt[name],+ for things that stand further back: ducks on a pond in front of its water, a grandmother at the window of a house+ layer drawn over cam.stage. */function paperCam(p, setName, v0 = {}, { after = null, stages = [] } = {}) {const root = mk('g', {}, p), view = mk('g', {}, root), world = mk('g', {}, view), layers = [], ops = [], softs = [], shakes = [];- let stage = null; const stageAt = {};- for (const L of SETS[setName]) {+ let stage = null; const stageAt = {}, set = SETS[setName];+ if (!set) throw new Error(`paperCam: no set '${setName}' in img/sets/sets.js (${Object.keys(SETS).join(', ')})`);+ after ??= (set.find(L => L.stage) || set.find(L => L.k === 1) || set[set.length - 1]).name;+ for (const n of [after, ...stages]) if (!set.some(L => L.name === n)) console.warn(`paperCam: set '${setName}' has no layer '${n}' (${set.map(L => L.name).join(', ')})`);+ for (const L of set) {const g = mk('g', {}, world), [x, y, width, height] = L.box, img = { x, y, width, height, preserveAspectRatio: 'none' };const sharp = mk('image', { href: `../img/sets/${setName}/${L.name}.webp`, ...img }, g);const blur = L.soft ? mk('image', { href: `../img/sets/${setName}/${L.name}-soft.webp`, ...img, visibility: 'hidden' }, g) : null;layers.push({ g, k: L.k, sharp, blur, name: L.name });if (stages.includes(L.name)) layers.push({ g: stageAt[L.name] = mk('g', {}, world), k: L.k });- if (L.name === after || (!after && L.k === 1 && !stage)) layers.push({ g: stage = mk('g', {}, world), k: 1 });+ if (L.name === after) layers.push({ g: stage = mk('g', {}, world), k: 1 });}+ if (!stage) layers.push({ g: stage = mk('g', {}, world), k: 1 }); // an unknown `after` (warned above): in front of everythingmk('rect', { width: 1600, height: 900, fill: 'url(#vignette)', 'pointer-events': 'none' }, root); // a tap goes through to the picture// Parallax is measured from the set's own framing (base), wherever the beat's first view is.const base = { x: 800, y: 450, z: 1 }, start = { ...base, ...v0 };diff --git a/.claude/skills/papermorph/assets/templates/picture-book/narration.en.json b/.claude/skills/papermorph/assets/templates/picture-book/narration.en.jsonindex 6a071fb..d0912ce 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/narration.en.json+++ b/.claude/skills/papermorph/assets/templates/picture-book/narration.en.json@@ -10,6 +10,15 @@"s01": "Once upon a time, a kid knocked on the door.","s02": { "speaker": "kid", "text": "Dad? Are you home?" },"s02b": { "speaker": "dad", "text": "[[open]]Of course I am. Come in." },- "s03": { "speaker": "kid", "text": "Good. I brought you a cat." }+ "s03": { "speaker": "kid", "text": "Good. I brought you a cat." },+ "q-cat": "Can you find the cat? Touch it!",+ "r-cat": "Where's the cat?",+ "w-cat": "The cat!",+ "q-dad": "Now find Dad!",+ "r-dad": "Where's Dad?",+ "w-dad": "Dad!",+ "w-kid": "That's the kid.",+ "q-done": "You found them all!",+ "q-there": "Look! There it is!"}}diff --git a/.claude/skills/papermorph/assets/templates/picture-book/scene1.js b/.claude/skills/papermorph/assets/templates/picture-book/scene1.jsindex 16a9af6..c241297 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/scene1.js+++ b/.claude/skills/papermorph/assets/templates/picture-book/scene1.js@@ -1,27 +1,38 @@-/* scene1.js — one scene of the film = one beat: a set, two puppets, a joined voice track, a sound effect. Copy it for- scene2.js … and list them in chapter.html. A scene is a pure function of time: stopClock calls the drawing once per- 12 fps frame with q, the beat's clock, so pause, seek and ?beat=N&t=S show exactly the frame a viewer would see.+/* scene1.js — one scene of the film = one beat: a set, three puppets, a joined voice track, a sound effect, and the+ things a listen-and-find stop asks for. Copy it for scene2.js … and list them in chapter.html. A scene is a pure+ function of time: stopClock calls the drawing once per 12 fps frame with q, the beat's clock, so pause, seek and+ ?beat=N&t=S show exactly the frame a viewer would see.Cut shots with cam.cut(view, t0), move with cam.to(view, t0, dur); a close-up on whoever speaks is a cut, not a zoom.Build the scene's pictures first (outside stopClock), then pose every puppet every frame. */'use strict';const PRE1 = 1.0; // seconds of picture before the first word (the beat's `pre`)+let THINGS1 = []; // what can be tapped in this picture, filled each time the scene builds; the beat's findWords reads itfunction scene1(p, D) {const cam = paperCam(p, 'room'); // the set 'room' from img/sets/sets.js; puppets go in cam.stagecam.cut({ x: 800, y: 450, z: 1 }, 0).to({ x: 860, y: 470, z: 1.12 }, 1, 9); // a slow push-inconst kid = kidPuppet(cam.stage, { coat: '#c94a3c', stripe: '#c94a3c' });const dad = kidPuppet(cam.stage, { coat: '#3e7fc4', stripe: '#f4f1ea' });+ const cat = catPuppet(cam.stage); // the four-legged rig (cast.js, section 3)+ // The listen-and-find stop after the scene (chapter.html's FIND1): every thing a child might tap says its name+ // (audio/en/w-<word>.mp3), so list the background's people too, not only what is asked for.+ THINGS1 = [{ g: cat.g, word: 'cat' }, { g: dad.g, word: 'dad' }, { g: kid.g, word: 'kid' }];sfx('scene1', .3, 'knock'); // audio/sfx/knock.mp3 (SKILL/scripts/sfx.py)const enter = clipAt('scene1', PRE1, 's02'); // when the kid's first line starts// the kid side-steps in from the left with planted feet (spStep, cast.js): whole steps (2/3 s each) that end at x 580// just before the line; x comes from the distance the steps cover, so the feet never slideconst STEP = 2 / 3, steps = Math.max(0, Math.floor((enter - .2) / STEP)), far = spStep(steps * STEP).d;+ // the cat walks in ahead of the kid and stops at its feet: route gives x and the distance d that plants the paws+ const CAT = [[0, -160], [Math.max(1, enter - .4), 330]];stopClock(D, (q, f) => {cam.apply(q, f);const w = spStep(Math.min(Math.floor(q * 6) / 6, steps * STEP)); // on twos, like everything elsekid.pose({ x: 580 - .95 * (far - w.d), y: 800, s: .95, look: .6, mouth: lips(q, 'scene1', PRE1, 's02', 's03'),legL: w.legL, legR: w.legR, bob: w.drop, shut: blinking(q, [2.4, 6.1]) }, f);+ const r = route(q, CAT, 1.3);+ cat.pose({ x: r.x, y: 800, s: 1.3, d: r.d, stand: r.stand, tail: 10 * Math.sin(q * 2), look: q > enter ? 1 : 0,+ shut: blinking(q, [3.0, 7.2]) }, f);dad.pose({ x: 1250, y: 800, s: 1, look: -.6, mouth: lips(q, 'scene1', PRE1, 's02b'), brow: q > enter ? -.3 : 0,shut: blinking(q, [3.3]) }, f);});diff --git a/.claude/skills/papermorph/assets/templates/picture-book/sets.js b/.claude/skills/papermorph/assets/templates/picture-book/sets.jsindex 0d068f1..60d275e 100644--- a/.claude/skills/papermorph/assets/templates/picture-book/sets.js+++ b/.claude/skills/papermorph/assets/templates/picture-book/sets.js@@ -6,7 +6,10 @@// scale bitmap pixels per world px (1.2 is plenty for a 1600 x 900 frame; raise it for layers a close-up fills).// soft false skips the blurred -soft copy (use it for small foreground pieces); the camera swaps the copy in for// shallow focus on close shots.-// The puppets stand on the first k = 1 layer ('floor' below) and in front of it; layers after it hide them (the table).+// stage true: the puppets stand in front of this layer (paperCam's default `after`).+// Without a stage mark the puppets stand on the first k = 1 layer ('floor' below) and in front of it; layers after it+// hide them (the table). Mark another layer when the puppets belong further forward, e.g. in front of a tree that is+// itself in front of the bank, with the water and the near bank still over them.// Give a layer more room than the 1600 x 900 frame (here -100 … 1700) so a pan or shake never shows its edge.// These sketches are a finished look on their own (free) and the composition reference an image model repaints:// bake one, give the picture to paint.py as a reference, and put the result in with painted.py.diff --git a/.claude/skills/papermorph/references/picture-books/puppets.md b/.claude/skills/papermorph/references/picture-books/puppets.mdindex 168b0ea..3d08d2a 100644--- a/.claude/skills/papermorph/references/picture-books/puppets.md+++ b/.claude/skills/papermorph/references/picture-books/puppets.md@@ -2,7 +2,13 @@The actors are paper puppets drawn in code: pieces of coloured paper pinned at the joints, moved a little each frame, like a cut-out film shot by hand. A pose is only a set of numbers, so any action the story needs (ducking, swinging an axe, diving through a window, shoving a thought bubble) costs a few lines, never a new drawing, and a puppet looks the same in every shot. The kit is in `assets/templates/picture-book/` (`paper.js`, `cast.js`, `shared.js`, `chapter.html`); `new_book.py picture` copies it into `site/<book>/lib/` and the first episode folder.-Two cast styles are on the shelf, both on `paper.js`: round-headed figures that face us, in the spirit of South Park (*Joke Collection*), built by the kit's `cast.js` (add a character by copying an entry of its `SHAPES`); and jointed storybook figures seen mostly in profile (*Little Red Riding Hood*: the wolf, Grandma, the woodcutter), which a book draws itself, a side and a front set per figure (start from that book's `lib/paper.js` and `lib/cast.js`, under `site/little-red-riding-hood/` in the Papermorph repository). Pick with the user; the first is quicker to build and to act with.+The kit's `cast.js` holds three kinds of puppet, all on `paper.js`, each with a working example; its header lists every pose key, and a book keeps the kinds its story needs:++1. **Round-headed figures that face us**, in the spirit of South Park (*Joke Collection*): `kidPuppet`; add a character by copying an entry of `SHAPES`. Quickest to build and to act with.+2. **Storybook figures seen mostly in profile**, a side set and a front set of pieces per figure (*Little Red Riding Hood*: Red, Mother, Grandma, the woodcutter, the wolf): `figurePuppet`, a child in a coat and a hat whose colours make other characters, on the shared `puppet()` and `common()`. Beyond the common keys it can look (`look`, the pupils), worry or frown (`brow`), blink (`shut`), bend at the waist (`lean`), duck or bend to pick something up with the feet kept on the ground (`crouch`, the far arm `fua`/`ffa`), take its hat off (`hat`; the hair is drawn under the hat, so the head is never bald) and hold a thing upright in its hand (`hold`).+3. **Four-legged animals** in profile (*The Little Horse Crosses the River*: the horses, the water buffalo): `beast()`, a two-bone leg rig whose walk and trot come from the distance covered, with `catPuppet` as the example; another animal is another drawing and its `geo` (the pins and leg lengths), as Little Horse's `lib/cast.js` shows for a foal, a mare and a buffalo.++Pick with the user. The two reference books' own `cast.js` files show the second and third kinds carried through a whole episode (`site/little-red-riding-hood/` and `site/little-horse/` in the Papermorph repository).## Contents@@ -22,16 +28,16 @@ Two cast styles are on the shelf, both on `paper.js`: round-headed figures that## Acting- **Nobody freezes.** Whoever speaks lip-syncs; everyone blinks at their own moments, never in unison; listeners' eyes follow the speaker; reactions get a small head turn or a lid drop. A crowd glances about on its own and turns as one only when something happens (a staggered snap, a frame or two apart).-- **Turning round.** A round-headed puppet turns by sliding its face across the head (`look`), as South Park does. A profile puppet turns as a whole-body swap: the side view squashes, the whole front figure shows for the narrowest frames, and it comes out mirrored. A front head on a side body looked wrong every time.-- **Feet don't slide.** A walk keeps the planted foot still while the hip rides over it, and the puppet's x comes from the distance the walk returns (`d`, in the puppet's units, times its scale), never from a separate tween. A profile figure uses the compass step `walk()` (`paper.js`): `d` grows as it goes forward, so one built facing right goes `x0 + d·s` and a mirrored one `x0 − d·s`; its `near`/`far` angles go to the near and far leg as they are. A figure that faces us while crossing the frame side-steps with `spStep()` (`cast.js`): step out, close, both legs leaning outward, `x0 ± d·s` by direction, a step every 2/3 s by default (keep the period a whole number of 1/3 s, so a drawn frame lands on the widest stance and only one foot moves at a time; the template's `scene1.js` walks the kid this way); `walk()`'s angles on a front figure cross the ankles every other step. `spWalk()` is the show's quick shuffle on the spot, for short moves where nobody watches the feet. Runs are on twos with a bigger bob. Check a walk on a strip at 1/12 s: the planted shoe should not move between frames.-- **Hands touch what they hold.** A held prop belongs to the hand's piece (`hold` is the screen-right hand, on `armR`; `holdL` the screen-left one, on `armL`); when something is handed over, both hands meet it. To put a hand on a point, ask the puppet: `aim(pose, 'R', [x, y])` gives the `armR`/`reachR` values for that pose (spread straight into the pose, or tween `arm` and `reach` from rest for a gesture), and `point(pose, 'mouth' | 'chin' | 'capL' | 'capR')` says where that place of the face is in the same pose, so a cup, a scratch or a chin on a hand lands right through a lean, a head tilt or a seat. A held thing hangs from the mitten's centre, so aim at the point less the thing's own offset (a cup's rim above the hand). A hand raised above the chin and in towards the face (a cup at the lips, a hand on the chin, a reach across the head) is drawn in front of the head; an arm raised out to the side (a wave, a cheer) stays behind it, and so does a hand at its own side of the head, so a scratch there wants `armFrontR: true` (or `armFrontL`; `false` keeps a hand behind). `far` above 1.25 means the point is out of reach: lean in, step closer or move the point. Look at a full-size still of the moment the hand arrives.+- **Turning round.** A round-headed puppet turns by sliding its face across the head (`look`), as South Park does. A storybook figure turns as a whole-body swap: tween `turn` from 1 to −1 and the side view squashes, the whole front figure shows while `|turn|` is under .55, and it comes out mirrored; `head: 'F'` shows the front figure outright. A front head on a side body looked wrong every time. A four-legged animal has no front figure: it squashes as a card turned over on the table, never thinner than a third of its width. On *Little Horse* reviewers still flagged such turns inside medium shots, and a turn on a cut read best (the next shot simply has the other `turn`); when it has to happen on screen, `flipTurn(q, t0, 1, -1)` turns it over in four frames on twos, in a wide shot.+- **Feet don't slide.** A walk keeps the planted foot still while the hip rides over it, and the puppet's x comes from the distance the walk returns (`d`, in the puppet's units, times its scale), never from a separate tween. A profile figure uses the compass step `walk()` (`paper.js`): `d` grows as it goes forward, so one built facing right goes `x0 + d·s` and a mirrored one `x0 − d·s`; its `near`/`far` angles go to the near and far leg as they are. A figure that faces us while crossing the frame side-steps with `spStep()` (`cast.js`): step out, close, both legs leaning outward, `x0 ± d·s` by direction, a step every 2/3 s by default (keep the period a whole number of 1/3 s, so a drawn frame lands on the widest stance and only one foot moves at a time; the template's `scene1.js` walks the kid this way); `walk()`'s angles on a front figure cross the ankles every other step. `spWalk()` is the show's quick shuffle on the spot, for short moves where nobody watches the feet. A storybook figure's feet are at y 170 (`hipOn(gy, s)` puts them on the ground at `gy`); `walker(x0, s, opts, dir, steps)` walks it and stops cleanly, the lifted foot set down beside the other, and `bigStep(u)` is one deliberate step (off a path onto the grass). A four-legged animal takes the distance itself: `route(q, [[t, x], …], s)` gives its `x`, the distance `d` for `pose({ d })` and `stand` for setting off and stopping, so its feet stay planted at any speed (`gait: 'walk'` one foot at a time, `'trot'` in diagonal pairs). Runs are on twos with a bigger bob. Check a walk on a strip at 1/12 s: the planted shoe should not move between frames.+- **Hands touch what they hold.** A held prop belongs to the hand's piece (`hold` is the screen-right hand, on `armR`; `holdL` the screen-left one, on `armL`); when something is handed over, both hands meet it. To put a hand on a point, ask the puppet: `aim(pose, 'R', [x, y])` gives the `armR`/`reachR` values for that pose (spread straight into the pose, or tween `arm` and `reach` from rest for a gesture), and `point(pose, 'mouth' | 'chin' | 'capL' | 'capR')` says where that place of the face is in the same pose, so a cup, a scratch or a chin on a hand lands right through a lean, a head tilt or a seat. A held thing hangs from the mitten's centre, so aim at the point less the thing's own offset (a cup's rim above the hand). A hand raised above the chin and in towards the face (a cup at the lips, a hand on the chin, a reach across the head) is drawn in front of the head; an arm raised out to the side (a wave, a cheer) stays behind it, and so does a hand at its own side of the head, so a scratch there wants `armFrontR: true` (or `armFrontL`; `false` keeps a hand behind). `far` above 1.25 means the point is out of reach: lean in, step closer or move the point. A storybook figure's `hold` puts a thing in its near hand and its front right hand at once, kept upright through any bend. A four-legged animal answers `at(name)` with a drawn point of the current pose (`'mouth'`, `'eye'`, a hip, knee or foot such as `'nfk'` or `'nfHoof'`, and any mark its drawing places), so on *Little Horse* the sack went from Mother's mouth onto the foal's back (`at('mouth')`, `at('back')`) and the ripples sat at the buffalo's hooves (`at('nfHoof')`). Look at a full-size still of the moment the hand arrives.- **Sitting reads from the knees.** A figure that faces us looks seated only when its thighs come towards us: `sit: H` sits on a seat H units above the feet (up to the shape's `legH − 12`, 34 on the kid; a higher seat counts as that), the lap and knees towards us and the shins down to the ground at the pose's `y`. `sit: true` only hides the legs and the shadow, for a seat whose front comes up to the coat (a desk row). A still beside the standing pose should read sitting without the set.- **Whatever says where something is follows what is drawn.** A helper a scene asks for a position (`point()`, `aim()`, a board's square, the top of a piece the kit adds) works from the same state the drawing uses this frame, a piece being lifted or carried included, and draw order comes from the pose alone, so a seek to any frame shows what playback showed (compare a playback frame with the same `?beat=N&t=S`).-- **Things behind things.** A counter, a cart, a desk row or a lectern sits on its own layer between puppets, so the person behind shows from the chest up (`paperCam(…, { after, stages })` puts puppet layers between set layers).+- **Things behind things.** A counter, a cart, a desk row or a lectern sits on its own layer between puppets, so the person behind shows from the chest up. `cam.stage`, where puppets go, is drawn just after one set layer: `after` names it, else the set's layer marked `stage: true` in `sets.js`, else its first layer with k 1. `stages: [layers]` adds a plane after each of those too (`cam.stageAt[name]`), for things that stand further back than the puppets. On *Little Horse* the river set needed its puppets in front of the tree and behind the water and the near bank (`after: 'tree'`), and the ducks swam on `stages: ['pond']`, in front of the pond's water; on *Little Red Riding Hood* the house front hides whoever is inside (`{ after: 'house', stages: ['inside'] }`). When a set always wants the same place, mark that layer `stage: true` once in `sets.js` rather than passing `after` in every scene.## Cameras-`paperCam(parent, set, view)` is one camera on one set: layers slide with parallax, `to`/`cut` move it on the scene's clock, `soft` swaps in the blurred copy of the set for close-ups, `shake(t0, dur, amp = 10)` jolts it (the engine's `cam.shake` takes the amplitude first), `show(layer, on)` swaps a layer (rain and snow versions of the same street). A scene can hold several cameras; cut between places by showing one `cam.root` and hiding the others. Close-ups zoom the same set and blur it, so the speaker stays sharp.+`paperCam(parent, set, view, { after, stages })` is one camera on one set: layers slide with parallax, `to`/`cut` move it on the scene's clock, `soft` swaps in the blurred copy of the set for close-ups, `shake(t0, dur, amp = 10)` jolts it (the engine's `cam.shake` takes the amplitude first), `show(layer, on)` swaps a layer (rain and snow versions of the same street). A scene can hold several cameras; cut between places by showing one `cam.root` and hiding the others. Close-ups zoom the same set and blur it, so the speaker stays sharp.## Performancediff --git a/.claude/skills/papermorph/scripts/bake_sets.py b/.claude/skills/papermorph/scripts/bake_sets.pyindex f493494..9b8c3a3 100644--- a/.claude/skills/papermorph/scripts/bake_sets.py+++ b/.claude/skills/papermorph/scripts/bake_sets.py@@ -5,8 +5,8 @@SETS.JS (template: assets/templates/picture-book/sets.js) defines window.SETS = {setName: () => [layer, ...]} andwindow.SET_DEFS (an SVG <defs> string with the paper filters). A layer is {name, k, box: [x, y, w, h] in world px,-scale, svg, soft?}: k is the parallax factor (1 = the puppets' plane), scale the bitmap's pixels per world px, soft:-false skips the blurred copy. Writes SITE/img/sets/<set>/<layer>.webp, <layer>-soft.webp and the placement manifest+scale, svg, soft?, stage?}: k is the parallax factor (1 = the puppets' plane), scale the bitmap's pixels per world px, soft:+false skips the blurred copy, stage: true makes it the layer the puppets stand in front of (paperCam's default `after`). Writes SITE/img/sets/<set>/<layer>.webp, <layer>-soft.webp and the placement manifestSITE/img/sets/sets.js that paper.js reads. The manifest keeps every set it already lists: without SET names only thesets it does not list yet are baked (one that is there may have been painted since), and with SET names those are bakedagain. --ref DIR also writes each baked set's layers as one 1600x900 picture, DIR/ref-<set>.png.@@ -42,7 +42,7 @@ async def main(sets_js, site, only, ref):if not names: print('every set is in the manifest already: name the ones to bake again')for n in names:frame = Image.new('RGBA', (1600, 900))- layers = await pg.evaluate(f'SETS[{json.dumps(n)}]().map(l => ({{name: l.name, k: l.k, box: l.box, soft: l.soft !== false}}))')+ layers = await pg.evaluate(f'SETS[{json.dumps(n)}]().map(l => ({{name: l.name, k: l.k, box: l.box, soft: l.soft !== false, ...(l.stage ? {{stage: true}} : {{}})}}))')(out / n).mkdir(parents=True, exist_ok=True)for i, L in enumerate(layers):for soft in ([False, True] if L['soft'] else [False]):diff --git a/.claude/skills/papermorph/scripts/new_book.py b/.claude/skills/papermorph/scripts/new_book.pyindex 3508ecd..1837f84 100644--- a/.claude/skills/papermorph/scripts/new_book.py+++ b/.claude/skills/papermorph/scripts/new_book.py@@ -69,8 +69,8 @@ def start(a, root, ch, site, work, content):copy(T / 'chapter.html', site / ch / 'index.html')copy(T / 'narration.en.json', narration)elif a.kind == 'picture':- (site / 'img' / 'puppets').mkdir(parents=True, exist_ok=True)- (work / 'art').mkdir(parents=True, exist_ok=True)+ for d in (site / 'img' / 'puppets', work / 'art', site / ch / 'audio' / 'sfx'):+ d.mkdir(parents=True, exist_ok=True)copy(PB / 'series.html', site / 'index.html')for f in (PB / 'lib').glob('*.js'):copy(f, site / 'lib' / f.name)@@ -101,7 +101,8 @@ def start(a, root, ch, site, work, content):print(f'\n{a.kind} book started: {site.relative_to(root)}/ (pilot {ch}); next:')print(f' uv run --with edge-tts python3 {S}/tts.py {narration.relative_to(root)} {A.relative_to(root)}')if a.kind == 'picture':- print(f' then level.py, mouths.py, join.py and sfx.py in tools/{a.book}/audio.sh; bake_sets.py, scenes, bake_puppets.py')+ print(f' uv run --with numpy python3 {S}/sfx.py {(site / ch / "audio" / "sfx").relative_to(root)} knock chime # the template scene\'s knock, the find stop\'s chime')+ print(f' then level.py, mouths.py, join.py in tools/{a.book}/audio.sh; bake_sets.py, scenes, bake_puppets.py')if a.kind == 'shorts':print(f' uv run --with numpy python3 {S}/sfx.py {(site / ch / "audio" / "sfx").relative_to(root)} whoosh bang tick thud')if a.maps:diff --git a/.claude/skills/papermorph/scripts/painted.py b/.claude/skills/papermorph/scripts/painted.pyindex 366f7ed..4a8bcf0 100644--- a/.claude/skills/papermorph/scripts/painted.py+++ b/.claude/skills/papermorph/scripts/painted.py@@ -28,7 +28,8 @@ first (it rewrites sets.js); run this again after any change. Paths in the manif"props": {"bun": "p-bun.png"} (largest side 800 px)}-A layer with neither `cut` nor `box` is a full frame. `font` names an entry of `fonts` or is a path; without one the+A layer with neither `cut` nor `box` is a full frame. "stage": true on a layer puts the puppets in front of it by+default (paperCam's `after`); without one they stand in front of the first layer with k 1. `font` names an entry of `fonts` or is a path; without one thefirst CJK-capable system font found is used (macOS Hiragino/PingFang/STHeiti, Windows YaHei, Noto/WenQuanYi on Linux)."""import json, pathlib, sys@@ -106,7 +107,7 @@ def main(manifest, site):im = im.resize((W, H), Image.LANCZOS); words(im, L.get('words', []), 0, 0, fonts, base)im = padded(im, pad, L.get('edge', 'mirror')); b = [-pad[0], -pad[1], W + 2 * pad[0], H + 2 * pad[1]]made.append((L['name'], im))- entry.append({'name': L['name'], 'k': L.get('k', 1), 'box': b, 'soft': True})+ entry.append({'name': L['name'], 'k': L.get('k', 1), 'box': b, 'soft': True, **({'stage': True} if L.get('stage') else {})})print(name, L['name'], b)out.mkdir(parents=True, exist_ok=True)for f in out.glob('*.webp'): f.unlink()diff --git a/site/little-horse/lib/paper.js b/site/little-horse/lib/paper.jsindex 83d11af..f16b2e8 100644--- a/site/little-horse/lib/paper.js+++ b/site/little-horse/lib/paper.js@@ -48,18 +48,28 @@ function stopClock(D, draw) { let last = null; clockRun(t => { const f = Math.flA view {x, y, z} is the world point at the frame's centre and the zoom. Moves: to(view, t0, dur) eases each givenkey from where the camera is at t0 (zooms keep one world point still, as the engine's camera does); cut(view, t0).Layers slide by their parallax factor k against the base view. soft(t0, on) swaps the far layers (k < 1) for their- blurred copies: shallow focus on close shots (on = 'all' blurs the puppets' plane too, for a set seen behind a close-up). Puppets go in cam.stage, on the k = 1 plane in front of `after`. */+ blurred copies: shallow focus on close shots (on = 'all' blurs the puppets' plane too, for a set seen behind a close-up).+ Puppets go in cam.stage, a k = 1 plane drawn just after the layer named `after`. Without one it is the set's layer+ marked stage: true in sets.js (bake_sets.py and painted.py keep the mark), else the first layer with k 1, so a set+ that always needs the same place for its puppets says so once (a river's tree in front of the bank, a house whose+ front hides whoever is inside). stages: [layer names] adds a plane after each of those layers too, cam.stageAt[name],+ for things that stand further back: ducks on a pond in front of its water, a grandmother at the window of a house+ layer drawn over cam.stage. */function paperCam(p, setName, v0 = {}, { after = null, stages = [] } = {}) {const root = mk('g', {}, p), view = mk('g', {}, root), world = mk('g', {}, view), layers = [], ops = [], softs = [], shakes = [];- let stage = null; const stageAt = {};- for (const L of SETS[setName]) {+ let stage = null; const stageAt = {}, set = SETS[setName];+ if (!set) throw new Error(`paperCam: no set '${setName}' in img/sets/sets.js (${Object.keys(SETS).join(', ')})`);+ after ??= (set.find(L => L.stage) || set.find(L => L.k === 1) || set[set.length - 1]).name;+ for (const n of [after, ...stages]) if (!set.some(L => L.name === n)) console.warn(`paperCam: set '${setName}' has no layer '${n}' (${set.map(L => L.name).join(', ')})`);+ for (const L of set) {const g = mk('g', {}, world), [x, y, width, height] = L.box, img = { x, y, width, height, preserveAspectRatio: 'none' };const sharp = mk('image', { href: `../img/sets/${setName}/${L.name}.webp`, ...img }, g);const blur = L.soft ? mk('image', { href: `../img/sets/${setName}/${L.name}-soft.webp`, ...img, visibility: 'hidden' }, g) : null;layers.push({ g, k: L.k, sharp, blur, name: L.name });if (stages.includes(L.name)) layers.push({ g: stageAt[L.name] = mk('g', {}, world), k: L.k });- if (L.name === after || (!after && L.k === 1 && !stage)) layers.push({ g: stage = mk('g', {}, world), k: 1 });+ if (L.name === after) layers.push({ g: stage = mk('g', {}, world), k: 1 });}+ if (!stage) layers.push({ g: stage = mk('g', {}, world), k: 1 }); // an unknown `after` (warned above): in front of everythingmk('rect', { width: 1600, height: 900, fill: 'url(#vignette)', 'pointer-events': 'none' }, root); // a tap goes through to the picture// Parallax is measured from the set's own framing (base), wherever the beat's first view is.const base = { x: 800, y: 450, z: 1 }, start = { ...base, ...v0 };diff --git a/site/little-red-riding-hood/lib/paper.js b/site/little-red-riding-hood/lib/paper.jsindex 83d11af..f16b2e8 100644--- a/site/little-red-riding-hood/lib/paper.js+++ b/site/little-red-riding-hood/lib/paper.js@@ -48,18 +48,28 @@ function stopClock(D, draw) { let last = null; clockRun(t => { const f = Math.flA view {x, y, z} is the world point at the frame's centre and the zoom. Moves: to(view, t0, dur) eases each givenkey from where the camera is at t0 (zooms keep one world point still, as the engine's camera does); cut(view, t0).Layers slide by their parallax factor k against the base view. soft(t0, on) swaps the far layers (k < 1) for their- blurred copies: shallow focus on close shots (on = 'all' blurs the puppets' plane too, for a set seen behind a close-up). Puppets go in cam.stage, on the k = 1 plane in front of `after`. */+ blurred copies: shallow focus on close shots (on = 'all' blurs the puppets' plane too, for a set seen behind a close-up).+ Puppets go in cam.stage, a k = 1 plane drawn just after the layer named `after`. Without one it is the set's layer+ marked stage: true in sets.js (bake_sets.py and painted.py keep the mark), else the first layer with k 1, so a set+ that always needs the same place for its puppets says so once (a river's tree in front of the bank, a house whose+ front hides whoever is inside). stages: [layer names] adds a plane after each of those layers too, cam.stageAt[name],+ for things that stand further back: ducks on a pond in front of its water, a grandmother at the window of a house+ layer drawn over cam.stage. */function paperCam(p, setName, v0 = {}, { after = null, stages = [] } = {}) {const root = mk('g', {}, p), view = mk('g', {}, root), world = mk('g', {}, view), layers = [], ops = [], softs = [], shakes = [];- let stage = null; const stageAt = {};- for (const L of SETS[setName]) {+ let stage = null; const stageAt = {}, set = SETS[setName];+ if (!set) throw new Error(`paperCam: no set '${setName}' in img/sets/sets.js (${Object.keys(SETS).join(', ')})`);+ after ??= (set.find(L => L.stage) || set.find(L => L.k === 1) || set[set.length - 1]).name;+ for (const n of [after, ...stages]) if (!set.some(L => L.name === n)) console.warn(`paperCam: set '${setName}' has no layer '${n}' (${set.map(L => L.name).join(', ')})`);+ for (const L of set) {const g = mk('g', {}, world), [x, y, width, height] = L.box, img = { x, y, width, height, preserveAspectRatio: 'none' };const sharp = mk('image', { href: `../img/sets/${setName}/${L.name}.webp`, ...img }, g);const blur = L.soft ? mk('image', { href: `../img/sets/${setName}/${L.name}-soft.webp`, ...img, visibility: 'hidden' }, g) : null;layers.push({ g, k: L.k, sharp, blur, name: L.name });if (stages.includes(L.name)) layers.push({ g: stageAt[L.name] = mk('g', {}, world), k: L.k });- if (L.name === after || (!after && L.k === 1 && !stage)) layers.push({ g: stage = mk('g', {}, world), k: 1 });+ if (L.name === after) layers.push({ g: stage = mk('g', {}, world), k: 1 });}+ if (!stage) layers.push({ g: stage = mk('g', {}, world), k: 1 }); // an unknown `after` (warned above): in front of everythingmk('rect', { width: 1600, height: 900, fill: 'url(#vignette)', 'pointer-events': 'none' }, root); // a tap goes through to the picture// Parallax is measured from the set's own framing (base), wherever the beat's first view is.const base = { x: 800, y: 450, z: 1 }, start = { ...base, ...v0 };