An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(lrrh): add a point-and-read meadow scene after Flowers
yzr1bdd1ed93207
diff --git a/site/little-red-riding-hood/ch01/audio/en/s04w.mp3 b/site/little-red-riding-hood/ch01/audio/en/s04w.mp3new file mode 100644index 0000000..413f6edBinary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/s04w.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/scene4w.mp3 b/site/little-red-riding-hood/ch01/audio/en/scene4w.mp3new file mode 100644index 0000000..581dc9eBinary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/scene4w.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/shots.js b/site/little-red-riding-hood/ch01/audio/en/shots.jsindex b1965a8..a403e22 100644--- a/site/little-red-riding-hood/ch01/audio/en/shots.js+++ b/site/little-red-riding-hood/ch01/audio/en/shots.js@@ -2,6 +2,7 @@ TIMINGS.scene1 = {"dur": 22.996, "marks": {}, "cues": [[0.138, "Once upon a timeTIMINGS.scene2 = {"dur": 8.688, "marks": {"s02.eyes": 4.45}, "cues": [[0.113, "Grandma lived on the other side of the woods, under three big oak trees."], [4.45, "But someone was watching."]], "parts": {"s02": 0}};TIMINGS.scene3 = {"dur": 16.276, "marks": {}, "cues": [[0.1, "Good morning, Little Red Riding Hood!"], [3.396, "Where are you off to?"], [5.826, "To Grandma's house."], [8.014, "It's under the three big oaks."], [11.144, "Cake\u2026 and a grandma."], [13.555, "What a lucky day!"]], "parts": {"s03": 0, "s03b": 5.726, "s03c": 11.044}};TIMINGS.scene4 = {"dur": 14.338, "marks": {"s04b.pick": 5.048, "s04b.run": 10.073}, "cues": [[0.1, "Why hurry?"], [1.704, "Look at all these lovely flowers!"], [5.048, "So Little Red Riding Hood left the path to pick a bunch for Grandma."], [10.073, "And the wolf ran straight to Grandma's house."]], "parts": {"s04": 0, "s04b": 4.91}};+TIMINGS.scene4w = {"dur": 5.808, "marks": {}, "cues": [[0.245, "Little Red Riding Hood saw so many things in the meadow.", 4.062], [3.883, "Touch them to hear their names!", 5.777]], "parts": {"s04w": 0}};TIMINGS.scene5 = {"dur": 10.91, "marks": {}, "cues": [[0.1, "Grandma!"], [1.704, "It's me, Little Red Riding Hood!"], [5.376, "Just lift the latch, dear, and come in."]], "parts": {"s05": 0, "s05b": 5.27}};TIMINGS.scene6 = {"dur": 12.208, "marks": {"s06.hide": 3.325, "s06.cap": 6.513}, "cues": [[0.138, "Grandma may have been poorly, but she was quick!"], [3.325, "She hopped into the wardrobe and held the door shut."], [6.513, "The wolf put on her nightcap and glasses, climbed into bed, and waited."]], "parts": {"s06": 0}};TIMINGS.scene7 = {"dur": 18.41, "marks": {}, "cues": [[0.1, "Good morning, Mr."], [1.5, "Woodcutter!"], [3.499, "Morning, Little Red!"], [5.719, "Say hello to your grandma for me!"], [9.045, "Little Red Riding Hood arrived with her flowers."], [12.207, "How strange."], [13.557, "The door was wide open."], [15.838, "Grandma?"]], "parts": {"s07w": 0, "s07x": 3.398, "s07": 8.932, "s07b": 15.738}};diff --git a/site/little-red-riding-hood/ch01/audio/en/timings.js b/site/little-red-riding-hood/ch01/audio/en/timings.jsindex 2f4f804..bb0e3f7 100644--- a/site/little-red-riding-hood/ch01/audio/en/timings.js+++ b/site/little-red-riding-hood/ch01/audio/en/timings.js@@ -126,6 +126,90 @@ window.TIMINGS = {]]},+ "s04w": {+ "dur": 5.808,+ "marks": {},+ "cues": [+ [+ 0.125,+ "Little Red Riding Hood saw so many things in the meadow."+ ],+ [+ 3.763,+ "Touch them to hear their names!"+ ]+ ]+ },+ "w-tree": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.138,+ "tree"+ ]+ ]+ },+ "w-flower": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.1,+ "flower"+ ]+ ]+ },+ "w-sun": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.113,+ "sun"+ ]+ ]+ },+ "w-cloud": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.1,+ "cloud"+ ]+ ]+ },+ "w-basket": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.1,+ "basket"+ ]+ ]+ },+ "w-bird": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.1,+ "bird"+ ]+ ]+ },+ "w-butterfly": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.113,+ "butterfly"+ ]+ ]+ },"s05": {"dur": 4.92,"marks": {},@@ -177,11 +261,7 @@ window.TIMINGS = {"cues": [[0.1,- "Good morning, Mr."- ],- [- 1.5,- "Woodcutter!"+ "Good morning, Mr. Woodcutter!"]]},diff --git a/site/little-red-riding-hood/ch01/audio/en/w-basket.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-basket.mp3new file mode 100644index 0000000..abbef36Binary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-basket.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/w-bird.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-bird.mp3new file mode 100644index 0000000..aa1d33bBinary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-bird.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/w-butterfly.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-butterfly.mp3new file mode 100644index 0000000..9a70a6fBinary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-butterfly.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/w-cloud.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-cloud.mp3new file mode 100644index 0000000..0dd1792Binary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-cloud.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/w-flower.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-flower.mp3new file mode 100644index 0000000..0bbf6dfBinary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-flower.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/w-sun.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-sun.mp3new file mode 100644index 0000000..89f03e5Binary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-sun.mp3 differdiff --git a/site/little-red-riding-hood/ch01/audio/en/w-tree.mp3 b/site/little-red-riding-hood/ch01/audio/en/w-tree.mp3new file mode 100644index 0000000..dc6d42aBinary files /dev/null and b/site/little-red-riding-hood/ch01/audio/en/w-tree.mp3 differdiff --git a/site/little-red-riding-hood/ch01/index.html b/site/little-red-riding-hood/ch01/index.htmlindex 9c42595..8a43503 100644--- a/site/little-red-riding-hood/ch01/index.html+++ b/site/little-red-riding-hood/ch01/index.html@@ -18,7 +18,7 @@<script src="audio/en/shots.js"></script><script>'use strict';-const CHAPTER = { number: 1, title: 'Little Red Riding Hood', minutes: 4, language: 'en' };+const CHAPTER = { number: 1, title: 'Little Red Riding Hood', minutes: 4, language: 'en', film: true };// A picture book: captions are on unless the reader turned them off.try { if (localStorage.getItem('captions') === null) setCaptions(true, false); } catch {}@@ -277,6 +277,105 @@ function scene4(p, D) {});}+/* ---------- scene 4w: in the meadow (point and read) ----------+ Meanwhile, back in the meadow: Red stands up from her picking and turns to us, and the page waits while the reader+ taps the things in the picture to hear their names. The camera holds still, so the hit shapes for the things baked+ into the set (tree, sun, cloud, flowers) are placed by where they show on screen at this view. */+const PRE4W = 1.2, CAM4W = { x: 3250, y: 480, z: 1.2 };+let MEADOW_THINGS = [], meadowDraw = null;+// A screen point of the fixed view, in the world of its k = 1 plane (where hit shapes and puppets go).+const meadowAt = (sx, sy) => [CAM4W.x + (sx - 800) / CAM4W.z, CAM4W.y + (sy - 450) / CAM4W.z];+function birdProp(parent) {+ const g = mk('g', {}, parent), body = mk('g', {}, g);+ body.innerHTML = `<g filter="url(#paper)"><path d="M-30,4 L-52,-6 L-50,12 Z" fill="#3f5f8a"/><ellipse cx="0" cy="0" rx="30" ry="21" fill="#5b82b8"/>+ <ellipse cx="6" cy="8" rx="17" ry="11" fill="#f1e2c4"/></g>`;+ const head = mk('g', {}, body);+ head.innerHTML = `<g filter="url(#paper)"><circle cx="24" cy="-18" r="15" fill="#5b82b8"/><path d="M37,-21 L50,-16 L37,-12 Z" fill="#efae48"/></g><circle cx="29" cy="-21" r="3.2" fill="#22150e"/>`;+ const wing = prop(body, `<g filter="url(#paper)"><path d="M-14,-6 Q4,-22 18,-4 Q2,10 -14,-6 Z" fill="#3f5f8a"/></g>`);+ const legs = prop(g, `<path d="M-4,18 l-3,14 M8,18 l2,14" stroke="#c98a3c" stroke-width="3"/>`);+ bakeAll(g);+ return { g, pose(x, y, s, { peck = 0, flap = 0, look = 0 } = {}) {+ tf(g, `translate(${x.toFixed(1)},${y.toFixed(1)}) scale(${s})`); vis(legs, !flap);+ tf(body, `translate(0,${flap ? -14 : 0}) rotate(${(peck * 28).toFixed(1)},10,10)`);+ tf(head, `rotate(${(look * 10).toFixed(1)},24,-8)`);+ tf(wing, flap ? `rotate(${flap > 0 ? -50 : 20},-14,-6)` : '');+ } };+}+function butterflyProp(parent) {+ const g = mk('g', {}, parent), wings = [-1, 1].map(d => prop(g, `<g filter="url(#paper)"><path d="M0,0 C${12 * d},-34 ${44 * d},-30 ${36 * d},-6 C${32 * d},6 ${12 * d},4 0,0 Z" fill="#e88ab0"/>+ <path d="M0,2 C${16 * d},8 ${30 * d},16 ${20 * d},30 C${10 * d},32 ${2 * d},18 0,2 Z" fill="#efae48"/><circle cx="${22 * d}" cy="-14" r="5" fill="#f6efe0"/></g>`));+ prop(g, `<g filter="url(#paper)"><rect x="-3.5" y="-16" width="7" height="34" rx="3.5" fill="#3b2a1e"/></g><path d="M-2,-15 q-6,-12 -12,-14 M2,-15 q6,-12 12,-14" stroke="#3b2a1e" stroke-width="2" fill="none"/>`);+ mk('circle', { r: 40, fill: 'transparent' }, g); // a finger-sized target even when the wings are shut+ return { g, pose(x, y, s, open) { tf(g, `translate(${x.toFixed(1)},${y.toFixed(1)}) scale(${s})`); wings.forEach(w => tf(w, `scale(${open},1)`)); } };+}+function scene4w(p, D) {+ const cam = paperCam(p, 'forest', CAM4W), st = cam.stage;+ cam.root.querySelector(':scope > rect').setAttribute('pointer-events', 'none'); // the vignette over the view: taps go through+ // the set's own clouds sit at the very top of this view: one more, lower and drifting, is the one to tap+ const sky = mk('g', {}, st);+ prop(sky, `<g filter="url(#paper)"><circle cx="-40" cy="10" r="30" fill="#fbf4e2"/><circle cx="0" cy="-8" r="40" fill="#fbf4e2"/>+ <circle cx="45" cy="8" r="32" fill="#fbf4e2"/><rect x="-70" y="10" width="148" height="30" rx="15" fill="#fbf4e2"/></g>`);+ mk('rect', { x: -80, y: -56, width: 170, height: 106, rx: 40, fill: 'transparent' }, sky);+ const hits = mk('g', {}, st); // invisible hit shapes over the set's own things, under the puppets+ const spot = (word, d) => { const g = mk('g', {}, hits); mk('path', { d, fill: 'transparent' }, g); return { g, word, clip: 'w-' + word }; };+ const at = (sx, sy) => meadowAt(sx, sy).map(v => v.toFixed(0)).join(',');+ const circle = (sx, sy, r) => { const [x, y] = meadowAt(sx, sy), R = r / CAM4W.z; return `M${x - R},${y} a${R},${R} 0 1 0 ${2 * R},0 a${R},${R} 0 1 0 ${-2 * R},0 Z`; };+ const box = (x0, y0, x1, y1) => `M${at(x0, y0)} L${at(x1, y0)} L${at(x1, y1)} L${at(x0, y1)} Z`;+ const things = [+ spot('sun', circle(1200, 85, 88)),+ spot('tree', box(905, 425, 1112, 690)),+ spot('flower', box(885, 700, 1040, 795)),+ ];+ const red = redPuppet(st), basket = mk('g', {}, st), bird = birdProp(st), fly = butterflyProp(st);+ mk('rect', { x: -44, y: -44, width: 88, height: 88, rx: 20, fill: 'transparent' }, basket);+ things.splice(1, 0, { g: sky, word: 'cloud', clip: 'w-cloud' });+ things.push({ g: basket, word: 'basket', clip: 'w-basket' }, { g: bird.g, word: 'bird', clip: 'w-bird' }, { g: fly.g, word: 'butterfly', clip: 'w-butterfly' });+ MEADOW_THINGS = things;+ const [RX, RY] = meadowAt(640, 0), GY = 738, s = .6, wipe = trunkWipe(p, 0, .8, 'out');+ const [BX, BY] = meadowAt(1478, 362); // the bird on the crown of the round tree at the right+ // Red: bent over a flower, then up and round to face us (1.0–1.6); after that she breathes and looks about,+ // for as long as the page waits (draw runs on past D).+ const draw = (q, f) => {+ cam.apply(q, f); wipe(q);+ const up = span(q, .9, 1.3), turn = q < 1.1 ? 1 : 1 - Math.min(1, (q - 1.1) / .5), front = q >= 1.6;+ const look = front ? Math.sin(q * .9) : 0, breathe = Math.sin(q * 2.4);+ red.pose({ x: RX, y: hipOn(GY, s) + 10 * (1 - up) - (front ? 1.5 * breathe : 0), s, turn, head: front ? 'F' : 'P',+ kNear: 30 * (1 - up), kFar: 20 * (1 - up), ua: front ? -8 : 40 * (1 - up) - 8 * up, fa: front ? -78 : 30 * (1 - up) - 78 * up,+ rua: 8 + 2 * breathe, rfa: -6, lua: -14, lfa: 40, headR: front ? 6 * look : 14 * (1 - up), cape: 3 + 2 * breathe,+ bouquet: 7, shut: blinking(q, [2.6, 6.4]) || (q > D && (q % 4.3) < 2 / FPS) }, f);+ // the basket's hit square follows her right hand+ tf(basket, `translate(${(RX + s * 22).toFixed(1)},${(hipOn(GY, s) + s * 25).toFixed(1)})`);+ const peck = Math.floor(q * 1.3) % 3 === 0 && (q * 1.3) % 1 < .25 ? 1 : 0;+ bird.pose(BX, BY, .8, { peck, look: peck ? 0 : Math.sign(Math.sin(q * .7)) });+ // the butterfly loops slowly over the flowers at the right, wings on twos+ const [FX, FY] = meadowAt(1275 + 50 * Math.sin(q * .8), 640 + 22 * Math.sin(q * 1.6));+ const [CX, CY] = meadowAt(560 + 40 * Math.sin(q / 6), 205);+ tf(sky, `translate(${CX.toFixed(1)},${CY.toFixed(1)}) scale(1.2)`);+ fly.pose(FX, FY, 1.3, [1, .7, .35, .7][Math.floor(q * FPS / 2) % 4]);+ };+ meadowDraw = draw;+ stopClock(D, draw);+}+// While the page waits, the clock of the beat stands still: run the picture on wall time from where it stopped.+function meadowAsk(done) {+ const i = P.i, gen = P.gen;+ let from = null;+ const tick = now => {+ if (P.gen !== gen || P.i !== i) return;+ if (P.waiting) {+ from ??= now - P.t * 1000;+ const q = (now - from) / 1000, f = Math.floor(q * FPS);+ meadowDraw?.(f / FPS, f);+ }+ requestAnimationFrame(tick);+ };+ requestAnimationFrame(tick);+ if (typeof tapWords === 'function') return tapWords(MEADOW_THINGS, done);+ // ponytail: stand-in until the engine's tapWords is merged: a tap says the word, Enter goes on+ for (const t of MEADOW_THINGS) t.g.addEventListener('click', () => P.waiting && P.gen === gen && new Audio(`audio/en/${t.clip}.mp3`).play());+ addEventListener('keydown', function go(e) { if (e.key === 'Enter' && P.waiting && P.gen === gen) { removeEventListener('keydown', go); done(); } });+}+/* ---------- scene 5: Grandma's door ---------- */const PRE5 = 4.0;[3.45, 3.62, 3.79].forEach(t => sfx('scene5', t, 'knock'));@@ -605,6 +704,7 @@ const BEATS = [['scene2', 'Into the woods', (m, D) => scene2(panel(0), D), { lead: false, pre: PRE2 }],['scene3', 'Good morning', (m, D) => scene3(panel(0), D), { lead: false, pre: PRE3 }],['scene4', 'Flowers', (m, D) => scene4(panel(0), D), { lead: false, pre: PRE4 }],+ ['scene4w', 'In the meadow', (m, D) => scene4w(panel(0), D), { lead: false, pre: PRE4W, ask: meadowAsk }],['scene5', 'Knock, knock', (m, D) => scene5(panel(0), D), { lead: false, pre: PRE5 }],['scene6', 'The wardrobe', (m, D) => scene6(panel(0), D), { lead: false, pre: PRE6 }],['scene7', 'The open door', (m, D) => scene7(panel(0), D), { lead: false, pre: PRE7 }],@@ -618,26 +718,32 @@ const BEATS = [// One track per part of the story, following the picture: its position is the time since the part began, so// pausing, seeking and changing beats keep it in step. Tracks crossfade at part changes; the music sits lower while// someone is speaking, and follows the player's volume.-const BGM = [['m1-home', ['scene1', 'scene2']], ['m2-wolf', ['scene3', 'scene4', 'scene5']], ['m3-chimney', ['scene6', 'scene7', 'scene8', 'scene9']], ['m4-ending', ['scene10', 'scene11']]]+const BGM = [['m1-home', ['scene1', 'scene2']], ['m2-wolf', ['scene3', 'scene4', 'scene4w', 'scene5']], ['m3-chimney', ['scene6', 'scene7', 'scene8', 'scene9']], ['m4-ending', ['scene10', 'scene11']]].map(([n, beats]) => ({ n, beats, a: Object.assign(new Audio(`audio/bgm/${n}.mp3`), { preload: 'auto', loop: true, volume: 0 }), v: 0 }));const beatLen = id => { const b = BEATS.find(x => x.id === id); return (b.pre || 0) + TIMINGS[id].dur + .6; };-let lastTick = performance.now();+let lastTick = performance.now(), bgmLast = { i: -1, t: 0 };function bgmTick(now) {const dt = Math.min(.1, (now - lastTick) / 1000); lastTick = now;const id = BEATS[P.i]?.id, on = P.started && P.playing && !P.waiting && !P.done;+ // While the page waits for the reader (scene4w), its track plays on; m.off is how long, so the track does not jump+ // back. A seek or a replay puts every track back where the film's own timing says.+ const wait = P.started && P.playing && P.waiting && !P.done;+ if (!(P.i === bgmLast.i && P.t >= bgmLast.t || P.i === bgmLast.i + 1)) for (const m of BGM) m.off = 0;+ bgmLast = { i: P.i, t: P.t };const speaking = P.audio && !P.audio.paused && !P.audio.ended;const master = +(document.getElementById('volume')?.value ?? 1) * (speaking ? .16 : .3);for (const m of BGM) {- const k = m.beats.indexOf(id), current = on && k >= 0;+ const k = m.beats.indexOf(id), current = (on || wait) && k >= 0;+ if (wait && current) m.off = (m.off || 0) + dt;m.v = Math.max(0, Math.min(1, m.v + (current ? 1 : -1) * dt / .8)); // 0.8 s fadesm.a.volume = m.v * master;if (current) {- const want = (m.beats.slice(0, k).reduce((s, b) => s + beatLen(b), 0) + P.t) % (m.a.duration || 1e9);+ const want = (m.beats.slice(0, k).reduce((s, b) => s + beatLen(b), 0) + P.t + (m.off || 0)) % (m.a.duration || 1e9);if (Math.abs(m.a.currentTime - want) > .5) m.a.currentTime = want;if (m.a.paused) m.a.play().catch(() => {});} else if (m.v === 0 && !m.a.paused) m.a.pause();}- if (!on && !P.done) for (const m of BGM) m.a.pause(); // paused: silence at once (at the end it fades out)+ if (!on && !wait && !P.done) for (const m of BGM) m.a.pause(); // paused: silence at once (at the end it fades out)requestAnimationFrame(bgmTick);}requestAnimationFrame(bgmTick);