An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PICTURE BOOK TITLE</title>
<link rel="stylesheet" href="../lib/engine.css">
<link rel="expect" href="#bar" blocking="render">
</head>
<body>
<!-- A picture-book episode: one beat per scene. Copy lib/*.js into site/<book>/lib/ next to the engine, this file to
site/<book>/chNN/index.html and scene1.js beside it. Order matters: engine, sets and baked pieces, kit, cast, the
audio data (tts.py: timings.js; mouths.py: mouths.js; join.py: shots.js), shared helpers, then the scenes. -->
<script src="../lib/engine.js"></script>
<script src="../img/sets/sets.js"></script>
<script src="../img/puppets/baked.js" onerror="0"></script>
<script src="../lib/paper.js"></script>
<script src="../lib/cast.js"></script>
<script src="audio/en/timings.js"></script>
<script src="audio/en/mouths.js"></script>
<script src="audio/en/shots.js"></script>
<script src="../lib/shared.js"></script>
<script src="scene1.js"></script>
<script>
'use strict';
// 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 exists
try { 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 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, ask: done => findWords(THINGS1, FIND1, done) }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
/* ---------- background music ----------
The engine's music(file, [scene ids], gain, fade): one looping track per scene group, placed by the time since its
first scene began, so pausing and seeking keep it in step; 0.8 s crossfades between tracks (or `fade` s); ducked to
30 % under the voices. Leave it out for a silent film; a scene can mute its music for a moment with
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); catPuppet(g); });
boot();
</script>
</body>
</html>