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>The Penguin and the Zoo</title>
<link rel="stylesheet" href="../lib/engine.css">
<link rel="expect" href="#bar" blocking="render">
</head>
<body>
<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>window.SP_SHUT = .9; // a shut eye keeps its lid line (as episode 3): a full lid left two blank skin ovals</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="seaside.js"></script>
<script src="scene1.js"></script>
<script src="scene2.js"></script>
<script src="scene3.js"></script>
<script src="scene4.js"></script>
<script>
'use strict';
const CHAPTER = { number: 5, title: 'The Penguin and the Zoo', minutes: 2, language: 'en', next: '../ch06/' };
try { if (localStorage.getItem('captions') === null) setCaptions(true, false); } catch {}
/* ---------- beats: one per scene ---------- */
const BEATS = [
['scene1', 'The follower', (m, D) => scene1(panel(0), D), { lead: false, pre: PRE1 }],
['scene2', 'Good idea!', (m, D) => scene2(panel(0), D), { lead: false, pre: PRE2 }],
['scene3', 'The next day', (m, D) => scene3(panel(0), D), { lead: false, pre: PRE3 }],
['scene4', 'At the beach', (m, D) => scene4(panel(0), D), { lead: false, pre: PRE4 }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
/* ---------- background music ----------
The Three Little Pigs' score (Lyria), reused from episode 2's folder: one track per listed scene, its position the
time since the track's first scene began, so pausing and seeking keep it in step; 0.8 s crossfades; lower under
speech. The home theme carries the walk through town (scenes 1–2; scene 2 may fade it for its tail with S2_HUSH);
scene 3 (the punchline) has no music; the march comes in for the beach and stops before the policeman's last stare
(scene 4 sets S4_STOP). */
const BGM = [['m1-home', ['scene1', 'scene2'], .3], ['m3-chimney', ['scene4'], .3]]
.map(([n, beats, gain]) => ({ n, beats, gain, a: Object.assign(new Audio(`../ch02/audio/bgm/${n}.mp3`), { preload: 'auto', loop: true, volume: 0 }), v: 0 }));
window.MUSIC_OFF = { scene2: t => t > (window.S2_HUSH ?? 1e9), scene4: t => t > (window.S4_STOP ?? 1e9) };
const beatLen = id => { const b = BEATS.find(x => x.id === id); return (b.pre || 0) + TIMINGS[id].dur + .6; };
let lastTick = performance.now(), duck = .3;
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;
// the music ducks well under the voices for the whole of a scene that has them (its silent opening and tail too, so
// it does not swell between lines), easing over about half a second
duck += Math.max(-dt, Math.min(dt, (P.audio ? .3 : .7) - duck));
const vol = +(document.getElementById('volume')?.value ?? 1) * duck;
for (const m of BGM) {
const k = m.beats.indexOf(id), current = on && k >= 0 && !(window.MUSIC_OFF?.[id]?.(P.t));
m.v = Math.max(0, Math.min(1, m.v + (current ? 1 : -1) * dt / .8));
m.a.volume = m.v * m.gain * vol;
if (current) {
const want = (m.beats.slice(0, k).reduce((s, b) => s + beatLen(b), 0) + P.t) % (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();
requestAnimationFrame(bgmTick);
}
requestAnimationFrame(bgmTick);
paperWarm(g => { manPuppet(g, { holds: { fish: fishSVG, bucket: bucketSVG, photo: photoSVG } }); copPuppet(g, { holds: { chips: chipsSVG, chip: chipSVG } }); penguinPuppet(g); prop(g, posterSVG); });
boot();
</script>
</body>
</html>