Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

feat(site): add The Three Little Pigs picture-book experiment

yzr7fcda31255be
diff --git a/engine/engine.js b/engine/engine.js
index 719a99d..883103d 100644
--- a/engine/engine.js
+++ b/engine/engine.js
@@ -1745,16 +1745,16 @@ const sorter = (items, trayXY) => (body, api) => {
const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
- const b = BEATS[i], tm = TIMINGS[b.id];
+ const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
const m = (k, off = 0) => {
if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);
- return tm.marks[k] + off;
+ return pre + tm.marks[k] + off;
};
S.cleared = false;
- b.run(m, tm.dur);
- if (S.cleared && b.lead !== false) leadIn();
+ b.run(m, pre + tm.dur);
+ if (S.cleared && b.lead !== false && !pre) leadIn();
TW.sort((a, c) => a.t0 - c.t0);
- return Math.max(tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
+ return Math.max(pre + tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
}
// A beat that clears the picture must not leave it empty while the narration has started.
// If nothing appears before LEAD_MAX, the opening group (every tween that starts within LEAD_GROUP s of the
@@ -1798,11 +1798,11 @@ function seek(i, play = P.playing) {
// Jump to a point inside beat i (frac of its narration); question beats always start at their beginning.
function seekInto(i, frac) {
seek(i, true);
- const t = BEATS[i].ask ? 0 : frac * TIMINGS[BEATS[i].id].dur;
+ const pre = BEATS[i].pre || 0, t = BEATS[i].ask ? 0 : frac * (pre + TIMINGS[BEATS[i].id].dur);
if (t < .3) return;
P.t = t;
evalTo(t);
- if (P.audio) P.audio.currentTime = t;
+ if (P.audio) P.audio.currentTime = Math.max(0, t - pre);
}
function start(i, play) {
stopAudio(); clearCards();
@@ -1818,7 +1818,7 @@ function start(i, play) {
a.onplaying = () => {
if (P.audio !== a) return;
$('soundNote').hidden = true;
- if (P.afail) { P.afail = false; a.currentTime = P.t; } // sound came back late: rejoin the picture where it is
+ if (P.afail) { P.afail = false; a.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0)); } // sound came back late: rejoin the picture where it is
};
const b = BEATS[i];
if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });
@@ -1850,8 +1850,12 @@ function setPlaying(v) {
P.playing = v;
const a = P.audio;
if (!a) return;
- if (v && !P.waiting && !a.ended && !P.afail) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
- else a.pause();
+ const lead = v && P.t < (BEATS[P.i]?.pre || 0);
+ if (v && !P.waiting && !a.ended && !P.afail && !lead) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
+ else if (lead && !a._unlocked) { // the clip starts later, outside this click: play it silently now so the browser allows that
+ a._unlocked = true; a.muted = true;
+ a.play().then(() => { if (P.t < (BEATS[P.i].pre || 0)) { a.pause(); a.currentTime = 0; } a.muted = false; }, () => { a.muted = false; });
+ } else a.pause();
}
function beatDone() {
evalTo(Infinity);
@@ -1869,8 +1873,12 @@ function frame(now) {
if (P.playing && !P.waiting && !P.done) {
const a = P.audio;
// While the clip plays, its clock drives the picture; before it starts or after it ends, wall time does.
- if (a && !P.afail && !a.ended) {
- if (a.currentTime > 0) { P.t = Math.max(P.t, a.currentTime); P.stall = 0; }
+ const pre = BEATS[P.i].pre || 0;
+ if (a && P.t < pre) { // the picture's lead before the narration, on wall time; then the clip starts
+ P.t += dt * P.rate;
+ if (P.t >= pre && !P.afail) { a.muted = false; a.currentTime = P.t - pre; a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); }); }
+ } else if (a && !P.afail && !a.ended) {
+ if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
evalTo(P.t);
@@ -1908,7 +1916,7 @@ function ui() {
const b = BEATS[P.i];
let text = '';
if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t > P.t + .05) break; text = line; }
+ for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
@@ -2026,6 +2034,7 @@ function boot() {
seek(+qs.get('beat'), false);
P.t = +(qs.get('t') || 0);
evalTo(P.t);
+ if (P.audio) P.audio.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0));
} else seek(0, false);
requestAnimationFrame(frame);
}
diff --git a/site/assets/three-little-pigs-cover.webp b/site/assets/three-little-pigs-cover.webp
new file mode 100644
index 0000000..be65cb0
Binary files /dev/null and b/site/assets/three-little-pigs-cover.webp differ
diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.js
index 719a99d..883103d 100644
--- a/site/elementary-algebra/lib/engine.js
+++ b/site/elementary-algebra/lib/engine.js
@@ -1745,16 +1745,16 @@ const sorter = (items, trayXY) => (body, api) => {
const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
- const b = BEATS[i], tm = TIMINGS[b.id];
+ const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
const m = (k, off = 0) => {
if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);
- return tm.marks[k] + off;
+ return pre + tm.marks[k] + off;
};
S.cleared = false;
- b.run(m, tm.dur);
- if (S.cleared && b.lead !== false) leadIn();
+ b.run(m, pre + tm.dur);
+ if (S.cleared && b.lead !== false && !pre) leadIn();
TW.sort((a, c) => a.t0 - c.t0);
- return Math.max(tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
+ return Math.max(pre + tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
}
// A beat that clears the picture must not leave it empty while the narration has started.
// If nothing appears before LEAD_MAX, the opening group (every tween that starts within LEAD_GROUP s of the
@@ -1798,11 +1798,11 @@ function seek(i, play = P.playing) {
// Jump to a point inside beat i (frac of its narration); question beats always start at their beginning.
function seekInto(i, frac) {
seek(i, true);
- const t = BEATS[i].ask ? 0 : frac * TIMINGS[BEATS[i].id].dur;
+ const pre = BEATS[i].pre || 0, t = BEATS[i].ask ? 0 : frac * (pre + TIMINGS[BEATS[i].id].dur);
if (t < .3) return;
P.t = t;
evalTo(t);
- if (P.audio) P.audio.currentTime = t;
+ if (P.audio) P.audio.currentTime = Math.max(0, t - pre);
}
function start(i, play) {
stopAudio(); clearCards();
@@ -1818,7 +1818,7 @@ function start(i, play) {
a.onplaying = () => {
if (P.audio !== a) return;
$('soundNote').hidden = true;
- if (P.afail) { P.afail = false; a.currentTime = P.t; } // sound came back late: rejoin the picture where it is
+ if (P.afail) { P.afail = false; a.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0)); } // sound came back late: rejoin the picture where it is
};
const b = BEATS[i];
if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });
@@ -1850,8 +1850,12 @@ function setPlaying(v) {
P.playing = v;
const a = P.audio;
if (!a) return;
- if (v && !P.waiting && !a.ended && !P.afail) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
- else a.pause();
+ const lead = v && P.t < (BEATS[P.i]?.pre || 0);
+ if (v && !P.waiting && !a.ended && !P.afail && !lead) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
+ else if (lead && !a._unlocked) { // the clip starts later, outside this click: play it silently now so the browser allows that
+ a._unlocked = true; a.muted = true;
+ a.play().then(() => { if (P.t < (BEATS[P.i].pre || 0)) { a.pause(); a.currentTime = 0; } a.muted = false; }, () => { a.muted = false; });
+ } else a.pause();
}
function beatDone() {
evalTo(Infinity);
@@ -1869,8 +1873,12 @@ function frame(now) {
if (P.playing && !P.waiting && !P.done) {
const a = P.audio;
// While the clip plays, its clock drives the picture; before it starts or after it ends, wall time does.
- if (a && !P.afail && !a.ended) {
- if (a.currentTime > 0) { P.t = Math.max(P.t, a.currentTime); P.stall = 0; }
+ const pre = BEATS[P.i].pre || 0;
+ if (a && P.t < pre) { // the picture's lead before the narration, on wall time; then the clip starts
+ P.t += dt * P.rate;
+ if (P.t >= pre && !P.afail) { a.muted = false; a.currentTime = P.t - pre; a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); }); }
+ } else if (a && !P.afail && !a.ended) {
+ if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
evalTo(P.t);
@@ -1908,7 +1916,7 @@ function ui() {
const b = BEATS[P.i];
let text = '';
if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t > P.t + .05) break; text = line; }
+ for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
@@ -2026,6 +2034,7 @@ function boot() {
seek(+qs.get('beat'), false);
P.t = +(qs.get('t') || 0);
evalTo(P.t);
+ if (P.audio) P.audio.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0));
} else seek(0, false);
requestAnimationFrame(frame);
}
diff --git a/site/index.html b/site/index.html
index ca3f228..4a3a9e3 100644
--- a/site/index.html
+++ b/site/index.html
@@ -31,7 +31,11 @@
</a>
</section>
<section class="shelf-tier" aria-labelledby="picture-title">
- <h2 class="visually-hidden" id="picture-title">Picture books for children · Coming soon</h2>
+ <h2 class="visually-hidden" id="picture-title">Picture books for children · One experiment, more coming soon</h2>
+ <a class="book-hotspot pigs-book" data-book="three-little-pigs" href="three-little-pigs/" aria-label="Open The Three Little Pigs, an animated picture book experiment and how it was made">
+ <img class="book-cover" src="assets/three-little-pigs-cover.webp" alt="" width="600" height="604">
+ <span class="book-caption"><strong>The Three Little Pigs <span aria-hidden="true">↗</span></strong><small>An experiment · how it was made</small></span>
+ </a>
</section>
<section class="shelf-tier" aria-labelledby="curious-title">
<h2 class="visually-hidden" id="curious-title">Curious books · Coming soon</h2>
diff --git a/site/lib/bookshelf.css b/site/lib/bookshelf.css
index 1f31a18..7fb9b30 100644
--- a/site/lib/bookshelf.css
+++ b/site/lib/bookshelf.css
@@ -24,6 +24,10 @@ a { color: inherit; }
.algebra-book { left: 10.1%; width: 26.1%; }
.math-book { left: 39.9%; width: 24.5%; }
.physics-book { left: 66.8%; width: 25.3%; }
+/* The middle shelf: our picture book's cover laid over the first painted book. */
+.pigs-book { left: 8.3%; width: 25.6%; top: 34.8%; height: 19.3%; overflow: hidden; }
+.book-cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 2px; box-shadow: 0 2px 6px #0004; }
+.pigs-book .book-caption { background: linear-gradient(110deg, #7a4a1ef5, #5a3414f0); }
.book-hotspot:hover { box-shadow: 0 0 0 2px #f7d998b3, 0 0 28px #edc97833; }
#shelf a:focus-visible { outline: 3px solid #f4d786; outline-offset: 5px; }
.book-caption { position: absolute; bottom: 0; left: 0; right: 0; display: flex; flex-direction: column; justify-content: center; gap: .35cqw; min-height: 6.45cqw; padding: 1.1cqw 1.2cqw .9cqw; color: #faf7e9; background: linear-gradient(110deg, #263d32f5, #182a23f0); box-shadow: 0 -2px 8px #0003; font: 1.4cqw/1.25 var(--ui); transition: background .2s; }
diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.js
index 719a99d..883103d 100644
--- a/site/math-notebook/lib/engine.js
+++ b/site/math-notebook/lib/engine.js
@@ -1745,16 +1745,16 @@ const sorter = (items, trayXY) => (body, api) => {
const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
- const b = BEATS[i], tm = TIMINGS[b.id];
+ const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
const m = (k, off = 0) => {
if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);
- return tm.marks[k] + off;
+ return pre + tm.marks[k] + off;
};
S.cleared = false;
- b.run(m, tm.dur);
- if (S.cleared && b.lead !== false) leadIn();
+ b.run(m, pre + tm.dur);
+ if (S.cleared && b.lead !== false && !pre) leadIn();
TW.sort((a, c) => a.t0 - c.t0);
- return Math.max(tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
+ return Math.max(pre + tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
}
// A beat that clears the picture must not leave it empty while the narration has started.
// If nothing appears before LEAD_MAX, the opening group (every tween that starts within LEAD_GROUP s of the
@@ -1798,11 +1798,11 @@ function seek(i, play = P.playing) {
// Jump to a point inside beat i (frac of its narration); question beats always start at their beginning.
function seekInto(i, frac) {
seek(i, true);
- const t = BEATS[i].ask ? 0 : frac * TIMINGS[BEATS[i].id].dur;
+ const pre = BEATS[i].pre || 0, t = BEATS[i].ask ? 0 : frac * (pre + TIMINGS[BEATS[i].id].dur);
if (t < .3) return;
P.t = t;
evalTo(t);
- if (P.audio) P.audio.currentTime = t;
+ if (P.audio) P.audio.currentTime = Math.max(0, t - pre);
}
function start(i, play) {
stopAudio(); clearCards();
@@ -1818,7 +1818,7 @@ function start(i, play) {
a.onplaying = () => {
if (P.audio !== a) return;
$('soundNote').hidden = true;
- if (P.afail) { P.afail = false; a.currentTime = P.t; } // sound came back late: rejoin the picture where it is
+ if (P.afail) { P.afail = false; a.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0)); } // sound came back late: rejoin the picture where it is
};
const b = BEATS[i];
if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });
@@ -1850,8 +1850,12 @@ function setPlaying(v) {
P.playing = v;
const a = P.audio;
if (!a) return;
- if (v && !P.waiting && !a.ended && !P.afail) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
- else a.pause();
+ const lead = v && P.t < (BEATS[P.i]?.pre || 0);
+ if (v && !P.waiting && !a.ended && !P.afail && !lead) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
+ else if (lead && !a._unlocked) { // the clip starts later, outside this click: play it silently now so the browser allows that
+ a._unlocked = true; a.muted = true;
+ a.play().then(() => { if (P.t < (BEATS[P.i].pre || 0)) { a.pause(); a.currentTime = 0; } a.muted = false; }, () => { a.muted = false; });
+ } else a.pause();
}
function beatDone() {
evalTo(Infinity);
@@ -1869,8 +1873,12 @@ function frame(now) {
if (P.playing && !P.waiting && !P.done) {
const a = P.audio;
// While the clip plays, its clock drives the picture; before it starts or after it ends, wall time does.
- if (a && !P.afail && !a.ended) {
- if (a.currentTime > 0) { P.t = Math.max(P.t, a.currentTime); P.stall = 0; }
+ const pre = BEATS[P.i].pre || 0;
+ if (a && P.t < pre) { // the picture's lead before the narration, on wall time; then the clip starts
+ P.t += dt * P.rate;
+ if (P.t >= pre && !P.afail) { a.muted = false; a.currentTime = P.t - pre; a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); }); }
+ } else if (a && !P.afail && !a.ended) {
+ if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
evalTo(P.t);
@@ -1908,7 +1916,7 @@ function ui() {
const b = BEATS[P.i];
let text = '';
if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t > P.t + .05) break; text = line; }
+ for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
@@ -2026,6 +2034,7 @@ function boot() {
seek(+qs.get('beat'), false);
P.t = +(qs.get('t') || 0);
evalTo(P.t);
+ if (P.audio) P.audio.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0));
} else seek(0, false);
requestAnimationFrame(frame);
}
diff --git a/site/physics-notebook/lib/engine.js b/site/physics-notebook/lib/engine.js
index 719a99d..883103d 100644
--- a/site/physics-notebook/lib/engine.js
+++ b/site/physics-notebook/lib/engine.js
@@ -1745,16 +1745,16 @@ const sorter = (items, trayXY) => (body, api) => {
const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
- const b = BEATS[i], tm = TIMINGS[b.id];
+ const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
const m = (k, off = 0) => {
if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);
- return tm.marks[k] + off;
+ return pre + tm.marks[k] + off;
};
S.cleared = false;
- b.run(m, tm.dur);
- if (S.cleared && b.lead !== false) leadIn();
+ b.run(m, pre + tm.dur);
+ if (S.cleared && b.lead !== false && !pre) leadIn();
TW.sort((a, c) => a.t0 - c.t0);
- return Math.max(tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
+ return Math.max(pre + tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
}
// A beat that clears the picture must not leave it empty while the narration has started.
// If nothing appears before LEAD_MAX, the opening group (every tween that starts within LEAD_GROUP s of the
@@ -1798,11 +1798,11 @@ function seek(i, play = P.playing) {
// Jump to a point inside beat i (frac of its narration); question beats always start at their beginning.
function seekInto(i, frac) {
seek(i, true);
- const t = BEATS[i].ask ? 0 : frac * TIMINGS[BEATS[i].id].dur;
+ const pre = BEATS[i].pre || 0, t = BEATS[i].ask ? 0 : frac * (pre + TIMINGS[BEATS[i].id].dur);
if (t < .3) return;
P.t = t;
evalTo(t);
- if (P.audio) P.audio.currentTime = t;
+ if (P.audio) P.audio.currentTime = Math.max(0, t - pre);
}
function start(i, play) {
stopAudio(); clearCards();
@@ -1818,7 +1818,7 @@ function start(i, play) {
a.onplaying = () => {
if (P.audio !== a) return;
$('soundNote').hidden = true;
- if (P.afail) { P.afail = false; a.currentTime = P.t; } // sound came back late: rejoin the picture where it is
+ if (P.afail) { P.afail = false; a.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0)); } // sound came back late: rejoin the picture where it is
};
const b = BEATS[i];
if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });
@@ -1850,8 +1850,12 @@ function setPlaying(v) {
P.playing = v;
const a = P.audio;
if (!a) return;
- if (v && !P.waiting && !a.ended && !P.afail) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
- else a.pause();
+ const lead = v && P.t < (BEATS[P.i]?.pre || 0);
+ if (v && !P.waiting && !a.ended && !P.afail && !lead) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
+ else if (lead && !a._unlocked) { // the clip starts later, outside this click: play it silently now so the browser allows that
+ a._unlocked = true; a.muted = true;
+ a.play().then(() => { if (P.t < (BEATS[P.i].pre || 0)) { a.pause(); a.currentTime = 0; } a.muted = false; }, () => { a.muted = false; });
+ } else a.pause();
}
function beatDone() {
evalTo(Infinity);
@@ -1869,8 +1873,12 @@ function frame(now) {
if (P.playing && !P.waiting && !P.done) {
const a = P.audio;
// While the clip plays, its clock drives the picture; before it starts or after it ends, wall time does.
- if (a && !P.afail && !a.ended) {
- if (a.currentTime > 0) { P.t = Math.max(P.t, a.currentTime); P.stall = 0; }
+ const pre = BEATS[P.i].pre || 0;
+ if (a && P.t < pre) { // the picture's lead before the narration, on wall time; then the clip starts
+ P.t += dt * P.rate;
+ if (P.t >= pre && !P.afail) { a.muted = false; a.currentTime = P.t - pre; a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); }); }
+ } else if (a && !P.afail && !a.ended) {
+ if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
evalTo(P.t);
@@ -1908,7 +1916,7 @@ function ui() {
const b = BEATS[P.i];
let text = '';
if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t > P.t + .05) break; text = line; }
+ for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
@@ -2026,6 +2034,7 @@ function boot() {
seek(+qs.get('beat'), false);
P.t = +(qs.get('t') || 0);
evalTo(P.t);
+ if (P.audio) P.audio.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0));
} else seek(0, false);
requestAnimationFrame(frame);
}
diff --git a/site/science/lib/engine.js b/site/science/lib/engine.js
index 719a99d..883103d 100644
--- a/site/science/lib/engine.js
+++ b/site/science/lib/engine.js
@@ -1745,16 +1745,16 @@ const sorter = (items, trayXY) => (body, api) => {
const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
function runBeat(i) {
TW = [];
- const b = BEATS[i], tm = TIMINGS[b.id];
+ const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
const m = (k, off = 0) => {
if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);
- return tm.marks[k] + off;
+ return pre + tm.marks[k] + off;
};
S.cleared = false;
- b.run(m, tm.dur);
- if (S.cleared && b.lead !== false) leadIn();
+ b.run(m, pre + tm.dur);
+ if (S.cleared && b.lead !== false && !pre) leadIn();
TW.sort((a, c) => a.t0 - c.t0);
- return Math.max(tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
+ return Math.max(pre + tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
}
// A beat that clears the picture must not leave it empty while the narration has started.
// If nothing appears before LEAD_MAX, the opening group (every tween that starts within LEAD_GROUP s of the
@@ -1798,11 +1798,11 @@ function seek(i, play = P.playing) {
// Jump to a point inside beat i (frac of its narration); question beats always start at their beginning.
function seekInto(i, frac) {
seek(i, true);
- const t = BEATS[i].ask ? 0 : frac * TIMINGS[BEATS[i].id].dur;
+ const pre = BEATS[i].pre || 0, t = BEATS[i].ask ? 0 : frac * (pre + TIMINGS[BEATS[i].id].dur);
if (t < .3) return;
P.t = t;
evalTo(t);
- if (P.audio) P.audio.currentTime = t;
+ if (P.audio) P.audio.currentTime = Math.max(0, t - pre);
}
function start(i, play) {
stopAudio(); clearCards();
@@ -1818,7 +1818,7 @@ function start(i, play) {
a.onplaying = () => {
if (P.audio !== a) return;
$('soundNote').hidden = true;
- if (P.afail) { P.afail = false; a.currentTime = P.t; } // sound came back late: rejoin the picture where it is
+ if (P.afail) { P.afail = false; a.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0)); } // sound came back late: rejoin the picture where it is
};
const b = BEATS[i];
if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });
@@ -1850,8 +1850,12 @@ function setPlaying(v) {
P.playing = v;
const a = P.audio;
if (!a) return;
- if (v && !P.waiting && !a.ended && !P.afail) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
- else a.pause();
+ const lead = v && P.t < (BEATS[P.i]?.pre || 0);
+ if (v && !P.waiting && !a.ended && !P.afail && !lead) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
+ else if (lead && !a._unlocked) { // the clip starts later, outside this click: play it silently now so the browser allows that
+ a._unlocked = true; a.muted = true;
+ a.play().then(() => { if (P.t < (BEATS[P.i].pre || 0)) { a.pause(); a.currentTime = 0; } a.muted = false; }, () => { a.muted = false; });
+ } else a.pause();
}
function beatDone() {
evalTo(Infinity);
@@ -1869,8 +1873,12 @@ function frame(now) {
if (P.playing && !P.waiting && !P.done) {
const a = P.audio;
// While the clip plays, its clock drives the picture; before it starts or after it ends, wall time does.
- if (a && !P.afail && !a.ended) {
- if (a.currentTime > 0) { P.t = Math.max(P.t, a.currentTime); P.stall = 0; }
+ const pre = BEATS[P.i].pre || 0;
+ if (a && P.t < pre) { // the picture's lead before the narration, on wall time; then the clip starts
+ P.t += dt * P.rate;
+ if (P.t >= pre && !P.afail) { a.muted = false; a.currentTime = P.t - pre; a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); }); }
+ } else if (a && !P.afail && !a.ended) {
+ if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
} else P.t += dt * P.rate;
evalTo(P.t);
@@ -1908,7 +1916,7 @@ function ui() {
const b = BEATS[P.i];
let text = '';
if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t > P.t + .05) break; text = line; }
+ for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
@@ -2026,6 +2034,7 @@ function boot() {
seek(+qs.get('beat'), false);
P.t = +(qs.get('t') || 0);
evalTo(P.t);
+ if (P.audio) P.audio.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0));
} else seek(0, false);
requestAnimationFrame(frame);
}
diff --git a/site/three-little-pigs/ch01/audio/bgm/m1-home.mp3 b/site/three-little-pigs/ch01/audio/bgm/m1-home.mp3
new file mode 100644
index 0000000..acdbe77
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/bgm/m1-home.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/bgm/m2-wolf.mp3 b/site/three-little-pigs/ch01/audio/bgm/m2-wolf.mp3
new file mode 100644
index 0000000..eca9045
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/bgm/m2-wolf.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/bgm/m3-chimney.mp3 b/site/three-little-pigs/ch01/audio/bgm/m3-chimney.mp3
new file mode 100644
index 0000000..073bb94
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/bgm/m3-chimney.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/bgm/m4-ending.mp3 b/site/three-little-pigs/ch01/audio/bgm/m4-ending.mp3
new file mode 100644
index 0000000..d50bf6a
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/bgm/m4-ending.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/mouths.js b/site/three-little-pigs/ch01/audio/en/mouths.js
new file mode 100644
index 0000000..a929812
--- /dev/null
+++ b/site/three-little-pigs/ch01/audio/en/mouths.js
@@ -0,0 +1 @@
+window.MOUTHS = {"s01":[[0.138,"E"],[0.242,"B"],[0.346,"C"],[0.45,"F"],[0.509,"A"],[0.569,"E"],[0.628,"B"],[0.688,"D"],[0.762,"B"],[0.9,"C"],[1.038,"A"],[1.175,"C"],[1.312,"X"],[1.488,"B"],[1.619,"C"],[1.75,"H"],[1.808,"C"],[1.865,"B"],[1.923,"H"],[1.98,"C"],[2.038,"A"],[2.171,"C"],[2.304,"B"],[2.438,"A"],[2.502,"D"],[2.567,"B"],[2.633,"C"],[2.698,"B"],[2.763,"B"],[2.808,"C"],[2.854,"B"],[2.9,"A"],[3.071,"D"],[3.242,"B"],[3.413,"D"],[3.494,"B"],[3.575,"B"],[3.667,"C"],[3.758,"B"],[3.85,"E"],[3.944,"G"],[4.037,"B"],[4.094,"E"],[4.15,"A"],[4.203,"F"],[4.255,"C"],[4.308,"H"],[4.36,"B"],[4.412,"B"],[4.48,"E"],[4.547,"A"],[4.615,"C"],[4.683,"B"],[4.75,"E"],[4.8,"G"],[4.85,"B"],[4.904,"C"],[4.958,"B"],[5.013,"F"],[5.287,"B"],[5.562,"X"]],"s01b":[[0.102,"B"],[0.212,"F"],[0.322,"B"],[0.432,"A"],[0.542,"C"],[0.727,"A"],[0.87,"C"],[1.014,"B"],[1.197,"C"],[1.38,"B"],[1.564,"X"],[2.474,"D"],[2.552,"B"],[2.63,"F"],[2.726,"D"],[2.821,"B"],[2.917,"F"],[3.086,"B"],[3.255,"G"],[3.303,"E"],[3.351,"B"],[3.398,"B"],[3.451,"C"],[3.503,"A"],[3.589,"C"],[3.676,"B"],[3.763,"A"],[3.872,"D"],[3.98,"B"],[4.089,"F"],[4.226,"E"],[4.364,"H"],[4.501,"G"],[4.639,"X"]],"s02":[[0.138,"B"],[0.2,"C"],[0.263,"G"],[0.392,"C"],[0.521,"B"],[0.65,"H"],[0.705,"C"],[0.76,"B"],[0.815,"H"],[0.87,"C"],[0.925,"A"],[1.042,"C"],[1.158,"B"],[1.275,"G"],[1.383,"F"],[1.492,"B"],[1.6,"D"],[1.675,"A"],[1.746,"C"],[1.817,"B"],[1.887,"B"],[1.998,"C"],[2.107,"B"],[2.218,"D"],[2.328,"B"],[2.475,"A"],[2.556,"C"],[2.638,"B"],[2.7,"C"],[2.763,"B"],[2.9,"E"],[3.038,"D"],[3.175,"B"],[3.312,"X"],[3.612,"B"],[3.75,"F"],[3.887,"C"],[4.025,"B"],[4.162,"X"],[4.463,"B"],[4.646,"F"],[4.829,"B"],[5.013,"X"],[5.275,"G"],[5.413,"H"],[5.55,"F"],[5.688,"A"],[5.825,"X"],[6.125,"B"],[6.175,"C"],[6.225,"B"],[6.275,"B"],[6.372,"F"],[6.469,"B"],[6.566,"C"],[6.662,"F"],[6.721,"D"],[6.779,"B"],[6.838,"B"],[6.909,"E"],[6.981,"B"],[7.053,"C"],[7.125,"A"],[7.173,"C"],[7.221,"G"],[7.269,"E"],[7.317,"B"],[7.365,"C"],[7.412,"H"],[7.596,"F"],[7.779,"B"],[7.962,"X"]],"s02b":[[0.096,"C"],[0.212,"B"],[0.328,"C"],[0.444,"A"],[0.581,"C"],[0.719,"B"],[0.856,"C"],[0.994,"X"],[1.782,"B"],[1.872,"C"],[1.962,"A"],[2.052,"C"],[2.141,"G"],[2.211,"E"],[2.28,"B"],[2.35,"D"],[2.407,"B"],[2.591,"D"],[2.774,"A"],[2.957,"X"]],"s03":[[0.138,"B"],[0.2,"C"],[0.263,"B"],[0.355,"C"],[0.448,"B"],[0.54,"E"],[0.633,"B"],[0.725,"H"],[0.787,"C"],[0.85,"B"],[0.913,"H"],[0.975,"C"],[1.038,"A"],[1.167,"C"],[1.296,"B"],[1.425,"B"],[1.475,"D"],[1.525,"B"],[1.575,"C"],[1.625,"B"],[1.675,"C"],[1.725,"B"],[1.775,"D"],[1.85,"A"],[1.928,"C"],[2.006,"H"],[2.084,"C"],[2.163,"E"],[2.213,"G"],[2.263,"B"],[2.446,"C"],[2.629,"B"],[2.812,"X"],[3.237,"B"],[3.421,"D"],[3.604,"A"],[3.787,"X"],[3.962,"B"],[4.146,"D"],[4.329,"A"],[4.513,"X"],[4.638,"B"],[4.821,"D"],[5.004,"A"],[5.188,"X"],[5.513,"D"],[5.588,"F"],[5.683,"E"],[5.777,"A"],[5.873,"H"],[5.968,"C"],[6.062,"H"],[6.133,"C"],[6.202,"B"],[6.272,"H"],[6.342,"C"],[6.412,"B"],[6.487,"F"],[6.562,"B"],[6.638,"C"],[6.713,"E"],[6.769,"G"],[6.825,"B"],[7.008,"C"],[7.192,"B"],[7.375,"X"]],"s03b":[[0.098,"B"],[0.157,"F"],[0.217,"B"],[0.276,"C"],[0.327,"B"],[0.377,"F"],[0.428,"B"],[0.479,"G"],[0.522,"E"],[0.566,"B"],[0.61,"A"],[0.885,"C"],[1.16,"X"],[1.75,"H"],[1.841,"C"],[1.933,"B"],[2.024,"A"],[2.091,"H"],[2.159,"C"],[2.226,"B"],[2.274,"E"],[2.321,"A"],[2.369,"C"],[2.417,"A"],[2.527,"F"],[2.637,"B"],[2.747,"C"],[2.857,"B"],[2.967,"X"]],"s04":[[0.138,"B"],[0.194,"C"],[0.25,"B"],[0.379,"C"],[0.508,"B"],[0.637,"H"],[0.7,"C"],[0.762,"B"],[0.825,"H"],[0.887,"C"],[0.95,"A"],[1.062,"C"],[1.175,"B"],[1.288,"B"],[1.378,"E"],[1.469,"B"],[1.559,"C"],[1.65,"A"],[1.788,"B"],[1.925,"C"],[2.062,"B"],[2.2,"X"],[2.612,"A"],[2.684,"B"],[2.756,"C"],[2.828,"B"],[2.9,"A"],[2.987,"C"],[3.075,"A"],[3.213,"B"],[3.35,"C"],[3.487,"B"],[3.712,"D"],[3.794,"H"],[3.875,"B"],[3.975,"C"],[4.075,"H"],[4.258,"E"],[4.442,"B"],[4.725,"F"],[4.797,"B"],[4.869,"C"],[4.941,"H"],[5.013,"B"],[5.071,"C"],[5.129,"B"],[5.188,"D"],[5.278,"B"],[5.369,"A"],[5.459,"B"],[5.55,"D"],[5.688,"B"],[5.825,"C"],[5.962,"B"],[6.1,"X"],[6.425,"B"],[6.492,"C"],[6.558,"B"],[6.625,"A"],[6.704,"B"],[6.783,"E"],[6.862,"B"],[6.942,"C"],[7.021,"B"],[7.1,"D"],[7.194,"B"],[7.287,"B"],[7.37,"C"],[7.452,"B"],[7.535,"C"],[7.617,"B"],[7.7,"H"],[7.792,"D"],[7.883,"F"],[7.975,"B"],[8.067,"C"],[8.158,"B"],[8.25,"X"]],"s04b":[[0.098,"D"],[0.199,"H"],[0.3,"B"],[0.352,"D"],[0.403,"B"],[0.455,"F"],[0.638,"E"],[0.821,"B"],[1.005,"X"],[1.679,"C"],[1.717,"F"],[1.756,"B"],[1.795,"C"],[1.833,"A"],[1.89,"C"],[1.948,"B"],[2.005,"C"],[2.062,"B"],[2.119,"B"],[2.155,"C"],[2.19,"G"],[2.374,"F"],[2.557,"B"],[2.74,"X"]],"s04c":[[0.064,"H"],[0.139,"D"],[0.213,"F"],[0.287,"B"],[0.361,"D"],[0.457,"H"],[0.554,"C"],[0.631,"F"],[0.709,"H"],[0.846,"C"],[0.984,"B"],[1.121,"C"],[1.259,"X"],[1.494,"D"],[1.572,"B"],[1.714,"E"],[1.855,"B"],[1.997,"B"],[2.094,"F"],[2.19,"B"],[2.287,"C"],[2.384,"B"],[2.464,"C"],[2.545,"A"],[2.625,"B"],[2.706,"C"],[2.757,"F"],[2.809,"B"],[2.946,"D"],[3.084,"G"],[3.221,"C"],[3.359,"X"]],"s05":[[0.138,"B"],[0.321,"C"],[0.504,"B"],[0.775,"F"],[0.863,"B"],[0.95,"E"],[1.006,"G"],[1.062,"B"],[1.113,"C"],[1.163,"F"],[1.438,"B"],[1.713,"X"],[1.887,"B"],[1.95,"D"],[2.013,"A"],[2.075,"C"],[2.138,"B"],[2.2,"C"],[2.263,"A"],[2.342,"C"],[2.421,"B"],[2.5,"A"],[2.583,"D"],[2.667,"B"],[2.75,"F"],[2.888,"E"],[3.025,"H"],[3.162,"G"],[3.3,"X"],[3.638,"B"],[3.706,"C"],[3.775,"B"],[3.853,"C"],[3.93,"G"],[4.007,"C"],[4.085,"B"],[4.162,"B"],[4.244,"C"],[4.325,"C"],[4.594,"B"],[4.862,"D"],[4.925,"B"],[4.987,"B"],[5.056,"C"],[5.125,"B"],[5.208,"A"],[5.292,"C"],[5.375,"H"],[5.458,"C"],[5.542,"B"],[5.625,"D"],[5.675,"B"],[5.778,"F"],[5.881,"B"],[5.984,"C"],[6.088,"B"],[6.198,"A"],[6.308,"C"],[6.418,"H"],[6.527,"C"],[6.638,"X"]],"s06a":[[0.103,"H"],[0.183,"C"],[0.263,"B"],[0.343,"H"],[0.422,"C"],[0.502,"A"],[0.653,"C"],[0.804,"B"],[0.954,"H"],[1.018,"C"],[1.082,"B"],[1.146,"H"],[1.21,"C"],[1.273,"A"],[1.457,"C"],[1.64,"B"],[1.832,"H"],[1.903,"C"],[1.974,"B"],[2.045,"A"],[2.105,"C"],[2.164,"B"],[2.231,"E"],[2.297,"A"],[2.364,"C"],[2.43,"C"],[2.705,"B"],[2.98,"X"]],"s06b":[[0.096,"B"],[0.2,"E"],[0.305,"B"],[0.409,"A"],[0.501,"C"],[0.594,"B"],[0.652,"C"],[0.71,"B"],[0.814,"C"],[0.918,"B"],[1.022,"E"],[1.086,"G"],[1.15,"A"],[1.236,"C"],[1.323,"B"],[1.413,"C"],[1.503,"B"],[1.592,"C"],[1.682,"B"],[1.79,"C"],[1.898,"B"],[2.006,"B"],[2.189,"C"],[2.373,"B"],[2.556,"X"]],"s06c":[[0.103,"B"],[0.165,"C"],[0.227,"B"],[0.289,"C"],[0.389,"H"],[0.489,"B"],[0.662,"F"],[0.835,"G"],[1.007,"D"],[1.081,"B"],[1.154,"C"],[1.253,"H"],[1.353,"A"],[1.537,"F"],[1.72,"G"],[1.925,"D"],[1.985,"B"],[2.045,"C"],[2.138,"H"],[2.231,"A"],[2.315,"H"],[2.399,"F"],[2.483,"C"],[2.568,"F"],[2.652,"B"],[2.736,"B"],[2.826,"F"],[2.916,"B"],[3.005,"C"],[3.095,"C"],[3.37,"B"],[3.645,"X"]],"s06d":[[0.125,"B"],[0.25,"E"],[0.375,"B"],[0.456,"C"],[0.537,"B"],[0.647,"F"],[0.757,"G"],[0.867,"C"],[0.977,"B"],[1.087,"X"],[1.225,"D"],[1.269,"B"],[1.312,"B"],[1.375,"C"],[1.438,"A"],[1.548,"F"],[1.657,"G"],[1.768,"C"],[1.877,"B"],[1.988,"X"],[2.188,"D"],[2.237,"B"],[2.288,"B"],[2.344,"C"],[2.4,"B"],[2.512,"D"],[2.625,"F"],[2.737,"B"],[2.834,"F"],[2.931,"B"],[3.028,"C"],[3.125,"G"],[3.181,"H"],[3.237,"C"],[3.294,"F"],[3.35,"D"],[3.533,"F"],[3.717,"C"],[3.9,"X"],[4.062,"B"],[4.112,"C"],[4.162,"H"],[4.232,"C"],[4.303,"B"],[4.372,"H"],[4.442,"C"],[4.513,"A"],[4.612,"C"],[4.713,"B"],[4.812,"B"],[4.912,"D"],[5.013,"B"],[5.112,"D"],[5.188,"B"],[5.263,"G"],[5.392,"D"],[5.521,"B"],[5.65,"D"],[5.694,"B"],[5.737,"B"],[5.812,"C"],[5.888,"B"],[6.025,"F"],[6.162,"H"],[6.3,"B"],[6.537,"B"],[6.594,"E"],[6.65,"B"],[6.704,"C"],[6.758,"B"],[6.812,"A"],[6.873,"B"],[6.933,"E"],[6.994,"B"],[7.054,"C"],[7.115,"B"],[7.175,"B"],[7.241,"F"],[7.306,"B"],[7.372,"C"],[7.438,"E"],[7.487,"G"],[7.537,"B"],[7.721,"C"],[7.904,"B"],[8.088,"X"]],"s07a":[[0.103,"H"],[0.183,"C"],[0.263,"B"],[0.343,"H"],[0.422,"C"],[0.502,"A"],[0.685,"C"],[0.869,"B"],[1.061,"H"],[1.132,"C"],[1.204,"B"],[1.276,"H"],[1.348,"C"],[1.42,"A"],[1.603,"C"],[1.786,"B"],[2.045,"H"],[2.129,"C"],[2.213,"B"],[2.297,"A"],[2.357,"C"],[2.417,"B"],[2.484,"E"],[2.55,"A"],[2.616,"C"],[2.683,"C"],[2.958,"B"],[3.233,"X"]],"s07b":[[0.098,"B"],[0.165,"E"],[0.233,"B"],[0.3,"A"],[0.36,"C"],[0.419,"B"],[0.467,"C"],[0.514,"B"],[0.59,"C"],[0.665,"B"],[0.74,"E"],[0.782,"G"],[0.824,"F"],[0.901,"B"],[0.979,"B"],[1.05,"C"],[1.121,"B"],[1.193,"C"],[1.264,"B"],[1.34,"C"],[1.415,"B"],[1.49,"B"],[1.674,"C"],[1.857,"B"],[2.04,"X"]],"s07c":[[0.125,"B"],[0.231,"E"],[0.338,"B"],[0.394,"C"],[0.45,"F"],[0.525,"E"],[0.6,"H"],[0.675,"G"],[0.75,"B"],[0.86,"F"],[0.97,"G"],[1.08,"C"],[1.19,"B"],[1.413,"D"],[1.456,"B"],[1.5,"B"],[1.562,"C"],[1.625,"A"],[1.735,"F"],[1.845,"G"],[1.955,"C"],[2.065,"B"],[2.175,"X"],[2.362,"D"],[2.412,"B"],[2.462,"B"],[2.519,"C"],[2.575,"B"],[2.671,"C"],[2.767,"B"],[2.862,"B"],[2.938,"F"],[3.013,"B"],[3.087,"C"],[3.163,"F"],[3.254,"E"],[3.346,"A"],[3.438,"H"],[3.529,"C"],[3.621,"B"],[3.812,"D"],[3.875,"B"],[3.938,"B"],[4.029,"F"],[4.121,"B"],[4.213,"C"],[4.281,"B"],[4.35,"B"],[4.487,"D"],[4.625,"A"],[4.762,"C"],[4.9,"X"],[5.037,"B"],[5.133,"F"],[5.229,"E"],[5.325,"H"],[5.388,"C"],[5.45,"B"],[5.513,"H"],[5.575,"C"],[5.638,"A"],[5.788,"C"],[5.938,"B"],[6.088,"B"],[6.192,"D"],[6.296,"B"],[6.4,"B"],[6.456,"E"],[6.513,"B"],[6.562,"C"],[6.612,"B"],[6.694,"F"],[6.775,"B"],[6.856,"C"],[6.938,"E"],[7.0,"G"],[7.062,"A"],[7.2,"B"],[7.338,"C"],[7.475,"B"],[7.612,"X"]],"s08a":[[0.103,"H"],[0.196,"C"],[0.289,"B"],[0.382,"H"],[0.476,"C"],[0.569,"A"],[0.752,"C"],[0.935,"B"],[1.119,"X"],[2.035,"H"],[2.218,"C"],[2.401,"B"],[2.585,"X"],[3.418,"A"],[3.693,"C"],[3.968,"X"],[4.641,"C"],[4.916,"B"],[5.191,"X"]],"s08b":[[0.077,"B"],[0.185,"E"],[0.292,"B"],[0.4,"A"],[0.483,"C"],[0.567,"B"],[0.625,"C"],[0.683,"B"],[0.82,"C"],[0.958,"B"],[1.095,"E"],[1.16,"G"],[1.224,"F"],[1.295,"B"],[1.366,"B"],[1.453,"C"],[1.54,"B"],[1.627,"C"],[1.714,"B"],[1.821,"C"],[1.929,"B"],[2.036,"B"],[2.219,"C"],[2.403,"B"],[2.586,"X"]],"s08c":[[0.138,"B"],[0.188,"C"],[0.237,"F"],[0.312,"E"],[0.387,"H"],[0.462,"G"],[0.537,"B"],[0.647,"F"],[0.757,"G"],[0.867,"C"],[0.977,"B"],[1.087,"X"],[1.225,"D"],[1.269,"B"],[1.312,"B"],[1.375,"C"],[1.438,"A"],[1.548,"F"],[1.657,"G"],[1.768,"C"],[1.877,"B"],[1.988,"X"],[2.4,"B"],[2.469,"C"],[2.538,"A"],[2.647,"F"],[2.758,"G"],[2.868,"C"],[2.978,"B"],[3.088,"X"],[3.3,"D"],[3.356,"B"],[3.413,"B"],[3.487,"C"],[3.562,"B"],[3.672,"F"],[3.782,"G"],[3.893,"C"],[4.002,"B"],[4.112,"X"],[4.513,"B"],[4.581,"C"],[4.65,"A"],[4.73,"F"],[4.81,"G"],[4.89,"C"],[4.97,"B"],[5.05,"F"],[5.104,"C"],[5.158,"B"],[5.213,"D"],[5.306,"H"],[5.4,"B"],[5.463,"C"],[5.525,"B"],[5.588,"A"],[5.771,"C"],[5.954,"B"],[6.138,"X"],[6.287,"A"],[6.342,"F"],[6.396,"B"],[6.45,"B"],[6.506,"C"],[6.562,"A"],[6.625,"B"],[6.688,"C"],[6.75,"B"],[6.812,"B"],[6.9,"F"],[6.987,"B"],[7.075,"C"],[7.162,"B"],[7.217,"C"],[7.271,"B"],[7.325,"B"],[7.413,"E"],[7.5,"B"],[7.588,"A"],[7.653,"E"],[7.719,"G"],[7.784,"C"],[7.85,"E"],[7.933,"B"],[8.017,"C"],[8.1,"A"],[8.283,"C"],[8.467,"B"],[8.65,"X"]],"s09a":[[0.138,"B"],[0.213,"C"],[0.287,"B"],[0.362,"B"],[0.412,"C"],[0.463,"F"],[0.55,"E"],[0.637,"H"],[0.725,"G"],[0.812,"B"],[0.871,"D"],[0.929,"B"],[0.988,"D"],[1.062,"B"],[1.181,"C"],[1.3,"B"],[1.419,"C"],[1.538,"C"],[1.721,"B"],[1.904,"C"],[2.088,"X"],[2.513,"B"],[2.581,"C"],[2.65,"B"],[2.741,"C"],[2.831,"A"],[2.922,"B"],[3.013,"F"],[3.106,"A"],[3.2,"E"],[3.283,"B"],[3.367,"E"],[3.45,"B"],[3.513,"C"],[3.575,"B"],[3.758,"F"],[3.942,"G"],[4.125,"X"],[4.275,"B"],[4.372,"F"],[4.469,"D"],[4.566,"B"],[4.662,"B"],[4.719,"C"],[4.775,"B"],[4.885,"C"],[4.995,"A"],[5.105,"B"],[5.215,"C"],[5.325,"X"]],"s09b":[[0.103,"B"],[0.249,"C"],[0.396,"B"],[0.542,"B"],[0.675,"C"],[0.808,"B"],[0.941,"B"],[1.124,"C"],[1.308,"B"],[1.491,"X"],[2.114,"C"],[2.221,"H"],[2.327,"B"],[2.39,"E"],[2.453,"A"],[2.517,"C"],[2.58,"B"],[2.673,"F"],[2.766,"B"],[2.859,"B"],[2.919,"C"],[2.979,"B"],[3.089,"C"],[3.199,"A"],[3.309,"B"],[3.419,"C"],[3.529,"X"]],"s09c":[[0.1,"A"],[0.175,"F"],[0.25,"B"],[0.325,"C"],[0.435,"B"],[0.545,"C"],[0.655,"B"],[0.765,"C"],[0.875,"X"],[1.225,"B"],[1.281,"C"],[1.337,"B"],[1.442,"C"],[1.546,"B"],[1.65,"H"],[1.708,"C"],[1.765,"B"],[1.823,"H"],[1.88,"C"],[1.938,"A"],[2.046,"C"],[2.154,"B"],[2.263,"B"],[2.325,"D"],[2.388,"B"],[2.45,"D"],[2.506,"B"],[2.562,"C"],[2.7,"B"],[2.837,"C"],[2.975,"B"],[3.25,"F"],[3.525,"X"],[3.788,"B"],[3.862,"C"],[3.938,"B"],[4.029,"C"],[4.121,"B"],[4.213,"D"],[4.325,"A"],[4.404,"C"],[4.483,"B"],[4.562,"A"],[4.642,"E"],[4.721,"B"],[4.8,"E"],[4.856,"G"],[4.912,"F"],[4.992,"D"],[5.072,"B"],[5.152,"C"],[5.232,"B"],[5.312,"E"],[5.388,"B"],[5.463,"B"],[5.513,"C"],[5.562,"G"],[5.7,"C"],[5.838,"B"],[5.975,"C"],[6.112,"X"]],"s10a":[[0.1,"B"],[0.196,"F"],[0.292,"B"],[0.388,"B"],[0.444,"C"],[0.5,"B"],[0.588,"C"],[0.675,"A"],[0.762,"B"],[0.85,"C"],[0.938,"B"],[1.003,"D"],[1.069,"A"],[1.134,"C"],[1.2,"B"],[1.25,"C"],[1.3,"F"],[1.438,"E"],[1.575,"H"],[1.713,"G"],[1.85,"X"],[1.975,"D"],[2.038,"B"],[2.1,"B"],[2.21,"A"],[2.32,"H"],[2.43,"D"],[2.54,"B"],[2.65,"X"],[3.075,"B"],[3.188,"C"],[3.3,"B"],[3.413,"C"],[3.5,"B"],[3.587,"E"],[3.675,"B"],[3.725,"C"],[3.775,"B"],[3.871,"E"],[3.967,"B"],[4.062,"F"],[4.173,"D"],[4.282,"B"],[4.393,"C"],[4.502,"B"],[4.612,"X"]],"s10b":[[0.103,"F"],[0.653,"X"],[1.449,"A"],[1.589,"C"],[1.729,"B"],[1.912,"C"],[2.095,"H"],[2.279,"X"]],"s10c":[[0.113,"F"],[0.213,"A"],[0.312,"B"],[0.369,"C"],[0.425,"B"],[0.505,"C"],[0.585,"A"],[0.665,"B"],[0.745,"C"],[0.825,"B"],[0.906,"C"],[0.988,"B"],[1.171,"E"],[1.354,"B"],[1.538,"X"],[1.75,"D"],[1.8,"B"],[1.85,"D"],[1.954,"F"],[2.058,"C"],[2.163,"B"],[2.244,"C"],[2.325,"B"],[2.425,"D"],[2.525,"B"],[2.625,"C"],[2.704,"B"],[2.783,"E"],[2.862,"B"],[2.912,"C"],[2.962,"F"],[3.237,"B"],[3.513,"X"],[3.888,"D"],[3.95,"B"],[4.013,"B"],[4.081,"C"],[4.15,"B"],[4.215,"C"],[4.28,"G"],[4.345,"C"],[4.41,"B"],[4.475,"B"],[4.547,"D"],[4.619,"A"],[4.691,"C"],[4.763,"A"],[4.946,"D"],[5.129,"B"],[5.312,"X"]],"s11":[[0.125,"G"],[0.188,"B"],[0.25,"E"],[0.312,"A"],[0.375,"B"],[0.454,"D"],[0.533,"B"],[0.613,"B"],[0.719,"C"],[0.825,"E"],[1.1,"B"],[1.387,"B"],[1.438,"C"],[1.488,"B"],[1.631,"C"],[1.775,"H"],[1.833,"C"],[1.89,"B"],[1.948,"H"],[2.005,"C"],[2.062,"A"],[2.212,"C"],[2.363,"B"],[2.513,"H"],[2.568,"C"],[2.623,"G"],[2.678,"C"],[2.732,"B"],[2.788,"B"],[2.859,"E"],[2.93,"B"],[3.002,"C"],[3.073,"B"],[3.145,"C"],[3.216,"B"],[3.288,"C"],[3.356,"B"],[3.425,"B"],[3.475,"C"],[3.525,"B"],[3.646,"E"],[3.767,"B"],[3.888,"A"],[3.947,"B"],[4.006,"C"],[4.066,"B"],[4.125,"B"],[4.263,"F"],[4.4,"B"],[4.537,"C"],[4.675,"X"],[5.062,"B"],[5.138,"C"],[5.213,"E"],[5.275,"B"],[5.338,"C"],[5.4,"B"],[5.463,"B"],[5.575,"F"],[5.688,"E"],[5.8,"B"],[5.86,"C"],[5.921,"H"],[5.981,"A"],[6.042,"C"],[6.102,"B"],[6.162,"A"],[6.22,"F"],[6.277,"C"],[6.335,"H"],[6.393,"B"],[6.45,"B"],[6.517,"C"],[6.583,"F"],[6.65,"B"],[6.788,"F"],[6.925,"A"],[7.062,"B"],[7.2,"X"],[7.412,"A"],[7.478,"B"],[7.544,"C"],[7.609,"B"],[7.675,"A"],[7.756,"C"],[7.838,"A"],[7.975,"B"],[8.113,"C"],[8.25,"B"],[8.388,"X"],[8.713,"D"],[8.788,"B"],[8.863,"B"],[8.944,"C"],[9.025,"D"],[9.144,"H"],[9.262,"H"],[9.327,"C"],[9.393,"G"],[9.457,"C"],[9.523,"B"],[9.588,"B"],[9.677,"D"],[9.767,"A"],[9.856,"C"],[9.946,"H"],[10.035,"C"],[10.125,"C"],[10.203,"G"],[10.281,"C"],[10.359,"B"],[10.438,"D"],[10.547,"G"],[10.658,"B"],[10.768,"C"],[10.878,"B"],[10.988,"X"]]};
diff --git a/site/three-little-pigs/ch01/audio/en/s01.mp3 b/site/three-little-pigs/ch01/audio/en/s01.mp3
new file mode 100644
index 0000000..c4b448c
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s01.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s01b.mp3 b/site/three-little-pigs/ch01/audio/en/s01b.mp3
new file mode 100644
index 0000000..ee8aafa
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s01b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s02.mp3 b/site/three-little-pigs/ch01/audio/en/s02.mp3
new file mode 100644
index 0000000..b497529
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s02.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s02b.mp3 b/site/three-little-pigs/ch01/audio/en/s02b.mp3
new file mode 100644
index 0000000..e38e501
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s02b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s03.mp3 b/site/three-little-pigs/ch01/audio/en/s03.mp3
new file mode 100644
index 0000000..851afc9
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s03.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s03b.mp3 b/site/three-little-pigs/ch01/audio/en/s03b.mp3
new file mode 100644
index 0000000..5c8520e
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s03b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s04.mp3 b/site/three-little-pigs/ch01/audio/en/s04.mp3
new file mode 100644
index 0000000..9ea2c36
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s04.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s04b.mp3 b/site/three-little-pigs/ch01/audio/en/s04b.mp3
new file mode 100644
index 0000000..710ca26
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s04b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s04c.mp3 b/site/three-little-pigs/ch01/audio/en/s04c.mp3
new file mode 100644
index 0000000..43d45bc
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s04c.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s05.mp3 b/site/three-little-pigs/ch01/audio/en/s05.mp3
new file mode 100644
index 0000000..db78edd
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s05.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s06a.mp3 b/site/three-little-pigs/ch01/audio/en/s06a.mp3
new file mode 100644
index 0000000..e2d7524
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s06a.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s06b.mp3 b/site/three-little-pigs/ch01/audio/en/s06b.mp3
new file mode 100644
index 0000000..80d77b7
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s06b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s06c.mp3 b/site/three-little-pigs/ch01/audio/en/s06c.mp3
new file mode 100644
index 0000000..147ab90
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s06c.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s06d.mp3 b/site/three-little-pigs/ch01/audio/en/s06d.mp3
new file mode 100644
index 0000000..9632457
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s06d.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s07a.mp3 b/site/three-little-pigs/ch01/audio/en/s07a.mp3
new file mode 100644
index 0000000..5a87311
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s07a.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s07b.mp3 b/site/three-little-pigs/ch01/audio/en/s07b.mp3
new file mode 100644
index 0000000..f5400d1
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s07b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s07c.mp3 b/site/three-little-pigs/ch01/audio/en/s07c.mp3
new file mode 100644
index 0000000..d59bd99
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s07c.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s08a.mp3 b/site/three-little-pigs/ch01/audio/en/s08a.mp3
new file mode 100644
index 0000000..b5b1ec0
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s08a.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s08b.mp3 b/site/three-little-pigs/ch01/audio/en/s08b.mp3
new file mode 100644
index 0000000..de8d62d
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s08b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s08c.mp3 b/site/three-little-pigs/ch01/audio/en/s08c.mp3
new file mode 100644
index 0000000..a2b4eeb
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s08c.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s09a.mp3 b/site/three-little-pigs/ch01/audio/en/s09a.mp3
new file mode 100644
index 0000000..4c73580
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s09a.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s09b.mp3 b/site/three-little-pigs/ch01/audio/en/s09b.mp3
new file mode 100644
index 0000000..4738f86
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s09b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s09c.mp3 b/site/three-little-pigs/ch01/audio/en/s09c.mp3
new file mode 100644
index 0000000..0040e16
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s09c.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s10a.mp3 b/site/three-little-pigs/ch01/audio/en/s10a.mp3
new file mode 100644
index 0000000..21444fb
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s10a.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s10b.mp3 b/site/three-little-pigs/ch01/audio/en/s10b.mp3
new file mode 100644
index 0000000..0e1605c
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s10b.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s10c.mp3 b/site/three-little-pigs/ch01/audio/en/s10c.mp3
new file mode 100644
index 0000000..0d76339
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s10c.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/s11.mp3 b/site/three-little-pigs/ch01/audio/en/s11.mp3
new file mode 100644
index 0000000..d356a81
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/s11.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot1.mp3 b/site/three-little-pigs/ch01/audio/en/shot1.mp3
new file mode 100644
index 0000000..1ec10e1
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot1.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot10.mp3 b/site/three-little-pigs/ch01/audio/en/shot10.mp3
new file mode 100644
index 0000000..256ae6f
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot10.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot11.mp3 b/site/three-little-pigs/ch01/audio/en/shot11.mp3
new file mode 100644
index 0000000..30a982d
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot11.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot2.mp3 b/site/three-little-pigs/ch01/audio/en/shot2.mp3
new file mode 100644
index 0000000..dbf400d
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot2.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot3.mp3 b/site/three-little-pigs/ch01/audio/en/shot3.mp3
new file mode 100644
index 0000000..9510fb4
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot3.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot4.mp3 b/site/three-little-pigs/ch01/audio/en/shot4.mp3
new file mode 100644
index 0000000..f788645
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot4.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot5.mp3 b/site/three-little-pigs/ch01/audio/en/shot5.mp3
new file mode 100644
index 0000000..84e36ca
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot5.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot6.mp3 b/site/three-little-pigs/ch01/audio/en/shot6.mp3
new file mode 100644
index 0000000..5f24a03
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot6.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot7.mp3 b/site/three-little-pigs/ch01/audio/en/shot7.mp3
new file mode 100644
index 0000000..6b7c11c
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot7.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot8.mp3 b/site/three-little-pigs/ch01/audio/en/shot8.mp3
new file mode 100644
index 0000000..64d31d5
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot8.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shot9.mp3 b/site/three-little-pigs/ch01/audio/en/shot9.mp3
new file mode 100644
index 0000000..9ac407f
Binary files /dev/null and b/site/three-little-pigs/ch01/audio/en/shot9.mp3 differ
diff --git a/site/three-little-pigs/ch01/audio/en/shots.js b/site/three-little-pigs/ch01/audio/en/shots.js
new file mode 100644
index 0000000..94c1a4b
--- /dev/null
+++ b/site/three-little-pigs/ch01/audio/en/shots.js
@@ -0,0 +1,11 @@
+TIMINGS.shot1 = {"dur": 11.654, "marks": {"s01.go": 1.488}, "cues": [[0.138, "Once upon a time, three little pigs packed their bags and set off to build homes of their own."], [6.236, "Goodbye, my dears!"], [8.608, "And watch out for the big bad wolf!"]], "parts": {"s01": 0, "s01b": 6.134}};
+TIMINGS.shot2 = {"dur": 16.574, "marks": {"s02.straw": 0.138, "s02.build": 3.612}, "cues": [[0.138, "The first little pig found a big haystack by the road."], [3.612, "Swish, swoosh, flump!"], [10.325, "Her house was done before lunch."], [13.046, "Easy peasy!"], [14.732, "Time for a nap."]], "parts": {"s02": 0, "s02b": 12.95}};
+TIMINGS.shot3 = {"dur": 14.618, "marks": {"s03.sticks": 0.138, "s03.hammer": 3.237}, "cues": [[0.138, "The second little pig gathered a pile of sticks."], [3.237, "Tap, tap, tap."], [8.213, "A wobbly little house of sticks."], [10.996, "Good enough for me!"], [12.648, "Let's play some music!"]], "parts": {"s03": 0, "s03b": 10.898}};
+TIMINGS.shot4 = {"dur": 16.444, "marks": {"s04.bricks": 0.138, "s04.laugh": 6.425}, "cues": [[0.138, "The third little pig chose bricks."], [2.612, "Brick by brick, all day long, until his arms ached."], [6.425, "His brother and sister laughed."], [9.088, "All that work?"], [10.669, "You're missing the fun!"], [12.764, "Laugh all you like."], [14.194, "A strong house keeps you safe."]], "parts": {"s04": 0, "s04b": 8.99, "s04c": 12.7}};
+TIMINGS.shot5 = {"dur": 7.032, "marks": {"s05.wolf": 0.138, "s05.sniff": 3.638, "s05.grin": 4.862}, "cues": [[0.138, "Then, out of the woods, came the big bad wolf."], [3.638, "He sniffed the air, and he smiled a hungry smile."]], "parts": {"s05": 0}};
+TIMINGS.shot6 = {"dur": 21.954, "marks": {"s06d.inhale": 12.359, "s06d.blow": 13.459, "s06d.gone": 15.622, "s06d.run": 17.496}, "cues": [[0.103, "Little pig, little pig, let me come in!"], [4.094, "Not by the hair of my chinny chin chin!"], [7.667, "Then I'll huff, and I'll puff, and I'll blow your house in!"], [12.359, "So he huffed, and he puffed, and the straw house flew away!"], [17.496, "The little pig ran as fast as she could, to her brother's house of sticks."]], "parts": {"s06a": 0, "s06b": 3.998, "s06c": 7.564, "s06d": 12.234}};
+TIMINGS.shot7 = {"dur": 17.236, "marks": {"s07c.inhale": 7.569, "s07c.wobble": 10.806, "s07c.fall": 13.056, "s07c.run": 14.281}, "cues": [[0.103, "Little pigs, little pigs, let me come in!"], [4.36, "Not by the hair of our chinny chin chins!"], [7.569, "So the wolf huffed, and he puffed, and the stick house wobbled, and down it came!"], [14.281, "Two little pigs ran to the house of bricks."]], "parts": {"s07a": 0, "s07b": 4.262, "s07c": 7.444}};
+TIMINGS.shot8 = {"dur": 19.884, "marks": {"s08c.puff1": 9.718, "s08c.puff2": 11.98, "s08c.puff3": 14.093, "s08c.flop": 17.267}, "cues": [[0.103, "Little pigs!"], [2.035, "Let!"], [3.418, "Me!"], [4.641, "In!"], [6.331, "Not by the hair of our chinny chin chins!"], [9.718, "The wolf huffed, and he puffed."], [11.98, "He puffed, and he huffed."], [14.093, "He puffed with all his might, but the brick house did not move one bit."]], "parts": {"s08a": 0, "s08b": 6.254, "s08c": 9.58}};
+TIMINGS.shot9 = {"dur": 17.788, "marks": {"s09a.idea": 0.138, "s09a.climb": 3.113, "s09c.pot": 11.432}, "cues": [[0.138, "Then the wolf had a sneaky idea."], [3.113, "He crept up onto the roof, toward the chimney."], [6.693, "Heh, heh, heh."], [8.704, "I'll come down the chimney!"], [11.432, "But inside, the third little pig had an idea too."], [15.12, "He set a big pot of water on the fire."]], "parts": {"s09a": 0, "s09b": 6.59, "s09c": 11.332}};
+TIMINGS.shot10 = {"dur": 15.552, "marks": {"s10a.drop": 0.1, "s10a.splash": 1.975, "s10c.shoot": 9.449, "s10c.away": 11.686}, "cues": [[0.1, "Down the chimney came the wolf, and splash!"], [3.575, "Right into the hot water."], [5.945, "Owww!"], [7.291, "My tail!"], [9.449, "Up the chimney he shot, and away he ran into the woods."], [13.824, "And he never came back."]], "parts": {"s10a": 0, "s10b": 5.842, "s10c": 9.336}};
+TIMINGS.shot11 = {"dur": 11.328, "marks": {"s11.dance": 0.125, "s11.help": 5.062, "s11.end": 8.713}, "cues": [[0.125, "From that day on, the three little pigs lived together in the strong brick house."], [5.062, "The other two helped build new rooms, brick by brick."], [8.713, "And they all lived happily ever after."]], "parts": {"s11": 0}};
diff --git a/site/three-little-pigs/ch01/audio/en/timings.js b/site/three-little-pigs/ch01/audio/en/timings.js
new file mode 100644
index 0000000..31bb1a7
--- /dev/null
+++ b/site/three-little-pigs/ch01/audio/en/timings.js
@@ -0,0 +1,425 @@
+window.TIMINGS = {
+ "s01": {
+ "dur": 5.784,
+ "marks": {
+ "go": 1.488
+ },
+ "cues": [
+ [
+ 0.138,
+ "Once upon a time, three little pigs packed their bags and set off to build homes of their own."
+ ]
+ ]
+ },
+ "s01b": {
+ "dur": 5.52,
+ "marks": {},
+ "cues": [
+ [
+ 0.102,
+ "Goodbye, my dears!"
+ ],
+ [
+ 2.474,
+ "And watch out for the big bad wolf!"
+ ]
+ ]
+ },
+ "s02": {
+ "dur": 8.4,
+ "marks": {
+ "straw": 0.138,
+ "build": 3.612
+ },
+ "cues": [
+ [
+ 0.138,
+ "The first little pig found a big haystack by the road."
+ ],
+ [
+ 3.612,
+ "Swish, swoosh, flump!"
+ ],
+ [
+ 6.125,
+ "Her house was done before lunch."
+ ]
+ ]
+ },
+ "s02b": {
+ "dur": 3.624,
+ "marks": {},
+ "cues": [
+ [
+ 0.096,
+ "Easy peasy!"
+ ],
+ [
+ 1.782,
+ "Time for a nap."
+ ]
+ ]
+ },
+ "s03": {
+ "dur": 7.848,
+ "marks": {
+ "sticks": 0.138,
+ "hammer": 3.237
+ },
+ "cues": [
+ [
+ 0.138,
+ "The second little pig gathered a pile of sticks."
+ ],
+ [
+ 3.237,
+ "Tap, tap, tap."
+ ],
+ [
+ 5.513,
+ "A wobbly little house of sticks."
+ ]
+ ]
+ },
+ "s03b": {
+ "dur": 3.72,
+ "marks": {},
+ "cues": [
+ [
+ 0.098,
+ "Good enough for me!"
+ ],
+ [
+ 1.75,
+ "Let's play some music!"
+ ]
+ ]
+ },
+ "s04": {
+ "dur": 8.64,
+ "marks": {
+ "bricks": 0.138,
+ "laugh": 6.425
+ },
+ "cues": [
+ [
+ 0.138,
+ "The third little pig chose bricks."
+ ],
+ [
+ 2.612,
+ "Brick by brick, all day long, until his arms ached."
+ ],
+ [
+ 6.425,
+ "His brother and sister laughed."
+ ]
+ ]
+ },
+ "s04b": {
+ "dur": 3.36,
+ "marks": {},
+ "cues": [
+ [
+ 0.098,
+ "All that work?"
+ ],
+ [
+ 1.679,
+ "You're missing the fun!"
+ ]
+ ]
+ },
+ "s04c": {
+ "dur": 3.744,
+ "marks": {},
+ "cues": [
+ [
+ 0.064,
+ "Laugh all you like."
+ ],
+ [
+ 1.494,
+ "A strong house keeps you safe."
+ ]
+ ]
+ },
+ "s05": {
+ "dur": 7.032,
+ "marks": {
+ "wolf": 0.138,
+ "sniff": 3.638,
+ "grin": 4.862
+ },
+ "cues": [
+ [
+ 0.138,
+ "Then, out of the woods, came the big bad wolf."
+ ],
+ [
+ 3.638,
+ "He sniffed the air, and he smiled a hungry smile."
+ ]
+ ]
+ },
+ "s06a": {
+ "dur": 3.648,
+ "marks": {},
+ "cues": [
+ [
+ 0.103,
+ "Little pig, little pig, let me come in!"
+ ]
+ ]
+ },
+ "s06b": {
+ "dur": 3.216,
+ "marks": {},
+ "cues": [
+ [
+ 0.096,
+ "Not by the hair of my chinny chin chin!"
+ ]
+ ]
+ },
+ "s06c": {
+ "dur": 4.32,
+ "marks": {},
+ "cues": [
+ [
+ 0.103,
+ "Then I'll huff, and I'll puff, and I'll blow your house in!"
+ ]
+ ]
+ },
+ "s06d": {
+ "dur": 8.52,
+ "marks": {
+ "inhale": 0.125,
+ "blow": 1.225,
+ "gone": 2.188,
+ "run": 4.062
+ },
+ "cues": [
+ [
+ 0.125,
+ "So he huffed, and he puffed, and the straw house flew away!"
+ ],
+ [
+ 4.062,
+ "The little pig ran as fast as she could, to her brother's house of sticks."
+ ]
+ ]
+ },
+ "s07a": {
+ "dur": 3.912,
+ "marks": {},
+ "cues": [
+ [
+ 0.103,
+ "Little pigs, little pigs, let me come in!"
+ ]
+ ]
+ },
+ "s07b": {
+ "dur": 2.832,
+ "marks": {},
+ "cues": [
+ [
+ 0.098,
+ "Not by the hair of our chinny chin chins!"
+ ]
+ ]
+ },
+ "s07c": {
+ "dur": 7.992,
+ "marks": {
+ "inhale": 0.125,
+ "wobble": 2.362,
+ "fall": 3.812,
+ "run": 5.037
+ },
+ "cues": [
+ [
+ 0.125,
+ "So the wolf huffed, and he puffed, and the stick house wobbled, and down it came!"
+ ],
+ [
+ 5.037,
+ "Two little pigs ran to the house of bricks."
+ ]
+ ]
+ },
+ "s08a": {
+ "dur": 5.904,
+ "marks": {},
+ "cues": [
+ [
+ 0.103,
+ "Little pigs!"
+ ],
+ [
+ 2.035,
+ "Let!"
+ ],
+ [
+ 3.418,
+ "Me!"
+ ],
+ [
+ 4.641,
+ "In!"
+ ]
+ ]
+ },
+ "s08b": {
+ "dur": 2.976,
+ "marks": {},
+ "cues": [
+ [
+ 0.077,
+ "Not by the hair of our chinny chin chins!"
+ ]
+ ]
+ },
+ "s08c": {
+ "dur": 8.904,
+ "marks": {
+ "puff1": 0.138,
+ "puff2": 2.4,
+ "puff3": 4.513,
+ "flop": 6.287
+ },
+ "cues": [
+ [
+ 0.138,
+ "The wolf huffed, and he puffed."
+ ],
+ [
+ 2.4,
+ "He puffed, and he huffed."
+ ],
+ [
+ 4.513,
+ "He puffed with all his might, but the brick house did not move one bit."
+ ]
+ ]
+ },
+ "s09a": {
+ "dur": 5.64,
+ "marks": {
+ "idea": 0.138,
+ "climb": 2.513
+ },
+ "cues": [
+ [
+ 0.138,
+ "Then the wolf had a sneaky idea."
+ ],
+ [
+ 2.513,
+ "He crept up onto the roof, toward the chimney."
+ ]
+ ]
+ },
+ "s09b": {
+ "dur": 4.392,
+ "marks": {},
+ "cues": [
+ [
+ 0.103,
+ "Heh, heh, heh."
+ ],
+ [
+ 2.114,
+ "I'll come down the chimney!"
+ ]
+ ]
+ },
+ "s09c": {
+ "dur": 6.456,
+ "marks": {
+ "pot": 0.1
+ },
+ "cues": [
+ [
+ 0.1,
+ "But inside, the third little pig had an idea too."
+ ],
+ [
+ 3.788,
+ "He set a big pot of water on the fire."
+ ]
+ ]
+ },
+ "s10a": {
+ "dur": 4.992,
+ "marks": {
+ "drop": 0.1,
+ "splash": 1.975
+ },
+ "cues": [
+ [
+ 0.1,
+ "Down the chimney came the wolf, and splash!"
+ ],
+ [
+ 3.075,
+ "Right into the hot water."
+ ]
+ ]
+ },
+ "s10b": {
+ "dur": 3.144,
+ "marks": {},
+ "cues": [
+ [
+ 0.103,
+ "Owww!"
+ ],
+ [
+ 1.449,
+ "My tail!"
+ ]
+ ]
+ },
+ "s10c": {
+ "dur": 5.616,
+ "marks": {
+ "shoot": 0.113,
+ "away": 1.75
+ },
+ "cues": [
+ [
+ 0.113,
+ "Up the chimney he shot, and away he ran into the woods."
+ ],
+ [
+ 3.888,
+ "And he never came back."
+ ]
+ ]
+ },
+ "s11": {
+ "dur": 11.328,
+ "marks": {
+ "dance": 0.125,
+ "help": 5.062,
+ "end": 8.713
+ },
+ "cues": [
+ [
+ 0.125,
+ "From that day on, the three little pigs lived together in the strong brick house."
+ ],
+ [
+ 5.062,
+ "The other two helped build new rooms, brick by brick."
+ ],
+ [
+ 8.713,
+ "And they all lived happily ever after."
+ ]
+ ]
+ }
+};
diff --git a/site/three-little-pigs/ch01/index.html b/site/three-little-pigs/ch01/index.html
new file mode 100644
index 0000000..24173fd
--- /dev/null
+++ b/site/three-little-pigs/ch01/index.html
@@ -0,0 +1,810 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>The Three Little Pigs</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="../lib/cast.js"></script>
+<script src="../lib/toon.js"></script>
+<script src="../img/mother/rig/rig.js"></script><script src="../img/pig1/rig/rig.js"></script><script src="../img/pig2/rig/rig.js"></script><script src="../img/pig3/rig/rig.js"></script><script src="../img/wolf/rig/rig.js"></script>
+<script src="../img/mother/pose/pose.js"></script><script src="../img/pig1/pose/pose.js"></script><script src="../img/pig2/pose/pose.js"></script><script src="../img/pig3/pose/pose.js"></script><script src="../img/wolf/pose/pose.js"></script>
+<script src="audio/en/timings.js"></script>
+<script src="audio/en/mouths.js"></script>
+<script src="audio/en/shots.js"></script>
+<script>
+'use strict';
+const CHAPTER = { number: 1, title: 'The Three Little Pigs', minutes: 4, language: 'en' };
+// A picture book: captions are on unless the reader turned them off.
+try { if (localStorage.getItem('captions') === null) setCaptions(true); } catch {}
+
+/* ---------- helpers ---------- */
+const clamp01 = x => Math.min(1, Math.max(0, x)), smooth = x => { x = clamp01(x); return x * x * (3 - 2 * x); };
+const dur = id => TIMINGS[id].dur;
+const mouthAt = (beat, t) => { let m = 'X'; for (const [at, s] of MOUTHS[beat] || []) { if (at > t) break; m = s; } return m; };
+// A painted place in layers that slide past each other with the camera; each layer but the nearest has a
+// pre-blurred copy that fades in on close shots (shallow focus).
+function scenery(cam, place, layers) {
+ const at = { x: -80, y: -45, width: 1760, height: 990 }, soft = [];
+ for (const [n, k] of layers) {
+ const g = cam.layer(k);
+ mk('image', { href: `../img/${place}/${n}.webp`, ...at }, g);
+ if (n !== 'front') soft.push(mk('image', { href: `../img/${place}/${n}-soft.webp`, ...at, opacity: 0 }, g));
+ }
+ return t => { const f = clamp01((cam.at(t).z - 2.4) / .9); soft.forEach(e => e.setAttribute('opacity', f)); };
+}
+// Shots: [time, view, [view, seconds]?]; the optional push eases toward a second view.
+function shots(cam, list) { for (const [t, v, push] of list) { cam.cut(v, t); if (push) cam.to(push[0], t + .01, push[1], soft); } }
+// A walk on the drawings, on twos: contact (near leg forward), passing, contact (far leg forward), passing.
+const LEGS = [1, 2, 3, 4], SWING = [2, 0, 1, 0], BOB = [1, -1, 1, -1];
+const walkPose = (tau, hold) => { const i = ((Math.floor(tau / hold) % 4) + 4) % 4; return { legs: LEGS[i], arm: SWING[i], bob: BOB[i] }; };
+
+/* ---------- shot 1: leaving home ---------- */
+// The dirt road runs past the gate and off to the right; the pigs set off along it and walk out of the picture,
+// easing into their pace. Positions are a function of time alone.
+const PIGS = [
+ { id: 'pig1', x: 870, g: 862, k: .4, go: 0, hold: .12, v: 115, stop: true, bounce: 8, lean: 4, seed: 11 },
+ { id: 'pig3', x: 745, g: 852, k: .41, go: .35, hold: .16, v: 100, bounce: 5, lean: 2, seed: 23 },
+ { id: 'pig2', x: 620, g: 842, k: .41, go: .9, hold: .22, v: 82, bounce: 7, lean: 6, seed: 37 },
+];
+const MOM = { x: 470, g: 810, k: .52 };
+const S1 = TIMINGS.shot1.parts.s01b, SET_OFF = 3.55, PACK = 2.44, LOOK = S1 + 2.47, WOLF = S1 + 3.45;
+function pigAt(o, T) {
+ // The first pig stops to wave back.
+ const tau = T - SET_OFF - o.go, u = Math.max(0, o.stop ? Math.min(tau, LOOK - .25 - SET_OFF - o.go) : tau), d = o.v * (u - (1 - Math.exp(-3 * u)) / 3);
+ return { tau, x: o.x + d, g: o.g - .05 * d, k: o.k * (1 - d / 6000) };
+}
+const inPic = ({ x, y, z }) => ({ x: Math.min(1640 - 800 / z, Math.max(800 / z - 40, x)), y: Math.min(910 - 450 / z, Math.max(450 / z - 20, y)), z });
+const pigsView = (T, z, dy = 0) => { const ps = PIGS.map(o => pigAt(o, T)); return inPic({ x: ps.reduce((s, p) => s + p.x, 0) / 3 + 40 / z, y: ps.reduce((s, p) => s + p.g, 0) / 3 - 70 + dy, z }); };
+const follow = (T0, z, dy) => ({ x: t => pigsView(T0 + t, z, dy).x, y: t => pigsView(T0 + t, z, dy).y, z });
+const momHead = z => inPic({ x: MOM.x + 30, y: MOM.g - 160, z }); // head and shoulders // her head a little above the middle
+
+function shot1(p, T0, D) {
+ const cam = camera(p, D, inPic({ x: 800, y: 450, z: 1 }));
+ // The ground, the cottage and the actors share the camera's own plane (k = 1); sky and hills lag, flowers lead.
+ const focus = scenery(cam, 'cottage', [['sky', .15], ['far', .4], ['ground', 1], ['mid', 1]]);
+ const actors = cam.layer(1);
+ const mom = TOON.posed(actors, 'mother');
+ const pigs = PIGS.map(o => ({ o, a: TOON.posed(actors, o.id) })).sort((u, v) => u.o.g - v.o.g);
+ pigs.forEach(({ a }) => actors.appendChild(a.root)); // nearer pigs in front
+ pigs.forEach(({ a }) => { // a bindle over the shoulder, behind the body
+ const [sx, sy] = a.R.shoulder;
+ mk('image', { href: '../img/props/bindle.webp', x: -425, y: -355, width: 850, height: 711, transform: `translate(${sx - 150},${sy - 120}) scale(-.55,.55) rotate(-8)` }, a.back);
+ });
+ const front = cam.layer(1.4);
+ mk('image', { href: '../img/cottage/front.webp', x: -80, y: -45, width: 1760, height: 990 }, front); // near flowers: gone on close shots
+ // The imagined wolf (screen space): thought bubbles from her head, then a round frame with the wolf grinning.
+ const bubbles = [0, 1, 2].map(i => mk('circle', { r: 10 + i * 8, fill: '#fff', stroke: '#151314', 'stroke-width': 4, opacity: 0 }, p));
+ const inset = G(p, { x: 1290, y: 245, s: 0 });
+ mk('circle', { r: 182, fill: '#fff', stroke: '#151314', 'stroke-width': 6 }, inset);
+ const clip = 'wolfclip' + Math.random().toString(36).slice(2, 8); // a fresh id: an old scene's clip may still be in the page
+ mk('clipPath', { id: clip }, mk('defs', {}, inset)).appendChild(mk('circle', { r: 168 }));
+ const inner = G(inset); inner.setAttribute('clip-path', `url(#${clip})`);
+ mk('circle', { r: 168, fill: '#22331d' }, inner);
+ for (let i = 0; i < 7; i++) mk('path', { d: `M${-175 + i * 55} 175L${-152 + i * 55} ${-50 - (i % 3) * 32}L${-130 + i * 55} 175Z`, fill: '#182714' }, inner);
+ const wolf = TOON.posed(inner, 'wolf');
+
+ shots(cam, [
+ [0, inPic({ x: 800, y: 450, z: 1 }), [inPic({ x: 690, y: 520, z: 1.25 }), 1.4]], // the cottage, pushing in
+ [1.47, inPic({ x: 690, y: 690, z: 2.4 }), [inPic({ x: 705, y: 686, z: 2.55 }), 2]], // the three of them, ready to go
+ [SET_OFF + .25, pigsView(SET_OFF + .25, 1.8), [pigsView(S1 + .3, 1.7), S1 - SET_OFF - .25]], // off they go: one smooth pan that ends on them
+ [S1, momHead(5.2), [momHead(5.6), 2.4]], // Mother calls after them
+ [LOOK, (p => inPic({ x: p.x - 120, y: p.g - 90, z: 2.3 }))(pigAt(PIGS[0], LOOK)), [(p => inPic({ x: p.x - 90, y: p.g - 90, z: 2.4 }))(pigAt(PIGS[0], WOLF)), WOLF - LOOK]], // the first pig turns and waves back
+ [WOLF, momHead(6.2), [momHead(6.8), D - WOLF]], // her worried face
+ ]);
+ clockRun(t => {
+ const T = T0 + t;
+ focus(t);
+ front.setAttribute('opacity', t < 1.47 ? 1 : 0); // near flowers only in the opening wide shot
+ for (const { o, a } of pigs) {
+ const at = pigAt(o, T), walking = at.tau > 0 && !(o.stop && T > LOOK - .25), wp = walkPose(at.tau, o.hold), hop = clamp01(1 - Math.abs(T - PACK - o.go * .3) / .18);
+ const waving = o.stop && T > LOOK;
+ a.pose({
+ x: at.x, ground: at.g, k: at.k, dir: waving ? -1 : 1, lean: walking ? o.lean : 0, // turns back to wave
+ legs: walking ? wp.legs : 0, arm: waving ? 3 : walking ? wp.arm : 0,
+ bob: (walking ? o.bounce * wp.bob : 0) + 14 * hop,
+ face: { blink: blinkAt(T, o.seed), gaze: [1, -.1], mouth: waving && Math.floor(T / .14) % 3 ? 'C' : 'X' },
+ });
+ }
+ // Mother: on her line she waves her handkerchief and calls; at "big bad wolf" a hand goes to her chest.
+ const s = T - S1, worried = T > WOLF - .1;
+ mom.pose({
+ x: MOM.x, ground: MOM.g, k: MOM.k, lean: s > 0 && !worried ? -2 : worried ? 2 : 0, bob: 3 * Math.sin(T * 2.1),
+ arm: worried ? 2 : s > 0 ? 1 : 0,
+ face: { mouth: s > 0 ? mouthAt('s01b', s) : 'X', blink: worried ? 0 : blinkAt(T, 3), gaze: [1, worried ? -.3 : 0], raise: worried ? .6 : s > 0 ? .4 : 0, wide: worried ? 1 : 0, worry: worried ? 1 : 0, smile: worried ? -.7 : .8 },
+ });
+ // The imagined wolf.
+ const show = T > WOLF + .05 ? 1 - Math.exp(-7 * (T - WOLF - .05)) * Math.cos(9 * (T - WOLF - .05)) : 0;
+ bubbles.forEach((e, i) => { e.setAttribute('opacity', clamp01((T - WOLF + .05 - i * .08) / .1)); e.setAttribute('cx', 1000 + i * 70); e.setAttribute('cy', 470 - i * 55 + 3 * Math.sin(T * 4 + i)); });
+ put(inset, { s: Math.max(0, show), r: 4 * Math.sin(T * 3) * show });
+ wolf.pose({ x: -55, ground: 560 + 8 * Math.abs(Math.sin(T * 4)), k: 2.1, lean: 4 * Math.sin(T * 3.3), arm: 0, face: { mouth: 'D', blink: blinkAt(T, 9), gaze: [.6, 0], raise: 1 } });
+ }, D);
+}
+
+/* ---------- shot 2: the straw house ---------- */
+// The meadow is 2100 × 900 world px: the road across at y 610–740, three plots behind it (x 200–650, 900–1300, 1500–1900).
+const MW = 2100;
+const inMeadow = ({ x, y, z }) => ({ x: Math.min(MW - 800 / z, Math.max(800 / z, x)), y: Math.min(900 - 450 / z, Math.max(450 / z, y)), z });
+function meadow(cam) {
+ const soft = [];
+ for (const [n, k, pad] of [['sky', .15, 260], ['far', .45, 160], ['ground', 1, 0]]) {
+ const g = cam.layer(k), at = { x: -pad, y: -pad * .43, width: MW + 2 * pad, height: 900 + .86 * pad };
+ mk('image', { href: `../img/meadow/${n}.webp`, ...at, preserveAspectRatio: 'none' }, g);
+ soft.push(mk('image', { href: `../img/meadow/${n}-soft.webp`, ...at, preserveAspectRatio: 'none', opacity: 0 }, g));
+ }
+ return t => { const f = clamp01((cam.at(t).z - 2.4) / .9); soft.forEach(e => e.setAttribute('opacity', f)); };
+}
+const prop = (p, n, x, base, h, [w0, h0]) => { // a prop standing with its base centre at (x, base), h tall
+ const w = h * w0 / h0, g = G(p, { x, y: base });
+ mk('image', { href: `../img/props/${n}.webp`, x: -w / 2, y: -h, width: w, height: h }, g);
+ return g;
+};
+// Word times on the shot's clock (silence was inserted after "swish", "swoosh" and "flump" for the building).
+const SHOT2 = { big: 1.68, steps: [3.61, 5.76, 7.88], house: 10.32, says: TIMINGS.shot2.parts.s02b };
+SHOT2.easy = SHOT2.says + .1; SHOT2.time = SHOT2.says + 1.78; SHOT2.nap = SHOT2.says + 2.41;
+const STRAW = { x: 410, base: 598, h: 400, size: [858, 916] }, HAY = { x: 800, base: 606, h: 230, size: [965, 867] };
+const HOUSE_AT = 560, HAY_AT = 700; // where she tosses from, where she picks up
+
+// A house in stages: one drawing per stage (img/props/<name>_1..3.webp, aligned), the current one shown;
+// each new stage lands with a squash and a puff of dust.
+function staged(p, name, { x, base, h, size }) {
+ const w = h * size[0] / size[1], g = G(p, { x, y: base });
+ const pics = [1, 2, 3].map(k => mk('image', { href: `../img/props/${name}_${k}.webp`, x: -w / 2, y: -h, width: w, height: h, visibility: 'hidden' }, g));
+ const dust = Array.from({ length: 9 }, (_, i) => mk('ellipse', { fill: '#eadfc2', opacity: 0 }, p));
+ return (stage, since, rock = 0) => { // stage 0 = nothing yet; since = seconds since it landed; rock: a lean, degrees
+ pics.forEach((e, k) => e.setAttribute('visibility', k === stage - 1 ? 'visible' : 'hidden'));
+ const sq = since < .6 ? 1 - .14 * Math.exp(-7 * since) * Math.cos(18 * since) : 1;
+ g.setAttribute('transform', `translate(${x},${base}) rotate(${rock}) scale(${2 - sq},${sq})`);
+ dust.forEach((e, i) => {
+ const q = clamp01(since / .7), a = (i / 8) * Math.PI, on = stage > 0 && since < .7;
+ e.setAttribute('cx', x + Math.cos(a) * (w * .35 + 90 * q) * (i % 2 ? 1 : -1)); e.setAttribute('cy', base - 10 - Math.sin(a) * 25 * q - 20 * q);
+ e.setAttribute('rx', 26 + 40 * q); e.setAttribute('ry', 16 + 22 * q); e.setAttribute('opacity', on ? .85 * (1 - q) : 0);
+ });
+ };
+}
+
+function shot2(p, D) {
+ const S2 = SHOT2, cam = camera(p, D, inMeadow({ x: 420, y: 560, z: 1.7 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ const house = staged(world, 'straw_house', STRAW);
+ const hay = prop(world, 'haystack', HAY.x, HAY.base, HAY.h, HAY.size);
+ const pig = TOON.posed(world, 'pig1');
+ const flying = mk('image', { href: '../img/props/bundle.webp', x: -55, y: -59, width: 110, height: 118, visibility: 'hidden' }, world);
+ const zzz = [0, 1, 2].map(i => { const e = T(world, 'z', { x: 0, y: 0, size: 38 + i * 12, weight: 900, fill: '#fff', o: 0 }); e.setAttribute('stroke', '#151314'); e.setAttribute('stroke-width', 5); e.setAttribute('paint-order', 'stroke'); return e; });
+ shots(cam, [
+ [0, inMeadow({ x: 330, y: 560, z: 1.7 }), [inMeadow({ x: 520, y: 545, z: 1.75 }), 2.8]], // she comes down the road
+ [S2.steps[0] - .45, inMeadow({ x: 580, y: 480, z: 1.5 }), [inMeadow({ x: 560, y: 470, z: 1.6 }), S2.house - S2.steps[0]]], // the building
+ [S2.house, inMeadow({ x: 500, y: 500, z: 1.8 }), [inMeadow({ x: 520, y: 505, z: 1.95 }), 2.4]], // done
+ [S2.easy - .05, { x: 600, y: 520, z: 3.4 }, [{ x: 605, y: 522, z: 3.6 }, 1.6]], // close: "Easy peasy!"
+ [S2.time - .1, inMeadow({ x: 470, y: 520, z: 2.1 }), [inMeadow({ x: 460, y: 540, z: 2.3 }), D - S2.time]], // and down she lies
+ ]);
+ const trips = S2.steps.map(w => w - .35), LAND = 1.2; // a trip: grab, carry, toss; the stage lands LAND after the grab
+ for (const a of trips) cam.shake(4, a + LAND, .3, 9);
+ const STOP = 2.3, X0 = -60, G0 = 690;
+ clockRun(t => {
+ focus(t);
+ // Which part of the work she is in, and where.
+ const k = trips.filter(a => t >= a).length - 1, a = trips[k] ?? 0, u = t - a, last = k === trips.length - 1;
+ let x = HAY_AT, dir = 1, whole = null, legs = 0, arm = 0, bob = 2 * Math.sin(t * 2.4), lean = 0, carry = false;
+ if (t < STOP) { const wp = walkPose(t, .12); x = X0 + (HAY_AT - X0) * t / STOP; legs = wp.legs; arm = wp.arm; bob = 7 * wp.bob; lean = 4; }
+ else if (k >= 0 && u < .75) { x = HAY_AT + (HOUSE_AT - HAY_AT) * smooth(u / .75); dir = -1; whole = 'carry'; carry = true; bob = -10 * Math.abs(Math.sin(u * 12)); }
+ else if (k >= 0 && u < 1.05) { x = HOUSE_AT; dir = -1; whole = 'toss'; bob = -14 * Math.sin(Math.PI * clamp01((u - .75) / .3)); }
+ else if (k >= 0 && !last && u < 1.85) { const q = (u - 1.05) / .8, wp = walkPose(u, .09); x = HOUSE_AT + (HAY_AT - HOUSE_AT) * smooth(q); legs = wp.legs; arm = wp.arm; bob = 8 * wp.bob; lean = 6; }
+ else if (k >= 0 && last) { x = HOUSE_AT; dir = u < 1.5 ? -1 : 1; bob = u > 1.5 && u < 1.9 ? -30 * Math.sin(Math.PI * (u - 1.5) / .4) : bob; arm = t > S2.house ? 4 : 0; }
+ const napping = t > S2.nap, sayT = t - S2.says, talking = sayT > 0 && t < S2.nap, wow = t > S2.big && t < trips[0] ? 1 : 0;
+ pig.pose({
+ x: napping ? 455 : x, ground: napping ? 640 : G0, k: napping ? .8 : .62, dir, lean,
+ legs, arm, bob, whole: napping ? 'nap' : whole,
+ face: { mouth: talking ? mouthAt('s02b', sayT) : 'X', blink: blinkAt(t, 11), gaze: wow ? [1, -.6] : [1, 0], raise: wow || talking ? .8 : 0, wide: wow, smile: .9 },
+ });
+ // The haystack loses a bite at each grab; the house gets its next stage when the bundle lands.
+ const bites = trips.filter(b => t >= b).length, left = 1 - bites / 3;
+ hay.setAttribute('transform', `translate(${HAY.x},${HAY.base}) scale(${.45 + .55 * left},${left})`);
+ hay.style.visibility = left > 0 ? '' : 'hidden';
+ const landed = trips.filter(b => t >= b + LAND), stage = landed.length;
+ house(stage, stage ? t - landed[stage - 1] - LAND : 9);
+ // The bundle she throws: an arc from her raised hands onto the house.
+ const fq = clamp01((u - .82) / (LAND - .82));
+ flying.setAttribute('visibility', k >= 0 && u > .82 && u < LAND ? 'visible' : 'hidden');
+ if (k >= 0) { const sx = HOUSE_AT - 30, sy = 470, ex = STRAW.x, ey = STRAW.base - STRAW.h * (k + 1) / 3.2;
+ flying.setAttribute('transform', `translate(${sx + (ex - sx) * fq},${sy + (ey - sy) * fq - 140 * Math.sin(Math.PI * fq)}) rotate(${-300 * fq})`); }
+ // Zzz rises above her as she naps.
+ zzz.forEach((z, i) => { const q = ((t - S2.nap - .4 - i * .45) % 1.6 + 1.6) % 1.6 / 1.6, on = t > S2.nap + .4 + i * .45; put(z, { x: 545 + 40 * q + i * 10, y: 560 - 130 * q, o: on ? Math.sin(Math.PI * q) : 0 }); });
+ }, D);
+}
+
+/* ---------- shots 3 and 4: the stick house and the brick house ---------- */
+// A house that grows from the ground up: its image clipped to a rising band. grow(f) shows the bottom f of it.
+function growing(p, n, x, base, h, size) {
+ const id = 'grow' + Math.random().toString(36).slice(2, 8), w = h * size[0] / size[1], hold = G(p);
+ const r = mk('rect', { x: x - w, width: 2 * w, y: base, height: 0 }, mk('clipPath', { id }, mk('defs', {}, p)));
+ hold.setAttribute('clip-path', `url(#${id})`);
+ const g = prop(hold, n, x, base, h, size);
+ return { g, hold, grow: f => { r.setAttribute('y', base - (h + 60) * f); r.setAttribute('height', (h + 60) * f + 4); } };
+}
+const notes = (p, n) => Array.from({ length: n }, (_, i) => { const e = T(p, i % 2 ? '♫' : '♪', { x: 0, y: 0, size: 44, weight: 700, fill: '#fff', o: 0 }); e.setAttribute('stroke', '#151314'); e.setAttribute('stroke-width', 5); e.setAttribute('paint-order', 'stroke'); return e; });
+const SHOT3 = { says: TIMINGS.shot3.parts.s03b, pile: 2.26, taps: [3.24, 4.86, 6.44], wobbly: 8.21 }; // silences after each "tap"
+SHOT3.music = SHOT3.says + 1.75;
+const STICKS = { x: 1030, base: 600, h: 390, size: [826, 895] }, PILE = { x: 1360, base: 612, h: 170, size: [895, 702] };
+
+function shot3(p, D) {
+ const S3 = SHOT3, cam = camera(p, D, inMeadow({ x: 1000, y: 560, z: 1.7 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ const house = staged(world, 'stick_house', STICKS), flyers = [0, 1, 2].map(() => mk('image', { href: '../img/props/stickpile.webp', x: -50, y: -20, width: 100, height: 40, visibility: 'hidden' }, world));
+ const pile = prop(world, 'stickpile', PILE.x, PILE.base, PILE.h, PILE.size);
+ const pig = TOON.posed(world, 'pig2'), music = notes(world, 4);
+ shots(cam, [
+ [0, inMeadow({ x: 860, y: 560, z: 1.7 }), [inMeadow({ x: 1060, y: 545, z: 1.75 }), 2.8]], // he strolls up to the plot
+ [S3.taps[0] - .3, inMeadow({ x: 1100, y: 480, z: 1.5 })], // tap, tap, tap
+ [S3.says - .05, { x: 1205, y: 525, z: 3.2 }, [{ x: 1210, y: 528, z: 3.4 }, 1.6]], // "Good enough for me!"
+ [S3.music - .1, inMeadow({ x: 1120, y: 500, z: 1.9 }), [inMeadow({ x: 1120, y: 510, z: 2.05 }), D - S3.music]], // and he dances
+ ]);
+ for (const w of S3.taps) cam.shake(3, w, .25, 10);
+ const STOP = 2.6, X0 = 760, X1 = 1180, G0 = 690;
+ clockRun(t => {
+ focus(t);
+ const walking = t < STOP, x = walking ? X0 + (X1 - X0) * t / STOP : X1, wp = walkPose(t, .22);
+ // Hammering: the hammer comes down on each "tap"; the house grows a third each time, then wobbles.
+ // Each "tap" starts three strikes; sticks fly from the pile, and the next stage of the house lands on the third.
+ const strikes = S3.taps.flatMap(w => [w, w + .35, w + .7]);
+ const hammering = t > S3.taps[0] - .35 && t < S3.taps[2] + 1;
+ const down = strikes.some(w => t > w - .05 && t < w + .15);
+ const lands = S3.taps.map(w => w + .75), stage = lands.filter(w => t >= w).length;
+ house(stage, stage ? t - lands[stage - 1] : 9, t > S3.wobbly ? 1.5 * Math.sin(t * 7) : 0); // the finished house keeps a little wobble
+ flyers.forEach((f, i) => {
+ const w = S3.taps[i], q = clamp01((t - w + .1) / .8);
+ f.setAttribute('visibility', q > 0 && q < 1 ? 'visible' : 'hidden');
+ f.setAttribute('transform', `translate(${PILE.x + (STICKS.x - PILE.x) * q},${PILE.base - 80 - (STICKS.h * (i + 1) / 3.4) * q - 160 * Math.sin(Math.PI * q)}) rotate(${-360 * q})`);
+ });
+ const left = 1 - S3.taps.filter(w => t >= w).length / 3;
+ pile.setAttribute('transform', `translate(${PILE.x},${PILE.base}) scale(${Math.max(.01, .4 + .6 * left)},${Math.max(.01, left)})`); pile.style.visibility = left > 0 ? '' : 'hidden';
+ // After his line, a little dance in place: steps on the beat, turning back and forth, notes in the air.
+ const dancing = t > S3.music + .2, sayT = t - S3.says;
+ const beat = Math.floor((t - S3.music) / .5); // an easy step every half second
+ pig.pose({
+ x, ground: G0, k: .62, lean: walking ? 6 : dancing ? 4 * Math.sin(t * 2 * Math.PI) : 0,
+ dir: dancing && beat % 8 >= 4 ? -1 : 1,
+ legs: walking ? wp.legs : dancing ? [1, 2, 3, 4][((beat % 4) + 4) % 4] : 0,
+ arm: hammering ? (down ? 5 : 4) : dancing ? 3 : 0,
+ bob: walking ? 7 * wp.bob : dancing ? -8 * Math.abs(Math.sin(t * 2 * Math.PI)) : 0,
+ face: { mouth: sayT > 0 && sayT < 3.8 ? mouthAt('s03b', sayT) : dancing ? 'F' : 'X', blink: blinkAt(t, 37), raise: sayT > 0 ? .5 : 0, smile: .9 },
+ });
+ music.forEach((e, i) => { const q = ((t - S3.music - i * .35) % 1.4 + 1.4) % 1.4 / 1.4, on = t > S3.music + i * .35; put(e, { x: x + 60 + 50 * Math.sin(q * 6 + i) , y: 470 - 160 * q, o: on ? Math.sin(Math.PI * q) : 0, r: 15 * Math.sin(q * 8) }); });
+ }, D);
+}
+
+const SHOT4 = { says2: TIMINGS.shot4.parts.s04b, says3: TIMINGS.shot4.parts.s04c, brick: 2.61, day: 3.71, ached: 5.19, laugh: 6.42 };
+const BRICKS = { x: 1700, base: 602, h: 380, size: [955, 851] }, BPILE = { x: 1930, base: 618, h: 150, size: [861, 759] };
+function shot4(p, D) {
+ const S4 = SHOT4, cam = camera(p, D, inMeadow({ x: 1650, y: 560, z: 1.7 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ const house = staged(world, 'brick_house', BRICKS), lands = [3.0, 4.35, 5.6]; // "brick by brick", "all day long", "ached"
+ prop(world, 'brickpile', BPILE.x, BPILE.base, BPILE.h, BPILE.size);
+ const sis = TOON.posed(world, 'pig1'), bro = TOON.posed(world, 'pig2'), pig = TOON.posed(world, 'pig3');
+ // Evening light for "all day long": a warm wash over the whole picture that deepens as the house goes up.
+ const dusk = mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: '#ff9a3c', opacity: 0, style: 'mix-blend-mode: multiply; pointer-events: none' }, p);
+ shots(cam, [
+ [0, inMeadow({ x: 1640, y: 540, z: 1.7 })], // the third plot, bricks
+ [S4.day - .1, inMeadow({ x: 1700, y: 470, z: 1.45 })], // all day long
+ [S4.laugh - .05, { x: 1380, y: 540, z: 2.2 }], // his brother and sister laugh
+ [S4.says2 - .05, { x: 1330, y: 520, z: 3 }, [{ x: 1335, y: 522, z: 3.2 }, S4.says3 - S4.says2]], // "All that work?"
+ [S4.says3 - .05, { x: 1600, y: 520, z: 3 }, [{ x: 1605, y: 520, z: 3.25 }, D - S4.says3]], // "A strong house keeps you safe."
+ ]);
+ clockRun(t => {
+ focus(t);
+ // Brick by brick: carry, set down, carry... faster and faster through the day; the house rises with each brick.
+ const lapse = t < S4.brick ? 0 : t < S4.day ? (t - S4.brick) / .6 : (S4.day - S4.brick) / .6 + (t - S4.day) * 4;
+ const working = t > S4.brick - .3 && t < S4.ached, cycle = Math.floor(lapse);
+ const stage = lands.filter(w => t >= w).length; house(stage, stage ? t - lands[stage - 1] : 9);
+ dusk.setAttribute('opacity', .32 * smoothstep(S4.day, S4.ached + .5, t));
+ const tired = t > S4.ached && t < S4.laugh, sayT = t - S4.says3;
+ pig.pose({
+ x: 1580, ground: 700, k: .64, lean: working ? 3 * Math.sin(lapse * Math.PI) : tired ? -4 : 0,
+ arm: working ? (cycle % 2 ? 5 : 4) : tired ? 6 : 0, bob: tired ? 6 : working ? 4 * Math.abs(Math.sin(lapse * Math.PI)) : 0,
+ face: { mouth: sayT > 0 ? mouthAt('s04c', sayT) : 'X', blink: tired ? .5 : blinkAt(t, 23), raise: sayT > 0 ? .3 : 0, smile: sayT > 0 ? .5 : tired ? -.3 : .4 },
+ });
+ // Brother and sister double up laughing; he stops to say his piece.
+ const laughing = t > S4.laugh, broT = t - S4.says2, broTalks = broT > 0 && t < S4.says3;
+ sis.pose({ x: 1290, ground: 702, k: .6, whole: laughing ? 'laugh' : null, bob: laughing ? -6 * Math.abs(Math.sin(t * 9)) : 0, face: { blink: blinkAt(t, 11) } });
+ bro.pose({ x: 1420, ground: 698, k: .62, whole: laughing && !broTalks ? 'laugh' : null, bob: laughing && !broTalks ? -6 * Math.abs(Math.sin(t * 8 + 1)) : 0, arm: broTalks ? 3 : 0,
+ face: { mouth: broTalks ? mouthAt('s04b', broT) : 'X', blink: blinkAt(t, 37), raise: broTalks ? .8 : 0, smile: .9 } });
+ }, D);
+}
+const smoothstep = (a, b, t) => smooth((t - a) / (b - a));
+
+/* ---------- shot 5: the wolf ---------- */
+// The edge of the woods (2100 × 900 world px): forest on the left, a sunny path out to the right. A big trunk in
+// front (x 468–734 of its layer) hides the wolf until he steps out.
+const PRE5 = 1, SHOT5 = Object.fromEntries(Object.entries({ out: .78, came: 1.89, wolf: 2.75, sniff: 3.77, smile: 5.12 }).map(([k, v]) => [k, v + PRE5])); // narration starts PRE5 s in
+function woods(cam) {
+ const soft = [];
+ for (const [n, k, pad] of [['sky', .25, 200], ['mid', 1, 0]]) {
+ const g = cam.layer(k), at = { x: -pad, y: -pad * .43, width: MW + 2 * pad, height: 900 + .86 * pad };
+ mk('image', { href: `../img/woods/${n}.webp`, ...at, preserveAspectRatio: 'none' }, g);
+ soft.push(mk('image', { href: `../img/woods/${n}-soft.webp`, ...at, preserveAspectRatio: 'none', opacity: 0 }, g));
+ }
+ return t => { const f = clamp01((cam.at(t).z - 2.4) / .9); soft.forEach(e => e.setAttribute('opacity', f)); };
+}
+function shot5(p, D) {
+ const S5 = SHOT5, cam = camera(p, D, { x: 600, y: 520, z: 1.5 });
+ const focus = woods(cam), world = cam.layer(1);
+ const wolf = TOON.posed(world, 'wolf');
+ const front = cam.layer(1.12);
+ mk('image', { href: '../img/woods/front.webp', x: 0, y: 0, width: MW, height: 900, preserveAspectRatio: 'none' }, front);
+ // Shadow over the forest that the wolf comes out of; the scent of pig drifting in from the right.
+ const gloom = mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: '#0b1a12', opacity: .35, style: 'pointer-events: none' }, p);
+ const scent = [0, 1, 2].map(i => mk('path', { fill: 'none', stroke: '#ffd0c4', 'stroke-width': 12, 'stroke-linecap': 'round', opacity: 0 }, world));
+ shots(cam, [
+ [0, { x: 560, y: 520, z: 1.5 }, [{ x: 640, y: 540, z: 1.65 }, S5.came]], // the dark woods; something behind the tree
+ [S5.came, { x: 820, y: 560, z: 1.45 }, [{ x: 900, y: 560, z: 1.5 }, S5.sniff - S5.came]], // out he steps
+ [S5.sniff - .05, { x: 1000, y: 470, z: 2.6 }, [{ x: 1005, y: 465, z: 2.8 }, S5.smile - S5.sniff]], // sniffing
+ [S5.smile - .05, { x: 1015, y: 450, z: 3.6 }, [{ x: 1020, y: 448, z: 4 }, D - S5.smile]], // the hungry smile
+ ]);
+ const X0 = 640, X1 = 1000, G0 = 830;
+ clockRun(t => {
+ focus(t);
+ gloom.setAttribute('opacity', .35 * (1 - smooth((t - S5.came) / 1.2)));
+ // Peek (a sliver of him by the trunk), then tiptoe out on twos, stop, sniff, grin.
+ const walking = t > S5.came && t < S5.sniff - .25, u = clamp01((t - S5.came) / (S5.sniff - .25 - S5.came));
+ const x = t < S5.out ? X0 - 40 : t < S5.came ? X0 + 20 * smooth((t - S5.out) / .5) : X0 + 20 + (X1 - X0 - 20) * u;
+ const whole = t > S5.smile ? 'grin' : t > S5.sniff - .2 ? 'sniff' : walking ? (Math.floor(t / .26) % 2 ? 'tip2' : 'tip1') : null;
+ const sniffBob = t > S5.sniff && t < S5.smile ? 4 * Math.sin(t * 28) * (Math.floor(t * 3) % 2) : 0;
+ wolf.pose({
+ x, ground: G0, k: 1.05, whole, lean: walking ? 3 * Math.sin(t * 12) : 0,
+ bob: walking ? -10 * Math.abs(Math.sin(t * Math.PI / .26)) : sniffBob - (t > S5.smile ? 4 * Math.sin(t * 6) : 0),
+ face: { blink: blinkAt(t, 9), gaze: [1, 0], raise: 0 },
+ });
+ // The scent: three wavy pink ribbons from the meadow to his nose while he sniffs.
+ scent.forEach((e, i) => {
+ // from the right, converging on his nose (about x 1070, y 450)
+ const on = clamp01((t - S5.sniff + .4 - i * .15) / .3) * (1 - clamp01((t - S5.smile) / .4)), y0 = 400 + i * 45, ph = t * 5 + i * 2;
+ let d = `M1560 ${y0}`; for (let k = 1; k <= 10; k++) { const q = k / 10, xx = 1560 - 480 * q, yy = y0 + (452 - y0) * q * q; d += ` Q${xx + 24} ${yy + 22 * Math.sin(ph + k) * (1 - q)} ${xx} ${yy}`; }
+ e.setAttribute('d', d); e.setAttribute('opacity', on * .55);
+ });
+ }, D);
+}
+
+/* ---------- shot 6: huff and puff ---------- */
+// The wolf comes along the road from the left to the straw house; the first pig answers from its window (x 323–388,
+// y 416–469). He blows from the left, so the straw, and then the pig, fly and run off to the right.
+const PRE6 = 2, P6 = TIMINGS.shot6.parts;
+const SHOT6 = { a: PRE6 + P6.s06a, b: PRE6 + P6.s06b, c: PRE6 + P6.s06c, d: PRE6 + P6.s06d };
+Object.assign(SHOT6, { huff: SHOT6.c + .49, puff: SHOT6.c + 1.35, blowIn: SHOT6.c + 2.23, inhale: SHOT6.d + .54, blow: SHOT6.d + 1.44, flew: SHOT6.d + 3.12 + 1.2, ran: SHOT6.d + 4.81 + 1.2 });
+const WIN = { x: 323, y: 416, w: 65, h: 53 }, WOLF6 = { x: 165, g: 712, k: .95 };
+function shot6(p, D) {
+ const S6 = SHOT6, cam = camera(p, D, inMeadow({ x: 420, y: 520, z: 1.5 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ const sticks = staged(world, 'stick_house', STICKS); staged(world, 'brick_house', BRICKS)(3, 9); // the other two houses stand where they were built
+ // The straw house in three bands that can fly apart; the first pig drawn inside its window (clipped).
+ const w = STRAW.h * STRAW.size[0] / STRAW.size[1], bands = [0, 1, 2].map(i => {
+ const id = 'sb' + i + Math.random().toString(36).slice(2, 7), y0 = -STRAW.h * (i + 1) / 3 - (i === 2 ? 30 : 0), y1 = -STRAW.h * i / 3;
+ mk('rect', { x: -w, y: y0, width: 2 * w, height: y1 - y0 + 2 }, mk('clipPath', { id }, mk('defs', {}, world)));
+ const g = G(world), inner = G(g); inner.setAttribute('clip-path', `url(#${id})`);
+ mk('image', { href: '../img/props/straw_house_3.webp', x: -w / 2, y: -STRAW.h, width: w, height: STRAW.h }, inner);
+ return g;
+ });
+ const winId = 'win' + Math.random().toString(36).slice(2, 7);
+ mk('rect', { x: WIN.x, y: WIN.y, width: WIN.w, height: WIN.h }, mk('clipPath', { id: winId }, mk('defs', {}, world)));
+ const inWin = G(world); inWin.setAttribute('clip-path', `url(#${winId})`);
+ mk('rect', { x: WIN.x, y: WIN.y, width: WIN.w, height: WIN.h, fill: '#3a2614' }, inWin); // the dark room behind her
+ const peek = TOON.posed(inWin, 'pig1');
+ const pig = TOON.posed(world, 'pig1'); // out in the open once the house is gone
+ const wolf = TOON.posed(world, 'wolf');
+ const wind = Array.from({ length: 22 }, (_, i) => mk('path', { fill: 'none', stroke: '#fff', 'stroke-width': 7 - (i % 3) * 2, 'stroke-linecap': 'round', opacity: 0 }, world));
+ const bits = Array.from({ length: 10 }, (_, i) => mk('image', { href: '../img/props/bundle.webp', x: -40, y: -43, width: 80, height: 86, visibility: 'hidden' }, world));
+ const wisps = Array.from({ length: 40 }, (_, i) => mk('path', { d: `M0 0l${22 + (i % 5) * 8} ${-3 - (i % 3) * 3}`, stroke: i % 3 ? '#e7b93a' : '#c9962a', 'stroke-width': 5, 'stroke-linecap': 'round', visibility: 'hidden' }, world));
+ const winC = { x: WIN.x + WIN.w / 2, y: WIN.y + WIN.h / 2 };
+ shots(cam, [
+ [0, inMeadow({ x: 380, y: 520, z: 1.5 }), [inMeadow({ x: 330, y: 540, z: 1.6 }), PRE6]], // he comes along the road
+ [S6.a, inMeadow({ x: 270, y: 520, z: 2.1 }), [inMeadow({ x: 280, y: 515, z: 2.25 }), S6.b - S6.a]], // "Little pig, little pig"
+ [S6.b - .1, { x: winC.x, y: winC.y + 4, z: 7.5 }, [{ x: winC.x, y: winC.y + 4, z: 8 }, S6.c - S6.b]], // in the window: "Not by the hair..."
+ [S6.c - .1, inMeadow({ x: WOLF6.x + 60, y: 470, z: 3.2 }), [inMeadow({ x: WOLF6.x + 60, y: 470, z: 3.5 }), S6.d - S6.c]], // "Then I'll huff..."
+ [S6.d - .05, inMeadow({ x: 440, y: 500, z: 1.45 }), [inMeadow({ x: 470, y: 490, z: 1.35 }), S6.ran - S6.d]], // the huffing, the puffing
+ [S6.ran - .1, inMeadow({ x: 560, y: 520, z: 1.6 }), [inMeadow({ x: 900, y: 500, z: 1.55 }), 1.6]], // and she runs to the stick house
+ ]);
+ cam.shake(6, S6.blow, S6.flew - S6.blow + .4, 11);
+ clockRun(t => {
+ focus(t);
+ // The wolf: tiptoe in; say his line; lean back on "huff", forward on "puff"; inhale (chest swelling), blow.
+ const walkIn = t < PRE6 - .2, xw = walkIn ? -120 + (WOLF6.x + 120) * t / (PRE6 - .2) : WOLF6.x;
+ const talkA = t - S6.a, talkC = t - S6.c, talking = (talkA > 0 && t < S6.b - .2) || (talkC > 0 && t < S6.d - .1);
+ const inhaling = t > S6.inhale - .1 && t < S6.blow - .05, blowing = t > S6.blow - .05 && t < S6.flew + .5;
+ const swell = inhaling ? smooth((t - S6.inhale + .1) / .6) : 0;
+ const whole = walkIn ? (Math.floor(t / .26) % 2 ? 'tip2' : 'tip1') : inhaling ? 'inhale' : blowing ? 'blow' : t > S6.flew + .5 ? 'grin' : null;
+ const lean = t > S6.c + .45 && t < S6.c + 1.3 ? -6 : t > S6.c + 1.3 && t < S6.d ? 6 : 0;
+ wolf.pose({
+ x: xw, ground: WOLF6.g, k: WOLF6.k, whole, lean,
+ sy: 1 + .12 * swell, bob: walkIn ? -10 * Math.abs(Math.sin(t * Math.PI / .26)) : blowing ? 3 * Math.sin(t * 40) : 0,
+ arm: talkA > 1.6 && t < S6.b ? 3 : t > S6.blowIn && t < S6.d ? 3 : 0,
+ face: { mouth: talkA > 0 && t < S6.b ? mouthAt('s06a', talkA) : talkC > 0 && t < S6.d ? mouthAt('s06c', talkC) : 'X', blink: blinkAt(t, 9), raise: talking ? .6 : 0, worry: talkC > 0 && t < S6.d ? .8 : 0, smile: talkC > 0 ? .2 : .7 },
+ });
+ // The house trembles under the wind, then its bands fly off to the right, spinning, highest first.
+ const gone = t > S6.flew, shake = blowing && !gone ? 2.5 * Math.sin(t * 37) * smooth((t - S6.blow) / 1) : 0;
+ bands.forEach((b, i) => {
+ const q = Math.max(0, t - S6.flew - (2 - i) * .08), x = STRAW.x + 900 * q + 300 * q * q, y = STRAW.base - 260 * q * (1 + i * .4) + 200 * q * q;
+ b.setAttribute('transform', `translate(${q > 0 ? x : STRAW.x + shake * (i + 1)},${q > 0 ? y : STRAW.base}) rotate(${q > 0 ? 220 * q * (i % 2 ? -1 : 1) : shake * (i + .5) * .6})`);
+ b.style.visibility = q < 2 ? '' : 'hidden';
+ });
+ // Her face in the window (before the house goes): ears up, then her line, defiant.
+ const talkB = t - S6.b;
+ inWin.style.visibility = gone ? 'hidden' : '';
+ peek.pose({ x: winC.x + 6, ground: winC.y + 158, k: .52, dir: -1, bob: 2 * Math.sin(t * 2),
+ face: { mouth: talkB > 0 && t < S6.c ? mouthAt('s06b', talkB) : 'X', blink: blinkAt(t, 11), raise: talkB > 0 ? .4 : 0, worry: talkB > 0 ? .6 : 0, smile: talkB > 0 ? -.3 : .3, wide: t > S6.inhale ? 1 : 0 } });
+ // Then she stands in the open where the house was, frozen; and runs for it, off to the right.
+ const r = t - S6.ran, run = r > 0, px = STRAW.x + (run ? 520 * r - 120 * (1 - Math.exp(-4 * r)) : 0);
+ pig.root.style.visibility = gone && px < STICKS.x ? '' : 'hidden'; // into her brother's house, which shudders as she slams the door
+ const inAt = S6.ran + (STICKS.x - STRAW.x + 120) / 520; sticks(3, t > inAt ? t - inAt : 9, t > inAt ? 3 * Math.exp(-5 * (t - inAt)) * Math.sin((t - inAt) * 30) : 0);
+ pig.pose({ x: px, ground: 690, k: .62, whole: run ? 'run' + (1 + Math.floor(r / .08) % 4) : null,
+ bob: run ? 0 : 4 * Math.sin(t * 30) * (gone ? 1 : 0), face: { wide: 1, worry: 1, blink: 0, smile: -.6, gaze: [-1, 0] }, dir: 1 });
+ // Wind from his mouth across the house; straw bundles and wisps blown away with it.
+ const mouth = { x: xw + 120 * WOLF6.k, y: WOLF6.g - 300 * WOLF6.k };
+ wind.forEach((e, i) => {
+ const q = ((t - S6.blow) * 1.8 + (i * .137) % 1) % 1, on = blowing && t > S6.blow ? 1 : 0, y = mouth.y + ((i * 37) % 120 - 60) * q;
+ const x0 = mouth.x + q * 900, len = 60 + (i % 4) * 30;
+ e.setAttribute('d', `M${x0} ${y}q${len / 2} ${10 * Math.sin(t * 9 + i)} ${len} 0`); e.setAttribute('opacity', on * (1 - q) * .9);
+ });
+ bits.forEach((e, i) => {
+ const q = t - S6.flew - i * .07, on = q > 0 && q < 1.6;
+ e.setAttribute('visibility', on ? 'visible' : 'hidden');
+ if (on) e.setAttribute('transform', `translate(${STRAW.x - 100 + (i * 41) % 200 + 1000 * q},${STRAW.base - 80 - (i * 53) % 280 - 300 * q + 260 * q * q}) rotate(${(i % 2 ? 1 : -1) * 500 * q})`);
+ });
+ wisps.forEach((e, i) => {
+ const q = t - S6.flew - (i % 10) * .04 + (blowing && !gone ? ((t * 2 + i * .13) % 1) - 1.1 : 0), on = (q > 0 && q < 1.4) || (blowing && !gone && i % 4 === 0);
+ e.setAttribute('visibility', on ? 'visible' : 'hidden');
+ const qq = Math.max(0, q) + (blowing && !gone ? ((t * 1.5 + i * .17) % 1) * .4 : 0);
+ e.setAttribute('transform', `translate(${STRAW.x - 150 + (i * 23) % 300 + 1100 * qq},${STRAW.base - (i * 31) % 380 - 120 * qq}) rotate(${i * 37 + 600 * qq})`);
+ });
+ }, D);
+}
+
+/* ---------- shot 7: the stick house ---------- */
+// The wolf follows the road to the stick house; the second pig answers from its window (x 1078–1108, y 445–484).
+// The house wobbles, wobbles, and comes down in a heap; both pigs run on to the brick house.
+const PRE7 = 2, P7 = TIMINGS.shot7.parts;
+const SHOT7 = { a: PRE7 + P7.s07a, b: PRE7 + P7.s07b, c: PRE7 + P7.s07c };
+Object.assign(SHOT7, { inhale: SHOT7.c + .75, blow: SHOT7.c + 1.62, wobble: SHOT7.c + 3.16 + 1, fall: SHOT7.c + 3.94 + 1.8, ran: SHOT7.c + 6.09 + 1.8 });
+const WIN7 = { x: 1078, y: 445, w: 30, h: 39 }, WOLF7 = { x: 760, g: 712, k: .95 };
+function shot7(p, D) {
+ const S7 = SHOT7, cam = camera(p, D, inMeadow({ x: 900, y: 520, z: 1.5 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ staged(world, 'brick_house', BRICKS)(3, 9);
+ const w = STICKS.h * STICKS.size[0] / STICKS.size[1], bands = [0, 1, 2].map(i => {
+ const id = 'kb' + i + Math.random().toString(36).slice(2, 7), y0 = -STICKS.h * (i + 1) / 3 - (i === 2 ? 40 : 0), y1 = -STICKS.h * i / 3;
+ mk('rect', { x: -w, y: y0, width: 2 * w, height: y1 - y0 + 2 }, mk('clipPath', { id }, mk('defs', {}, world)));
+ const g = G(world), inner = G(g); inner.setAttribute('clip-path', `url(#${id})`);
+ mk('image', { href: '../img/props/stick_house_3.webp', x: -w / 2, y: -STICKS.h, width: w, height: STICKS.h }, inner);
+ return g;
+ });
+ const heap = prop(world, 'stickpile', STICKS.x, STICKS.base + 6, 150, PILE.size); heap.style.visibility = 'hidden';
+ const dust = Array.from({ length: 12 }, () => mk('ellipse', { fill: '#eadfc2', opacity: 0 }, world));
+ const winId = 'win7' + Math.random().toString(36).slice(2, 7);
+ mk('rect', { x: WIN7.x, y: WIN7.y, width: WIN7.w, height: WIN7.h }, mk('clipPath', { id: winId }, mk('defs', {}, world)));
+ const inWin = G(world); inWin.setAttribute('clip-path', `url(#${winId})`);
+ mk('rect', { x: WIN7.x, y: WIN7.y, width: WIN7.w, height: WIN7.h, fill: '#2a1a0e' }, inWin);
+ const peek = TOON.posed(inWin, 'pig2');
+ const pigs = [TOON.posed(world, 'pig2'), TOON.posed(world, 'pig1')];
+ const wolf = TOON.posed(world, 'wolf');
+ const wind = Array.from({ length: 22 }, (_, i) => mk('path', { fill: 'none', stroke: '#fff', 'stroke-width': 7 - (i % 3) * 2, 'stroke-linecap': 'round', opacity: 0 }, world));
+ const sticks = Array.from({ length: 16 }, (_, i) => mk('rect', { x: -40 - (i % 3) * 10, y: -5, width: 80 + (i % 3) * 20, height: 10, rx: 5, fill: i % 2 ? '#7a4a24' : '#8f5a2c', stroke: '#151314', 'stroke-width': 3, visibility: 'hidden' }, world));
+ const winC = { x: WIN7.x + WIN7.w / 2, y: WIN7.y + WIN7.h / 2 };
+ shots(cam, [
+ [0, inMeadow({ x: 760, y: 520, z: 1.5 }), [inMeadow({ x: 820, y: 530, z: 1.55 }), PRE7]], // he walks on to the next house
+ [S7.a, inMeadow({ x: 900, y: 510, z: 2 }), [inMeadow({ x: 910, y: 505, z: 2.15 }), S7.b - S7.a]], // "Little pigs, little pigs"
+ [S7.b - .1, { x: winC.x, y: winC.y + 3, z: 12 }, [{ x: winC.x, y: winC.y + 3, z: 13 }, S7.c - S7.b]], // in the window: "Not by the hair..."
+ [S7.c - .05, inMeadow({ x: 980, y: 480, z: 1.4 }), [inMeadow({ x: 1000, y: 470, z: 1.3 }), S7.ran - S7.c]], // huff, puff, wobble, down
+ [S7.ran - .1, inMeadow({ x: 1150, y: 520, z: 1.6 }), [inMeadow({ x: 1500, y: 510, z: 1.55 }), 2]], // two pigs run to the brick house
+ ]);
+ cam.shake(5, S7.blow, S7.fall - S7.blow, 11); cam.shake(14, S7.fall, .6, 8);
+ clockRun(t => {
+ focus(t);
+ const walkIn = t < PRE7 - .2, xw = walkIn ? 380 + (WOLF7.x - 380) * t / (PRE7 - .2) : WOLF7.x;
+ const talkA = t - S7.a, inhaling = t > S7.inhale - .1 && t < S7.blow - .05, blowing = t > S7.blow - .05 && t < S7.fall + .5;
+ const swell = inhaling ? smooth((t - S7.inhale + .1) / .6) : 0;
+ wolf.pose({
+ x: xw, ground: WOLF7.g, k: WOLF7.k, whole: walkIn ? (Math.floor(t / .26) % 2 ? 'tip2' : 'tip1') : inhaling ? 'inhale' : blowing ? 'blow' : t > S7.fall + .5 ? 'grin' : null,
+ sy: 1 + .14 * swell, bob: walkIn ? -10 * Math.abs(Math.sin(t * Math.PI / .26)) : blowing ? 3 * Math.sin(t * 40) : 0,
+ arm: talkA > 1.9 && t < S7.b ? 3 : 0,
+ face: { mouth: talkA > 0 && t < S7.b ? mouthAt('s07a', talkA) : 'X', blink: blinkAt(t, 9), raise: talkA > 0 && t < S7.b ? .6 : 0, smile: .7 },
+ });
+ // The house: shivers in the wind, three big wobbles, then its bands drop and topple into a heap.
+ const wob = t > S7.wobble && t < S7.fall ? 7 * Math.sin((t - S7.wobble) * 2 * Math.PI * 3 / (S7.fall - S7.wobble)) : blowing ? 1.5 * Math.sin(t * 33) : 0;
+ const f = t - S7.fall, down = f > 0;
+ bands.forEach((b, i) => {
+ const q = clamp01((f - (2 - i) * .05) / .45), drop = (STICKS.h * i / 3) * q * q, side = (i - 1) * 90 * q, rot = (i % 2 ? -1 : 1) * 70 * q;
+ b.setAttribute('transform', `translate(${STICKS.x + side},${STICKS.base + drop}) rotate(${down ? rot : wob * (1 + i * .3)})`);
+ b.style.visibility = f > .55 ? 'hidden' : '';
+ });
+ heap.style.visibility = f > .45 ? '' : 'hidden';
+ dust.forEach((e, i) => { const q = clamp01((f - .4) / .9), a = (i / 11) * Math.PI, on = f > .4 && f < 1.3;
+ e.setAttribute('cx', STICKS.x + Math.cos(a) * (120 + 160 * q) * (i % 2 ? 1 : -1)); e.setAttribute('cy', STICKS.base - 20 - Math.sin(a) * 60 * q);
+ e.setAttribute('rx', 40 + 60 * q); e.setAttribute('ry', 24 + 30 * q); e.setAttribute('opacity', on ? .9 * (1 - q) : 0); });
+ sticks.forEach((e, i) => { // thrown up, they come down and lie on the ground in front of the heap
+ const q = f - .3 - (i % 4) * .04, on = q > 0, land = STICKS.base + 30 + (i * 13) % 110, y = STICKS.base - 120 - (i * 29) % 200 - 420 * q + 900 * q * q;
+ const qx = Math.min(q, .9), down = y >= land;
+ e.setAttribute('visibility', on && f < 6 ? 'visible' : 'hidden');
+ if (on) e.setAttribute('transform', `translate(${STICKS.x + ((i * 47) % 300 - 150) * (1 + 1.6 * qx)},${Math.min(y, land)}) rotate(${down ? (i * 23) % 40 - 20 : (i % 2 ? 1 : -1) * 520 * q + i * 40})`);
+ });
+ // The second pig at the window; then both pigs in the open, shaking, and off they run to the bricks.
+ const talkB = t - S7.b;
+ inWin.style.visibility = down ? 'hidden' : '';
+ peek.pose({ x: winC.x + 3, ground: winC.y + 92, k: .3, dir: -1,
+ face: { mouth: talkB > 0 && t < S7.c ? mouthAt('s07b', talkB) : 'X', blink: blinkAt(t, 37), raise: talkB > 0 ? .4 : 0, worry: talkB > 0 ? .6 : 0, smile: -.2, wide: t > S7.inhale ? 1 : 0 } });
+ pigs.forEach((pg, i) => {
+ const r = t - S7.ran - i * .15, run = r > 0, px = STICKS.x - 40 + i * 90 + (run ? 520 * r - 120 * (1 - Math.exp(-4 * r)) : 0);
+ pg.root.style.visibility = f > .5 && px < BRICKS.x ? '' : 'hidden';
+ pg.pose({ x: px, ground: 696 - i * 6, k: .62, whole: run ? 'run' + (1 + Math.floor((r + i * .04) / .08) % 4) : null,
+ bob: run ? 0 : 4 * Math.sin(t * 30 + i), face: { wide: 1, worry: 1, blink: 0, smile: -.6, gaze: [-1, 0] } });
+ });
+ const mouth = { x: xw + 120 * WOLF7.k, y: WOLF7.g - 300 * WOLF7.k };
+ wind.forEach((e, i) => {
+ const q = ((t - S7.blow) * 1.8 + (i * .137) % 1) % 1, on = blowing && t > S7.blow ? 1 : 0, y = mouth.y + ((i * 37) % 120 - 60) * q;
+ e.setAttribute('d', `M${mouth.x + q * 700} ${y}q${(60 + (i % 4) * 30) / 2} ${10 * Math.sin(t * 9 + i)} ${60 + (i % 4) * 30} 0`); e.setAttribute('opacity', on * (1 - q) * .9);
+ });
+ }, D);
+}
+
+/* ---------- shot 8: the brick house ---------- */
+// He tries the brick house: a furious "Let! Me! In!", three pigs crammed in its window answering together, three
+// huffs that move nothing, and he collapses. Window in the world: x 1561–1601, y 459–520.
+const PRE8 = 1.6, P8 = TIMINGS.shot8.parts;
+const SHOT8 = { a: PRE8 + P8.s08a, b: PRE8 + P8.s08b, c: PRE8 + P8.s08c };
+Object.assign(SHOT8, { stomps: [2.03, 3.42, 4.64].map(w => SHOT8.a + w), puffs: [[.54, 1.44], [2.54, 3.56], [4.65, 5.59]].map(([i, b]) => [SHOT8.c + i - .3, SHOT8.c + b]),
+ flop: SHOT8.c + 6.1, bit: SHOT8.c + 8.1 + 1.4 });
+const WIN8 = { x: 1561, y: 459, w: 40, h: 61 }, WIN8B = { x: 1820, y: 465, w: 33, h: 55 }, WOLF8 = { x: 1330, g: 712, k: .95 };
+function shot8(p, D) {
+ const S8 = SHOT8, cam = camera(p, D, inMeadow({ x: 1500, y: 520, z: 1.5 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ prop(world, 'stickpile', STICKS.x, STICKS.base + 6, 150, PILE.size); // what is left of the stick house
+ staged(world, 'brick_house', BRICKS)(3, 9);
+ // Two windows: the third pig in the left one, his brother and sister squeezed into the right one.
+ const winG = W => { const id = 'w8' + Math.random().toString(36).slice(2, 7);
+ mk('rect', { x: W.x, y: W.y, width: W.w, height: W.h }, mk('clipPath', { id }, mk('defs', {}, world)));
+ const g = G(world); g.setAttribute('clip-path', `url(#${id})`); mk('rect', { x: W.x, y: W.y, width: W.w, height: W.h, fill: '#3a2614' }, g); return g; };
+ const L = winG(WIN8), Rw = winG(WIN8B);
+ const crew = [['pig1', Rw, WIN8B, -7, .27], ['pig2', Rw, WIN8B, 9, .27], ['pig3', L, WIN8, 0, .32]].map(([n, g, W, dx, k]) => ({ a: TOON.posed(g, n), W, dx, k }));
+ const wolf = TOON.posed(world, 'wolf');
+ const wind = Array.from({ length: 22 }, (_, i) => mk('path', { fill: 'none', stroke: '#fff', 'stroke-width': 7 - (i % 3) * 2, 'stroke-linecap': 'round', opacity: 0 }, world));
+ const sweat = [0, 1, 2].map(() => mk('path', { d: 'M0 -14Q9 0 0 8Q-9 0 0 -14Z', fill: '#9fd6ff', stroke: '#151314', 'stroke-width': 2.5, visibility: 'hidden' }, world));
+ const win = { x: WIN8.x + WIN8.w / 2, y: WIN8.y + WIN8.h / 2 };
+ shots(cam, [
+ [0, inMeadow({ x: 1350, y: 520, z: 1.5 }), [inMeadow({ x: 1420, y: 520, z: 1.55 }), PRE8]], // on to the brick house
+ [S8.a - .1, { x: WOLF8.x + 50, y: 470, z: 3 }, [{ x: WOLF8.x + 50, y: 470, z: 3.3 }, S8.b - S8.a]], // "Little pigs! Let! Me! In!"
+ [S8.b - .1, { x: 1708, y: 492, z: 4 }, [{ x: 1708, y: 492, z: 4.3 }, S8.c - S8.b]], // three faces in the windows
+ [S8.c - .05, inMeadow({ x: 1480, y: 470, z: 1.45 }), [inMeadow({ x: 1490, y: 470, z: 1.6 }), S8.flop - S8.c]], // huff after huff
+ [S8.flop, { x: WOLF8.x + 40, y: 600, z: 2.6 }, [{ x: WOLF8.x + 40, y: 610, z: 2.8 }, S8.bit - S8.flop - .2]], // he collapses
+ [S8.bit - .2, { x: 1708, y: 492, z: 3.8 }, [{ x: 1708, y: 492, z: 4.2 }, D - S8.bit + .2]], // and they laugh at him
+ ]);
+ for (const [, b] of S8.puffs) cam.shake(4, b, .9, 10);
+ S8.stomps.forEach(w => cam.shake(7, w, .25, 8));
+ clockRun(t => {
+ focus(t);
+ const walkIn = t < PRE8 - .15, xw = walkIn ? 1000 + (WOLF8.x - 1000) * t / (PRE8 - .15) : WOLF8.x;
+ // Which puff, and where in it: inhale until the blow word, blow for 0.9 s; the third is the biggest.
+ const k = S8.puffs.findIndex(([i, b]) => t > i && t < b + .9), [pi, pb] = S8.puffs[Math.max(0, k)];
+ const inhaling = k >= 0 && t < pb, blowing = k >= 0 && t >= pb, big = k === 2 ? 1.5 : 1;
+ const flopped = t > S8.flop, talkA = t - S8.a, stomp = S8.stomps.some(w => t > w - .05 && t < w + .2);
+ wolf.pose({
+ x: xw, ground: WOLF8.g, k: WOLF8.k,
+ whole: walkIn ? (Math.floor(t / .26) % 2 ? 'tip2' : 'tip1') : flopped ? 'flop' : inhaling ? 'inhale' : blowing ? 'blow' : null,
+ sy: inhaling ? 1 + .12 * big * smooth((t - pi) / (pb - pi)) : 1,
+ bob: walkIn ? -10 * Math.abs(Math.sin(t * Math.PI / .26)) : blowing ? 3 * big * Math.sin(t * 40) : stomp ? 10 : flopped ? 2 * Math.sin(t * 9) : 0,
+ lean: talkA > 0 && t < S8.b ? 6 : 0, arm: talkA > 1.8 && t < S8.b ? 3 : 0,
+ face: { mouth: talkA > 0 && t < S8.b ? mouthAt('s08a', talkA) : 'X', blink: blinkAt(t, 9), raise: 0, worry: talkA > 0 && t < S8.b ? 1 : 0, smile: -.5, wide: stomp ? 1 : 0 },
+ });
+ // Sweat flies off him when he collapses.
+ sweat.forEach((e, i) => { const q = ((t - S8.flop - i * .3) % 1.2 + 1.2) % 1.2 / 1.2, on = flopped;
+ e.setAttribute('visibility', on ? 'visible' : 'hidden'); e.setAttribute('transform', `translate(${xw + 60 + (i - 1) * 50 + 40 * q * (i - 1)},${520 - 60 * Math.sin(Math.PI * q) + 80 * q}) rotate(${(i - 1) * 30})`); });
+ // The three in the window: chin chin chins together, then laughing.
+ const talkB = t - S8.b, laughing = t > S8.bit - .3, scared = t > S8.c && t < S8.flop;
+ crew.forEach(({ a, W, dx, k: kk }, i) => a.pose({ x: W.x + W.w / 2 + dx, ground: W.y + W.h / 2 + 300 * kk + 2, k: kk, dir: -1,
+ whole: laughing && i < 2 ? 'laugh' : null, bob: laughing ? -3 * Math.abs(Math.sin(t * 9 + i)) : 0,
+ face: { mouth: talkB > 0 && t < S8.c ? mouthAt('s08b', talkB) : laughing ? 'D' : 'X', blink: blinkAt(t, 11 + i * 13), raise: talkB > 0 ? .5 : 0,
+ worry: scared ? .5 : 0, wide: scared ? 1 : 0, smile: talkB > 0 && t < S8.c ? -.2 : .9 } }));
+ const mouth = { x: xw + 120 * WOLF8.k, y: WOLF8.g - 300 * WOLF8.k };
+ wind.forEach((e, i) => {
+ const q = ((t - pb) * 1.8 + (i * .137) % 1) % 1, on = blowing ? 1 : 0, y = mouth.y + ((i * 37) % 120 - 60) * q;
+ e.setAttribute('d', `M${mouth.x + q * 500 * big} ${y}q${(60 + (i % 4) * 30) / 2} ${10 * Math.sin(t * 9 + i)} ${60 + (i % 4) * 30} 0`); e.setAttribute('opacity', on * (1 - q) * .9);
+ });
+ }, D);
+}
+
+/* ---------- shots 9–11: the chimney, the pot, ever after ---------- */
+// The brick house in the world: chimney x 1797–1874 (top y 222), roof ridge at (1760, 282), left eave at (1491, 423).
+// Inside (img/interior.webp, 1600 × 900): the pot hook at (1293, 390), the fire at (1353, 571), the floor at y 782.
+const HOOK = { x: 1293, y: 392 }, FLOOR = 782, CHIM = { x: 1835, y: 226 };
+function interior(cam) { mk('image', { href: '../img/interior.webp', x: 0, y: 0, width: 1600, height: 900 }, cam.world); }
+function flames(p) { // a flickering fire over the painted one
+ const fl = Array.from({ length: 7 }, (_, i) => mk('path', { fill: i % 2 ? '#ffb22e' : '#ff7a1a', opacity: .85 }, p));
+ return t => fl.forEach((e, i) => { const x = 1275 + i * 26, h = 60 + 30 * Math.sin(t * (9 + i) + i * 2) + (i % 3) * 12;
+ e.setAttribute('d', `M${x - 18} 600Q${x - 12} ${600 - h * .6} ${x + 4 * Math.sin(t * 7 + i)} ${600 - h}Q${x + 12} ${600 - h * .6} ${x + 18} 600Z`); });
+}
+const steamPuffs = p => Array.from({ length: 8 }, () => mk('ellipse', { fill: '#fff', opacity: 0 }, p));
+const potAt = (p, x, y, h = 230) => { const w = h * 802 / 901, g = G(p, { x, y }); mk('image', { href: '../img/props/pot.webp', x: -w / 2, y: 0, width: w, height: h }, g); return g; }; // hung by its handle top
+
+const P9 = TIMINGS.shot9.parts, S9 = { idea: 1.54, crept: 3.25, roof: 4.18, chim: 5.38, says: P9.s09b, inside: P9.s09c + .33, set: P9.s09c + 3.94, fire: P9.s09c + 5.56 };
+function shot9(p, D) {
+ const cam = camera(p, D, inMeadow({ x: 1500, y: 520, z: 1.5 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ staged(world, 'brick_house', BRICKS)(3, 9);
+ const ladder = mk('image', { href: '../img/props/ladder.webp', x: -60, y: -340, width: 98, height: 345, transform: 'translate(1478,712) rotate(14)' }, world);
+ const wolf = TOON.posed(world, 'wolf');
+ const bulb = G(world, { o: 0 }); mk('circle', { r: 26, fill: '#fff59a', stroke: '#151314', 'stroke-width': 4 }, bulb); mk('rect', { x: -10, y: 22, width: 20, height: 14, fill: '#aaa', stroke: '#151314', 'stroke-width': 3 }, bulb);
+ for (let i = 0; i < 6; i++) mk('line', { x1: Math.cos(i * 1.05) * 34, y1: Math.sin(i * 1.05) * 34 - 4, x2: Math.cos(i * 1.05) * 48, y2: Math.sin(i * 1.05) * 48 - 4, stroke: '#ffd400', 'stroke-width': 5, 'stroke-linecap': 'round' }, bulb);
+ // Inside: a second camera on the room, cut to on "But inside".
+ const cam2 = camera(p, D, { x: 800, y: 450, z: 1 }); interior(cam2); cam2.el.style.display = 'none'; // display, not visibility: a child set visible would show through
+ const fire = flames(cam2.world), pot = potAt(cam2.world, 0, 0), pig = TOON.posed(cam2.world, 'pig3'), sibs = [TOON.posed(cam2.world, 'pig1'), TOON.posed(cam2.world, 'pig2')];
+ shots(cam, [
+ [0, { x: WOLF8.x + 40, y: 600, z: 2.6 }, [{ x: WOLF8.x + 40, y: 580, z: 2.8 }, S9.crept]], // the idea
+ [S9.crept - .1, inMeadow({ x: 1620, y: 470, z: 1.5 }), [inMeadow({ x: 1700, y: 340, z: 1.6 }), S9.says - S9.crept]], // up the ladder, over the roof
+ [S9.says - .1, { x: CHIM.x - 60, y: 175, z: 2.8 }, [{ x: CHIM.x - 50, y: 170, z: 3 }, S9.inside - S9.says]], // "Heh, heh, heh"
+ ]);
+ cam2.to({ x: 1100, y: 520, z: 1.4 }, S9.inside, D - S9.inside, soft);
+ clockRun(t => {
+ focus(t); fire(t);
+ const inside = t > S9.inside - .05; cam.el.style.display = inside ? 'none' : ''; cam2.el.style.display = inside ? '' : 'none';
+ // Up from the ground: get up, the idea, the ladder (ground to eave), the roof (eave to chimney), at the chimney.
+ const up = clamp01((t - S9.crept) / (S9.roof - S9.crept)), over = clamp01((t - S9.roof) / (S9.chim + .3 - S9.roof));
+ let x = WOLF8.x, g = WOLF8.g, whole = t < .6 ? 'flop' : t < S9.crept ? 'grin' : null, lean = 0;
+ if (t > S9.crept) { x = 1440 + 50 * up; g = 712 - 290 * up; lean = -10 * up; }
+ if (t > S9.roof) { x = 1495 + (CHIM.x - 90 - 1495) * over; g = 423 - (423 - 300) * over; lean = -16 * (1 - over); }
+ const talk = t - S9.says, talking = talk > 0 && t < S9.inside;
+ if (t > S9.chim + .3) { whole = talking ? null : 'grin'; lean = 0; }
+ const stepping = t > S9.crept && t < S9.chim + .3, wp9 = walkPose(t, .14);
+ wolf.pose({ x, ground: g, k: .8, whole, lean, legs: stepping ? wp9.legs : 0, bob: stepping ? 5 * wp9.bob : 0,
+ face: { mouth: talking ? mouthAt('s09b', talk) : 'X', blink: blinkAt(t, 9), raise: talking ? .7 : 0, smile: .9 }, arm: talking && talk > 2 ? 3 : 0 });
+ put(bulb, { x: x + 60, y: g - 370, o: t > S9.idea && t < S9.crept ? 1 : 0, s: t > S9.idea ? 1 + .3 * Math.exp(-8 * (t - S9.idea)) * Math.sin((t - S9.idea) * 20) : 0 });
+ // Inside: he carries the pot to the fire and hangs it on the hook; the others watch from the table.
+ const q = clamp01((t - S9.set) / 1.2), carrying = t > S9.inside && t < S9.set + 1.2;
+ const px = 760 + (HOOK.x - 150 - 760) * q;
+ pig.pose({ x: px, ground: FLOOR, k: 1, legs: carrying && q > 0 && q < 1 ? walkPose(t, .16).legs : 0, arm: carrying ? 1 : 0, // hand forward under the pot (arm 4 holds a brick)
+ face: { blink: blinkAt(t, 23), smile: t > S9.fire ? .9 : .5, raise: t > S9.inside + 1 && t < S9.set ? .6 : 0, gaze: [1, -.2] } });
+ pot.setAttribute('transform', q < 1 ? `translate(${px + 95},${FLOOR - 300 - 60 * Math.sin(Math.PI * q)}) scale(.75)` : `translate(${HOOK.x},${HOOK.y + 6}) rotate(${4 * Math.exp(-3 * (t - S9.set - 1.2)) * Math.sin((t - S9.set) * 9)})`);
+ sibs.forEach((a, i) => a.pose({ x: 330 + i * 150, ground: FLOOR + 10, k: .92, face: { blink: blinkAt(t, 11 + i * 26), worry: .6, gaze: [1, 0] } }));
+ }, D);
+}
+
+const P10 = TIMINGS.shot10.parts, S10 = { down: .1, wolf: 1.3, splash: 2.6, hot: 4.27, ow: P10.s10b + .1, tail: P10.s10b + 1.73, up: P10.s10c + .11, shot: P10.s10c + .99, away: P10.s10c + 2.45, woods: P10.s10c + 3.56, never: P10.s10c + 4.75 };
+function shot10(p, D) {
+ const cam = camera(p, D, { x: 1150, y: 450, z: 1.3 }); interior(cam);
+ const fire = flames(cam.world);
+ // The wolf drawn only above the pot's bottom (he sinks into it, never out under it); the pot drawn over him.
+ const cid = 'pot' + Math.random().toString(36).slice(2, 7), inside = G(cam.world);
+ mk('rect', { x: 0, y: -2000, width: 1600, height: 2000 + HOOK.y + 200 }, mk('clipPath', { id: cid }, mk('defs', {}, cam.world)));
+ inside.setAttribute('clip-path', `url(#${cid})`);
+ const wolfIn = TOON.posed(inside, 'wolf'), pot = potAt(cam.world, HOOK.x, HOOK.y + 6);
+ const RIM = HOOK.y + 66, rings = [0, 1, 2].map(() => mk('ellipse', { fill: 'none', stroke: '#dff4ff', 'stroke-width': 4, opacity: 0 }, cam.world));
+ const bubbles = Array.from({ length: 9 }, () => mk('circle', { fill: '#cfeeff', stroke: '#5aa9d6', 'stroke-width': 2, opacity: 0 }, cam.world));
+ const steam = steamPuffs(cam.world), drops = Array.from({ length: 16 }, () => mk('path', { d: 'M0 -12Q8 0 0 8Q-8 0 0 -12Z', fill: '#8fd3ff', stroke: '#151314', 'stroke-width': 2.5, visibility: 'hidden' }, cam.world));
+ const pigs = [['pig1', 380], ['pig2', 520], ['pig3', 720]].map(([n, x]) => ({ a: TOON.posed(cam.world, n), x }));
+ // Outside, for the shot up the chimney and the run to the woods.
+ const out = camera(p, D, inMeadow({ x: 1600, y: 400, z: 1.2 })); const focus = meadow(out), world = out.layer(1);
+ staged(world, 'brick_house', BRICKS)(3, 9); out.el.style.display = 'none';
+ const wolfOut = TOON.posed(world, 'wolf'), smoke = Array.from({ length: 12 }, () => mk('circle', { fill: '#9a9a9a', opacity: 0 }, world));
+ cam.to({ x: HOOK.x, y: 470, z: 2.2 }, S10.wolf - .4, .8, io);
+ cam.shake(10, S10.splash, .5, 9); cam.to({ x: 1000, y: 470, z: 1.3 }, S10.ow + .2, .6, io); // close on the pot until he howls
+ out.to({ x: 1150, y: 480, z: 1.15 }, S10.away, S10.never - S10.away, soft);
+ clockRun(t => {
+ fire(t); focus(t);
+ const outside = t > S10.shot - .3; out.el.style.display = outside ? '' : 'none'; cam.el.style.display = outside ? 'none' : '';
+ // Down he drops (arms out), splash, sits steaming in the pot, then howls and shoots back up.
+ const fall = clamp01((t - S10.wolf + .3) / (S10.splash - S10.wolf + .3)), inPot = t > S10.splash, rise = t > S10.ow ? (t - S10.ow) : 0;
+ // In the pot: plunge out of sight, bubbles, his head comes up to the eyes, he goes red and shakes, then OWWW.
+ const SUNK = RIM + 290, EYES = RIM + 175, w = t - S10.splash;
+ const plunge = smooth(w / .35), surface = smooth((w - 1.3) / 1.1), shake = t > S10.hot ? Math.min(1, (t - S10.hot) / .8) : 0;
+ const gyIn = SUNK - (SUNK - EYES) * surface + (w < .35 ? -(SUNK - RIM - 60) * (1 - plunge) : 0);
+ const gy = !inPot ? -200 + (RIM + 60 + 200) * fall * fall : t < S10.ow ? gyIn + 3 * Math.sin(t * 60) * shake : EYES - 900 * rise * rise;
+ const red = inPot && t < S10.ow + .4 ? clamp01((t - S10.hot + .3) / 1) : 0;
+ wolfIn.root.style.filter = red > 0 ? `sepia(${.5 * red}) saturate(${1 + 3 * red}) hue-rotate(${-25 * red}deg)` : ''; // boiling red
+ rings.forEach((e, i) => { const q = clamp01((w - i * .18) / .9); e.setAttribute('cx', HOOK.x); e.setAttribute('cy', RIM + 4); e.setAttribute('rx', 30 + 70 * q); e.setAttribute('ry', 6 + 12 * q); e.setAttribute('opacity', inPot && q < 1 ? .9 * (1 - q) : 0); });
+ bubbles.forEach((e, i) => { const q = ((w - .4 - i * .19) % .7 + .7) % .7 / .7, on = w > .4 && t < S10.ow;
+ e.setAttribute('cx', HOOK.x - 60 + (i * 29) % 120); e.setAttribute('cy', RIM + 10 - 14 * q); e.setAttribute('r', (4 + (i % 3) * 3) * (q < .85 ? 1 : 1.6)); e.setAttribute('opacity', on ? (q < .85 ? .9 : 0) : 0); });
+ wolfIn.pose({ x: HOOK.x + 4 * Math.sin(t * 47) * shake * (t < S10.ow ? 1 : 0), ground: gy, k: .7, whole: !inPot ? 'inhale' : t > S10.ow - .1 ? 'howl' : null, sy: t > S10.ow ? 1 + .5 * clamp01(rise * 3) : 1,
+ face: { blink: 0, wide: 1, worry: red, smile: -red, gaze: [1, -.4 * red] } });
+ cam.world.appendChild(pot); // the pot in front of him: he sits inside it
+ drops.forEach((e, i) => { const q = t - S10.splash - (i % 4) * .03, on = q > 0 && q < .9, a = -Math.PI * (i / 15);
+ e.setAttribute('visibility', on ? 'visible' : 'hidden'); e.setAttribute('transform', `translate(${HOOK.x + Math.cos(a) * 420 * q},${HOOK.y + 30 + Math.sin(a) * 380 * q + 700 * q * q}) rotate(${a * 57 + 90})`); });
+ steam.forEach((e, i) => { const q = ((t - S10.splash - i * .25) % 2 + 2) % 2 / 2, on = inPot && t < S10.shot;
+ e.setAttribute('cx', HOOK.x - 60 + (i * 17) % 120 + 20 * Math.sin(t * 2 + i)); e.setAttribute('cy', HOOK.y + 10 - 220 * q); e.setAttribute('rx', 20 + 30 * q); e.setAttribute('ry', 14 + 20 * q); e.setAttribute('opacity', on ? .8 * (1 - q) : 0); });
+ pigs.forEach(({ a, x }, i) => a.pose({ x, ground: FLOOR + 10, k: .92, whole: t > S10.ow + .4 && i < 2 ? 'laugh' : null,
+ face: { blink: blinkAt(t, 11 + i * 12), wide: t > S10.splash ? 1 : 0, gaze: [1, -.3], smile: .9 } }));
+ // Outside: out of the chimney, stretched, high into the sky; down again and off to the woods with a smoking tail.
+ const u = t - S10.shot, flyUp = u < 1.2, ox = flyUp ? CHIM.x - 180 * u : CHIM.x - 216 - 520 * (u - 1.2);
+ const oy = flyUp ? CHIM.y + 40 - 300 * Math.sin(Math.PI * u / 1.2) + 450 * Math.max(0, u - .6) ** 2 * 4 : 712; // up, over, down to the road
+ const wr = walkPose(u, .07);
+ wolfOut.pose({ x: ox, ground: oy, k: .8, whole: flyUp ? 'howl' : null, dir: flyUp ? 1 : -1, sy: flyUp ? 1.4 : 1, lean: flyUp ? 0 : 10,
+ legs: flyUp ? 0 : wr.legs, arm: flyUp ? 0 : wr.arm, bob: flyUp ? 0 : 10 * wr.bob, face: { blink: 0, wide: 1, worry: 1, mouth: 'D', smile: -.6 } });
+ smoke.forEach((e, i) => { const q = ((t * 1.6 + i / 12) % 1), on = u > 0 && t < S10.never + .5;
+ e.setAttribute('cx', ox + (u > .9 ? 80 : 0) + 120 * q * (u > .9 ? 1 : 0)); e.setAttribute('cy', oy - 120 + (flyUp ? 200 * q : -60 * q)); e.setAttribute('r', 14 + 30 * q); e.setAttribute('opacity', on ? .6 * (1 - q) : 0); });
+ }, D);
+}
+
+const S11 = { pigs: 1.49, brick: 3.89, other: 5.21, bricks: 7.41, happily: 9.59, after: 10.44 }, END = 3.2;
+function shot11(p, D) {
+ const cam = camera(p, D + END, inMeadow({ x: 1700, y: 520, z: 1.8 }));
+ const focus = meadow(cam), world = cam.layer(1);
+ const house = staged(world, 'brick_house', BRICKS);
+ const pigs = ['pig1', 'pig2', 'pig3'].map(n => TOON.posed(world, n));
+ const shed = prop(world, 'brickpile', BRICKS.x + 260, BRICKS.base + 20, 130, BPILE.size);
+ const glow = mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: '#ffcf7a', opacity: 0, style: 'mix-blend-mode: soft-light; pointer-events: none' }, p);
+ const black = mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: '#141210', opacity: 0 }, p);
+ const end = T(p, 'The End', { x: 800, y: 470, size: 110, weight: 800, fill: '#fff6e0', anchor: 'middle', o: 0 });
+ end.setAttribute('font-family', 'Georgia, serif'); end.setAttribute('font-style', 'italic');
+ cam.to(inMeadow({ x: 1700, y: 500, z: 1.6 }), 0, S11.other, soft);
+ cam.to(inMeadow({ x: 1850, y: 480, z: 1.9 }), S11.other, S11.happily - S11.other, soft);
+ cam.to(inMeadow({ x: 1300, y: 450, z: 1 }), S11.happily, D + END - S11.happily, soft);
+ clockRun(t => {
+ focus(t); house(3, 9);
+ // Dancing in a ring in front of the house; then two of them help: hammering, laying bricks; then dancing again.
+ const helping = t > S11.other && t < S11.happily, ring = !helping;
+ pigs.forEach((a, i) => {
+ const ph = t * 2.2 + i * 2.09, x = 1640 + Math.cos(ph) * 120, back = Math.sin(ph) < 0;
+ const hx = [1880, 1960, 1800][i];
+ a.pose(ring ? { x, ground: 702 + Math.sin(ph) * 14, k: .62 + Math.sin(ph) * .03, dir: Math.cos(ph + Math.PI / 2) > 0 ? 1 : -1,
+ legs: walkPose(t + i * .1, .18).legs, arm: 3, bob: -10 * Math.abs(Math.sin(t * 8 + i)), face: { blink: blinkAt(t, 11 + i * 12), mouth: 'D', smile: 1 } }
+ : { x: hx, ground: 705, k: .62, dir: i === 2 ? 1 : -1,
+ arm: i === 1 ? (Math.floor(t / .35) % 2 ? 5 : 4) : i === 2 ? (Math.floor(t / .6) % 2 ? 5 : 4) : 3, legs: 0,
+ face: { blink: blinkAt(t, 11 + i * 12), smile: .9 } });
+ a.root.parentNode.appendChild(back ? a.root : a.root);
+ });
+ glow.setAttribute('opacity', .5 * smooth((t - S11.happily) / 1.5));
+ black.setAttribute('opacity', smooth((t - D - .2) / 1.4));
+ put(end, { o: smooth((t - D - .9) / 1), y: 470 - 20 * smooth((t - D - .9) / 1) });
+ }, D + END);
+}
+
+/* ---------- beats: [id, title, run(m, D), extra] ---------- */
+const BEATS = [
+ ['shot1', 'Leaving home', (m, D) => shot1(panel(0), 0, D), { lead: false }], // narration and Mother's line, one clip
+ ['shot2', 'The straw house', (m, D) => shot2(panel(0), D), { lead: false }],
+ ['shot3', 'The stick house', (m, D) => shot3(panel(0), D), { lead: false }],
+ ['shot4', 'The brick house', (m, D) => shot4(panel(0), D), { lead: false }],
+ ['shot5', 'The wolf', (m, D) => shot5(panel(0), D), { lead: false, pre: PRE5 }],
+ ['shot6', 'Huff and puff', (m, D) => shot6(panel(0), D), { lead: false, pre: PRE6 }],
+ ['shot7', 'The stick house falls', (m, D) => shot7(panel(0), D), { lead: false, pre: PRE7 }],
+ ['shot8', 'The brick house stands', (m, D) => shot8(panel(0), D), { lead: false, pre: PRE8 }],
+ ['shot9', 'Down the chimney', (m, D) => shot9(panel(0), D), { lead: false }],
+ ['shot10', 'Splash!', (m, D) => shot10(panel(0), D), { lead: false }],
+ ['shot11', 'Happily ever after', (m, D) => shot11(panel(0), D), { lead: false }],
+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
+
+// Decode every character drawing and prop when the page opens, before any scene needs it.
+for (const n of ['mother', 'pig1', 'pig2', 'pig3', 'wolf']) {
+ for (const k in POSES[n].parts) TOON.preload(`../img/${n}/pose/${k}.webp`);
+ for (const k in RIGS[n].parts) TOON.preload(`../img/${n}/rig/${k}.webp`);
+}
+for (const k of ['bindle', 'bundle', 'haystack', 'stickpile', 'brickpile', 'straw_house_1', 'straw_house_2', 'straw_house_3', 'stick_house_1', 'stick_house_2', 'stick_house_3', 'brick_house_1', 'brick_house_2', 'brick_house_3']) TOON.preload(`../img/props/${k}.webp`);
+/* ---------- background music ---------- */
+// 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', ['shot1', 'shot2', 'shot3', 'shot4']], ['m2-wolf', ['shot5', 'shot6', 'shot7', 'shot8']], ['m3-chimney', ['shot9', 'shot10']], ['m4-ending', ['shot11']]]
+ .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();
+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;
+ 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;
+ m.v = Math.max(0, Math.min(1, m.v + (current ? 1 : -1) * dt / .8)); // 0.8 s fades
+ m.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);
+ 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)
+ requestAnimationFrame(bgmTick);
+}
+requestAnimationFrame(bgmTick);
+boot();
+</script>
+</body>
+</html>
diff --git a/site/three-little-pigs/img/bg_far.webp b/site/three-little-pigs/img/bg_far.webp
new file mode 100644
index 0000000..98fbc08
Binary files /dev/null and b/site/three-little-pigs/img/bg_far.webp differ
diff --git a/site/three-little-pigs/img/bg_front.webp b/site/three-little-pigs/img/bg_front.webp
new file mode 100644
index 0000000..a984ab2
Binary files /dev/null and b/site/three-little-pigs/img/bg_front.webp differ
diff --git a/site/three-little-pigs/img/bg_mid.webp b/site/three-little-pigs/img/bg_mid.webp
new file mode 100644
index 0000000..d472c87
Binary files /dev/null and b/site/three-little-pigs/img/bg_mid.webp differ
diff --git a/site/three-little-pigs/img/cottage.webp b/site/three-little-pigs/img/cottage.webp
new file mode 100644
index 0000000..7653a15
Binary files /dev/null and b/site/three-little-pigs/img/cottage.webp differ
diff --git a/site/three-little-pigs/img/cottage/far-soft.webp b/site/three-little-pigs/img/cottage/far-soft.webp
new file mode 100644
index 0000000..b5366fb
Binary files /dev/null and b/site/three-little-pigs/img/cottage/far-soft.webp differ
diff --git a/site/three-little-pigs/img/cottage/far.webp b/site/three-little-pigs/img/cottage/far.webp
new file mode 100644
index 0000000..03c63d7
Binary files /dev/null and b/site/three-little-pigs/img/cottage/far.webp differ
diff --git a/site/three-little-pigs/img/cottage/front.webp b/site/three-little-pigs/img/cottage/front.webp
new file mode 100644
index 0000000..4f1500e
Binary files /dev/null and b/site/three-little-pigs/img/cottage/front.webp differ
diff --git a/site/three-little-pigs/img/cottage/ground-soft.webp b/site/three-little-pigs/img/cottage/ground-soft.webp
new file mode 100644
index 0000000..a7da581
Binary files /dev/null and b/site/three-little-pigs/img/cottage/ground-soft.webp differ
diff --git a/site/three-little-pigs/img/cottage/ground.webp b/site/three-little-pigs/img/cottage/ground.webp
new file mode 100644
index 0000000..317d7e5
Binary files /dev/null and b/site/three-little-pigs/img/cottage/ground.webp differ
diff --git a/site/three-little-pigs/img/cottage/mid-soft.webp b/site/three-little-pigs/img/cottage/mid-soft.webp
new file mode 100644
index 0000000..29b9e64
Binary files /dev/null and b/site/three-little-pigs/img/cottage/mid-soft.webp differ
diff --git a/site/three-little-pigs/img/cottage/mid.webp b/site/three-little-pigs/img/cottage/mid.webp
new file mode 100644
index 0000000..1b78a80
Binary files /dev/null and b/site/three-little-pigs/img/cottage/mid.webp differ
diff --git a/site/three-little-pigs/img/cottage/sky-soft.webp b/site/three-little-pigs/img/cottage/sky-soft.webp
new file mode 100644
index 0000000..7b90f25
Binary files /dev/null and b/site/three-little-pigs/img/cottage/sky-soft.webp differ
diff --git a/site/three-little-pigs/img/cottage/sky.webp b/site/three-little-pigs/img/cottage/sky.webp
new file mode 100644
index 0000000..588289d
Binary files /dev/null and b/site/three-little-pigs/img/cottage/sky.webp differ
diff --git a/site/three-little-pigs/img/house_brick.webp b/site/three-little-pigs/img/house_brick.webp
new file mode 100644
index 0000000..3cd5cbf
Binary files /dev/null and b/site/three-little-pigs/img/house_brick.webp differ
diff --git a/site/three-little-pigs/img/house_sticks.webp b/site/three-little-pigs/img/house_sticks.webp
new file mode 100644
index 0000000..33f44fc
Binary files /dev/null and b/site/three-little-pigs/img/house_sticks.webp differ
diff --git a/site/three-little-pigs/img/house_straw.webp b/site/three-little-pigs/img/house_straw.webp
new file mode 100644
index 0000000..3d28df0
Binary files /dev/null and b/site/three-little-pigs/img/house_straw.webp differ
diff --git a/site/three-little-pigs/img/interior.webp b/site/three-little-pigs/img/interior.webp
new file mode 100644
index 0000000..555993d
Binary files /dev/null and b/site/three-little-pigs/img/interior.webp differ
diff --git a/site/three-little-pigs/img/meadow/far-soft.webp b/site/three-little-pigs/img/meadow/far-soft.webp
new file mode 100644
index 0000000..166e5e6
Binary files /dev/null and b/site/three-little-pigs/img/meadow/far-soft.webp differ
diff --git a/site/three-little-pigs/img/meadow/far.webp b/site/three-little-pigs/img/meadow/far.webp
new file mode 100644
index 0000000..a2880a9
Binary files /dev/null and b/site/three-little-pigs/img/meadow/far.webp differ
diff --git a/site/three-little-pigs/img/meadow/ground-soft.webp b/site/three-little-pigs/img/meadow/ground-soft.webp
new file mode 100644
index 0000000..461a2a7
Binary files /dev/null and b/site/three-little-pigs/img/meadow/ground-soft.webp differ
diff --git a/site/three-little-pigs/img/meadow/ground.webp b/site/three-little-pigs/img/meadow/ground.webp
new file mode 100644
index 0000000..09aa70f
Binary files /dev/null and b/site/three-little-pigs/img/meadow/ground.webp differ
diff --git a/site/three-little-pigs/img/meadow/sky-soft.webp b/site/three-little-pigs/img/meadow/sky-soft.webp
new file mode 100644
index 0000000..a86f920
Binary files /dev/null and b/site/three-little-pigs/img/meadow/sky-soft.webp differ
diff --git a/site/three-little-pigs/img/meadow/sky.webp b/site/three-little-pigs/img/meadow/sky.webp
new file mode 100644
index 0000000..df241c6
Binary files /dev/null and b/site/three-little-pigs/img/meadow/sky.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/arm0.webp b/site/three-little-pigs/img/mother/pose/arm0.webp
new file mode 100644
index 0000000..d620f11
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/arm0.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/arm1.webp b/site/three-little-pigs/img/mother/pose/arm1.webp
new file mode 100644
index 0000000..9490659
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/arm1.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/arm2.webp b/site/three-little-pigs/img/mother/pose/arm2.webp
new file mode 100644
index 0000000..0eec006
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/arm2.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/faceplate.webp b/site/three-little-pigs/img/mother/pose/faceplate.webp
new file mode 100644
index 0000000..8e43a71
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/faceplate.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/fig0.webp b/site/three-little-pigs/img/mother/pose/fig0.webp
new file mode 100644
index 0000000..5a057e5
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/fig0.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/mouth1.webp b/site/three-little-pigs/img/mother/pose/mouth1.webp
new file mode 100644
index 0000000..5107162
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/mouth1.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/mouth2.webp b/site/three-little-pigs/img/mother/pose/mouth2.webp
new file mode 100644
index 0000000..0227a0b
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/mouth2.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/mouth3.webp b/site/three-little-pigs/img/mother/pose/mouth3.webp
new file mode 100644
index 0000000..e1a2e11
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/mouth3.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/mouth4.webp b/site/three-little-pigs/img/mother/pose/mouth4.webp
new file mode 100644
index 0000000..0ffe7c0
Binary files /dev/null and b/site/three-little-pigs/img/mother/pose/mouth4.webp differ
diff --git a/site/three-little-pigs/img/mother/pose/pose.js b/site/three-little-pigs/img/mother/pose/pose.js
new file mode 100644
index 0000000..7a6faca
--- /dev/null
+++ b/site/three-little-pigs/img/mother/pose/pose.js
@@ -0,0 +1 @@
+window.POSES = window.POSES || {}; POSES.mother = {"size": [1024, 1536], "parts": {"fig0": [142, 23, 652, 1471], "arm0": [186, 510, 315, 564], "arm1": [22, 47, 471, 621], "arm2": [270, 511, 366, 340], "mouth1": [523, 345, 211, 133], "mouth2": [543, 355, 194, 142], "mouth3": [523, 335, 213, 208], "mouth4": [523, 345, 212, 166], "faceplate": [159, 151, 584, 1052]}, "legs": 0, "arms": 3, "mouths": 4, "wholes": [], "ground": 1493};
diff --git a/site/three-little-pigs/img/mother/rig/eye0.webp b/site/three-little-pigs/img/mother/rig/eye0.webp
new file mode 100644
index 0000000..f8d6c3f
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/eye0.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/eye1.webp b/site/three-little-pigs/img/mother/rig/eye1.webp
new file mode 100644
index 0000000..b261504
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/eye1.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/hand.webp b/site/three-little-pigs/img/mother/rig/hand.webp
new file mode 100644
index 0000000..c8fa1db
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/hand.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/head.webp b/site/three-little-pigs/img/mother/rig/head.webp
new file mode 100644
index 0000000..49af92b
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/head.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/line0.webp b/site/three-little-pigs/img/mother/rig/line0.webp
new file mode 100644
index 0000000..7adda9d
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/line0.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/line1.webp b/site/three-little-pigs/img/mother/rig/line1.webp
new file mode 100644
index 0000000..b39afcf
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/line1.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/line2.webp b/site/three-little-pigs/img/mother/rig/line2.webp
new file mode 100644
index 0000000..6019f00
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/line2.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/line3.webp b/site/three-little-pigs/img/mother/rig/line3.webp
new file mode 100644
index 0000000..e7b8994
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/line3.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/lower.webp b/site/three-little-pigs/img/mother/rig/lower.webp
new file mode 100644
index 0000000..ab3369e
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/lower.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/pupil0.webp b/site/three-little-pigs/img/mother/rig/pupil0.webp
new file mode 100644
index 0000000..f2568bc
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/pupil0.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/pupil1.webp b/site/three-little-pigs/img/mother/rig/pupil1.webp
new file mode 100644
index 0000000..d69a6d0
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/pupil1.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/rig.js b/site/three-little-pigs/img/mother/rig/rig.js
new file mode 100644
index 0000000..2ef604e
--- /dev/null
+++ b/site/three-little-pigs/img/mother/rig/rig.js
@@ -0,0 +1 @@
+window.RIGS = window.RIGS || {}; RIGS.mother = {"size": [1024, 1536], "neck": [543, 517], "lid": "#fea19b", "brows": ["line0", "line1", "line2"], "marks": [], "mouth": "line3", "ground": 1493, "waist": 743, "shoulder": [372, 650], "root": [372, 665], "wrist": [392, 955], "elbow": [386, 866], "armWidth": 105, "skin": "#fca49c", "parts": {"head": [261, 23, 508, 515], "eye0": [515, 201, 101, 147], "pupil0": [554, 219, 56, 117], "eye1": [637, 207, 58, 114], "pupil1": [645, 212, 42, 94], "line0": [563, 78, 16, 21], "line1": [632, 161, 19, 14], "line2": [523, 163, 55, 49], "line3": [552, 374, 169, 50], "upper": [189, 486, 523, 261], "lower": [142, 703, 652, 791], "sleeve": [272, 511, 227, 259], "hand": [341, 943, 112, 128]}, "eyes": ["eye0", "eye1"]};
diff --git a/site/three-little-pigs/img/mother/rig/sleeve.webp b/site/three-little-pigs/img/mother/rig/sleeve.webp
new file mode 100644
index 0000000..cb28c71
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/sleeve.webp differ
diff --git a/site/three-little-pigs/img/mother/rig/upper.webp b/site/three-little-pigs/img/mother/rig/upper.webp
new file mode 100644
index 0000000..74d44f0
Binary files /dev/null and b/site/three-little-pigs/img/mother/rig/upper.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/arm0.webp b/site/three-little-pigs/img/pig1/pose/arm0.webp
new file mode 100644
index 0000000..ff5543e
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/arm0.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/arm1.webp b/site/three-little-pigs/img/pig1/pose/arm1.webp
new file mode 100644
index 0000000..d37710f
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/arm1.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/arm2.webp b/site/three-little-pigs/img/pig1/pose/arm2.webp
new file mode 100644
index 0000000..3ee6fe7
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/arm2.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/arm3.webp b/site/three-little-pigs/img/pig1/pose/arm3.webp
new file mode 100644
index 0000000..9b216f3
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/arm3.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/arm4.webp b/site/three-little-pigs/img/pig1/pose/arm4.webp
new file mode 100644
index 0000000..09f2ee5
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/arm4.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/carry.webp b/site/three-little-pigs/img/pig1/pose/carry.webp
new file mode 100644
index 0000000..b7ddd6b
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/carry.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/faceplate.webp b/site/three-little-pigs/img/pig1/pose/faceplate.webp
new file mode 100644
index 0000000..125f896
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/faceplate.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/fig0.webp b/site/three-little-pigs/img/pig1/pose/fig0.webp
new file mode 100644
index 0000000..159c361
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/fig0.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/fig1.webp b/site/three-little-pigs/img/pig1/pose/fig1.webp
new file mode 100644
index 0000000..81043bf
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/fig1.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/fig2.webp b/site/three-little-pigs/img/pig1/pose/fig2.webp
new file mode 100644
index 0000000..84656b4
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/fig2.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/fig3.webp b/site/three-little-pigs/img/pig1/pose/fig3.webp
new file mode 100644
index 0000000..62f5929
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/fig3.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/fig4.webp b/site/three-little-pigs/img/pig1/pose/fig4.webp
new file mode 100644
index 0000000..ce1794c
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/fig4.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/laugh.webp b/site/three-little-pigs/img/pig1/pose/laugh.webp
new file mode 100644
index 0000000..c7db20b
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/laugh.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/mouth1.webp b/site/three-little-pigs/img/pig1/pose/mouth1.webp
new file mode 100644
index 0000000..8c0e3b9
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/mouth1.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/mouth2.webp b/site/three-little-pigs/img/pig1/pose/mouth2.webp
new file mode 100644
index 0000000..53750d7
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/mouth2.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/mouth3.webp b/site/three-little-pigs/img/pig1/pose/mouth3.webp
new file mode 100644
index 0000000..6fdbd17
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/mouth3.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/mouth4.webp b/site/three-little-pigs/img/pig1/pose/mouth4.webp
new file mode 100644
index 0000000..7ab39c9
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/mouth4.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/nap.webp b/site/three-little-pigs/img/pig1/pose/nap.webp
new file mode 100644
index 0000000..2f83f81
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/nap.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/pose.js b/site/three-little-pigs/img/pig1/pose/pose.js
new file mode 100644
index 0000000..127c1df
--- /dev/null
+++ b/site/three-little-pigs/img/pig1/pose/pose.js
@@ -0,0 +1 @@
+window.POSES = window.POSES || {}; POSES.pig1 = {"size": [1024, 1536], "parts": {"fig0": [102, 44, 716, 1443], "fig1": [103, 44, 715, 1426], "fig2": [103, 44, 715, 1442], "fig3": [103, 44, 715, 1435], "fig4": [103, 44, 715, 1436], "carry": [85, 44, 918, 1428], "laugh": [90, 59, 758, 1428], "nap": [16, 493, 994, 494], "run1": [35, 145, 958, 1240], "run2": [42, 132, 909, 1253], "run3": [84, 112, 827, 1168], "run4": [27, 142, 976, 1255], "toss": [135, 39, 832, 1456], "arm0": [309, 606, 240, 516], "arm1": [376, 612, 266, 367], "arm2": [187, 609, 335, 420], "arm3": [207, 374, 343, 426], "arm4": [250, 584, 299, 333], "mouth1": [568, 463, 147, 118], "mouth2": [560, 458, 158, 144], "mouth3": [558, 443, 226, 191], "mouth4": [546, 449, 234, 150], "faceplate": [203, 206, 587, 434]}, "legs": 4, "arms": 5, "mouths": 4, "wholes": ["carry", "laugh", "nap", "run1", "run2", "run3", "run4", "toss"], "ground": 1486};
diff --git a/site/three-little-pigs/img/pig1/pose/run1.webp b/site/three-little-pigs/img/pig1/pose/run1.webp
new file mode 100644
index 0000000..f3ade34
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/run1.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/run2.webp b/site/three-little-pigs/img/pig1/pose/run2.webp
new file mode 100644
index 0000000..1975e96
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/run2.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/run3.webp b/site/three-little-pigs/img/pig1/pose/run3.webp
new file mode 100644
index 0000000..324342d
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/run3.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/run4.webp b/site/three-little-pigs/img/pig1/pose/run4.webp
new file mode 100644
index 0000000..239a119
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/run4.webp differ
diff --git a/site/three-little-pigs/img/pig1/pose/toss.webp b/site/three-little-pigs/img/pig1/pose/toss.webp
new file mode 100644
index 0000000..bd296a7
Binary files /dev/null and b/site/three-little-pigs/img/pig1/pose/toss.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/body.webp b/site/three-little-pigs/img/pig1/rig/body.webp
new file mode 100644
index 0000000..cd68cf5
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/body.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/eye0.webp b/site/three-little-pigs/img/pig1/rig/eye0.webp
new file mode 100644
index 0000000..ad48046
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/eye0.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/eye1.webp b/site/three-little-pigs/img/pig1/rig/eye1.webp
new file mode 100644
index 0000000..25a09e4
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/eye1.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/foot0.webp b/site/three-little-pigs/img/pig1/rig/foot0.webp
new file mode 100644
index 0000000..15429b0
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/foot0.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/foot1.webp b/site/three-little-pigs/img/pig1/rig/foot1.webp
new file mode 100644
index 0000000..bee6bc7
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/foot1.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/hand.webp b/site/three-little-pigs/img/pig1/rig/hand.webp
new file mode 100644
index 0000000..c855f6a
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/hand.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/line0.webp b/site/three-little-pigs/img/pig1/rig/line0.webp
new file mode 100644
index 0000000..a6ef6cb
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/line0.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/line1.webp b/site/three-little-pigs/img/pig1/rig/line1.webp
new file mode 100644
index 0000000..18b6e81
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/line1.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/line2.webp b/site/three-little-pigs/img/pig1/rig/line2.webp
new file mode 100644
index 0000000..825a6a4
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/line2.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/pupil0.webp b/site/three-little-pigs/img/pig1/rig/pupil0.webp
new file mode 100644
index 0000000..b3a937c
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/pupil0.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/pupil1.webp b/site/three-little-pigs/img/pig1/rig/pupil1.webp
new file mode 100644
index 0000000..8308981
Binary files /dev/null and b/site/three-little-pigs/img/pig1/rig/pupil1.webp differ
diff --git a/site/three-little-pigs/img/pig1/rig/rig.js b/site/three-little-pigs/img/pig1/rig/rig.js
new file mode 100644
index 0000000..1e821b9
--- /dev/null
+++ b/site/three-little-pigs/img/pig1/rig/rig.js
@@ -0,0 +1 @@
+window.RIGS = window.RIGS || {}; RIGS.pig1 = {"size": [1024, 1536], "lid": "#fea7a2", "brows": ["line0", "line1"], "marks": [], "mouth": "line2", "legs": [{"part": "foot0", "hip": [416, 1262], "ankle": [396, 1362], "width": 127}, {"part": "foot1", "hip": [550, 1262], "ankle": [551, 1362], "width": 118}], "legSkin": "#fca4a4", "ground": 1486, "shoulder": [362, 714], "root": [362, 714], "wrist": [370, 998], "elbow": [373, 840], "armWidth": 119, "skin": "#fcaca4", "parts": {"eye0": [524, 278, 107, 171], "pupil0": [566, 304, 58, 125], "eye1": [664, 269, 52, 146], "pupil1": [675, 285, 33, 117], "line0": [659, 216, 23, 18], "line1": [516, 228, 59, 69], "line2": [574, 478, 120, 43], "foot0": [298, 1352, 160, 135], "foot1": [486, 1352, 188, 126], "body": [103, 44, 715, 1226], "hand": [309, 986, 120, 135]}, "eyes": ["eye0", "eye1"]};
diff --git a/site/three-little-pigs/img/pig2/pose/arm0.webp b/site/three-little-pigs/img/pig2/pose/arm0.webp
new file mode 100644
index 0000000..5bda4fb
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/arm0.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/arm1.webp b/site/three-little-pigs/img/pig2/pose/arm1.webp
new file mode 100644
index 0000000..11c7308
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/arm1.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/arm2.webp b/site/three-little-pigs/img/pig2/pose/arm2.webp
new file mode 100644
index 0000000..aabe5db
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/arm2.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/arm3.webp b/site/three-little-pigs/img/pig2/pose/arm3.webp
new file mode 100644
index 0000000..345e13a
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/arm3.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/arm4.webp b/site/three-little-pigs/img/pig2/pose/arm4.webp
new file mode 100644
index 0000000..85dc765
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/arm4.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/arm5.webp b/site/three-little-pigs/img/pig2/pose/arm5.webp
new file mode 100644
index 0000000..c724f0d
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/arm5.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/faceplate.webp b/site/three-little-pigs/img/pig2/pose/faceplate.webp
new file mode 100644
index 0000000..26037cd
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/faceplate.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/fig0.webp b/site/three-little-pigs/img/pig2/pose/fig0.webp
new file mode 100644
index 0000000..7e03242
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/fig0.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/fig1.webp b/site/three-little-pigs/img/pig2/pose/fig1.webp
new file mode 100644
index 0000000..06b0f3b
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/fig1.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/fig2.webp b/site/three-little-pigs/img/pig2/pose/fig2.webp
new file mode 100644
index 0000000..1f26b09
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/fig2.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/fig3.webp b/site/three-little-pigs/img/pig2/pose/fig3.webp
new file mode 100644
index 0000000..c3708a5
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/fig3.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/fig4.webp b/site/three-little-pigs/img/pig2/pose/fig4.webp
new file mode 100644
index 0000000..d135b10
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/fig4.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/laugh.webp b/site/three-little-pigs/img/pig2/pose/laugh.webp
new file mode 100644
index 0000000..bb5490f
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/laugh.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/mouth1.webp b/site/three-little-pigs/img/pig2/pose/mouth1.webp
new file mode 100644
index 0000000..2804afe
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/mouth1.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/mouth2.webp b/site/three-little-pigs/img/pig2/pose/mouth2.webp
new file mode 100644
index 0000000..84b2a3b
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/mouth2.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/mouth3.webp b/site/three-little-pigs/img/pig2/pose/mouth3.webp
new file mode 100644
index 0000000..ee70051
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/mouth3.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/mouth4.webp b/site/three-little-pigs/img/pig2/pose/mouth4.webp
new file mode 100644
index 0000000..c4b39cc
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/mouth4.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/pose.js b/site/three-little-pigs/img/pig2/pose/pose.js
new file mode 100644
index 0000000..ac27416
--- /dev/null
+++ b/site/three-little-pigs/img/pig2/pose/pose.js
@@ -0,0 +1 @@
+window.POSES = window.POSES || {}; POSES.pig2 = {"size": [1024, 1536], "parts": {"fig0": [207, 30, 597, 1467], "fig1": [208, 30, 597, 1459], "fig2": [208, 30, 597, 1476], "fig3": [208, 30, 612, 1455], "fig4": [208, 30, 596, 1475], "laugh": [95, 58, 732, 1438], "run1": [28, 145, 943, 1244], "run2": [44, 190, 941, 1132], "run3": [50, 91, 870, 1239], "run4": [24, 158, 899, 1196], "arm0": [275, 631, 205, 513], "arm1": [340, 634, 312, 368], "arm2": [248, 625, 232, 392], "arm3": [81, 105, 380, 668], "arm4": [101, 84, 258, 551], "arm5": [337, 754, 526, 260], "mouth1": [539, 419, 229, 137], "mouth2": [547, 423, 216, 190], "mouth3": [541, 416, 232, 203], "mouth4": [540, 420, 232, 144], "faceplate": [221, 108, 584, 1372]}, "legs": 4, "arms": 6, "mouths": 4, "wholes": ["laugh", "run1", "run2", "run3", "run4"], "ground": 1496};
diff --git a/site/three-little-pigs/img/pig2/pose/run1.webp b/site/three-little-pigs/img/pig2/pose/run1.webp
new file mode 100644
index 0000000..a8e3501
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/run1.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/run2.webp b/site/three-little-pigs/img/pig2/pose/run2.webp
new file mode 100644
index 0000000..e148fd5
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/run2.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/run3.webp b/site/three-little-pigs/img/pig2/pose/run3.webp
new file mode 100644
index 0000000..ca0a01a
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/run3.webp differ
diff --git a/site/three-little-pigs/img/pig2/pose/run4.webp b/site/three-little-pigs/img/pig2/pose/run4.webp
new file mode 100644
index 0000000..1024372
Binary files /dev/null and b/site/three-little-pigs/img/pig2/pose/run4.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/body.webp b/site/three-little-pigs/img/pig2/rig/body.webp
new file mode 100644
index 0000000..38a949b
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/body.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/eye0.webp b/site/three-little-pigs/img/pig2/rig/eye0.webp
new file mode 100644
index 0000000..d44d44c
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/eye0.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/eye1.webp b/site/three-little-pigs/img/pig2/rig/eye1.webp
new file mode 100644
index 0000000..df4b182
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/eye1.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/foot0.webp b/site/three-little-pigs/img/pig2/rig/foot0.webp
new file mode 100644
index 0000000..80fb6a6
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/foot0.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/foot1.webp b/site/three-little-pigs/img/pig2/rig/foot1.webp
new file mode 100644
index 0000000..61cf021
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/foot1.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/hand.webp b/site/three-little-pigs/img/pig2/rig/hand.webp
new file mode 100644
index 0000000..b99dd89
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/hand.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/head.webp b/site/three-little-pigs/img/pig2/rig/head.webp
new file mode 100644
index 0000000..913e594
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/head.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line0.webp b/site/three-little-pigs/img/pig2/rig/line0.webp
new file mode 100644
index 0000000..252ff93
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line0.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line1.webp b/site/three-little-pigs/img/pig2/rig/line1.webp
new file mode 100644
index 0000000..aa83e76
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line1.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line2.webp b/site/three-little-pigs/img/pig2/rig/line2.webp
new file mode 100644
index 0000000..5fb75f3
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line2.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line3.webp b/site/three-little-pigs/img/pig2/rig/line3.webp
new file mode 100644
index 0000000..4f0b6a3
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line3.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line4.webp b/site/three-little-pigs/img/pig2/rig/line4.webp
new file mode 100644
index 0000000..5622e2b
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line4.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line5.webp b/site/three-little-pigs/img/pig2/rig/line5.webp
new file mode 100644
index 0000000..9412069
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line5.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/line6.webp b/site/three-little-pigs/img/pig2/rig/line6.webp
new file mode 100644
index 0000000..272966c
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/line6.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/pupil0.webp b/site/three-little-pigs/img/pig2/rig/pupil0.webp
new file mode 100644
index 0000000..222ecd8
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/pupil0.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/pupil1.webp b/site/three-little-pigs/img/pig2/rig/pupil1.webp
new file mode 100644
index 0000000..4bd4978
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/pupil1.webp differ
diff --git a/site/three-little-pigs/img/pig2/rig/rig.js b/site/three-little-pigs/img/pig2/rig/rig.js
new file mode 100644
index 0000000..b0f5bb6
--- /dev/null
+++ b/site/three-little-pigs/img/pig2/rig/rig.js
@@ -0,0 +1 @@
+window.RIGS = window.RIGS || {}; RIGS.pig2 = {"size": [1024, 1536], "neck": [578, 626], "lid": "#fe948c", "brows": ["line0", "line1", "line2", "line3"], "marks": ["line4", "line5"], "mouth": "line6", "legs": [{"part": "foot0", "hip": [439, 1268], "ankle": [397, 1385], "width": 145}, {"part": "foot1", "hip": [589, 1268], "ankle": [608, 1385], "width": 112}], "legSkin": "#fc948c", "ground": 1496, "shoulder": [370, 760], "root": [370, 775], "wrist": [353, 1191], "elbow": [357, 1163], "armWidth": 16, "skin": "#9c6434", "parts": {"head": [208, 30, 597, 617], "eye0": [535, 267, 107, 153], "pupil0": [575, 274, 60, 127], "eye1": [666, 258, 62, 132], "pupil1": [669, 263, 46, 112], "line0": [238, 167, 53, 29], "line1": [654, 198, 12, 21], "line2": [521, 195, 64, 68], "line3": [252, 269, 31, 36], "line4": [786, 365, 13, 54], "line5": [734, 398, 13, 24], "line6": [568, 449, 170, 51], "foot0": [280, 1375, 201, 122], "foot1": [515, 1375, 228, 107], "body": [205, 581, 535, 695], "sleeve": [278, 630, 202, 499], "hand": [346, 1179, 15, 24]}, "eyes": ["eye0", "eye1"]};
diff --git a/site/three-little-pigs/img/pig2/rig/sleeve.webp b/site/three-little-pigs/img/pig2/rig/sleeve.webp
new file mode 100644
index 0000000..96a9598
Binary files /dev/null and b/site/three-little-pigs/img/pig2/rig/sleeve.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm0.webp b/site/three-little-pigs/img/pig3/pose/arm0.webp
new file mode 100644
index 0000000..800d0c8
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm0.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm1.webp b/site/three-little-pigs/img/pig3/pose/arm1.webp
new file mode 100644
index 0000000..86db09a
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm1.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm2.webp b/site/three-little-pigs/img/pig3/pose/arm2.webp
new file mode 100644
index 0000000..93da7ba
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm2.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm3.webp b/site/three-little-pigs/img/pig3/pose/arm3.webp
new file mode 100644
index 0000000..cf75106
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm3.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm4.webp b/site/three-little-pigs/img/pig3/pose/arm4.webp
new file mode 100644
index 0000000..00d2e67
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm4.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm5.webp b/site/three-little-pigs/img/pig3/pose/arm5.webp
new file mode 100644
index 0000000..4f59187
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm5.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/arm6.webp b/site/three-little-pigs/img/pig3/pose/arm6.webp
new file mode 100644
index 0000000..9045ff5
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/arm6.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/faceplate.webp b/site/three-little-pigs/img/pig3/pose/faceplate.webp
new file mode 100644
index 0000000..76c1941
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/faceplate.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/fig0.webp b/site/three-little-pigs/img/pig3/pose/fig0.webp
new file mode 100644
index 0000000..3ac0eff
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/fig0.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/fig1.webp b/site/three-little-pigs/img/pig3/pose/fig1.webp
new file mode 100644
index 0000000..c79799e
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/fig1.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/fig2.webp b/site/three-little-pigs/img/pig3/pose/fig2.webp
new file mode 100644
index 0000000..a9bb0f4
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/fig2.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/fig3.webp b/site/three-little-pigs/img/pig3/pose/fig3.webp
new file mode 100644
index 0000000..56923c4
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/fig3.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/fig4.webp b/site/three-little-pigs/img/pig3/pose/fig4.webp
new file mode 100644
index 0000000..71727bd
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/fig4.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/mouth1.webp b/site/three-little-pigs/img/pig3/pose/mouth1.webp
new file mode 100644
index 0000000..dc3d783
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/mouth1.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/mouth2.webp b/site/three-little-pigs/img/pig3/pose/mouth2.webp
new file mode 100644
index 0000000..1d4881d
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/mouth2.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/mouth3.webp b/site/three-little-pigs/img/pig3/pose/mouth3.webp
new file mode 100644
index 0000000..2986a82
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/mouth3.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/mouth4.webp b/site/three-little-pigs/img/pig3/pose/mouth4.webp
new file mode 100644
index 0000000..db3ca5e
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/mouth4.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/pose.js b/site/three-little-pigs/img/pig3/pose/pose.js
new file mode 100644
index 0000000..36fbd45
--- /dev/null
+++ b/site/three-little-pigs/img/pig3/pose/pose.js
@@ -0,0 +1 @@
+window.POSES = window.POSES || {}; POSES.pig3 = {"size": [1024, 1536], "parts": {"fig0": [218, 29, 574, 1459], "fig1": [200, 29, 615, 1441], "fig2": [218, 29, 574, 1459], "fig3": [218, 29, 586, 1449], "fig4": [218, 29, 574, 1460], "run1": [12, 109, 999, 1248], "run2": [28, 208, 968, 1112], "run3": [87, 101, 842, 1138], "run4": [14, 168, 988, 1178], "arm0": [279, 578, 215, 505], "arm1": [340, 553, 317, 444], "arm2": [250, 576, 228, 429], "arm3": [99, 317, 458, 420], "arm4": [336, 552, 478, 344], "arm5": [343, 552, 553, 531], "arm6": [278, 209, 278, 514], "mouth1": [570, 422, 191, 120], "mouth2": [559, 404, 198, 179], "mouth3": [538, 392, 227, 209], "mouth4": [540, 407, 217, 130], "faceplate": [315, 114, 456, 1357]}, "legs": 4, "arms": 7, "mouths": 4, "wholes": ["run1", "run2", "run3", "run4"], "ground": 1487};
diff --git a/site/three-little-pigs/img/pig3/pose/run1.webp b/site/three-little-pigs/img/pig3/pose/run1.webp
new file mode 100644
index 0000000..f12ed63
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/run1.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/run2.webp b/site/three-little-pigs/img/pig3/pose/run2.webp
new file mode 100644
index 0000000..162baf8
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/run2.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/run3.webp b/site/three-little-pigs/img/pig3/pose/run3.webp
new file mode 100644
index 0000000..b83a8da
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/run3.webp differ
diff --git a/site/three-little-pigs/img/pig3/pose/run4.webp b/site/three-little-pigs/img/pig3/pose/run4.webp
new file mode 100644
index 0000000..f275e25
Binary files /dev/null and b/site/three-little-pigs/img/pig3/pose/run4.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/body.webp b/site/three-little-pigs/img/pig3/rig/body.webp
new file mode 100644
index 0000000..ecbf8a0
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/body.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/eye0.webp b/site/three-little-pigs/img/pig3/rig/eye0.webp
new file mode 100644
index 0000000..4ad5613
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/eye0.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/eye1.webp b/site/three-little-pigs/img/pig3/rig/eye1.webp
new file mode 100644
index 0000000..87ef3e2
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/eye1.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/foot0.webp b/site/three-little-pigs/img/pig3/rig/foot0.webp
new file mode 100644
index 0000000..a80fa39
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/foot0.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/foot1.webp b/site/three-little-pigs/img/pig3/rig/foot1.webp
new file mode 100644
index 0000000..406e32f
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/foot1.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/hand.webp b/site/three-little-pigs/img/pig3/rig/hand.webp
new file mode 100644
index 0000000..b2c60f4
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/hand.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line0.webp b/site/three-little-pigs/img/pig3/rig/line0.webp
new file mode 100644
index 0000000..fd080b7
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line0.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line1.webp b/site/three-little-pigs/img/pig3/rig/line1.webp
new file mode 100644
index 0000000..9136344
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line1.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line2.webp b/site/three-little-pigs/img/pig3/rig/line2.webp
new file mode 100644
index 0000000..4a4d26b
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line2.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line3.webp b/site/three-little-pigs/img/pig3/rig/line3.webp
new file mode 100644
index 0000000..3eca645
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line3.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line4.webp b/site/three-little-pigs/img/pig3/rig/line4.webp
new file mode 100644
index 0000000..56cae44
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line4.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line5.webp b/site/three-little-pigs/img/pig3/rig/line5.webp
new file mode 100644
index 0000000..5a82094
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line5.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line6.webp b/site/three-little-pigs/img/pig3/rig/line6.webp
new file mode 100644
index 0000000..95dc731
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line6.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/line7.webp b/site/three-little-pigs/img/pig3/rig/line7.webp
new file mode 100644
index 0000000..80a4eb5
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/line7.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/pupil0.webp b/site/three-little-pigs/img/pig3/rig/pupil0.webp
new file mode 100644
index 0000000..a369883
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/pupil0.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/pupil1.webp b/site/three-little-pigs/img/pig3/rig/pupil1.webp
new file mode 100644
index 0000000..1e73b11
Binary files /dev/null and b/site/three-little-pigs/img/pig3/rig/pupil1.webp differ
diff --git a/site/three-little-pigs/img/pig3/rig/rig.js b/site/three-little-pigs/img/pig3/rig/rig.js
new file mode 100644
index 0000000..758fda5
--- /dev/null
+++ b/site/three-little-pigs/img/pig3/rig/rig.js
@@ -0,0 +1 @@
+window.RIGS = window.RIGS || {}; RIGS.pig3 = {"size": [1024, 1536], "lid": "#fea496", "brows": ["line0", "line1", "line2", "line3", "line4"], "marks": ["line5", "line6"], "mouth": "line7", "legs": [{"part": "foot0", "hip": [403, 1300], "ankle": [377, 1372], "width": 137}, {"part": "foot1", "hip": [591, 1300], "ankle": [620, 1372], "width": 127}], "legSkin": "#fca494", "ground": 1487, "shoulder": [373, 603], "root": [373, 603], "wrist": [347, 936], "elbow": [329, 753], "armWidth": 58, "skin": "#fcac9c", "parts": {"eye0": [526, 257, 114, 147], "pupil0": [569, 264, 65, 129], "eye1": [663, 252, 52, 119], "pupil1": [674, 258, 32, 106], "line0": [620, 110, 25, 11], "line1": [530, 189, 75, 60], "line2": [660, 201, 18, 27], "line3": [345, 276, 35, 36], "line4": [325, 270, 65, 50], "line5": [715, 345, 14, 16], "line6": [695, 374, 14, 72], "line7": [568, 435, 163, 48], "foot0": [272, 1362, 177, 126], "foot1": [528, 1362, 232, 109], "body": [218, 29, 574, 1279], "hand": [279, 924, 146, 157]}, "eyes": ["eye0", "eye1"]};
diff --git a/site/three-little-pigs/img/props/bindle.webp b/site/three-little-pigs/img/props/bindle.webp
new file mode 100644
index 0000000..f2d4ab4
Binary files /dev/null and b/site/three-little-pigs/img/props/bindle.webp differ
diff --git a/site/three-little-pigs/img/props/brick_house.webp b/site/three-little-pigs/img/props/brick_house.webp
new file mode 100644
index 0000000..847711e
Binary files /dev/null and b/site/three-little-pigs/img/props/brick_house.webp differ
diff --git a/site/three-little-pigs/img/props/brick_house_1.webp b/site/three-little-pigs/img/props/brick_house_1.webp
new file mode 100644
index 0000000..236aba0
Binary files /dev/null and b/site/three-little-pigs/img/props/brick_house_1.webp differ
diff --git a/site/three-little-pigs/img/props/brick_house_2.webp b/site/three-little-pigs/img/props/brick_house_2.webp
new file mode 100644
index 0000000..8063bd1
Binary files /dev/null and b/site/three-little-pigs/img/props/brick_house_2.webp differ
diff --git a/site/three-little-pigs/img/props/brick_house_3.webp b/site/three-little-pigs/img/props/brick_house_3.webp
new file mode 100644
index 0000000..de5d7d1
Binary files /dev/null and b/site/three-little-pigs/img/props/brick_house_3.webp differ
diff --git a/site/three-little-pigs/img/props/brickpile.webp b/site/three-little-pigs/img/props/brickpile.webp
new file mode 100644
index 0000000..4401ff7
Binary files /dev/null and b/site/three-little-pigs/img/props/brickpile.webp differ
diff --git a/site/three-little-pigs/img/props/bundle.webp b/site/three-little-pigs/img/props/bundle.webp
new file mode 100644
index 0000000..05d6004
Binary files /dev/null and b/site/three-little-pigs/img/props/bundle.webp differ
diff --git a/site/three-little-pigs/img/props/haystack.webp b/site/three-little-pigs/img/props/haystack.webp
new file mode 100644
index 0000000..73d6397
Binary files /dev/null and b/site/three-little-pigs/img/props/haystack.webp differ
diff --git a/site/three-little-pigs/img/props/ladder.webp b/site/three-little-pigs/img/props/ladder.webp
new file mode 100644
index 0000000..1e07812
Binary files /dev/null and b/site/three-little-pigs/img/props/ladder.webp differ
diff --git a/site/three-little-pigs/img/props/pot.webp b/site/three-little-pigs/img/props/pot.webp
new file mode 100644
index 0000000..5605b50
Binary files /dev/null and b/site/three-little-pigs/img/props/pot.webp differ
diff --git a/site/three-little-pigs/img/props/stick_house.webp b/site/three-little-pigs/img/props/stick_house.webp
new file mode 100644
index 0000000..4f8435b
Binary files /dev/null and b/site/three-little-pigs/img/props/stick_house.webp differ
diff --git a/site/three-little-pigs/img/props/stick_house_1.webp b/site/three-little-pigs/img/props/stick_house_1.webp
new file mode 100644
index 0000000..11a16f2
Binary files /dev/null and b/site/three-little-pigs/img/props/stick_house_1.webp differ
diff --git a/site/three-little-pigs/img/props/stick_house_2.webp b/site/three-little-pigs/img/props/stick_house_2.webp
new file mode 100644
index 0000000..20ced25
Binary files /dev/null and b/site/three-little-pigs/img/props/stick_house_2.webp differ
diff --git a/site/three-little-pigs/img/props/stick_house_3.webp b/site/three-little-pigs/img/props/stick_house_3.webp
new file mode 100644
index 0000000..7d67b19
Binary files /dev/null and b/site/three-little-pigs/img/props/stick_house_3.webp differ
diff --git a/site/three-little-pigs/img/props/stickpile.webp b/site/three-little-pigs/img/props/stickpile.webp
new file mode 100644
index 0000000..c26fa59
Binary files /dev/null and b/site/three-little-pigs/img/props/stickpile.webp differ
diff --git a/site/three-little-pigs/img/props/straw_house.webp b/site/three-little-pigs/img/props/straw_house.webp
new file mode 100644
index 0000000..8a16ef4
Binary files /dev/null and b/site/three-little-pigs/img/props/straw_house.webp differ
diff --git a/site/three-little-pigs/img/props/straw_house_1.webp b/site/three-little-pigs/img/props/straw_house_1.webp
new file mode 100644
index 0000000..f1e2fb6
Binary files /dev/null and b/site/three-little-pigs/img/props/straw_house_1.webp differ
diff --git a/site/three-little-pigs/img/props/straw_house_2.webp b/site/three-little-pigs/img/props/straw_house_2.webp
new file mode 100644
index 0000000..5b70d72
Binary files /dev/null and b/site/three-little-pigs/img/props/straw_house_2.webp differ
diff --git a/site/three-little-pigs/img/props/straw_house_3.webp b/site/three-little-pigs/img/props/straw_house_3.webp
new file mode 100644
index 0000000..99388e4
Binary files /dev/null and b/site/three-little-pigs/img/props/straw_house_3.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/arm0.webp b/site/three-little-pigs/img/wolf/pose/arm0.webp
new file mode 100644
index 0000000..03fcfa0
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/arm0.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/arm1.webp b/site/three-little-pigs/img/wolf/pose/arm1.webp
new file mode 100644
index 0000000..68abe77
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/arm1.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/arm2.webp b/site/three-little-pigs/img/wolf/pose/arm2.webp
new file mode 100644
index 0000000..f883bf2
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/arm2.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/arm3.webp b/site/three-little-pigs/img/wolf/pose/arm3.webp
new file mode 100644
index 0000000..071eae8
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/arm3.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/blow.webp b/site/three-little-pigs/img/wolf/pose/blow.webp
new file mode 100644
index 0000000..60f7a2a
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/blow.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/faceplate.webp b/site/three-little-pigs/img/wolf/pose/faceplate.webp
new file mode 100644
index 0000000..29dd87c
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/faceplate.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/fig0.webp b/site/three-little-pigs/img/wolf/pose/fig0.webp
new file mode 100644
index 0000000..d7da408
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/fig0.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/fig1.webp b/site/three-little-pigs/img/wolf/pose/fig1.webp
new file mode 100644
index 0000000..900c98a
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/fig1.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/fig2.webp b/site/three-little-pigs/img/wolf/pose/fig2.webp
new file mode 100644
index 0000000..deb1a88
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/fig2.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/fig3.webp b/site/three-little-pigs/img/wolf/pose/fig3.webp
new file mode 100644
index 0000000..dabad00
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/fig3.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/fig4.webp b/site/three-little-pigs/img/wolf/pose/fig4.webp
new file mode 100644
index 0000000..808855b
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/fig4.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/flop.webp b/site/three-little-pigs/img/wolf/pose/flop.webp
new file mode 100644
index 0000000..515308d
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/flop.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/grin.webp b/site/three-little-pigs/img/wolf/pose/grin.webp
new file mode 100644
index 0000000..f79198a
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/grin.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/howl.webp b/site/three-little-pigs/img/wolf/pose/howl.webp
new file mode 100644
index 0000000..c29a156
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/howl.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/inhale.webp b/site/three-little-pigs/img/wolf/pose/inhale.webp
new file mode 100644
index 0000000..0cac982
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/inhale.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/mouth1.webp b/site/three-little-pigs/img/wolf/pose/mouth1.webp
new file mode 100644
index 0000000..1aab0e7
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/mouth1.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/mouth2.webp b/site/three-little-pigs/img/wolf/pose/mouth2.webp
new file mode 100644
index 0000000..25d0b0a
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/mouth2.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/mouth3.webp b/site/three-little-pigs/img/wolf/pose/mouth3.webp
new file mode 100644
index 0000000..8c0c054
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/mouth3.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/mouth4.webp b/site/three-little-pigs/img/wolf/pose/mouth4.webp
new file mode 100644
index 0000000..52a2ac3
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/mouth4.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/pose.js b/site/three-little-pigs/img/wolf/pose/pose.js
new file mode 100644
index 0000000..a5e4e23
--- /dev/null
+++ b/site/three-little-pigs/img/wolf/pose/pose.js
@@ -0,0 +1 @@
+window.POSES = window.POSES || {}; POSES.wolf = {"size": [1024, 1536], "parts": {"fig0": [140, 26, 696, 1472], "fig1": [141, 25, 832, 1460], "fig2": [141, 25, 695, 1471], "fig3": [140, 25, 805, 1457], "fig4": [140, 25, 779, 1473], "blow": [19, 178, 998, 1272], "flop": [21, 323, 986, 1059], "grin": [126, 65, 803, 1433], "howl": [72, 47, 742, 1426], "inhale": [62, 24, 819, 1474], "sniff": [141, 41, 637, 1457], "tip1": [75, 54, 847, 1434], "tip2": [53, 58, 879, 1425], "arm0": [387, 454, 181, 653], "arm1": [407, 637, 312, 529], "arm2": [344, 557, 189, 570], "arm3": [395, 455, 603, 715], "mouth1": [550, 266, 232, 169], "mouth2": [549, 259, 260, 212], "mouth3": [505, 259, 328, 264], "mouth4": [548, 259, 290, 176], "faceplate": [143, 28, 693, 1222]}, "legs": 4, "arms": 4, "mouths": 4, "wholes": ["blow", "flop", "grin", "howl", "inhale", "sniff", "tip1", "tip2"], "ground": 1497};
diff --git a/site/three-little-pigs/img/wolf/pose/sniff.webp b/site/three-little-pigs/img/wolf/pose/sniff.webp
new file mode 100644
index 0000000..b749156
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/sniff.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/tip1.webp b/site/three-little-pigs/img/wolf/pose/tip1.webp
new file mode 100644
index 0000000..e252ff4
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/tip1.webp differ
diff --git a/site/three-little-pigs/img/wolf/pose/tip2.webp b/site/three-little-pigs/img/wolf/pose/tip2.webp
new file mode 100644
index 0000000..1d0d21c
Binary files /dev/null and b/site/three-little-pigs/img/wolf/pose/tip2.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/body.webp b/site/three-little-pigs/img/wolf/rig/body.webp
new file mode 100644
index 0000000..6b1b72e
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/body.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/eye0.webp b/site/three-little-pigs/img/wolf/rig/eye0.webp
new file mode 100644
index 0000000..6fd2d05
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/eye0.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/foot0.webp b/site/three-little-pigs/img/wolf/rig/foot0.webp
new file mode 100644
index 0000000..70e873f
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/foot0.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/foot1.webp b/site/three-little-pigs/img/wolf/rig/foot1.webp
new file mode 100644
index 0000000..57b7646
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/foot1.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/hand.webp b/site/three-little-pigs/img/wolf/rig/hand.webp
new file mode 100644
index 0000000..30daf56
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/hand.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/line0.webp b/site/three-little-pigs/img/wolf/rig/line0.webp
new file mode 100644
index 0000000..70473b0
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/line0.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/line1.webp b/site/three-little-pigs/img/wolf/rig/line1.webp
new file mode 100644
index 0000000..0f680cb
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/line1.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/line2.webp b/site/three-little-pigs/img/wolf/rig/line2.webp
new file mode 100644
index 0000000..644802b
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/line2.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/line3.webp b/site/three-little-pigs/img/wolf/rig/line3.webp
new file mode 100644
index 0000000..f194d4e
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/line3.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/line4.webp b/site/three-little-pigs/img/wolf/rig/line4.webp
new file mode 100644
index 0000000..039f293
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/line4.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/line5.webp b/site/three-little-pigs/img/wolf/rig/line5.webp
new file mode 100644
index 0000000..e40c2a5
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/line5.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/pupil0.webp b/site/three-little-pigs/img/wolf/rig/pupil0.webp
new file mode 100644
index 0000000..86035c7
Binary files /dev/null and b/site/three-little-pigs/img/wolf/rig/pupil0.webp differ
diff --git a/site/three-little-pigs/img/wolf/rig/rig.js b/site/three-little-pigs/img/wolf/rig/rig.js
new file mode 100644
index 0000000..64264ff
--- /dev/null
+++ b/site/three-little-pigs/img/wolf/rig/rig.js
@@ -0,0 +1 @@
+window.RIGS = window.RIGS || {}; RIGS.wolf = {"size": [1024, 1536], "lid": "#565857", "brows": ["line0", "line1"], "marks": ["line3", "line4", "line5"], "mouth": "line2", "legs": [{"part": "foot0", "hip": [502, 1150], "ankle": [464, 1385], "width": 118}, {"part": "foot1", "hip": [607, 1150], "ankle": [659, 1385], "width": 92}], "legSkin": "#545454", "ground": 1497, "shoulder": [467, 607], "root": [467, 607], "wrist": [477, 1008], "elbow": [460, 791], "armWidth": 102, "skin": "#5c5c5c", "parts": {"eye0": [554, 139, 134, 138], "pupil0": [570, 145, 94, 104], "line0": [416, 38, 9, 68], "line1": [633, 140, 24, 23], "line2": [558, 282, 241, 98], "line3": [511, 362, 14, 12], "line4": [577, 377, 45, 12], "line5": [626, 381, 57, 22], "foot0": [330, 1375, 232, 123], "foot1": [562, 1375, 214, 111], "body": [141, 25, 695, 1225], "hand": [414, 996, 132, 169]}, "eyes": ["eye0"]};
diff --git a/site/three-little-pigs/img/woods/front.webp b/site/three-little-pigs/img/woods/front.webp
new file mode 100644
index 0000000..b7c9c0b
Binary files /dev/null and b/site/three-little-pigs/img/woods/front.webp differ
diff --git a/site/three-little-pigs/img/woods/mid-soft.webp b/site/three-little-pigs/img/woods/mid-soft.webp
new file mode 100644
index 0000000..3de1729
Binary files /dev/null and b/site/three-little-pigs/img/woods/mid-soft.webp differ
diff --git a/site/three-little-pigs/img/woods/mid.webp b/site/three-little-pigs/img/woods/mid.webp
new file mode 100644
index 0000000..e652cc1
Binary files /dev/null and b/site/three-little-pigs/img/woods/mid.webp differ
diff --git a/site/three-little-pigs/img/woods/sky-soft.webp b/site/three-little-pigs/img/woods/sky-soft.webp
new file mode 100644
index 0000000..ce4797e
Binary files /dev/null and b/site/three-little-pigs/img/woods/sky-soft.webp differ
diff --git a/site/three-little-pigs/img/woods/sky.webp b/site/three-little-pigs/img/woods/sky.webp
new file mode 100644
index 0000000..b56ba9e
Binary files /dev/null and b/site/three-little-pigs/img/woods/sky.webp differ
diff --git a/site/three-little-pigs/index.html b/site/three-little-pigs/index.html
new file mode 100644
index 0000000..2f23d38
--- /dev/null
+++ b/site/three-little-pigs/index.html
@@ -0,0 +1,137 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>The Three Little Pigs — how it was made</title>
+<meta name="description" content="An experiment: a picture book animated from a story alone, with an image model for the art and code for the motion. What we tried, what worked, and why it stayed out of the Skill.">
+<style>
+ :root { --ink: #2f2418; --soft: #6b5a46; --paper: #fbf5e8; --card: #fffaf0; --line: #e4d6bb; --accent: #b4532a; --ui: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif; --serif: "Iowan Old Style", Palatino, Georgia, serif; color-scheme: light; }
+ * { box-sizing: border-box; }
+ body { margin: 0; background: var(--paper); color: var(--ink); font: 18px/1.65 var(--ui); }
+ a { color: var(--accent); }
+ header.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 40px; align-items: center; max-width: 1180px; margin: 0 auto; padding: 48px 24px 24px; }
+ .hero img { width: 100%; border-radius: 10px; box-shadow: 0 14px 40px #4a33182e; }
+ .back { display: inline-block; margin-bottom: 18px; font-size: 15px; color: var(--soft); text-decoration: none; }
+ h1 { margin: 0 0 8px; font: 700 clamp(34px, 4.6vw, 56px)/1.05 var(--serif); }
+ .tag { display: inline-block; margin-bottom: 18px; padding: 2px 12px; border: 1.5px solid var(--accent); border-radius: 99px; color: var(--accent); font-size: 14px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
+ .lede { font-size: 20px; color: #4a3b2a; }
+ .watch { display: inline-flex; align-items: center; gap: 10px; margin-top: 10px; padding: 14px 26px; border-radius: 99px; background: var(--ink); color: #fff6e0; font-weight: 600; text-decoration: none; }
+ .watch:hover { background: #4a3826; }
+ .watch small { opacity: .75; font-weight: 500; }
+ main { max-width: 900px; margin: 0 auto; padding: 8px 24px 80px; }
+ h2 { margin: 64px 0 8px; font: 700 32px/1.2 var(--serif); }
+ h3 { margin: 32px 0 4px; font: 700 21px/1.3 var(--ui); }
+ figure { margin: 18px 0 26px; }
+ figure img { display: block; width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
+ figcaption { margin-top: 8px; font-size: 15px; color: var(--soft); }
+ .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
+ .stills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
+ .stills img { width: 100%; border-radius: 6px; display: block; }
+ .verdict { margin: 18px 0; padding: 4px 22px; border-left: 4px solid var(--accent); background: var(--card); border-radius: 0 8px 8px 0; }
+ .numbers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
+ .numbers div { padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; text-align: center; }
+ .numbers b { display: block; font: 700 28px/1.1 var(--serif); }
+ .numbers span { font-size: 14px; color: var(--soft); }
+ ol.tries { padding-left: 22px; }
+ code { font-size: .88em; background: #f1e6cf; padding: 1px 5px; border-radius: 4px; }
+ footer { max-width: 900px; margin: 0 auto; padding: 0 24px 60px; color: var(--soft); font-size: 15px; }
+ @media (max-width: 760px) {
+ header.hero { grid-template-columns: 1fr; padding-top: 28px; }
+ .pair, .numbers { grid-template-columns: 1fr 1fr; }
+ .stills { grid-template-columns: 1fr 1fr; }
+ }
+</style>
+</head>
+<body>
+<header class="hero">
+ <img src="making/cover.webp" alt="The Three Little Pigs: the wolf blows at the straw house while the first little pig peeks out of the window.">
+ <div>
+ <a class="back" href="../">← Back to the bookshelf</a><br>
+ <span class="tag">An experiment</span>
+ <h1>The Three Little Pigs</h1>
+ <p class="lede">The other books on this shelf start from a textbook and draw every picture in code. This one started from nothing but the story. An image model painted the characters and places, and code made them move, speak and dance. It works, and it's fun to watch. But the method turned out not good enough to become part of the Papermorph Skill. Here is how it was made, and why.</p>
+ <a class="watch" href="ch01/">▶ Watch the film <small>4½ minutes · narrated · music</small></a>
+ </div>
+</header>
+
+<main>
+ <div class="stills">
+ <img src="making/still-1.webp" alt="Mother Pig waves goodbye with her handkerchief." loading="lazy">
+ <img src="making/still-2.webp" alt="The first pig carries straw to her half-built house." loading="lazy">
+ <img src="making/still-5.webp" alt="The wolf licks his lips." loading="lazy">
+ <img src="making/still-6.webp" alt="The straw house flies apart." loading="lazy">
+ <img src="making/still-8.webp" alt="Three pigs in the windows of the brick house." loading="lazy">
+ <img src="making/still-11.webp" alt="Happily ever after." loading="lazy">
+ </div>
+
+ <h2>What we set out to do</h2>
+ <p>Take a story with no book and no pictures, and make it an animated film you can pause, scrub and read along with. The pages are the same kind as the rest of the shelf: static web pages, one SVG stage, narration clips driving every move. What was new: the art came from an image model (OpenAI's gpt-image through OpenRouter), and the goal was for it to feel like a TV cartoon, not a slideshow.</p>
+ <figure><img src="making/styles.webp" alt="The same scene in three styles: gouache, cut paper, TV cartoon." loading="lazy"><figcaption>Style tests, one scene in three looks. We chose the TV cartoon (right).</figcaption></figure>
+
+ <h2>Four tries at a character</h2>
+ <ol class="tries">
+ <li><b>Rotating painted parts.</b> We cut the wolf into image pieces and rotated them at the joints. Too stiff: it read as a paper puppet, with seams at every knee.</li>
+ <li><b>Painted body, code-drawn limbs.</b> Arms and legs became bendable SVG curves with feet planted by inverse kinematics. Much livelier, but the first scene, shot from one fixed camera, still felt like a slideshow.</li>
+ <li><b>Separately painted parts.</b> Heads, bodies, sleeves and hands from separate generations never lined up: arms came out beside the sleeve, collars doubled, hands went missing.</li>
+ <li><b>Characters drawn entirely in code.</b> They lined up perfectly, but looked far too crude next to the painted world.</li>
+ </ol>
+ <div class="pair">
+ <figure><img src="making/try1-rigid.webp" alt="The wolf assembled from rigid painted parts." loading="lazy"><figcaption>Try 1: rigid parts.</figcaption></figure>
+ <figure><img src="making/try2-hose.webp" alt="The wolf with bendable code-drawn limbs." loading="lazy"><figcaption>Try 2: bendable limbs.</figcaption></figure>
+ <figure><img src="making/try3-sheets.webp" alt="Mother Pig's arm emerging beside her sleeve." loading="lazy"><figcaption>Try 3: parts that don't fit.</figcaption></figure>
+ <figure><img src="making/try4-handdrawn.webp" alt="Mother Pig drawn in code, crude." loading="lazy"><figcaption>Try 4: drawn in code.</figcaption></figure>
+ </div>
+
+ <h2>What finally worked</h2>
+ <h3>One picture, edited, never redrawn</h3>
+ <p>Each character got one large picture. Every other version was an <em>edit</em> of that same picture: without the near arm, without eyes and mouth, with the legs in each walking pose, with each mouth shape. Because the edits change only a few percent of the pixels, they line up exactly, and a script can cut parts out wherever two pictures differ.</p>
+ <figure><img src="making/edits-mother.webp" alt="Mother Pig three times: complete, without her arm, without her face." loading="lazy"><figcaption>Mother Pig as drawn, without her arm (the dress behind it painted in), and without her face.</figcaption></figure>
+ <h3>Vectorized, then swapped like a TV cartoon</h3>
+ <p>The cut parts were traced into vector shapes, so close-ups stay sharp. Then they were baked back to images, because live tracing was too slow. Movement comes from swapping drawings the way TV cartoons do. Legs walk on four drawings, each held for a few frames. Arms swap between drawn gestures. Big actions, like sleeping or running, are whole drawings of their own. Code adds the rest: body bounce, blinks, eye movement and the camera.</p>
+ <figure><img src="making/vectorize.webp" alt="Mother Pig painted, vectorized, and zoomed in three times." loading="lazy"><figcaption>Painted, vectorized, and the vector zoomed in three times.</figcaption></figure>
+ <figure><img src="making/walk-wolf.webp" alt="Four walking drawings of the wolf." loading="lazy"><figcaption>The wolf's walk: four drawings, all edits of the same picture.</figcaption></figure>
+ <figure><img src="making/whole-poses.webp" alt="The first pig carrying, tossing, napping, laughing and running." loading="lazy"><figcaption>Whole-body drawings for actions that limbs alone can't do.</figcaption></figure>
+ <figure><img src="making/wolf-poses.webp" alt="The wolf sniffing, grinning, inhaling, blowing, tiptoeing, collapsing and howling." loading="lazy"><figcaption>Every wolf action in the film is one of these.</figcaption></figure>
+ <h3>Faces that talk</h3>
+ <p>Each face has a featureless "faceplate" laid over it. On top go moving eyes, lids that slide down to blink, and brows. Mouth shapes are painted by the model, and each one is timed to a word from the voice track.</p>
+ <figure><img src="making/mouths-wolf.webp" alt="The wolf's mouth: closed, and four open shapes." loading="lazy"><figcaption>The wolf's mouths. Each is a block of the muzzle with a soft edge, so the jaw can really open.</figcaption></figure>
+ <figure><img src="making/mouths-mother.webp" alt="Mother Pig's mouth: closed and four shapes." loading="lazy"></figure>
+
+ <h2>Places, houses and the camera</h2>
+ <p>Backgrounds were painted, then separated into layers: sky, hills, ground, buildings, and flowers close to the camera. Layers slide past each other as the camera moves, and the background softens in close-ups. The houses come in three aligned stages, so building them is a series of thumps, not a wipe. The camera cuts on words: a close-up for whoever speaks, a follow shot when someone runs. Silences were spliced into the narration to give the building and the huffing room to happen.</p>
+ <figure><img src="making/layers.webp" alt="The cottage scene as five separate layers." loading="lazy"><figcaption>Mother Pig's cottage in five layers.</figcaption></figure>
+ <figure><img src="making/houses.webp" alt="Each house in three construction stages." loading="lazy"><figcaption>Three houses, three stages each.</figcaption></figure>
+ <p>The voices are free text-to-speech, one voice per character; when all three pigs answer the wolf, three voices are stretched to the same length and mixed into a chorus. The music, four instrumental pieces, was generated with Google's Lyria and crossfades between parts of the story, dipping under the voices.</p>
+
+ <h2>What kept going wrong</h2>
+ <p>Almost every fix came from a problem spotted while watching, and many of them were specific to one character.</p>
+ <figure><img src="making/bugs-hands.webp" alt="A hollow arm, a missing hand, and ghost legs." loading="lazy"><figcaption>A see-through arm (fur the same colour as the body behind it fooled the cutting), a missing hand, ghost legs from blending two drawings.</figcaption></figure>
+ <ul>
+ <li>The second pig wore no trousers in his first design. The image model's safety filter kept refusing his pictures. Another model redrew each one slightly differently, so his body flickered as he walked. In the end he got shorts and was redrawn from scratch.</li>
+ <li>A held object belongs to one drawing: the third pig carried the pot while still holding a brick, because his carrying arm was the brick-carrying drawing.</li>
+ <li>Anything without its own drawing slides instead of moving, like the wolf running away on a single pose, until we gave it the walking legs.</li>
+ <li>Quality "high" cost five times "medium" and, once traced, looked the same. We found out late.</li>
+ </ul>
+ <figure><img src="making/medium-vs-high.webp" alt="Medium and high quality side by side, zoomed in." loading="lazy"><figcaption>Medium (left) and high (right), vectorized and zoomed in three times.</figcaption></figure>
+
+ <h2>The numbers</h2>
+ <div class="numbers">
+ <div><b>~4½ min</b><span>11 scenes</span></div>
+ <div><b>~220</b><span>generated pictures</span></div>
+ <div><b>$10.7</b><span>pictures and music</span></div>
+ <div><b>1 day</b><span>of making and fixing</span></div>
+ </div>
+
+ <h2>Why it isn't in the Skill</h2>
+ <div class="verdict">
+ <p><b>Every new action needs new drawings.</b> In a book drawn in code, a new movement is a few lines. Here, picking up a pot, climbing a ladder or running away each means another round of edits per character, plus cutting, checking and fixing. The film can only do what was drawn, and you notice the gaps.</p>
+ <p><b>Consistency has to be fought for, character by character.</b> Hips, collars, sleeves, fur and mouths each needed their own handling. A safety filter or a second model could break a character halfway through.</p>
+ <p><b>It doesn't get cheaper with practice.</b> The first scenes were polished. The later ones, made faster, came out rough. A Skill should make the hundredth chapter as good as the first. This method makes each one cost about the same, in money and attention.</p>
+ </div>
+ <p>So the story is finished and stays here, as a record of a path we walked and wouldn't recommend as it stands. What would change our mind: image models that can hand back a character as a real, bendable rig, or video models that keep a character consistent and can be steered word by word.</p>
+ <p><a class="watch" href="ch01/">▶ Watch the film</a></p>
+</main>
+<footer>Story: the English folk tale, retold for this film (in this version nobody gets eaten). Pictures generated with OpenAI gpt-image and Google Gemini image models, music with Google Lyria, voices with Microsoft Edge text-to-speech. Part of <a href="../">Papermorph</a>.</footer>
+</body>
+</html>
diff --git a/site/three-little-pigs/lib/book.css b/site/three-little-pigs/lib/book.css
new file mode 100644
index 0000000..5d49bfb
--- /dev/null
+++ b/site/three-little-pigs/lib/book.css
@@ -0,0 +1,9 @@
+/* This book's own settings, imported by engine.css. The engine files next to this one are the same in every book
+ and are replaced when the engine is updated; this file is not.
+ Settings (uncomment to use):
+:root {
+ --math-font: "Avenir Next", Arial, sans-serif; face for numbers and formulas (default: a serif, see engine.js)
+ --progress-key: "progress"; localStorage key shared with the cover (default: one per book folder)
+}
+ Style overrides go here too. They come before the engine's rules, so make each selector more specific than the
+ engine's, e.g. ':root .card.band' for '.card.band'. */
diff --git a/site/three-little-pigs/lib/cast.js b/site/three-little-pigs/lib/cast.js
new file mode 100644
index 0000000..8b1c6d7
--- /dev/null
+++ b/site/three-little-pigs/lib/cast.js
@@ -0,0 +1,241 @@
+// The cast of The Three Little Pigs. Drawn parts (torso, heads, hands, feet, the wolf's tail) come from the image model;
+// limbs and the pigs' tails are SVG, so they bend. Every frame an actor is posed from a plain state object, so a
+// picture is a pure function of time. Coordinates of parts are pixels of their own images; everything else is in
+// actor units (stage pixels at scale 1), with the ground at y = 0 and the actor facing right.
+const CAST = (() => {
+ const head = (src, pivot, s) => ({ src, pivot, s });
+ // Each head drawing hangs from a pivot near the bottom of the drawing (measured from the images), so swapping
+ // drawings keeps the head on its neck. Mother's and the second pig's heads have their collars cut away: the
+ // collar belongs to the torso, which is drawn over an SVG neck.
+ const PIVOT = {
+ mother: [[132, 226], [129, 229], [126, 220], [131, 224], [134, 241]], pig2: [[147, 251], [142, 245], [151, 247], [145, 243], [145, 254]],
+ pig1: [[156, 269], [152, 261], [142, 253], [148, 261], [152, 259]], pig3: [[136, 261], [134, 260], [137, 261], [132, 259], [135, 261]],
+ };
+ const pig = (id, heads, hs) => Object.fromEntries(heads.map((n, i) => [n, head(`${id}/h${i + 1}`, PIVOT[id][i], hs)]));
+ // Torsos have no arms, sleeves or (with a neck) heads; a sleeve is its own piece, turning with the upper arm.
+ return {
+ mother: {
+ torso: { src: 'mother/body', s: .26, neck: [370, 52], shoulder: [300, 150], hipN: [440, 900], hipF: [350, 900] },
+ neck: { up: 20, w: 30 }, sleeve: { src: 'mother/sleeve', at: [140, 60], dir: 90, s: .2 }, // ends about halfway down the upper arm
+ heads: pig('mother', ['smile', 'call', 'worried', 'laugh', 'surprised'], .5),
+ // A face without features (face.png, same scale as the head drawings); eyes, brows and mouth are drawn on it.
+ face: { src: 'mother/face', pivot: [138, 216], eyes: [[163, 121, 17, 22], [213, 104, 8, 17]], brows: [[138, 90, 176, 84], [204, 79, 222, 77]], lashes: true, mouth: [196, 182, 72] },
+ leg: [30, 28, 26], arm: [80, 52, 22], skin: '#f6a99a',
+ hand: { src: 'mother/hand', at: [65, 20], dir: 90, s: .2 }, fist: { src: 'mother/fist', at: [70, 20], dir: 90, s: .2 },
+ foot: { src: 'mother/foot', at: [64, 110], h: 249, s: .2 },
+ },
+ pig1: {
+ torso: { src: 'pig1/body', s: .195, neck: [363, 40], shoulder: [332, 120], hipN: [430, 830], hipF: [350, 830], tail: [150, 600] },
+ sleeve: { src: 'pig1/sleeve', at: [100, 40], dir: 90, s: .195 },
+ heads: pig('pig1', ['happy', 'scared', 'sleepy', 'surprised', 'laugh'], .48),
+ leg: [26, 26, 26], arm: [42, 38, 24], skin: '#f6a99a',
+ hand: { src: 'pig1/hand', at: [80, 200], dir: 90, s: .17 }, fist: { src: 'pig1/fist', at: [78, 170], dir: 90, s: .17 },
+ foot: { src: 'pig1/foot', at: [95, 200], h: 348, s: .2 },
+ },
+ pig2: {
+ torso: { src: 'pig2/body', s: .225, neck: [264, 48], shoulder: [208, 138], hipN: [416, 920], hipF: [250, 920], tail: [40, 760] },
+ neck: { up: 16, w: 30 }, sleeve: { src: 'pig2/sleeve', at: [110, 50], dir: 75, s: .225 },
+ heads: pig('pig2', ['grin', 'scared', 'laugh', 'whistle', 'shocked'], .44),
+ leg: [22, 22, 28], arm: [40, 36, 20], skin: '#f6a99a',
+ hand: { src: 'pig2/hand', at: [12, 140], dir: 0, s: .2 }, fist: { src: 'pig2/fist', at: [10, 110], dir: 0, s: .2 },
+ foot: { src: 'pig2/foot', at: [80, 200], h: 334, s: .22 },
+ },
+ pig3: {
+ torso: { src: 'pig3/body', s: .236, neck: [230, 35], shoulder: [115, 200], hipN: [380, 850], hipF: [150, 850], tail: [40, 700] },
+ sleeve: { src: 'pig3/sleeve', at: [110, 50], dir: 90, s: .236 },
+ heads: pig('pig3', ['determined', 'calm', 'wink', 'surprised', 'laugh'], .44),
+ leg: [22, 22, 28], arm: [40, 36, 22], skin: '#f6a99a',
+ hand: { src: 'pig3/hand', at: [8, 178], dir: 0, s: .2 }, fist: { src: 'pig3/fist', at: [8, 100], dir: 0, s: .2 },
+ foot: { src: 'pig3/foot', at: [70, 80], h: 218, s: .22 },
+ },
+ wolf: {
+ torso: { src: 'wolf/torso', s: .62, neck: [118, 22], shoulder: [118, 125], hipN: [128, 392], hipF: [108, 392] },
+ tailImg: { src: 'wolf/tail', at: [35, 360], root: [22, 85], s: .5 },
+ heads: Object.fromEntries(['neutral', 'sly', 'angry', 'puff', 'shock', 'howl', 'sniff', 'sneak', 'dizzy', 'lick'].map(n => [n, head(`wolf/${n}`, [92, 240], .8)])),
+ leg: [125, 103, 45], arm: [114, 100, 34], skin: '#4e4a4b',
+ fist: { src: 'wolf/fist', at: [58, 14], dir: 90, s: .44 }, foot: { src: 'wolf/foot', at: [46, 16], h: 94, s: .42 },
+ },
+ };
+})();
+
+// actor(parent, spec) builds the parts once; a.pose(state) places them. State (defaults in brackets):
+// x, ground: hip above this world point; k [1] scale; dir [1] facing right or -1; lean [0] degrees about the hip;
+// sy [1] squash of the torso (area kept); drop [0] hip lowered by (crouch); bob [0] extra hip drop;
+// feet: [[x, lift], [x, lift]] near and far, world x and lift above the ground (default: under the hip);
+// arms: [{ up, bend, hand }] near and far: degrees back from hanging, elbow bend (negative = forward), 'hand' or 'fist';
+// head: name [first], tilt [0] degrees, pop [1] scale, back [false] looking behind; tail [0] degrees of wag;
+// face (characters with a drawn face): mouth shape letter, smile, blink, gaze [x, y], raise, worry, wide.
+function actor(parent, spec) {
+ const NSV = 'http://www.w3.org/2000/svg', INK = '#151314';
+ const el = (tag, attrs, p) => { const e = document.createElementNS(NSV, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); p.appendChild(e); return e; };
+ const src = n => `../img/${n}.png`;
+ const T = spec.torso, R = Math.PI / 180;
+ const root = el('g', {}, parent);
+ const layer = () => el('g', {}, root);
+ const farArmG = layer(), farLegG = layer(), tailG = layer(), backG = layer(), nearLegG = layer(), neckG = layer(), torsoG = layer(), frontG = layer(), headG = layer(), nearArmG = layer();
+ farArmG.style.filter = farLegG.style.filter = 'brightness(.78)';
+ // The torso image, its pelvis (between the hip roots) at the hip origin.
+ const pelvis = [(T.hipN[0] + T.hipF[0]) / 2, (T.hipN[1] + T.hipF[1]) / 2];
+ const torsoImg = el('image', { href: src(T.src), transform: `scale(${T.s}) translate(${-pelvis[0]},${-pelvis[1]})` }, torsoG);
+ const headImg = el('image', {}, headG);
+ // The drawn face: eyes (white, pupil, highlight, a closed-lid line), brows and a mouth, in face-image pixels.
+ const F = spec.face, faceG = F && el('g', {}, headG), faceImg = F && el('image', { href: src(F.src) }, faceG);
+ const eyes = F ? F.eyes.map(([x, y, rx, ry], i) => {
+ const g = el('g', {}, faceG), open = el('g', {}, g);
+ el('ellipse', { rx, ry, fill: '#fff', stroke: INK, 'stroke-width': i ? 3.5 : 4.5 }, open);
+ const pupil = el('ellipse', { rx: rx * .5, ry: ry * .55, fill: INK }, open), shine = el('circle', { r: rx * .16, fill: '#fff' }, open);
+ const shut = el('path', { d: `M${-rx * 1.05} 0Q0 ${ry * .55} ${rx * 1.05} 0`, fill: 'none', stroke: INK, 'stroke-width': 4.5, 'stroke-linecap': 'round' }, g);
+ const lash = F.lashes && el('path', { d: `M${rx * .55} ${-ry * .8}l${rx * .45} ${-ry * .3}M${rx * .85} ${-ry * .45}l${rx * .5} ${-ry * .12}`, fill: 'none', stroke: INK, 'stroke-width': 3.5, 'stroke-linecap': 'round' }, open);
+ return { x, y, rx, ry, g, open, pupil, shine, shut };
+ }) : [];
+ const brows = F ? F.brows.map(() => el('path', { fill: 'none', stroke: INK, 'stroke-width': 7, 'stroke-linecap': 'round' }, faceG)) : [];
+ const mouthG = F && el('g', {}, faceG);
+ const mouthIn = F && el('path', { fill: '#7b2430', stroke: INK, 'stroke-width': 4.5, 'stroke-linejoin': 'round' }, mouthG);
+ const tongue = F && el('path', { fill: '#ef7d86' }, mouthG), teeth = F && el('path', { fill: '#fff' }, mouthG);
+ const mouthLine = F && el('path', { fill: 'none', stroke: INK, 'stroke-width': 5, 'stroke-linecap': 'round' }, mouthG);
+ // Mouth shapes (Rhubarb's set) in mouth units, the mouth's front under the snout on the right: [open height, width, teeth].
+ const MOUTH = { X: [0, 1], A: [0, .9], B: [7, .8, 1], C: [16, .95], D: [26, 1], E: [20, .7], F: [11, .45], G: [7, .75, 1], H: [17, .9] };
+ // A hose limb: one smooth curve through the joint, ink outline under the skin colour; a drawn hand or foot at the end.
+ function hose(g, w, sleeve) {
+ const out = el('path', { fill: 'none', stroke: INK, 'stroke-width': w + 7, 'stroke-linecap': 'round' }, g);
+ const end = el('image', {}, g);
+ const fill = el('path', { fill: 'none', stroke: spec.skin, 'stroke-width': w, 'stroke-linecap': 'round' }, g);
+ const sl = sleeve && el('image', { href: src(sleeve.src) }, g); // over the limb's root, turning with the upper arm
+ return (a, k, b, part, ang, upAng) => {
+ const c = [2 * k[0] - (a[0] + b[0]) / 2, 2 * k[1] - (a[1] + b[1]) / 2], d = `M${a}Q${c} ${b}`;
+ out.setAttribute('d', d); fill.setAttribute('d', d);
+ if (end._src !== part.src) { end.setAttribute('href', src(part.src)); end._src = part.src; }
+ end.setAttribute('transform', `translate(${b}) rotate(${ang}) scale(${part.s}) translate(${-part.at[0]},${-part.at[1]})`);
+ if (sl) sl.setAttribute('transform', `translate(${a}) rotate(${upAng - sleeve.dir}) scale(${sleeve.s}) translate(${-sleeve.at[0]},${-sleeve.at[1]})`);
+ };
+ }
+ const [L1, L2, LW] = spec.leg, [A1, A2, AW] = spec.arm;
+ const nearLeg = hose(nearLegG, LW), farLeg = hose(farLegG, LW), nearArm = hose(nearArmG, AW, spec.sleeve), farArm = hose(farArmG, AW, spec.sleeve);
+ // A neck: a short SVG column from inside the collar up into the head, under the torso so the collar covers its root.
+ const neckPaths = spec.neck && [el('path', { fill: 'none', stroke: INK, 'stroke-width': spec.neck.w + 7, 'stroke-linecap': 'round' }, neckG), el('path', { fill: 'none', stroke: spec.skin, 'stroke-width': spec.neck.w, 'stroke-linecap': 'round' }, neckG)];
+ // Pig tails: a curl that wags; the wolf's is a drawing.
+ let tail;
+ if (spec.tailImg) { const ti = spec.tailImg; tail = el('image', { href: src(ti.src) }, tailG); }
+ else if (T.tail) {
+ const d = 'M0 0c-10 -2 -18 6 -14 14c4 8 16 6 16 -3c0 -8 -10 -10 -14 -4';
+ el('path', { d, fill: 'none', stroke: INK, 'stroke-width': 7, 'stroke-linecap': 'round' }, tailG);
+ el('path', { d, fill: 'none', stroke: spec.skin, 'stroke-width': 3, 'stroke-linecap': 'round' }, tailG);
+ }
+ const legLen = L1 + L2, ankleH = (spec.foot.h - spec.foot.at[1]) * spec.foot.s; // ankle above the sole
+ function ik(h, a) { // knee bends forward
+ const dx = a[0] - h[0], dy = a[1] - h[1], d = Math.min(Math.max(Math.hypot(dx, dy), Math.abs(L1 - L2) + 1), legLen * .999);
+ const th = Math.atan2(dy, dx) - Math.acos((L1 * L1 + d * d - L2 * L2) / (2 * L1 * d));
+ return [h[0] + L1 * Math.cos(th), h[1] + L1 * Math.sin(th)];
+ }
+ const a = {
+ root, spec, back: backG, front: frontG, // back/front: drawn in torso image pixels, moving with the torso
+ pose(s) {
+ const k = s.k ?? 1, face = s.dir ?? 1, lean = s.lean ?? 0, sy = s.sy ?? 1, sx = 1 / sy;
+ const hipY = -(ankleH + legLen * .94 - (s.drop ?? 0) - (s.bob ?? 0));
+ root.setAttribute('transform', `translate(${s.x},${s.ground}) scale(${face * k},${k})`);
+ // A point on the torso drawing, in actor units: pelvis-relative, squashed, leaned about the hip.
+ const c = Math.cos(lean * R), sn = Math.sin(lean * R);
+ const on = ([px, py]) => { const lx = (px - pelvis[0]) * T.s * sx, ly = (py - pelvis[1]) * T.s * sy; return [lx * c - ly * sn, hipY + lx * sn + ly * c]; };
+ torsoG.setAttribute('transform', `translate(0,${hipY}) rotate(${lean}) scale(${sx},${sy})`);
+ const tp = `translate(0,${hipY}) rotate(${lean}) scale(${sx * T.s},${sy * T.s}) translate(${-pelvis[0]},${-pelvis[1]})`;
+ backG.setAttribute('transform', tp); frontG.setAttribute('transform', tp);
+ // Head: swap drawings; pop is a quick squash that hides the swap.
+ const hd = spec.heads[s.head?.name] || Object.values(spec.heads)[0], pop = s.head?.pop ?? 1;
+ if (headImg._src !== hd.src) { headImg.setAttribute('href', src(hd.src)); headImg._src = hd.src; }
+ let nk = on(T.neck);
+ if (spec.neck) { // the head rides on top of the neck, which leans a little with the head
+ const tilt = (s.head?.tilt ?? 0) * .4 + lean, top = [nk[0] + spec.neck.up * Math.sin(tilt * R), nk[1] - spec.neck.up * Math.cos(tilt * R)];
+ const base = on([T.neck[0], T.neck[1] + 40]);
+ neckPaths.forEach(p => p.setAttribute('d', `M${base}L${top}`)); nk = top;
+ }
+ const back = s.head?.back ? -1 : 1; // back: the head turned to look behind
+ headG.setAttribute('transform', `translate(${nk}) rotate(${back * (s.head?.tilt ?? 0) + lean}) scale(${back * pop},${1 / pop})`);
+ const fc = F && s.face; // a drawn face replaces the head drawings
+ headImg.style.display = fc ? 'none' : ''; if (F) faceG.style.display = fc ? '' : 'none';
+ if (!fc) headImg.setAttribute('transform', `scale(${hd.s}) translate(${-hd.pivot[0]},${-hd.pivot[1]})`);
+ else {
+ faceG.setAttribute('transform', `scale(${hd.s}) translate(${-F.pivot[0]},${-F.pivot[1]})`);
+ const [gx, gy] = fc.gaze || [1, 0], blink = fc.blink ?? 0, wide = fc.wide ?? 0, worry = fc.worry ?? 0, raise = fc.raise ?? 0;
+ eyes.forEach(e => {
+ const open = Math.max(.06, (1 - blink) * (1 + .12 * wide));
+ e.g.setAttribute('transform', `translate(${e.x},${e.y})`); e.open.setAttribute('transform', `scale(1,${open})`);
+ e.shut.style.opacity = blink > .7 ? 1 : 0; e.open.style.opacity = blink > .7 ? 0 : 1;
+ const px = e.rx * (.22 + .32 * gx), py = e.ry * .32 * gy, ps = 1 - .3 * wide;
+ e.pupil.setAttribute('transform', `translate(${px},${py}) scale(${ps})`); e.shine.setAttribute('transform', `translate(${px + e.rx * .12},${py - e.ry * .2})`);
+ });
+ // Brows: raise lifts both ends, worry lifts the inner (front) end and drops the outer one.
+ F.brows.forEach(([x1, y1, x2, y2], i) => {
+ const up = 9 * raise + 6 * wide, mx = (x1 + x2) / 2, my = (y1 + y2) / 2 - 7 - up;
+ brows[i].setAttribute('d', `M${x1} ${y1 - up + 6 * worry}Q${mx} ${my - 4 * worry} ${x2} ${y2 - up - 9 * worry}`);
+ });
+ const [m0, m1, mw] = F.mouth, [h, wk, th] = MOUTH[fc.mouth || 'X'] || MOUTH.X, w = mw * wk / 2, sm = fc.smile ?? .6;
+ mouthG.setAttribute('transform', `translate(${m0 + mw / 2 - w},${m1})`); // narrow shapes stay at the front
+ const L = [-w, -2 - 9 * sm], Rt = [w, -2]; // back corner (lifts with a smile), front under the snout
+ if (!h) { mouthLine.setAttribute('d', `M${L}Q${(L[0] + Rt[0]) / 2} ${10 * sm} ${Rt}`); mouthIn.setAttribute('d', ''); tongue.setAttribute('d', ''); teeth.setAttribute('d', ''); }
+ else {
+ const lip = `M${L}Q0 ${-4 + 3 * sm} ${Rt}`;
+ mouthIn.setAttribute('d', `${lip}Q${w * .2} ${h * 1.25} ${L}Z`); mouthLine.setAttribute('d', '');
+ tongue.setAttribute('d', h > 12 ? `M${-w * .55} ${h * .55}Q${w * .1} ${h * .3 + (fc.mouth === 'H' ? -8 : 0)} ${w * .6} ${h * .45}Q${w * .1} ${h * 1.05} ${-w * .55} ${h * .55}Z` : '');
+ teeth.setAttribute('d', th ? `M${-w * .6} ${-2 - 4 * sm}L${w * .8} -1L${w * .75} 5L${-w * .55} 4Z` : '');
+ }
+ }
+ // Legs: ankle targets from world x and lift; feet roll toe-down as they lift.
+ const local = ([wx, lift]) => [(wx - s.x) / (face * k), -ankleH - lift / k];
+ const feet = s.feet || [[s.x, 0], [s.x, 0]];
+ [[nearLeg, T.hipN, feet[0]], [farLeg, T.hipF, feet[1]]].forEach(([draw, hip, f]) => {
+ const h = on(hip), an = local(f);
+ draw(h, ik(h, an), an, spec.foot, Math.min(25, f[1] * .6 / k));
+ });
+ // Arms: angles from hanging straight down; the hand turns with the forearm.
+ const sh = on(T.shoulder), arms = s.arms || [{}, {}];
+ [[nearArm, arms[0]], [farArm, arms[1]]].forEach(([draw, arm = {}]) => {
+ const a1 = (90 + (arm.up ?? 0) + lean) * R, a2 = a1 + (arm.bend ?? -15) * R;
+ const e = [sh[0] + A1 * Math.cos(a1), sh[1] + A1 * Math.sin(a1)], w = [e[0] + A2 * Math.cos(a2), e[1] + A2 * Math.sin(a2)];
+ const part = (arm.hand === 'hand' ? spec.hand : spec.fist) || spec.fist || spec.hand;
+ draw(sh, e, w, part, a2 / R - part.dir, a1 / R);
+ const i = draw === nearArm ? 0 : 1, grip = [w[0] + 22 * Math.cos(a2), w[1] + 22 * Math.sin(a2)]; // inside the hand, along the forearm
+ (a.wrists ||= [])[i] = [s.x + face * k * w[0], s.ground + k * w[1]]; // world, for held props
+ (a.grips ||= [])[i] = { at: [s.x + face * k * grip[0], s.ground + k * grip[1]], ang: face > 0 ? a2 / R : 180 - a2 / R };
+ });
+ if (spec.tailImg) {
+ const ti = spec.tailImg, tp = on(ti.at);
+ tail.setAttribute('transform', `translate(${tp}) rotate(${lean + (s.tail ?? 0)}) scale(${-ti.s},${ti.s}) translate(${-ti.root[0]},${-ti.root[1]})`);
+ } else if (T.tail) tailG.setAttribute('transform', `translate(${on(T.tail)}) rotate(${lean + (s.tail ?? 0)}) scale(.9)`);
+ },
+ };
+ return a;
+}
+
+// A walk that starts from standing, as a pure function of tau (seconds since the first step). Each foot is planted
+// while the body passes over it, then swings to its next plant. Returns the distance walked d, both feet as
+// [distance, lift] (near, far), the hip's drop (bob, + is down) and, for a skip, the body's rise (up).
+function walk(tau, { T = .8, stance = .6, v = 150, acc = .4, lift = 14, bob = 4, hop = 0 } = {}) {
+ const dist = u => u <= 0 ? 0 : u < acc ? v * u * u / (2 * acc) : v * (u - acc / 2);
+ const foot = off => {
+ if (tau <= 0) return [0, 0];
+ const c = tau / T + off, n = Math.floor(c), u = c - n, plant = j => dist((j + stance / 2 - off) * T);
+ if (u < stance) return [plant(n), 0];
+ const q = (u - stance) / (1 - stance);
+ return [plant(n) + (plant(n + 1) - plant(n)) * q * q * (3 - 2 * q), Math.sin(Math.PI * q) * lift];
+ };
+ const ramp = Math.min(1, Math.max(0, tau / .3));
+ return { d: dist(tau), feet: [foot(stance), foot(stance + .5)], bob: ramp * bob * Math.cos(4 * Math.PI * (tau / T - .48)),
+ up: ramp * hop * Math.abs(Math.sin(2 * Math.PI * (tau / T - .4))) };
+}
+
+// Follow-through, seekable: a damped spring's response to an input signal f(t), as a weighted sum of f over the last
+// `win` seconds. No state, so any frame can be computed on its own. hz: natural frequency; z: damping ratio.
+function lag(f, t, { hz = 2.5, z = .35, win = 1.6, n = 40 } = {}) {
+ const w = 2 * Math.PI * hz, wd = w * Math.sqrt(1 - z * z), dt = win / n;
+ let sum = 0, norm = 0;
+ for (let i = 0; i < n; i++) { const tau = (i + .5) * dt, h = Math.exp(-z * w * tau) * Math.sin(wd * tau); sum += h * f(t - tau); norm += h; }
+ return sum / norm;
+}
+// Repeatable noise and automatic blinks: each character has its own seed.
+const hash = x => { const s = Math.sin(x * 127.1 + 311.7) * 43758.5453; return s - Math.floor(s); };
+const wobble = (t, seed, hz = .3) => Math.sin(t * hz * 6.283 + seed) * .6 + Math.sin(t * hz * 2.71 * 6.283 + seed * 3) * .4;
+function blinkAt(t, seed) {
+ let at = .8 + hash(seed) * 1.5, prev = -9, i = 1;
+ while (at <= t) { prev = at; at += 2 + 4 * hash(seed + i++); }
+ const d = t - prev; return d < .16 ? Math.sin(Math.PI * d / .16) : 0;
+}
diff --git a/site/three-little-pigs/lib/contents.css b/site/three-little-pigs/lib/contents.css
new file mode 100644
index 0000000..3f59f10
--- /dev/null
+++ b/site/three-little-pigs/lib/contents.css
@@ -0,0 +1,115 @@
+/* The book's cover and contents (index.html): the chalkboard look, the cover, the guide, the chapter grid and the
+ page-to-page motion. A book's own <style> after this file sets its theme: the colour and font tokens below, and the
+ few rules a theme redraws (e.g. body::before for the paper). */
+:root {
+ --page: #0f1613; --board: #1d2b27; --panel: #22322d; --edge: #3a5047;
+ --chalk: #ece8dc; --dim: #9aaba3; --faint: #5d7068; --task: #f0b45a; --quiz: #86c9e8; --good: #8fd6b0;
+ --ui: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
+ --book: "Iowan Old Style", Palatino, Georgia, serif;
+ --ease: cubic-bezier(.2, .8, .2, 1);
+ --top-bg: rgba(22, 33, 29, .86); --top-line: #2a3b35; /* the sticky contents header */
+ --lift: rgba(0, 0, 0, .3); /* a card's shadow on hover */
+ color-scheme: dark;
+}
+* { box-sizing: border-box; }
+html { scroll-padding-top: 90px; }
+body { margin: 0; min-height: 100svh; background: var(--board); color: var(--chalk); font: 18px/1.5 var(--ui); }
+/* Chalkboard: the same grain and vignette as the lesson stage. */
+body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
+ background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(0, 0, 0, .38)),
+ url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 .92 0 0 0 0 .95 0 0 0 0 .9 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23g)'/%3E%3C/svg%3E"); }
+a { color: inherit; }
+a:focus-visible { outline: 3px solid var(--task); outline-offset: 3px; }
+.kicker { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--quiz); }
+
+/* ---------- cover ---------- */
+#cover { position: relative; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center;
+ padding: 48px 16px 64px; text-align: center; overflow: hidden; }
+.open #cover, body:not(.open) #contents { display: none; }
+#cover > * { animation: rise .8s var(--ease) backwards; }
+#cover .mascot { animation: none; margin-bottom: 26px; view-transition-name: guide; }
+#cover .kicker { animation-delay: .9s; }
+#cover h1 { animation-delay: 1s; }
+#cover .lede { animation-delay: 1.12s; }
+#cover .acts { animation-delay: 1.24s; }
+#cover .meta { animation-delay: 1.36s; }
+h1 { margin: 14px 0 18px; font: 500 clamp(44px, 8.4vw, 92px)/1.02 var(--book); letter-spacing: -.01em; view-transition-name: book; }
+h1 i { color: var(--task); font-style: italic; }
+.lede { max-width: 34em; margin: 0 0 34px; color: var(--dim); font-size: clamp(17px, 2.2vw, 20px); text-wrap: balance; }
+.acts { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
+.btn { display: inline-flex; align-items: center; gap: 12px; padding: 14px 30px; border-radius: 999px; font-weight: 600; font-size: 19px; text-decoration: none;
+ transition: transform .25s var(--ease), background-color .25s, border-color .25s; }
+.btn[hidden] { display: none; }
+.btn:hover { transform: translateY(-2px); }
+.btn.go { background: var(--chalk); color: var(--board); }
+.btn.quiet { border: 1.5px solid var(--edge); color: var(--chalk); }
+.btn.quiet:hover { border-color: var(--dim); }
+.btn svg { width: 15px; height: 15px; fill: currentColor; }
+.meta { margin: 30px 0 0; color: var(--faint); font-size: 15px; letter-spacing: .04em; }
+/* Faint chalk notes around the edges of the board. */
+.chalk { position: absolute; inset: 0; z-index: -1; pointer-events: none; animation: none !important; }
+.chalk span { position: absolute; font: italic 400 clamp(22px, 3vw, 38px) var(--book); color: var(--chalk); opacity: 0; white-space: nowrap;
+ animation: chalk 1.6s ease-out forwards, drift 14s ease-in-out infinite alternate; animation-delay: calc(var(--d) * 1s), calc(var(--d) * 1s); }
+@keyframes chalk { to { opacity: .075; } }
+@keyframes drift { to { translate: 0 -10px; } }
+@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
+
+/* ---------- the guide: an infinity sign whose loops are its eyes ---------- */
+.mascot { display: block; overflow: visible; }
+.mascot .mbody { transform-box: view-box; transform-origin: 60px 46px; animation: bob 3.4s ease-in-out infinite; }
+.mascot .pupil { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
+.mascot .joy { display: none; }
+#cover:has(.go:hover, .go:focus-visible) .pupil { display: none; }
+#cover:has(.go:hover, .go:focus-visible) .joy { display: inline; }
+.draw .loop { stroke-dasharray: 1 1; animation: draw 1.3s cubic-bezier(.6, 0, .3, 1) .15s backwards; }
+.draw .face { animation: pop .45s var(--ease) 1.25s backwards; }
+@keyframes draw { from { stroke-dashoffset: 1; } }
+@keyframes pop { from { opacity: 0; transform: scale(.6); } }
+.draw .face { transform-box: view-box; transform-origin: 60px 44px; }
+@keyframes bob { 50% { transform: translateY(-3px) rotate(-2deg); } }
+@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
+
+/* ---------- contents ---------- */
+.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 14px; padding: 12px max(16px, calc(50% - 590px));
+ background: var(--top-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--top-line); }
+.home { display: flex; align-items: center; gap: 12px; text-decoration: none; border-radius: 10px; }
+.home .mascot { view-transition-name: guide; }
+.home strong { font: 500 22px/1.1 var(--book); view-transition-name: book; }
+.home strong i { color: var(--task); }
+.prog { margin-left: auto; color: var(--dim); font-size: 15px; white-space: nowrap; }
+.prog b { color: var(--good); font-weight: 600; }
+main#contents { padding-bottom: 80px; }
+.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 12px; }
+.ch { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr auto; column-gap: 16px; row-gap: 8px; min-height: 112px;
+ padding: 16px 18px 14px 16px; border-radius: 16px; background: var(--panel); border: 1.5px solid var(--edge); border-left: 6px solid var(--c);
+ text-decoration: none; transition: transform .3s var(--ease), border-color .3s, box-shadow .3s; }
+.ch:hover { transform: translateY(-3px); border-color: var(--c); box-shadow: 0 14px 34px var(--lift); }
+.ch b { grid-row: span 2; min-width: 1.15em; font: 500 42px/1 var(--book); color: var(--c); font-variant-numeric: lining-nums tabular-nums; }
+.ch span { font-size: 18px; line-height: 1.3; }
+.ch small { color: var(--dim); font-size: 14px; }
+.ch.done small::before { content: var(--done, "✓ Finished · "); color: var(--good); font-weight: 600; }
+.ch.last small::after { content: var(--last, " · Last opened"); color: var(--quiz); }
+.ch.here:focus-visible { outline-color: var(--c); }
+.ch.here { animation: here 1.8s ease-out .3s; }
+@keyframes here { 0% { box-shadow: 0 0 0 0 var(--c); } 25% { box-shadow: 0 0 0 5px var(--c); } 100% { box-shadow: 0 0 0 14px transparent; } }
+.stagger .top { animation: rise .6s var(--ease) backwards; }
+.stagger .unit h2, .stagger .ch { animation: rise .6s var(--ease) backwards; animation-delay: calc(min(var(--i), 14) * 32ms + 80ms); }
+
+/* ---------- page-to-page motion ---------- */
+@view-transition { navigation: auto; }
+/* Firefox flickers through view transitions (the header blinks for several frames): it switches without one, and the
+ contents still rise in. -moz-orient exists only in Firefox. */
+@supports (-moz-orient: inline) { @view-transition { navigation: none; } }
+::view-transition-group(*) { animation-duration: .5s; animation-timing-function: var(--ease); }
+::view-transition-old(lesson), ::view-transition-new(lesson) { height: 100%; object-fit: cover; }
+::view-transition-old(lesson) { animation-duration: .18s; }
+@media (max-width: 560px) {
+ .home strong { font-size: 18px; }
+ #contents .top { flex-wrap: wrap; gap: 8px 12px; }
+ .ch { min-height: 0; }
+ .chalk span:not(:nth-child(3), :nth-child(4), :nth-child(7)) { display: none; }
+}
+@media (prefers-reduced-motion: reduce) {
+ *, *::before, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; transition: none !important; }
+ .chalk span { opacity: .075; }
+}
diff --git a/site/three-little-pigs/lib/contents.js b/site/three-little-pigs/lib/contents.js
new file mode 100644
index 0000000..6b3272b
--- /dev/null
+++ b/site/three-little-pigs/lib/contents.js
@@ -0,0 +1,192 @@
+/* The book's cover and contents (index.html): interface text, the chapter list with reading progress, the guide,
+ and the cover ↔ contents ↔ lesson motion. Load it in <head>; after the markup, the page calls
+ Contents.book({ units, start, hues }) with its chapter list. */
+'use strict';
+// Observe aborted incoming transitions before the first rendering opportunity.
+addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
+
+const Contents = (() => {
+ // Interface text in the page's <html lang>, as in the lessons; missing keys fall back to English.
+ // A value is a string or plural forms { one, few, many, other } chosen by vars.n.
+ const TRANSLATIONS = {
+ en: {
+ open: 'Open the book', toCover: 'Back to the cover', resume: 'Continue · Chapter {n}', unit: 'Unit {n}', minutes: '{n} min',
+ meta: '{chapters}{samples} · {units} · with sound', metaChapters: { one: '{n} chapter', other: '{n} chapters' },
+ metaUnits: { one: '{n} unit', other: '{n} units' }, metaSamples: { one: ' + {n} sample', other: ' + {n} samples' }, samples: 'Sample chapters, another look',
+ chapterCount: { one: '{n} chapter', other: '{n} chapters' }, finished: '{done} of {n} finished',
+ doneMark: '✓ Finished · ', lastMark: ' · Last opened',
+ },
+ ru: {
+ open: 'Открыть книгу', toCover: 'К обложке', resume: 'Продолжить · Глава {n}', unit: 'Раздел {n}', minutes: '{n} мин',
+ meta: '{chapters}{samples} · {units} · со звуком',
+ metaChapters: { one: '{n} глава', few: '{n} главы', many: '{n} глав', other: '{n} главы' },
+ metaUnits: { one: '{n} раздел', few: '{n} раздела', many: '{n} разделов', other: '{n} раздела' },
+ metaSamples: { one: ' + {n} пробная', few: ' + {n} пробные', many: ' + {n} пробных', other: ' + {n} пробной' },
+ samples: 'Пробные главы в другом стиле',
+ chapterCount: { one: '{n} глава', few: '{n} главы', many: '{n} глав', other: '{n} главы' }, finished: 'Пройдено {done} из {n}',
+ doneMark: '✓ Пройдено · ', lastMark: ' · Открыта последней',
+ },
+ zh: {
+ open: '打开这本书', toCover: '返回封面', resume: '继续 · 第 {n} 章', unit: '第 {n} 单元', minutes: '{n} 分钟',
+ meta: '{chapters}{samples} · {units} · 有配音', metaChapters: '{n} 章', metaUnits: '{n} 个单元',
+ metaSamples: ' + {n} 个示例章', samples: '示例章,另一种风格',
+ chapterCount: '{n} 章', finished: '已完成 {done} / {n}',
+ doneMark: '✓ 已完成 · ', lastMark: ' · 上次打开',
+ },
+ ja: {
+ open: '本を開く', toCover: '表紙に戻る', resume: '続きから · 第{n}章', unit: '単元 {n}', minutes: '{n}分',
+ meta: '{chapters}{samples} · {units} · 音声つき', metaChapters: '{n}章', metaUnits: '{n}単元',
+ metaSamples: ' + サンプル{n}章', samples: 'サンプル章(別のスタイル)',
+ chapterCount: '{n}章', finished: '{n}章中 {done}章 完了',
+ doneMark: '✓ 完了 · ', lastMark: ' · 最後に開いた章',
+ },
+ };
+ const LANGUAGE = (document.documentElement.lang || 'en').toLowerCase().split('-')[0];
+ function translate(key, vars = {}) {
+ const language = TRANSLATIONS[LANGUAGE]?.[key] !== undefined ? LANGUAGE : 'en';
+ let text = TRANSLATIONS[language][key] ?? key;
+ if (typeof text === 'object') {
+ let rules;
+ try { rules = new Intl.PluralRules(language); } catch { rules = new Intl.PluralRules('en'); }
+ text = text[rules.select(vars.n)] ?? text.other;
+ }
+ return text.replace(/\{(\w+)\}/g, (placeholder, name) => name in vars ? vars[name] : placeholder);
+ }
+ const $ = id => document.getElementById(id);
+ const id = n => 'ch' + String(n).padStart(2, '0');
+ const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const HUES = ['#f4a48c', '#86c9e8', '#f3c95c', '#e8a0c8', '#8fd6b0', '#bba8ee', '#f0b45a'];
+
+ // Fixed interface text: data-t replaces an element's first text, data-t-label its aria-label.
+ function translatePage() {
+ for (const element of document.querySelectorAll('[data-t]')) element.firstChild.nodeValue = translate(element.dataset.t);
+ for (const element of document.querySelectorAll('[data-t-label]')) element.setAttribute('aria-label', translate(element.dataset.tLabel));
+ document.documentElement.style.setProperty('--done', JSON.stringify(translate('doneMark')));
+ document.documentElement.style.setProperty('--last', JSON.stringify(translate('lastMark')));
+ }
+
+ // Reading progress { done: [chapter numbers], last }, written by the lessons. The engine and this page derive the
+ // same key from the book's folder; a book that predates that passes its own key.
+ function progress(key) {
+ let P = {};
+ try {
+ const saved = JSON.parse(localStorage.getItem(key) || '{}');
+ if (saved && typeof saved === 'object' && !Array.isArray(saved)) P = saved;
+ } catch {}
+ return { last: P.last, done: new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger(n) && n > 0) : []) };
+ }
+
+ // The chapter cards, unit by unit, with progress, the header count, the cover's meta line and its resume button.
+ // A unit's optional third entry { unit, chapter, sample, href } numbers it from elsewhere in the book; a sample chapter,
+ // made to show another look, is not counted with the book's chapters, and a unit of samples has no unit number.
+ // With href, the sample lives in another book folder (its own progress): its card links there and leaves this book's
+ // numbering and progress alone. A chapter's own third entry { href, chapter } does the same for that chapter alone;
+ // without href, its chapter is only the number shown on the card.
+ // start.label is the number shown for start.chapter (folders keep the book's numbers; lessons set CHAPTER.label).
+ function contents(units, start, hues, P) {
+ let n = start.chapter - 1, total = 0, i = 0, away = 0; // i staggers the entrance, in reading order
+ const samples = new Set(), shown = k => k - start.chapter + (start.label ?? start.chapter);
+ $('units').innerHTML = units.map(([name, chs, o = {}], u) => {
+ if (o.chapter && !o.href) n = o.chapter - 1;
+ return `<section class="unit" style="--c:${hues[u % hues.length]};--i:${i++}">${Units.header(u, o.sample ? translate('samples') : translate('unit', { n: o.unit ?? u + start.unit }), name)}<div class="grid">` +
+ chs.map(([t, min, c = {}], k) => {
+ const href = c.href ?? o.href;
+ if (href) { away++; return `<a class="ch" href="${href}" style="--i:${i++}"><b>${c.chapter ?? (o.chapter ?? 1) + k}</b><span>${esc(t)}</span><small>${translate('minutes', { n: min })}</small></a>`; }
+ n++; if (o.sample) samples.add(n); else total++;
+ const cls = 'ch' + (P.done.has(n) ? ' done' : '') + (P.last === n ? ' last' : '');
+ return `<a class="${cls}" id="${id(n)}" href="${id(n)}/" style="--i:${i++}"><b>${c.chapter ?? shown(n)}</b><span>${esc(t)}</span><small>${translate('minutes', { n: min })}</small></a>`;
+ }).join('') + '</div></section>';
+ }).join('');
+ // A unit's sketch draws itself the first time the unit scrolls into view.
+ Units.watch();
+ const finished = [...P.done].filter(k => k >= start.chapter && k <= n && !samples.has(k)).length;
+ $('prog').innerHTML = finished ? translate('finished', { done: `<b>${finished}</b>`, n: total }) : translate('chapterCount', { n: total });
+ $('meta').textContent = translate('meta', {
+ chapters: translate('metaChapters', { n: total }),
+ samples: samples.size + away ? translate('metaSamples', { n: samples.size + away }) : '',
+ units: translate('metaUnits', { n: units.filter(x => !x[2]?.sample).length }) });
+ const last = Number.isInteger(P.last) && $(id(P.last));
+ if (last) {
+ const r = $('resume');
+ r.hidden = false;
+ r.href = last.getAttribute('href');
+ r.textContent = translate('resume', { n: last.querySelector('b').textContent });
+ }
+ }
+
+ // The guide, drawn the same way as in the lessons, in the page's chalk (ink) colour.
+ function lemniscate(cx, cy, a, k) {
+ let d = '';
+ for (let i = 0; i <= 96; i++) {
+ const t = i / 96 * 2 * Math.PI, sn = Math.sin(t), q = 1 + sn * sn;
+ d += (i ? 'L' : 'M') + (cx + a * Math.cos(t) / q).toFixed(1) + ' ' + (cy + k * a * sn * Math.cos(t) / q).toFixed(1);
+ }
+ return d + 'Z';
+ }
+ function guides(ink) {
+ for (const svg of document.querySelectorAll('svg.mascot')) {
+ svg.setAttribute('viewBox', '0 0 120 84');
+ svg.setAttribute('aria-hidden', 'true');
+ const ln = `fill="none" stroke="${ink}" stroke-linecap="round" stroke-linejoin="round"`;
+ svg.innerHTML = `<g class="mbody"><path class="loop" pathLength="1" d="${lemniscate(60, 40, 52, 1.5)}" ${ln} stroke-width="6"/><g class="face">` +
+ [33, 87].map(x => `<circle class="pupil" cx="${x}" cy="40" r="6.5" fill="${ink}"/><path class="joy" d="M${x - 7} 43Q${x} 32 ${x + 7} 43" ${ln} stroke-width="4"/>`).join('') +
+ `<path d="M55 62Q60 67 65 62" ${ln} stroke-width="3.5"/></g></g>`;
+ }
+ }
+
+ // The cover and the contents share this page: no hash or #book shows the cover, #contents or #chNN the contents.
+ // Lessons link back with #chNN, so the reader lands on the chapter they just left.
+ function views() {
+ const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
+ function show(animate) {
+ const open = location.hash.length > 1 && location.hash !== '#book';
+ const apply = () => {
+ document.body.classList.toggle('open', open);
+ document.body.classList.toggle('stagger', animate && open);
+ const here = open ? $(location.hash.slice(1)) : null;
+ document.querySelectorAll('.here').forEach(e => e.classList.remove('here'));
+ if (here?.classList.contains('ch')) { here.scrollIntoView({ block: 'center' }); here.classList.add('here'); }
+ else scrollTo(0, 0);
+ if (animate) {
+ const heading = document.querySelector(open ? '#contents .home' : '#cover h1');
+ heading?.setAttribute('tabindex', '-1');
+ heading?.focus({ preventScroll: true });
+ }
+ };
+ if (animate && document.startViewTransition && !reduced && !CSS.supports('-moz-orient', 'inline')) {
+ const transition = document.startViewTransition(apply);
+ // Navigation can interrupt either promise; the new view is already applied.
+ transition.ready.catch(() => {});
+ transition.finished.catch(() => {});
+ } else apply();
+ }
+ addEventListener('hashchange', () => show(true));
+ show(false);
+
+ // Between pages, the chosen card grows into the lesson frame and the frame shrinks back into its card.
+ let named = null;
+ const name = el => {
+ if (named) named.style.viewTransitionName = '';
+ named = el;
+ if (el) el.style.viewTransitionName = 'lesson';
+ };
+ document.addEventListener('click', e => { const a = e.target.closest('a[href^="ch"]'); if (a) name(a); });
+ addEventListener('pagereveal', e => {
+ const target = (location.hash.length > 1 && $(location.hash.slice(1))?.closest('.ch')) || (named?.offsetParent && named);
+ name(e.viewTransition && target ? target : null);
+ e.viewTransition?.finished.then(() => name(null), () => name(null));
+ });
+ }
+
+ // units: [[unit title, [[chapter title, minutes], ...], { unit, chapter, sample, href }?], ...]. Chapters are numbered in
+ // order from start (a book whose scope starts mid-way keeps the original numbers in its folders, and may show them
+ // from start.label). hues: one colour per unit, cycling.
+ function book({ units, start = { unit: 1, chapter: 1 }, hues = HUES, progressKey, ink } = {}) {
+ translatePage();
+ contents(units, start, hues, progress(progressKey ?? 'animebook:progress:' + new URL('.', location.href).pathname));
+ guides(ink || getComputedStyle(document.documentElement).getPropertyValue('--chalk').trim() || '#ece8dc');
+ views();
+ }
+
+ return { book, translate };
+})();
diff --git a/site/three-little-pigs/lib/engine.css b/site/three-little-pigs/lib/engine.css
new file mode 100644
index 0000000..9b9be00
--- /dev/null
+++ b/site/three-little-pigs/lib/engine.css
@@ -0,0 +1,235 @@
+@import url(volume.css);
+@import url(book.css); /* this book's own settings and overrides (not shared), before the rules below */
+:root {
+ --page: #0f1613; --board: #1d2b27; --panel: #22322d; --edge: #3a5047;
+ --chalk: #ece8dc; --dim: #9aaba3; --faint: #5d7068;
+ --task: #f0b45a; --quiz: #86c9e8; --good: #8fd6b0; --bad: #f08c7a;
+ --ui: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
+ color-scheme: dark;
+}
+* { box-sizing: border-box; }
+html, body { height: 100%; margin: 0; overflow: hidden; background: var(--page); }
+body { color: var(--chalk); font: 26px/1.4 var(--ui); }
+button { font: inherit; color: inherit; cursor: pointer; }
+button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--task); outline-offset: 3px; }
+button[hidden] { display: none; }
+
+/* One fixed 1600×960 frame (900 stage + 60 controls), scaled to fit the window. */
+#frame { position: absolute; left: 50%; top: 50%; width: 1600px; height: 960px; transform: translate(-50%, -50%) scale(var(--k, .5));
+ border-radius: 20px; overflow: hidden; background: var(--board); box-shadow: 0 0 0 1px var(--edge), 0 30px 80px rgba(0, 0, 0, .45); }
+#stage { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; display: block;
+ background: radial-gradient(75% 75% at 50% 45%, rgba(0,0,0,0) 60%, rgba(0,0,0,.35)), var(--grain, none), #1d2b27; }
+#ui { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; pointer-events: none; }
+#ui > * { pointer-events: auto; }
+
+.cover { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; display: grid; place-items: center; background: rgba(15, 22, 19, .5); border: 0; }
+.cover[hidden] { display: none; }
+.cover > div { display: flex; flex-direction: column; align-items: center; }
+.cover-k { margin: 0 0 10px; text-align: center; font-size: 22px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--quiz); }
+.cover-t { margin: 0 0 44px; max-width: 1200px; text-align: center; font: 500 64px/1.15 "Iowan Old Style", Palatino, Georgia, serif; color: var(--chalk); text-wrap: balance; }
+.cover > div > * { animation: rise .7s cubic-bezier(.2, .8, .2, 1) backwards; }
+.cover-t { animation-delay: .08s; }
+.cover .go { animation-delay: .18s; }
+.cover small { animation-delay: .26s; }
+@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
+.cover .go { display: inline-flex; align-items: center; gap: 16px; padding: 20px 40px; border-radius: 999px; background: var(--chalk); color: var(--board); font-weight: 600; font-size: 32px; }
+.cover small { display: block; margin-top: 22px; font-size: 22px; text-align: center; color: var(--dim); }
+.paused-mark { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; display: none; place-items: center; pointer-events: none; }
+.paused .paused-mark { display: grid; }
+.paused-mark div { padding: 14px 30px; border-radius: 999px; background: rgba(15, 22, 19, .85); color: var(--dim); font-size: 22px; }
+
+/* Question cards inside the picture. */
+.card { position: absolute; padding: 20px 26px; border-radius: 20px; background: rgba(34, 50, 45, .97); border: 1.5px solid var(--edge); border-left: 7px solid var(--quiz); box-shadow: 0 14px 44px rgba(0, 0, 0, .35); }
+.card.band { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-areas: "pic head body acts" "pic fb body acts"; column-gap: 28px; align-items: center; align-content: center; min-height: 150px; }
+.band .mascot { grid-area: pic; }
+.band .head { grid-area: head; align-self: end; }
+.band .fb { grid-area: fb; align-self: start; }
+.band .body { grid-area: body; }
+.band .acts { grid-area: acts; }
+.side .mascot { float: right; margin: -2px -4px 6px 10px; }
+.kicker { margin: 0 0 4px; font-size: 20px; font-weight: 600; color: var(--quiz); }
+.prompt { margin: 0; font-size: 28px; line-height: 1.35; }
+.side .prompt { font-size: 24px; }
+.body:empty { display: none; }
+.side .body { margin-top: 14px; }
+.opts { display: flex; gap: 12px; flex-wrap: wrap; }
+.opt { padding: 8px 24px; border-radius: 999px; border: 2px solid var(--edge); background: transparent; color: var(--chalk); font-size: 24px; min-height: 58px; display: inline-flex; align-items: center; }
+.opt:hover:not(:disabled) { border-color: var(--dim); }
+.opt[aria-pressed="true"] { background: var(--c, var(--chalk)); border-color: var(--c, var(--chalk)); color: #1b2320; font-weight: 600; }
+.opt.good { border-color: var(--good); box-shadow: 0 0 0 3px rgba(143, 214, 176, .35); }
+.opt.bad { border-color: var(--bad); color: var(--bad); }
+.opt:disabled { cursor: default; }
+.fb { margin-top: 8px; font-size: 22px; line-height: 1.4; color: var(--chalk); }
+.fb:empty { display: none; }
+.fb.ok::before { content: "✓ "; color: var(--good); font-weight: 700; }
+.fb.no::before { content: "✗ "; color: var(--bad); font-weight: 700; }
+.fb ul { margin: 6px 0 0; padding-left: 22px; }
+.side .fb { max-height: 110px; overflow: auto; font-size: 20px; }
+.acts { display: flex; gap: 12px; align-items: center; }
+.side .acts { margin-top: 16px; }
+.side .acts { flex-wrap: wrap; gap: 10px; }
+.side .btn { padding: 8px 16px; font-size: 20px; }
+.card.side { padding: 18px 22px; }
+.btn { padding: 10px 28px; border-radius: 999px; border: 0; background: var(--chalk); color: var(--board); font-weight: 600; font-size: 22px; white-space: nowrap; }
+.btn.quiet { background: transparent; color: var(--dim); border: 1.5px solid var(--edge); }
+.btn.go { background: var(--quiz); color: #10242e; }
+.btn:disabled { background: var(--edge); color: var(--dim); cursor: default; }
+
+.grid .row { display: grid; grid-template-columns: 170px minmax(0, 1fr) 34px; gap: 16px; align-items: center; padding: 5px 0 5px 12px; border-bottom: 1px solid #2e433b; }
+.grid .num { display: flex; justify-content: flex-end; align-items: center; font-size: 26px; }
+.grid.text .row { grid-template-columns: minmax(0, 1fr) auto 34px; }
+.grid.text .num { justify-content: flex-start; }
+.grid .opts { gap: 8px; }
+.grid .opt { padding: 3px 16px; min-height: 42px; font-size: 20px; }
+.grid .mark { font-weight: 700; text-align: center; }
+.grid .mark.good { color: var(--good); }
+.grid .mark.bad { color: var(--bad); }
+.grid .why { grid-column: 1 / -1; font-size: 19px; color: var(--dim); padding-left: 186px; }
+.grid.text .why { padding-left: 0; }
+.grid .why:empty { display: none; }
+
+.hit { cursor: pointer; }
+.hit .ring { fill: transparent; stroke: var(--chalk); stroke-width: 2.5; stroke-opacity: 0; }
+.hit:hover .ring, .hit:focus .ring { stroke-opacity: .7; }
+.hit.bad .ring { stroke: var(--bad); stroke-opacity: 1; }
+.hit.good .ring { stroke: var(--good); stroke-opacity: 1; stroke-width: 4; }
+.tok { cursor: grab; touch-action: none; } /* a finger drags the chip instead of scrolling the page */
+
+/* Controls strip, part of the frame. */
+#bar { position: absolute; left: 0; top: 900px; width: 1600px; height: 60px; display: flex; align-items: center; gap: 10px; padding: 0 20px; background: #16211d; border-top: 1px solid #2a3b35; }
+.icon { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--edge); background: var(--panel); display: grid; place-items: center; flex: none; padding: 0; }
+.icon svg { width: 18px; height: 18px; fill: var(--chalk); }
+.icon .i-pause { display: none; }
+.is-playing .icon .i-play { display: none; }
+.is-playing .icon .i-pause { display: block; }
+.segs { flex: 1; display: flex; gap: 4px; height: 30px; align-items: center; min-width: 0; margin: 0 8px; }
+.seg { position: relative; display: block; min-width: 0; height: 8px; border-radius: 4px; background: #2f4640; border: 0; padding: 0; overflow: hidden; }
+.seg:hover { height: 12px; }
+.seg i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--chalk); }
+.seg.ask { background: #2d4a57; }
+.seg.ask i { background: var(--quiz); }
+.step { width: 300px; flex: none; color: var(--dim); font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
+/* Keep the control strip usable without scaling down its touch targets. */
+@media (max-width: 700px) {
+ #frame { top: calc(50% - 50px); overflow: visible; }
+ #bar { width: calc(1600px * var(--k)); height: auto; flex-wrap: wrap; gap: 6px; padding: 8px;
+ transform: scale(calc(1 / var(--k))); transform-origin: left top; border-radius: 0 0 12px 12px; }
+ #bar .icon { width: 36px; height: 40px; }
+ .step { display: none; }
+ #bHelp { display: none; } /* keyboard shortcuts; room for the speed button on a phone */
+ #bar .icon.speed { width: 36px; min-width: 0; padding: 0; font-size: 12px; letter-spacing: -.3px; }
+ .segs { order: 1; }
+ .segs { min-width: 80px; margin: 0; }
+}
+.sound-note { position: absolute; left: 24px; top: 20px; margin: 0; padding: 8px 18px; border-radius: 12px; background: rgba(15, 22, 19, .85); color: var(--dim); font-size: 19px; }
+.sound-note[hidden] { display: none; }
+.blanks .brow { padding: 8px 0; border-bottom: 1px solid #2e433b; }
+.blanks .brow:last-child { border-bottom: 0; }
+.blanks .bline { line-height: 64px; white-space: nowrap; }
+.blanks .mark { display: inline-block; margin-left: 14px; font-weight: 700; }
+.blanks .mark.good { color: var(--good); animation: pop .35s ease-out; }
+.blanks .mark.bad { color: var(--bad); }
+.blanks .why { font-size: 19px; color: var(--dim); line-height: 1.35; }
+.blanks .why:empty { display: none; }
+.box { height: 52px; margin: 0 6px; padding: 0 6px; border: 0; border-bottom: 3px solid var(--quiz); border-radius: 8px 8px 0 0; background: rgba(236, 232, 220, .07); color: var(--chalk); font: 32px var(--math-font, "STIX Two Text", "Cambria Math", "Iowan Old Style", Palatino, Georgia, serif); text-align: center; vertical-align: -6px; }
+.box:focus { outline: none; background: rgba(134, 201, 232, .16); }
+.box.good { border-color: var(--good); }
+.box.bad { border-color: var(--bad); }
+.box:disabled { opacity: 1; }
+kbd { display: inline-block; min-width: 1.5em; padding: 0 .4em; margin-left: .5em; border: 1.5px solid currentColor; border-radius: 6px; font: 600 .7em/1.5 var(--ui); text-align: center; vertical-align: .12em; opacity: .6; }
+.opt kbd { margin: 0 .6em 0 0; }
+.keys { margin: 6px 0 0; font-size: 18px; color: var(--dim); }
+.keys kbd { margin: 0 .15em; }
+.grid .row.cur { background: rgba(236, 232, 220, .05); box-shadow: inset 4px 0 var(--quiz); }
+.help { position: absolute; left: 0; top: 0; width: 1600px; height: 900px; display: grid; place-items: center; background: rgba(10, 16, 14, .72); }
+.help[hidden] { display: none; }
+.help-box { width: 1120px; padding: 40px 50px; border-radius: 22px; background: var(--panel); border: 1.5px solid var(--edge); }
+.help h2 { margin: 0 0 22px; font-size: 32px; font-weight: 600; }
+.help h3 { margin: 0 0 12px; font-size: 20px; font-weight: 600; color: var(--quiz); }
+.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 44px; }
+.help dl { margin: 0; display: grid; grid-template-columns: 150px 1fr; row-gap: 10px; font-size: 22px; }
+.help dt { text-align: right; padding-right: 18px; white-space: nowrap; }
+.help dt kbd { margin: 0 0 0 .3em; opacity: .9; }
+.help dd { margin: 0; color: var(--dim); }
+.help-close { margin: 26px 0 0; font-size: 18px; color: var(--dim); }
+.icon.txt { font-size: 20px; font-weight: 700; color: var(--dim); }
+/* Optional captions of the narration, one sentence at a time. Off by default: teaching text lives in the picture. */
+.caption { position: absolute; left: 50%; bottom: 78px; transform: translateX(-50%); width: max-content; max-width: 1180px; padding: 10px 24px; border-radius: 14px; background: rgba(10, 16, 14, .82); color: var(--chalk); font-size: 28px; line-height: 1.35; text-align: center; pointer-events: none; }
+.caption[hidden] { display: none; }
+.icon.cc { font-size: 15px; font-weight: 700; color: var(--dim); }
+.icon.cc[aria-pressed="true"] { background: var(--chalk); border-color: var(--chalk); color: var(--board); }
+.card.side { overflow: auto; }
+svg.m { display: inline-block; overflow: visible; }
+.card b { font-weight: 700; } /* not 'bolder' (900 under a 600 prompt) */
+.card { animation: card-in .45s cubic-bezier(.2, .9, .3, 1.15); }
+.fb:not(:empty) { animation: fb-in .3s ease-out; }
+.opt.bad, .grid .mark.bad { animation: shake .4s; }
+.grid .mark.good { animation: pop .35s ease-out; }
+@keyframes card-in { from { opacity: 0; transform: translateY(24px) scale(.98); } }
+@keyframes fb-in { from { opacity: 0; transform: translateY(8px); } }
+@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.3); } }
+@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
+/* Full-screen chapter practice. */
+.card.screen { height: 900px; padding: 50px 70px; border: 0; border-radius: 0; background: transparent; box-shadow: none; animation: screen-in .5s ease-out; max-height: none; overflow: visible; }
+.screen .kicker { font-size: 22px; }
+.screen .prompt { font-size: 40px; font-weight: 600; }
+.screen .body { margin-top: 30px; }
+.card.screen { display: flex; flex-direction: column; }
+.screen .head { order: 1; } .screen .body { order: 2; }
+.screen .fb { order: 3; max-width: 1080px; margin: 26px 0 0; font-size: 24px; } /* feedback right under the answers */
+/* Practice screens: the bottom 130 px hold the buttons. Long answers scroll inside the body, so the feedback under
+ them stays in view after a wrong answer adds a 'why' line to each row. */
+.card.screen:not(.sort):not(.fin) { padding-bottom: 130px; }
+.card.screen:not(.sort):not(.fin) > .head, .card.screen:not(.sort):not(.fin) > .fb { flex: none; }
+.card.screen:not(.sort):not(.fin) > .body { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
+.screen .acts { position: absolute; right: 70px; bottom: 48px; }
+.screen .grid .row { grid-template-columns: 200px minmax(0, 1fr) 40px; padding: 9px 0 9px 12px; }
+.screen .grid.text .row { grid-template-columns: minmax(0, 1fr) auto 40px; }
+.screen .grid .opt { font-size: 22px; min-height: 50px; padding: 4px 20px; }
+.screen .grid .why { padding-left: 216px; font-size: 20px; }
+.screen .grid.text .why { padding-left: 0; }
+#ui > .screen.sort { pointer-events: none; }
+.screen.sort > * { pointer-events: auto; }
+.screen.sort .head { position: absolute; right: 34px; top: 40px; width: 330px; }
+.screen.sort .prompt { font-size: 28px; }
+.screen.sort .fb { position: absolute; margin: 0; left: auto; right: 34px; bottom: 116px; width: 330px; max-height: 240px; overflow: auto; font-size: 20px; }
+.screen.sort .acts { right: 34px; }
+.fin .finwrap { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; text-align: center; padding-bottom: 60px; }
+.fin .mascot { margin-bottom: 28px; }
+.fin .fb, .fin .acts { position: static; }
+.fin .fb { order: 0; margin: 0; } /* result lines, not answer feedback: keep them above the buttons */
+.fin .acts { margin-top: 30px; }
+@keyframes screen-in { from { opacity: 0; } }
+
+/* The guide: an infinity sign whose loops are its eyes. */
+.mascot { display: block; flex: none; overflow: visible; }
+.mascot .mbody { transform-box: view-box; transform-origin: 60px 46px; animation: bob 3.4s ease-in-out infinite; }
+.mascot .eyes { transition: transform .3s; }
+.mascot .pupil { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
+.mascot .joy, .mascot .flat { display: none; }
+.mascot.happy .pupil { display: none; }
+.mascot.happy .joy { display: inline; }
+.mascot.happy .mbody { animation: hop .55s ease-out 2, bob 3.4s ease-in-out 1.1s infinite; }
+.mascot.oops .eyes { transform: translate(-3px, 4px); }
+.mascot.oops .smile { display: none; }
+.mascot.oops .flat { display: inline; }
+.mascot.oops .mbody { animation: wobble .5s ease-in-out, bob 3.4s ease-in-out .5s infinite; }
+@keyframes bob { 50% { transform: translateY(-3px) rotate(-2deg); } }
+@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
+@keyframes hop { 40% { transform: translateY(-12px) rotate(4deg); } }
+@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(6deg); } }
+@media (prefers-reduced-motion: reduce) { .card, .fb, .opt, .grid .mark, .mascot * { animation: none !important; } }
+
+a.icon { text-decoration: none; }
+a.btn { text-decoration: none; display: inline-block; }
+/* Page-to-page motion: the contents card grows into this frame, and shrinks back on the way out. */
+@view-transition { navigation: auto; }
+#frame { view-transition-name: lesson; }
+::view-transition-group(lesson) { animation-duration: .5s; animation-timing-function: cubic-bezier(.2, .8, .2, 1); }
+::view-transition-old(lesson), ::view-transition-new(lesson) { height: 100%; object-fit: cover; }
+::view-transition-old(lesson) { animation-duration: .18s; }
+@media (prefers-reduced-motion: reduce) { .cover > div > * { animation: none; } ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; } }
+/* The finish screen speaks the same type as the chapter cover and the contents page. */
+.fin .kicker { font-size: 20px; letter-spacing: .14em; text-transform: uppercase; }
+.fin .prompt { margin: 6px 0 14px; font: 500 56px/1.15 "Iowan Old Style", Palatino, Georgia, serif; }
+.icon.speed { width: auto; min-width: 44px; padding: 0 10px; border-radius: 22px; font-size: 16px; }
diff --git a/site/three-little-pigs/lib/engine.js b/site/three-little-pigs/lib/engine.js
new file mode 100644
index 0000000..883103d
--- /dev/null
+++ b/site/three-little-pigs/lib/engine.js
@@ -0,0 +1,2040 @@
+// Papermorph lesson engine: stage, drawing, timeline, questions, player.
+// A chapter page loads this file, defines CHAPTER and BEATS, then calls boot().
+'use strict';
+// A fast follow-up navigation can abort the incoming page transition.
+addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
+
+/* ---------- interface language ---------- */
+// The page's <html lang> picks the interface text; CHAPTER.language picks the audio folder. Set both alike.
+// A value is a string or plural forms { one, few, many, other } chosen by vars.n. Missing keys fall back to English.
+const TRANSLATIONS = {
+ en: {
+ decimalSign: '.', stageLabel: 'Lesson animation', stageLabelTitled: 'Lesson animation: {title}',
+ shortcuts: 'Keyboard shortcuts', lesson: 'Lesson', questions: 'Questions',
+ helpPlay: 'Play or pause', helpStep: 'Previous or next step', helpStepInQuestion: 'Change step during a question', helpRestart: 'Start over',
+ helpCaptions: 'Captions on or off', helpSpeed: 'Slower or faster', helpFullScreen: 'Full screen', helpList: 'Show this list',
+ helpChoose: 'Choose an answer or a ring', helpTrueFalse: 'True or false', helpRows: 'Move between rows',
+ helpNumberLine: 'Move along the number line, or pick a number to sort', helpEnter: 'Check, then continue',
+ helpShowAnswer: 'Show the answer', helpLeaveBox: 'Leave an answer box', helpClose: 'Press {key} to close.',
+ paused: 'Paused. Press space or click to continue.',
+ soundFailed: 'Sound could not play. The lesson continues with the on-screen text.',
+ startLesson: 'Start lesson', coverKeys: 'Press {space} to start, {help} for shortcuts.', spaceKey: 'Space',
+ chapterNumber: 'Chapter {n}', aboutMinutes: 'About {n} minutes, with sound and quick checks.',
+ allChapters: 'All chapters', playLabel: 'Play or pause (space)', backLabel: 'Previous step (left arrow)', restartLabel: 'Restart lesson',
+ volumeLabel: 'Adjust volume', volumeTitle: 'Volume (0 = muted)', volumeSlider: 'Volume',
+ helpLabel: 'Keyboard shortcuts (?)', speedLabel: 'Playback speed (< and >)', captionsLabel: 'Captions (C)', fullScreenLabel: 'Full screen', goToStep: 'Go to step {n}: {title}',
+ quickCheck: 'Quick check', countOf: '{k} of {n}', check: 'Check', showAnswer: 'Show answer', nextQuestion: 'Next question', continue: 'Continue',
+ correct: 'Correct. ', notQuite: 'Not quite. ', answerPrefix: 'Answer: ', keysPrefix: 'Keys: ',
+ hintMove: ' move, ', hintChoose: ' choose', hintChooseOrClickGrid: ' choose, or click the grid', hintMoveAlongLine: ' move along the line, ',
+ hintChooseOrClick: ' choose, or click', hintRow: ' row, ', hintTypeFraction: 'type numbers like 3/4 or −2 1/4, ', hintTypeNumber: 'type the number, ',
+ hintTypeDecimal: 'type the number, ', hintNextBox: ' next box, ', hintCheck: ' check, ', hintLeaveBox: ' leave the box',
+ hintPickNumber: ' pick a number, ', hintPickRing: ' choose its ring',
+ rowsRight: '{r} of {n} right. Fix the rows marked ✗ and check again.',
+ choicesShown: 'the correct choices are now selected.', numbersShown: 'the correct numbers are filled in.',
+ notPlacedYet: '{x} is not placed yet.',
+ realRingIsEmpty: '{x}: every real number is rational or irrational, so that space has no numbers of its own.',
+ ringsRight: '{r} of {n} in the right ring.', ringsShown: 'every number is now in its smallest ring.',
+ chipPlaced: '{x}, placed in {ring}', chipNotPlaced: '{x}, not placed', pointLabel: 'The point {v}', answerBox: 'Answer',
+ stepsLeftOfZero: '{n} steps left of 0',
+ natural: 'Natural', whole: 'Whole', integers: 'Integers', rational: 'Rational', irrational: 'Irrational', real: 'Real', integerColumn: 'Integer',
+ trueLabel: 'True', falseLabel: 'False',
+ chapterComplete: 'Chapter {n} complete', quickChecks: 'Quick checks', chapterPractice: 'Chapter practice',
+ firstTryScore: '{name}: {r} of {t} right on the first try.', notAttempted: '{name}: not attempted.',
+ watchAgain: 'Watch again', nextChapter: 'Next chapter',
+ },
+ ru: {
+ decimalSign: ',', stageLabel: 'Анимация урока', stageLabelTitled: 'Анимация урока: {title}',
+ shortcuts: 'Горячие клавиши', lesson: 'Урок', questions: 'Вопросы',
+ helpPlay: 'Пуск или пауза', helpStep: 'Предыдущий или следующий шаг', helpStepInQuestion: 'Сменить шаг во время вопроса', helpRestart: 'Начать сначала',
+ helpCaptions: 'Субтитры вкл. или выкл.', helpSpeed: 'Медленнее или быстрее', helpFullScreen: 'Полноэкранный режим', helpList: 'Показать этот список',
+ helpChoose: 'Выбрать ответ или круг', helpTrueFalse: 'Верно или неверно', helpRows: 'Перейти между строками',
+ helpNumberLine: 'Двигаться по числовой прямой или выбрать число для сортировки', helpEnter: 'Проверить, затем продолжить',
+ helpShowAnswer: 'Показать ответ', helpLeaveBox: 'Выйти из поля ответа', helpClose: 'Нажмите {key}, чтобы закрыть.',
+ paused: 'Пауза. Нажмите пробел или щёлкните, чтобы продолжить.',
+ soundFailed: 'Звук не воспроизводится. Урок продолжится с текстом на экране.',
+ startLesson: 'Начать урок', coverKeys: '{space} — начать, {help} — горячие клавиши.', spaceKey: 'Пробел',
+ chapterNumber: 'Глава {n}',
+ aboutMinutes: { one: 'Около {n} минуты, со звуком и проверками.', few: 'Около {n} минут, со звуком и проверками.',
+ many: 'Около {n} минут, со звуком и проверками.', other: 'Около {n} минуты, со звуком и проверками.' },
+ allChapters: 'Все главы', playLabel: 'Пуск или пауза (пробел)', backLabel: 'Предыдущий шаг (стрелка влево)', restartLabel: 'Начать урок заново',
+ volumeLabel: 'Настроить громкость', volumeTitle: 'Громкость (0 — без звука)', volumeSlider: 'Громкость',
+ helpLabel: 'Горячие клавиши (?)', speedLabel: 'Скорость воспроизведения (< и >)', captionsLabel: 'Субтитры (C)', fullScreenLabel: 'Полный экран', goToStep: 'Перейти к шагу {n}: {title}',
+ quickCheck: 'Проверь себя', countOf: '{k} из {n}', check: 'Проверить', showAnswer: 'Показать ответ', nextQuestion: 'Следующий вопрос', continue: 'Продолжить',
+ correct: 'Верно. ', notQuite: 'Не совсем. ', answerPrefix: 'Ответ: ', keysPrefix: 'Клавиши: ',
+ hintMove: ' двигаться, ', hintChoose: ' выбрать', hintChooseOrClickGrid: ' выбрать или щёлкнуть по сетке', hintMoveAlongLine: ' двигаться по прямой, ',
+ hintChooseOrClick: ' выбрать или щёлкнуть', hintRow: ' строка, ', hintTypeFraction: 'вводите числа вида 3/4 или −2 1/4, ', hintTypeNumber: 'введите число, ',
+ hintTypeDecimal: 'вводите числа вида 0,75, ', hintNextBox: ' следующее поле, ', hintCheck: ' проверить, ', hintLeaveBox: ' выйти из поля',
+ hintPickNumber: ' выбрать число, ', hintPickRing: ' выбрать его круг',
+ rowsRight: 'Верно {r} из {n}. Исправьте строки с ✗ и проверьте снова.',
+ choicesShown: 'правильные варианты отмечены.', numbersShown: 'правильные числа вписаны.',
+ notPlacedYet: '{x}: ещё не размещено.',
+ realRingIsEmpty: '{x}: каждое действительное число рационально или иррационально, поэтому своих чисел у этой области нет.',
+ ringsRight: 'В нужном круге: {r} из {n}.', ringsShown: 'каждое число теперь в своём наименьшем круге.',
+ chipPlaced: '{x}, в круге «{ring}»', chipNotPlaced: '{x}, не размещено', pointLabel: 'Точка {v}', answerBox: 'Ответ',
+ stepsLeftOfZero: { one: '{n} шаг влево от 0', few: '{n} шага влево от 0', many: '{n} шагов влево от 0', other: '{n} шага влево от 0' },
+ natural: 'Натуральные', whole: 'Целые неотрицательные', integers: 'Целые', rational: 'Рациональные', irrational: 'Иррациональные', real: 'Действительные', integerColumn: 'Целые',
+ trueLabel: 'Верно', falseLabel: 'Неверно',
+ chapterComplete: 'Глава {n} пройдена', quickChecks: 'Проверь себя', chapterPractice: 'Практика по главе',
+ firstTryScore: '{name}: {r} из {t} верно с первой попытки.', notAttempted: '{name}: не выполнялось.',
+ watchAgain: 'Смотреть снова', nextChapter: 'Следующая глава',
+ },
+ zh: {
+ decimalSign: '.', stageLabel: '课程动画', stageLabelTitled: '课程动画:{title}',
+ shortcuts: '键盘快捷键', lesson: '课程', questions: '题目',
+ helpPlay: '播放或暂停', helpStep: '上一步或下一步', helpStepInQuestion: '答题时切换步骤', helpRestart: '从头开始',
+ helpCaptions: '打开或关闭字幕', helpSpeed: '减速或加速', helpFullScreen: '全屏', helpList: '显示此列表',
+ helpChoose: '选择答案或圆环', helpTrueFalse: '对或错', helpRows: '在各行之间移动',
+ helpNumberLine: '在数轴上移动,或选一个数来分类', helpEnter: '检查,然后继续',
+ helpShowAnswer: '显示答案', helpLeaveBox: '离开答题框', helpClose: '按 {key} 关闭。',
+ paused: '已暂停。按空格键或点击继续。',
+ soundFailed: '声音无法播放。课程将借助屏幕上的文字继续。',
+ startLesson: '开始上课', coverKeys: '按 {space} 开始,按 {help} 查看快捷键。', spaceKey: '空格',
+ chapterNumber: '第 {n} 章', aboutMinutes: '约 {n} 分钟,含配音和随堂小测。',
+ allChapters: '全部章节', playLabel: '播放或暂停(空格)', backLabel: '上一步(左方向键)', restartLabel: '重新开始本课',
+ volumeLabel: '调节音量', volumeTitle: '音量(0 为静音)', volumeSlider: '音量',
+ helpLabel: '键盘快捷键(?)', speedLabel: '播放速度(< 和 >)', captionsLabel: '字幕(C)', fullScreenLabel: '全屏', goToStep: '跳到第 {n} 步:{title}',
+ quickCheck: '小测', countOf: '{k} / {n}', check: '检查', showAnswer: '显示答案', nextQuestion: '下一题', continue: '继续',
+ correct: '正确。', notQuite: '还不对。', answerPrefix: '答案:', keysPrefix: '按键:',
+ hintMove: ' 移动,', hintChoose: ' 选择', hintChooseOrClickGrid: ' 选择,或点击网格', hintMoveAlongLine: ' 沿数轴移动,',
+ hintChooseOrClick: ' 选择,或点击', hintRow: ' 换行,', hintTypeFraction: '可输入 3/4 或 −2 1/4 这样的数,', hintTypeNumber: '输入数字,',
+ hintTypeDecimal: '输入数字,', hintNextBox: ' 下一个框,', hintCheck: ' 检查,', hintLeaveBox: ' 离开答题框',
+ hintPickNumber: ' 选一个数,', hintPickRing: ' 选它所在的圆环',
+ rowsRight: '{n} 行中对了 {r} 行。改正标 ✗ 的行,再检查一次。',
+ choicesShown: '正确选项已经选上。', numbersShown: '正确的数已经填上。',
+ notPlacedYet: '{x} 还没有放好。',
+ realRingIsEmpty: '{x}:每个实数不是有理数就是无理数,所以这一块没有只属于它的数。',
+ ringsRight: '{n} 个中有 {r} 个放在了正确的圆环里。', ringsShown: '每个数现在都在它所属的最小圆环里。',
+ chipPlaced: '{x},放在「{ring}」', chipNotPlaced: '{x},未放置', pointLabel: '点 {v}', answerBox: '答案',
+ stepsLeftOfZero: '0 左边 {n} 步',
+ natural: '正整数', whole: '非负整数', integers: '整数', rational: '有理数', irrational: '无理数', real: '实数', integerColumn: '整数',
+ trueLabel: '对', falseLabel: '错',
+ chapterComplete: '第 {n} 章完成', quickChecks: '小测', chapterPractice: '本章练习',
+ firstTryScore: '{name}:第一次就答对 {r} / {t}。', notAttempted: '{name}:未作答。',
+ watchAgain: '再看一遍', nextChapter: '下一章',
+ },
+ ja: {
+ decimalSign: '.', stageLabel: '授業アニメーション', stageLabelTitled: '授業アニメーション:{title}',
+ shortcuts: 'キーボードショートカット', lesson: '授業', questions: '問題',
+ helpPlay: '再生/一時停止', helpStep: '前または次のステップ', helpStepInQuestion: '問題の途中でステップを移動', helpRestart: '最初から',
+ helpCaptions: '字幕のオン/オフ', helpSpeed: '遅く/速く', helpFullScreen: '全画面', helpList: 'この一覧を表示',
+ helpChoose: '答えまたは輪を選ぶ', helpTrueFalse: '正しい/誤り', helpRows: '行を移動',
+ helpNumberLine: '数直線上を移動、または分類する数を選ぶ', helpEnter: '答え合わせ、そして次へ',
+ helpShowAnswer: '答えを表示', helpLeaveBox: '解答欄から出る', helpClose: '{key} で閉じる。',
+ paused: '一時停止中。スペースキーかクリックで再開します。',
+ soundFailed: '音声を再生できません。画面の文字で授業を続けます。',
+ startLesson: '授業を始める', coverKeys: '{space} で開始、{help} でショートカット一覧。', spaceKey: 'スペース',
+ chapterNumber: '第{n}章', aboutMinutes: '約{n}分、音声と確認問題つき。',
+ allChapters: 'すべての章', playLabel: '再生/一時停止(スペース)', backLabel: '前のステップ(左矢印)', restartLabel: '授業を最初から',
+ volumeLabel: '音量を調整', volumeTitle: '音量(0 でミュート)', volumeSlider: '音量',
+ helpLabel: 'キーボードショートカット(?)', speedLabel: '再生速度(< と >)', captionsLabel: '字幕(C)', fullScreenLabel: '全画面', goToStep: 'ステップ {n}:{title} へ移動',
+ quickCheck: '確認問題', countOf: '{k} / {n}', check: '答え合わせ', showAnswer: '答えを見る', nextQuestion: '次の問題', continue: '続ける',
+ correct: '正解。', notQuite: 'おしい。', answerPrefix: '答え:', keysPrefix: 'キー:',
+ hintMove: ' 移動、', hintChoose: ' 選ぶ', hintChooseOrClickGrid: ' 選ぶ、またはマス目をクリック', hintMoveAlongLine: ' 数直線上を移動、',
+ hintChooseOrClick: ' 選ぶ、またはクリック', hintRow: ' 行、', hintTypeFraction: '3/4 や −2 1/4 のように入力、', hintTypeNumber: '数を入力、',
+ hintTypeDecimal: '数を入力、', hintNextBox: ' 次の欄、', hintCheck: ' 答え合わせ、', hintLeaveBox: ' 欄から出る',
+ hintPickNumber: ' 数を選ぶ、', hintPickRing: ' その輪を選ぶ',
+ rowsRight: '{n} 行中 {r} 行正解。✗ の行を直して、もう一度答え合わせ。',
+ choicesShown: '正しい選択肢を選びました。', numbersShown: '正しい数を入れました。',
+ notPlacedYet: '{x} はまだ置かれていません。',
+ realRingIsEmpty: '{x}:実数はどれも有理数か無理数なので、この部分だけに入る数はありません。',
+ ringsRight: '{n} 個中 {r} 個が正しい輪に入っています。', ringsShown: 'どの数も、入るいちばん小さい輪に移しました。',
+ chipPlaced: '{x}、「{ring}」に配置', chipNotPlaced: '{x}、未配置', pointLabel: '点 {v}', answerBox: '答え',
+ stepsLeftOfZero: '0 から左へ {n}',
+ natural: '自然数', whole: '0 以上の整数', integers: '整数', rational: '有理数', irrational: '無理数', real: '実数', integerColumn: '整数',
+ trueLabel: '正しい', falseLabel: '誤り',
+ chapterComplete: '第{n}章 完了', quickChecks: '確認問題', chapterPractice: '章末練習',
+ firstTryScore: '{name}:1 回目で {t} 問中 {r} 問正解。', notAttempted: '{name}:未挑戦。',
+ watchAgain: 'もう一度見る', nextChapter: '次の章へ',
+ },
+};
+const LANGUAGE = (document.documentElement.lang || 'en').toLowerCase().split('-')[0];
+const pluralRules = {};
+// Interface text in LANGUAGE: translate('chapterNumber', { n: 3 }) → 'Chapter 3'. Chapters may use it too, e.g. for practice labels.
+function translate(key, vars = {}) {
+ const language = TRANSLATIONS[LANGUAGE]?.[key] !== undefined ? LANGUAGE : 'en';
+ let text = TRANSLATIONS[language][key] ?? key;
+ if (typeof text === 'object') {
+ try { pluralRules[language] ??= new Intl.PluralRules(language); } catch { pluralRules[language] = new Intl.PluralRules('en'); }
+ text = text[pluralRules[language].select(vars.n)] ?? text.other;
+ }
+ return text.replace(/\{(\w+)\}/g, (placeholder, name) => name in vars ? vars[name] : placeholder);
+}
+const DECIMAL_SIGN = translate('decimalSign'); // shown by num() and accepted by answer boxes
+const isLatinLetter = key => /^[a-z]$/i.test(key);
+// A letter shortcut on any keyboard layout: the typed letter, or the same physical key when the layout types a non-Latin letter.
+const isShortcut = (event, letter) => event.key.toLowerCase() === letter.toLowerCase()
+ || (isLatinLetter(letter) && !isLatinLetter(event.key) && event.code === 'Key' + letter.toUpperCase());
+// A punctuation shortcut (code 'Comma', 'Period') on a layout that types a non-Latin letter on that key.
+const isShortcutCode = (event, code) => /^\p{L}$/u.test(event.key) && !isLatinLetter(event.key) && event.code === code;
+
+document.body.insertAdjacentHTML('afterbegin', `<div id="frame">
+ <svg id="stage" viewBox="0 0 1600 900" role="img" aria-label="${translate('stageLabel')}">
+ <g id="scene"></g>
+ </svg>
+ <div id="ui"></div>
+ <div class="paused-mark"><div>${translate('paused')}</div></div>
+ <div class="caption" id="caption" hidden></div>
+ <div class="help" id="help" hidden role="dialog" aria-label="${translate('shortcuts')}">
+ <div class="help-box">
+ <h2>${translate('shortcuts')}</h2>
+ <div class="help-cols">
+ <div><h3>${translate('lesson')}</h3><dl>
+ <dt><kbd>${translate('spaceKey')}</kbd></dt><dd>${translate('helpPlay')}</dd>
+ <dt><kbd>←</kbd><kbd>→</kbd></dt><dd>${translate('helpStep')}</dd>
+ <dt><kbd>Shift</kbd><kbd>←</kbd><kbd>→</kbd></dt><dd>${translate('helpStepInQuestion')}</dd>
+ <dt><kbd>Home</kbd></dt><dd>${translate('helpRestart')}</dd>
+ <dt><kbd>C</kbd></dt><dd>${translate('helpCaptions')}</dd>
+ <dt><kbd>&lt;</kbd><kbd>&gt;</kbd></dt><dd>${translate('helpSpeed')}</dd>
+ <dt><kbd>F</kbd></dt><dd>${translate('helpFullScreen')}</dd>
+ <dt><kbd>?</kbd></dt><dd>${translate('helpList')}</dd>
+ </dl></div>
+ <div><h3>${translate('questions')}</h3><dl>
+ <dt><kbd>1</kbd>–<kbd>6</kbd></dt><dd>${translate('helpChoose')}</dd>
+ <dt><kbd>T</kbd><kbd>F</kbd></dt><dd>${translate('helpTrueFalse')}</dd>
+ <dt><kbd>↑</kbd><kbd>↓</kbd></dt><dd>${translate('helpRows')}</dd>
+ <dt><kbd>←</kbd><kbd>→</kbd></dt><dd>${translate('helpNumberLine')}</dd>
+ <dt><kbd>Enter</kbd></dt><dd>${translate('helpEnter')}</dd>
+ <dt><kbd>S</kbd></dt><dd>${translate('helpShowAnswer')}</dd>
+ <dt><kbd>Esc</kbd></dt><dd>${translate('helpLeaveBox')}</dd>
+ </dl></div>
+ </div>
+ <p class="help-close">${translate('helpClose', { key: '<kbd>Esc</kbd>' })}</p>
+ </div>
+ </div>
+ <p class="sound-note" id="soundNote" hidden>${translate('soundFailed')}</p>
+ <button class="cover" id="cover"><div>
+ <p class="cover-k" id="coverK"></p>
+ <h1 class="cover-t" id="coverT"></h1>
+ <span class="go"><svg width="24" height="24" viewBox="0 0 18 18"><path d="M3 1.5v15l13-7.5z" fill="currentColor"/></svg>${translate('startLesson')}</span>
+ <small><span id="coverMeta"></span> ${translate('coverKeys', { space: `<kbd>${translate('spaceKey')}</kbd>`, help: '<kbd>?</kbd>' })}</small>
+ </div></button>
+ <div id="bar">
+ <a class="icon" id="bHome" href="../" aria-label="${translate('allChapters')}" title="${translate('allChapters')}">
+ <svg viewBox="0 0 18 18"><path d="M2 2h6v6H2zM10 2h6v6h-6zM2 10h6v6H2zM10 10h6v6h-6z"/></svg>
+ </a>
+ <button class="icon" id="bPlay" aria-label="${translate('playLabel')}">
+ <svg class="i-play" viewBox="0 0 18 18"><path d="M4 2v14l12-7z"/></svg>
+ <svg class="i-pause" viewBox="0 0 18 18"><path d="M3.5 2h4v14h-4zM10.5 2h4v14h-4z"/></svg>
+ </button>
+ <button class="icon" id="bBack" aria-label="${translate('backLabel')}">
+ <svg viewBox="0 0 18 18"><path d="M3 2h2.5v14H3zM16 2v14L6.5 9z"/></svg>
+ </button>
+ <button class="icon" id="bRestart" aria-label="${translate('restartLabel')}">
+ <svg viewBox="0 0 18 18"><path d="M9 2.5a6.5 6.5 0 1 1-6.3 8.1l2-.5A4.5 4.5 0 1 0 9 4.5V7L4.5 3.5 9 0z"/></svg>
+ </button>
+ <div class="segs" id="segs"></div>
+ <div class="step" id="stepName"></div>
+ <button class="icon txt" id="bHelp" aria-label="${translate('helpLabel')}" title="${translate('helpLabel')}">?</button>
+ <button class="icon txt speed" id="bSpeed" aria-label="${translate('speedLabel')}" title="${translate('speedLabel')}">1×</button>
+ <button class="icon cc" id="bCC" aria-pressed="false" aria-label="${translate('captionsLabel')}" title="${translate('captionsLabel')}">CC</button>
+ <button class="icon" id="bFull" aria-label="${translate('fullScreenLabel')}">
+ <svg viewBox="0 0 18 18"><path d="M1 1h6v2H3v4H1zM11 1h6v6h-2V3h-4zM1 11h2v4h4v2H1zM15 11h2v6h-6v-2h4z"/></svg>
+ </button>
+ </div>
+</div>`);
+
+// Board colour, grain and vignette are a static CSS background of #stage (engine.css). The grain is a small noise
+// texture made once here: an SVG turbulence filter behind animated content is recomputed on every frame in Firefox.
+{
+ const c = document.createElement('canvas'); c.width = c.height = 256;
+ const x = c.getContext('2d'), d = x.createImageData(256, 256);
+ for (let i = 0, s = 7; i < d.data.length; i += 4) { s = s * 16807 % 2147483647; d.data.set([235, 242, 230, 4 + s % 12], i); }
+ x.putImageData(d, 0, 0);
+ document.getElementById('stage').style.setProperty('--grain', `url(${c.toDataURL()})`);
+}
+
+/* ---------- drawing helpers ---------- */
+const NS = 'http://www.w3.org/2000/svg';
+const COL = { nat: '#f4a48c', whole: '#86c9e8', int: '#f3c95c', rat: '#e8a0c8', irr: '#8fd6b0', real: '#bba8ee',
+ chalk: '#ece8dc', dim: '#9aaba3', faint: '#5d7068', task: '#f0b45a', good: '#8fd6b0', bad: '#f08c7a', board: '#1d2b27' };
+const UI = '"Avenir Next","Segoe UI","Helvetica Neue",Arial,sans-serif';
+// Book settings (lib/book.css, next to engine.css and imported by it): --math-font for numbers and formulas,
+// --progress-key for the localStorage key the cover and chapters share.
+const BOOK = getComputedStyle(document.documentElement);
+const bookSetting = name => BOOK.getPropertyValue(name).trim().replace(/^(["'])([^"']*)\1$/, '$2'); // unquote a lone string only
+const MATH = bookSetting('--math-font') || '"STIX Two Text","Cambria Math","Iowan Old Style",Palatino,Georgia,serif';
+const NAME = { nat: translate('natural'), whole: translate('whole'), int: translate('integers'), rat: translate('rational'), irr: translate('irrational'), real: translate('real') };
+// Card positions inside the 1600×900 picture.
+const BAND = { x: 96, y: 686, w: 1408, cls: 'band' }; // bottom band (moves up when taller than the space left)
+const RIGHT = { x: 1258, y: 546, w: 330, cls: 'side', maxH: 346 }; // right of the number map
+const TOPR = { x: 960, y: 70, w: 624, cls: 'side', maxH: 470 }; // top right, above the number line
+const SCREEN = { x: 0, y: 0, w: 1600, cls: 'screen' };
+const SORT_SCREEN = { x: 0, y: 0, w: 1600, cls: 'screen sort' };
+const $m = (...parts) => ({ m: parts });
+
+function mk(tag, attrs = {}, parent) {
+ const e = document.createElementNS(NS, tag);
+ for (const k in attrs) e.setAttribute(k, attrs[k]);
+ if (parent) parent.appendChild(e);
+ return e;
+}
+// Every animated element keeps a small state object; render() writes it to the DOM.
+// Keys: x y s r o (transform/opacity), d (0..1 stroke drawn), a_<attr> numeric attr, c_<attr> hex colour.
+function st(e) { return e._st || (e._st = { x: 0, y: 0, s: 1, r: 0, o: 1 }); }
+function put(e, o) { Object.assign(st(e), o); render(e); return e; }
+// Unchanged transform/opacity are not rewritten: per-frame updates of still elements cost repaints (notably in Firefox).
+function render(e) {
+ const s = e._st, tf = s.x || s.y || s.s !== 1 || s.r ? `translate(${s.x},${s.y}) rotate(${s.r}) scale(${s.s})` : null;
+ if (tf !== e._tf) { if (tf) e.setAttribute('transform', tf); else e.removeAttribute('transform'); e._tf = tf; }
+ if (s.o !== e._o) { e.setAttribute('opacity', s.o); e._o = s.o; }
+ if (s.d !== undefined) {
+ e.setAttribute('stroke-dashoffset', 1 - s.d);
+ e.style.visibility = s.d < .002 ? 'hidden' : '';
+ }
+ for (const k in s) {
+ if (k.startsWith('a_')) e.setAttribute(k.slice(2), s[k]);
+ else if (k.startsWith('c_')) e.setAttribute(k.slice(2), s[k]);
+ }
+}
+function G(parent, o = {}) { return put(mk('g', {}, parent), o); }
+function path(parent, d, attrs = {}, o = {}) {
+ const p = mk('path', { d, fill: 'none', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', ...attrs }, parent);
+ if (o.d !== undefined) { p.setAttribute('pathLength', 1); p.setAttribute('stroke-dasharray', '1 1'); }
+ return put(p, o);
+}
+function T(parent, str, { x = 0, y = 0, size = 30, fill = COL.chalk, font = UI, weight = 500, anchor = 'start', o = 1 } = {}) {
+ const t = mk('text', { 'font-size': size, fill, 'font-family': font, 'font-weight': weight, 'text-anchor': anchor }, parent);
+ t.textContent = str;
+ t.style.whiteSpace = 'pre';
+ return put(t, { x, y, o });
+}
+const ctx2d = document.createElement('canvas').getContext('2d');
+function textW(str, size, italic = false) { ctx2d.font = `${italic ? 'italic ' : ''}${size}px ${MATH}`; return ctx2d.measureText(str).width; }
+const VAR = /(?<![A-Za-z°])(?:(?!(?:of|in|is|to|or|at|on|by|as|an|if|it|be|no|so|up|we|my)(?![A-Za-z]))[a-z]{1,2}|(?!(?:If|In|It|Is|On|At|No|So|Or|An|As|To|By|Up)(?![A-Za-z]))[a-z]?[A-Z]{1,3}[a-z]?)(?![A-Za-z])/g; // capitals: A, PV, nRT // short lowercase runs are variables (a, x, ab), except short English words
+const F = (n, d) => ({ f: [String(n), String(d)] }); // fraction
+const R = (x, i) => ({ r: x && x.f ? x : String(x), i: i && String(i) }); // root of a number or of F(n, d); i = index, e.g. 3 for a cube root
+const E = x => ({ sup: String(x) }); // exponent, raised after the part before it
+const TX = tex => ({ tex: String(tex) }); // LaTeX, drawn by MathJax; the book loads lib/mathjax.js right after this file
+const $tex = tex => $m(TX(tex)); // LaTeX inline in HTML text
+// MathJax takes this object as its configuration when lib/mathjax.js loads after the engine.
+window.MathJax ??= {
+ startup: { typeset: false }, // no page scan; formulas are converted on demand
+ svg: { fontCache: 'none', mtextInheritFont: true }, // self-contained paths; \text{} in the book's math font
+ tex: { packages: { '[-]': ['noerrors', 'noundefined'] }, // a typo stops the page, like a misspelt mark
+ formatError: (_, error) => { throw error; } },
+ options: { enableMenu: false },
+};
+const TEX_CACHE = new Map(); // TeX source -> { graphic, viewBox }; seek() redraws every earlier beat
+// A copy of the formula's MathJax drawing: units of 1/1000 em, baseline at y = 0; viewBox is [x, y, width, height].
+function texGraphic(tex) {
+ let drawn = TEX_CACHE.get(tex);
+ if (!drawn) {
+ if (!window.MathJax?.tex2svg) throw new Error(`TX('${tex}') needs lib/mathjax.js: load ../lib/mathjax.js right after engine.js`);
+ if (!document.getElementById('MJX-SVG-styles')) document.head.append(MathJax.svgStylesheet()); // draws table rules and frames
+ let svg;
+ try { svg = MathJax.tex2svg(tex, { display: false, family: MATH }).querySelector('svg'); } // family: \text{} is measured in the font it is drawn in
+ catch (error) { throw new Error(`TX('${tex}'): ${error.message}`); }
+ const graphic = mk('g');
+ graphic.append(...svg.childNodes);
+ drawn = { graphic, viewBox: svg.getAttribute('viewBox').split(' ').map(Number) };
+ TEX_CACHE.set(tex, drawn);
+ }
+ return { graphic: drawn.graphic.cloneNode(true), viewBox: drawn.viewBox };
+}
+// The part of a TeX formula marked \class{name}{...}, ready for tw/fx on c_color and o.
+// MathJax places the part with its own transform, so the tweens act on a group inside it.
+function texPart(el, name) {
+ const part = el.querySelector(`g.${CSS.escape(name)}`);
+ if (!part) throw new Error(`texPart: no \\class{${name}}{…} in this formula`);
+ if (!part._tweenGroup) {
+ const group = mk('g');
+ group.append(...part.childNodes);
+ part.append(group);
+ const color = part.closest('[color]')?.getAttribute('color'); // the formula's fill
+ put(group, /^#[\da-f]{6}$/i.test(color) ? { c_color: color } : {});
+ part._tweenGroup = group;
+ }
+ return part._tweenGroup;
+}
+const OV = x => ({ ov: String(x) }); // digits under a repeat bar: ['0.', OV('3')] is 0.333…
+// Math expression from parts: 'text' | F(n,d) | R(x) | E(exp) | OV(digits) | TX(tex). Baseline at y; anchor start/middle/end.
+// _ascent and _descent are the TeX parts' height above and below the baseline (0 without TX).
+function M(parent, parts, { x = 0, y = 0, size = 36, fill = COL.chalk, anchor = 'middle', o = 1, s = 1 } = {}) {
+ const g = G(parent, { x, y, o, s });
+ const inner = mk('g', {}, g);
+ const lw = size * .05;
+ const text = (str, tx, ty, sz) => {
+ const t = mk('text', { x: tx, y: ty, 'font-size': sz, 'font-family': MATH, fill }, inner);
+ t.style.whiteSpace = 'pre';
+ let w = 0, last = 0;
+ const run = (piece, italic) => {
+ if (!piece) return;
+ mk('tspan', italic ? { 'font-style': 'italic' } : {}, t).textContent = piece;
+ w += textW(piece, sz, italic);
+ };
+ for (const m of str.matchAll(VAR)) { run(str.slice(last, m.index), false); run(m[0], true); last = m.index + m[0].length; }
+ run(str.slice(last), false);
+ return w;
+ };
+ const rule = (x1, x2, yy) => mk('path', { d: `M${x1} ${yy}H${x2}`, stroke: fill, 'stroke-width': lw, 'stroke-linecap': 'round' }, inner);
+ let cx = 0, ascent = 0, descent = 0;
+ for (const p of parts) {
+ if (typeof p === 'string') cx += text(p, cx, 0, size);
+ else if (p.tex !== undefined) {
+ const { graphic, viewBox: [, top, w, h] } = texGraphic(p.tex), k = size / 1000; // 1000 units = 1 em = size
+ graphic.setAttribute('transform', `translate(${cx},0) scale(${k})`);
+ graphic.setAttribute('color', fill); // MathJax paints with currentColor
+ inner.append(graphic);
+ ascent = Math.max(ascent, -top * k);
+ descent = Math.max(descent, (top + h) * k);
+ cx += w * k;
+ } else if (p.f) {
+ const fs = size * .72, [n, d] = p.f, wn = textW(n, fs), wd = textW(d, fs);
+ const w = Math.max(wn, wd) + size * .2, bar = -size * .3;
+ text(n, cx + (w - wn) / 2, bar - size * .12, fs);
+ text(d, cx + (w - wd) / 2, bar + size * .62, fs);
+ rule(cx + size * .04, cx + w - size * .04, bar);
+ cx += w + size * .04;
+ } else if (p.r) {
+ const fr = typeof p.r === 'object', mid = fr ? -size * .12 : -size * .3, bot = fr ? size * .45 : size * .06, top = fr ? -size * 1.12 : -size * .82;
+ let x0 = cx + size * .04;
+ if (p.i) { const iw = textW(p.i, size * .42); text(p.i, x0, mid - size * .14, size * .42); x0 += Math.max(0, iw - size * .12); } // index in the radical's crook
+ let w;
+ if (fr) { // a fraction under the radical, laid out like F()
+ const fs = size * .72, [n, d] = p.r.f, wn = textW(n, fs), wd = textW(d, fs), bx = x0 + size * .56, bar = -size * .3;
+ w = Math.max(wn, wd) + size * .2;
+ text(n, bx + (w - wn) / 2, bar - size * .12, fs);
+ text(d, bx + (w - wd) / 2, bar + size * .62, fs);
+ mk('path', { d: `M${bx + size * .04} ${bar}H${bx + w - size * .04}`, stroke: fill, 'stroke-width': lw, 'stroke-linecap': 'round' }, inner);
+ } else { w = textW(p.r, size); text(p.r, x0 + size * .56, 0, size); }
+ mk('path', { d: `M${x0} ${mid}L${x0 + size * .1} ${mid - size * .06}L${x0 + size * .27} ${bot}L${x0 + size * .45} ${top}H${x0 + size * .56 + w + size * .06}`,
+ fill: 'none', stroke: fill, 'stroke-width': lw, 'stroke-linejoin': 'round', 'stroke-linecap': 'round' }, inner);
+ cx = x0 + size * .56 + w + size * .1;
+ } else if (p.sup !== undefined) {
+ cx += text(p.sup, cx + size * .03, -size * .45, size * .62) + size * .06;
+ } else if (p.ov !== undefined) {
+ const w = text(p.ov, cx, 0, size);
+ rule(cx + size * .04, cx + w - size * .02, -size * .8);
+ cx += w;
+ }
+ }
+ const dx = anchor === 'middle' ? -cx / 2 : anchor === 'end' ? -cx : 0;
+ inner.setAttribute('transform', `translate(${dx},0)`);
+ g._w = cx;
+ g._ascent = ascent;
+ g._descent = descent;
+ return g;
+}
+// Pill-shaped number token, centred on (x, y).
+function chip(parent, parts, color, { x = 0, y = 0, o = 1, s = 1, size = 34 } = {}) {
+ const g = G(parent, { x, y, o, s });
+ const rect = mk('rect', {}, g);
+ const m = M(g, parts, { size, y: size * .3 });
+ const w = Math.max(m._w + 36, 64);
+ let h = size * (parts.some(p => p.f) ? 1.75 : 1.45);
+ if (m._ascent) { // a TeX formula: centre it and grow the pill to fit
+ const above = Math.max(size * 1.05, m._ascent), below = Math.max(size * .45, m._descent);
+ put(m, { y: (above - below) / 2 });
+ h = Math.max(h, m._ascent + m._descent + size * .4);
+ }
+ for (const [k, v] of Object.entries({ x: -w / 2, y: -h / 2, width: w, height: h, rx: h / 2, fill: COL.board, stroke: color, 'stroke-width': 2.5 })) rect.setAttribute(k, v);
+ g._rect = rect;
+ return g;
+}
+// A row of math tokens laid out left to right. Items: string | parts array | { t, fill }.
+// Each token is centred on its own x, so it can move alone (swaps, sliding parentheses). Spacing comes from the strings.
+function tokens(parent, items, { x = 0, y = 0, size = 44, fill = COL.chalk, anchor = 'start', o = 1 } = {}) {
+ const els = items.map(it => {
+ const spec = it && it.t !== undefined ? it : { t: it };
+ return M(parent, [].concat(spec.t), { size, fill: spec.fill || fill, o });
+ });
+ return layRow(els, { x, y, size, anchor }, e => put(e, { x: e._px, y }));
+}
+// Place a row's tokens side by side. Each token keeps its planned centre in _px, so later steps
+// can be planned before earlier tweens have run.
+function layRow(els, { x, y, size, anchor }, move) {
+ const total = els.reduce((a, e) => a + e._w, 0);
+ let cx = anchor === 'middle' ? x - total / 2 : anchor === 'end' ? x - total : x;
+ for (const e of els) { e._px = cx + e._w / 2; move(e); cx += e._w; }
+ return Object.assign(els, { w: total, x, y, size, anchor });
+}
+// One simplification step: box tokens i..j, shrink them into a single result token, then close the gap.
+// Returns the new row. live = true runs on the question clock (inside ask) instead of the lesson clock.
+function collapse(row, i, j, parts, t0, { color = COL.task, fill = COL.chalk, live = false } = {}) {
+ const run = live ? fx : tw, p = row[0].parentNode, { size, y } = row;
+ const left = row[i]._px - row[i]._w / 2, right = row[j]._px + row[j]._w / 2;
+ let above = size * .95, height = size * 1.3;
+ const tall = row.slice(i, j + 1).filter(e => e._ascent); // TeX tokens may reach higher and lower than text
+ if (tall.length) {
+ above = Math.max(above, ...tall.map(e => e._ascent + 8));
+ height = above + Math.max(size * .35, ...tall.map(e => e._descent + 8));
+ }
+ const box = put(mk('rect', { rx: 10, fill: 'none', stroke: color, 'stroke-width': 3 }, p),
+ { o: 0, a_x: left - 8, a_y: y - above, a_width: right - left + 16, a_height: height });
+ run(box, { o: 1 }, t0, .3);
+ run(box, { o: 0 }, t0 + 1.2, .3);
+ const res = M(p, parts, { size, fill, o: 0, x: (left + right) / 2, y });
+ for (let k = i; k <= j; k++) run(row[k], { o: 0, s: .6 }, t0 + .8, .35);
+ run(res, { o: 1 }, t0 + .95, .35);
+ const next = [...row.slice(0, i), res, ...row.slice(j + 1)];
+ return layRow(next, row, e => run(e, { x: e._px }, t0 + 1.3, .5));
+}
+// Vertical number line at x; Yf maps a value to its y. Labels sit on the left.
+function vAxis(p, { x, Yf, lo, hi, step = 1, t0 = .1, unit = '' }) {
+ draw(path(p, `M${x} ${Yf(lo - .5)}V${Yf(hi + .5)}`, { stroke: COL.chalk, 'stroke-width': 3 }, { d: 0 }), t0, .8);
+ for (let v = lo; v <= hi; v += step) {
+ const g = G(p, { o: 0 });
+ path(g, `M${x - 9} ${Yf(v)}H${x + 9}`, { stroke: COL.dim, 'stroke-width': 2.5 });
+ T(g, num(v) + unit, { x: x - 46, y: Yf(v) + 9, size: 24, fill: v === 0 ? COL.chalk : COL.dim, font: MATH, anchor: 'end' });
+ show(g, t0 + .2 + Math.abs(v - lo) * .02);
+ }
+}
+// Thermometer from lo (bottom) to hi (top). set(v, t0, run) moves the column; run = tw (lesson) or fx (answer).
+function thermometer(p, { x = 800, bottom = 600, top = 200, lo = -10, hi = 15, step = 5, value = 0, color = COL.nat } = {}) {
+ const Yt = v => bottom - (v - lo) / (hi - lo) * (bottom - top), bulb = bottom + 32, g = G(p);
+ mk('rect', { x: x - 18, y: top - 24, width: 36, height: bulb - top + 24, rx: 18, fill: COL.board, stroke: COL.dim, 'stroke-width': 2.5 }, g);
+ mk('circle', { cx: x, cy: bulb, r: 26, fill: color }, g);
+ const merc = put(mk('rect', { x: x - 9, width: 18, rx: 9, fill: color }, g), { a_y: Yt(value), a_height: bulb - Yt(value) });
+ for (let v = lo; v <= hi; v += step) {
+ path(g, `M${x - 30} ${Yt(v)}H${x - 18}`, { stroke: COL.dim, 'stroke-width': 2 });
+ T(g, `${num(v)}°`, { x: x - 40, y: Yt(v) + 9, size: 24, fill: v === 0 ? COL.chalk : COL.dim, font: MATH, anchor: 'end' });
+ }
+ return { g, merc, Yt, set: (v, t0, run = tw, dur = 1.2) => run(merc, { a_y: Yt(v), a_height: bulb - Yt(v) }, t0, dur) };
+}
+/* ---------- fractions: rows with strikable parts, bars and brackets ---------- */
+// A row of fractions and symbols whose numerators and denominators can be struck out one by one.
+// items: { f: [n, d], fill } | 'symbol text'. The fraction bars sit on y.
+function fracRow(p, items, { x = 800, y = 300, size = 60, anchor = 'middle', o = 0 } = {}) {
+ const fs = size * .8, g = G(p, { o });
+ const els = items.map(it => {
+ if (typeof it === 'string') {
+ const w = textW(it, size);
+ return { w, draw(cx) { this.cx = cx; T(g, it, { x: cx, y: y + size * .33, size, font: MATH, fill: COL.chalk, anchor: 'middle' }); } };
+ }
+ const [n, d] = it.f.map(String), w = Math.max(textW(n, fs), textW(d, fs)) + size * .35, fill = it.fill || COL.chalk;
+ return { w, n, d, draw(cx) {
+ this.cx = cx;
+ path(g, `M${cx - w / 2 + 4} ${y}H${cx + w / 2 - 4}`, { stroke: fill, 'stroke-width': size * .055 });
+ this.num = T(g, n, { x: cx, y: y - size * .18, size: fs, font: MATH, fill, anchor: 'middle' });
+ this.den = T(g, d, { x: cx, y: y + size * .78, size: fs, font: MATH, fill, anchor: 'middle' });
+ } };
+ });
+ const total = els.reduce((a, e) => a + e.w, 0);
+ let cx = anchor === 'middle' ? x - total / 2 : x;
+ for (const e of els) { e.draw(cx + e.w / 2); cx += e.w; }
+ return Object.assign(els, { g, y, size, x0: anchor === 'middle' ? x - total / 2 : x, w: total });
+}
+// Strike the numerator ('num') or denominator ('den') of fraction k and write its reduced value beside it.
+function reduce(row, k, part, value, color, t0, run = tw) {
+ const e = row[k], { y, size } = row, top = part === 'num';
+ const cy = top ? y - size * .42 : y + size * .52, g = row.g;
+ const slash = path(g, `M${e.cx - size * .28} ${cy + size * .3}L${e.cx + size * .28} ${cy - size * .3}`, { stroke: color, 'stroke-width': 3.5 }, { d: 0 });
+ const nv = T(g, String(value), { x: e.cx + size * .02, y: top ? y - size * .92 : y + size * 1.36, size: size * .5, font: MATH, fill: color, anchor: 'middle', o: 0 });
+ run(slash, { d: 1 }, t0, .4); run(nv, { o: 1 }, t0 + .3, .4);
+ run(e[part], { o: .45 }, t0 + .3, .4);
+}
+function rect(p, x, y, w, h, fill, o = 0, stroke = 'none') {
+ return put(mk('rect', { x, y, width: w, height: h, fill, stroke, 'stroke-width': 2.5 }, p), { o });
+}
+function bracketH(p, x1, x2, y, label, color, t0) {
+ draw(path(p, `M${x1} ${y - 10}V${y}H${x2}V${y - 10}`, { stroke: color, 'stroke-width': 3 }, { d: 0 }), t0, .5);
+ show(T(p, label, { x: (x1 + x2) / 2, y: y + 32, size: 26, fill: color, font: MATH, anchor: 'middle', o: 0 }), t0 + .3);
+}
+
+/* ---------- decimal point that hops between digits (ch10, ch20) ---------- */
+// Digits in evenly spaced slots with a decimal point that can hop between them.
+// places = digits after the point (0 = point at the far right, hidden).
+function pointRow(p, digits, x, y, places, { size = 72, fill = COL.chalk, sign = '' } = {}) {
+ const g = G(p, { o: 0 }), w = size * .7, n = digits.length, x0 = x - n * w / 2;
+ if (sign) T(g, sign, { x: x0 - w * .6, y, size, fill, font: MATH, anchor: 'middle' });
+ const ds = [...digits].map((c, i) => T(g, c, { x: x0 + i * w + w / 2, y, size, fill, font: MATH, anchor: 'middle' }));
+ const px = k => x0 + (n - k) * w;
+ const dot = mk('circle', { r: size * .065, fill: COL.task }, g);
+ put(dot, { x: px(places), y: y - size * .02, o: places ? 1 : 0 });
+ const trail = path(g, '', { stroke: COL.task, 'stroke-width': 2.5, 'stroke-dasharray': '5 6' });
+ return { g, ds, dot, px, w,
+ hop(from, to, t0, run = tw, dur = .55) {
+ const steps = Math.abs(to - from);
+ run(dot, { o: 1 }, t0, .2);
+ let d = '';
+ for (let k = 0; k < steps; k++) {
+ const a = px(from + Math.sign(to - from) * k), b = px(from + Math.sign(to - from) * (k + 1));
+ d += `M${a} ${y - 10}Q${(a + b) / 2} ${y - size * .9} ${b} ${y - 10}`;
+ }
+ trail.setAttribute('d', d);
+ put(trail, { o: 0 }); run(trail, { o: .9 }, t0 + steps * dur, .3);
+ (run === tw ? prog : fxp)(q => {
+ const s = q * steps, k = Math.min(steps - 1, Math.floor(s)), f = s - k;
+ const a = px(from + Math.sign(to - from) * k), b = px(from + Math.sign(to - from) * (k + 1));
+ put(dot, { x: a + (b - a) * f, y: y - size * .02 - Math.sin(Math.PI * f) * size * .7 });
+ }, t0, steps * dur, lin);
+ } };
+}
+
+/* ---------- balance scale for equations (ch24, ch25) ---------- */
+// A balance scale. Its pans hang from the beam ends; tilt(deg, t0) rocks it (positive: left side down).
+function balance(p, { x = 800, y = 330, L = 300 } = {}) {
+ const g = G(p, { o: 0 });
+ path(g, `M${x} ${y}L${x - 50} ${y + 330}H${x + 50}Z`, { stroke: COL.dim, 'stroke-width': 3, fill: mix(COL.board, COL.dim, .15) });
+ const beam = G(g, { x, y });
+ path(beam, `M${-L} 0H${L}`, { stroke: COL.chalk, 'stroke-width': 6 });
+ mk('circle', { r: 10, fill: COL.chalk }, beam);
+ const pan = side => {
+ const pg = G(g, { x: x + side * L, y });
+ path(pg, 'M0 0L-90 110M0 0L90 110', { stroke: COL.dim, 'stroke-width': 2 });
+ path(pg, 'M-110 110Q0 150 110 110Z', { stroke: side < 0 ? COL.whole : COL.nat, 'stroke-width': 3, fill: mix(COL.board, side < 0 ? COL.whole : COL.nat, .2) });
+ return pg;
+ };
+ const Lp = pan(-1), Rp = pan(1);
+ let angle = 0;
+ const place = a => {
+ const r = a * Math.PI / 180, dx = L * Math.cos(r), dy = L * Math.sin(r);
+ put(beam, { r: -a }); put(Lp, { x: x - dx, y: y + dy }); put(Rp, { x: x + dx, y: y - dy });
+ };
+ return {
+ g, L: Lp, R: Rp,
+ // Content sits on a pan: text or math at (0, 90) in pan coordinates.
+ load(side, parts, color, t0, size = 44) { const e = M(side < 0 ? Lp : Rp, parts, { y: 96, size, fill: color, o: 0 }); show(e, t0); return e; },
+ tilt(a, t0, run = prog) { const from = angle; angle = a; run(q => place(from + (a - from) * back(q)), t0, .9); },
+ };
+}
+/* ---------- algebra tiles (ch23, ch25) ---------- */
+const XL = 120, UN = 30; // length of x, size of 1
+const TS = { x2: [XL, XL, COL.real], x: [UN, XL, COL.whole], y: [UN, 90, COL.nat], one: [UN, UN, COL.int] };
+function atile(p, kind, x, y, neg = false, o = 0) {
+ const [w, h, c] = TS[kind], g = G(p, { x, y, o, s: o ? 1 : .6 });
+ mk('rect', { x: -w / 2, y: -h / 2, width: w, height: h, rx: 5, fill: neg ? COL.board : mix(COL.board, c, .55), stroke: neg ? COL.bad : c, 'stroke-width': neg ? 3.5 : 2.5, 'stroke-dasharray': neg ? '7 5' : '' }, g);
+ g.kind = kind; g.neg = neg;
+ return g;
+}
+const popIn = (els, t0, step = .08) => els.forEach((e, i) => tw(e, { o: 1, s: 1 }, t0 + i * step, .35, back));
+// n tiles of a kind in a row starting at x.
+const tileRow = (p, kind, n, x, y, neg = false, gap = 12) => Array.from({ length: n }, (_, i) => atile(p, kind, x + i * (TS[kind][0] + gap), y, neg));
+// Pair each negative tile with a positive one: they move together and vanish.
+function cancel(pos, negs, t0) {
+ negs.forEach((n, i) => {
+ const a = pos[i];
+ tw(n, { x: st(a).x, y: st(a).y }, t0 + i * .3, .6);
+ tw(n, { o: 0, s: .5 }, t0 + i * .3 + .7, .3); tw(a, { o: 0, s: .5 }, t0 + i * .3 + .7, .3);
+ });
+}
+/* ---------- inequality graphs (ch26, ch27) ---------- */
+// Solution ray on the number line: endpoint v, closed or open circle, dir +1 (right) or −1 (left).
+function ray(p, v, closed, dir, t0, color = COL.task, run = tw) {
+ const end = X(dir > 0 ? 5.7 : -5.7), g = G(p, { o: 1 });
+ const line = path(g, `M${X(v)} ${Y0}H${end}`, { stroke: color, 'stroke-width': 7 }, { d: 0 });
+ const head = path(g, `M${end - 18 * dir} ${Y0 - 13}L${end} ${Y0}L${end - 18 * dir} ${Y0 + 13}`, { stroke: color, 'stroke-width': 6 }, { o: 0 });
+ const dot = G(g, { x: X(v), y: Y0, s: 0, o: 0 });
+ mk('circle', { r: 13, fill: closed ? color : COL.board, stroke: color, 'stroke-width': 4 }, dot);
+ run(dot, { s: 1, o: 1 }, t0, .4, back);
+ run(line, { d: 1 }, t0 + .3, .8); run(head, { o: 1 }, t0 + 1, .2);
+ return g;
+}
+// Segment between a and b on the number line, each end open or closed.
+function segment(p, a, b, ca, cb, t0, color = COL.task, run = tw) {
+ const g = G(p, { o: 1 });
+ const line = path(g, `M${X(a)} ${Y0}H${X(b)}`, { stroke: color, 'stroke-width': 7 }, { d: 0 });
+ const ends = [[a, ca], [b, cb]].map(([v, c]) => {
+ const d = G(g, { x: X(v), y: Y0, s: 0, o: 0 });
+ mk('circle', { r: 13, fill: c ? color : COL.board, stroke: color, 'stroke-width': 4 }, d);
+ run(d, { s: 1, o: 1 }, t0, .4, back);
+ return d;
+ });
+ run(line, { d: 1 }, t0 + .3, .8);
+ g.parentNode.appendChild(g); ends.forEach(e => g.appendChild(e));
+ return g;
+}
+/* ---------- equation steps (ch25 onward) ---------- */
+// One line of an equation or inequality with its sign at xEq, so a column of steps lines up. note: grey hint on the right.
+function eqLine(p, L, R, y, t0, { xEq = 760, fill = COL.chalk, size = 50, note, sym = '=', symFill, noteX = 1180 } = {}) {
+ const g = G(p, { o: 0 });
+ M(g, [].concat(L), { x: xEq - size * .6, y, size, fill, anchor: 'end' });
+ M(g, [sym], { x: xEq, y, size, fill: symFill || fill });
+ M(g, [].concat(R), { x: xEq + size * .6, y, size, fill, anchor: 'start' });
+ if (note) T(g, note, { x: noteX, y: y - 8, size: 26, fill: COL.task, weight: 600 });
+ show(g, t0);
+ return g;
+}
+/* ---------- data on a number line: dot plots (unit 7) ---------- */
+// Axis for data from lo to hi drawn between x0 and x1 at baseline y; every: label every n-th tick.
+// shape 'x' draws line-plot crosses instead of dots.
+// Returns D: D.V(value) -> x; D.dot(v, color, t0) stacks a dot above v; D.mark(v, color, t0, label) is a
+// balance triangle under the axis that can slide with D.slide(mark, v, t0).
+function dataLine(p, { lo, hi, x0 = 200, x1 = 1400, y = 600, step = 1, every = 1, t0 = .1, r = 13, size = 22, shape = 'dot' }) {
+ const V = v => x0 + (v - lo) / (hi - lo) * (x1 - x0), g = G(p, { o: 0 });
+ path(g, `M${x0 - 24} ${y}H${x1 + 24}`, { stroke: COL.dim, 'stroke-width': 3 });
+ for (let v = lo, i = 0; v <= hi + 1e-9; v += step, i++) {
+ path(g, `M${V(v)} ${y - 7}V${y + 7}`, { stroke: COL.dim, 'stroke-width': 2 });
+ if (i % every === 0) T(g, num(+v.toFixed(6)), { x: V(v), y: y + 26 + size, size, fill: COL.dim, font: MATH, anchor: 'middle' });
+ }
+ show(g, t0);
+ const D = {
+ g, V, y, r, count: {},
+ top: v => y - 6 - r - ((D.count[v] || 1) - 1) * (2 * r + 5),
+ dot(v, color, t0, { run = tw, into = p, from } = {}) {
+ D.count[v] = (D.count[v] || 0) + 1;
+ let d;
+ if (shape === 'x') { d = G(into); path(d, `M${-r * .75} ${-r * .75}L${r * .75} ${r * .75}M${r * .75} ${-r * .75}L${-r * .75} ${r * .75}`, { stroke: color, 'stroke-width': 5 }); }
+ else d = mk('circle', { r, fill: color, stroke: COL.board, 'stroke-width': 2 }, into);
+ put(d, { x: V(v), y: D.top(v), s: 0, o: 0 });
+ if (from !== undefined) { put(d, { y: from, s: 1 }); run(d, { o: 1 }, t0, .2); run(d, { y: D.top(v) }, t0, .7, back); }
+ else run(d, { s: 1, o: 1 }, t0, .45, back);
+ return d;
+ },
+ dots: (vals, color, t0, gap = .15, opts) => vals.map((v, i) => D.dot(v, color, t0 + i * gap, opts)),
+ mark(v, color, t0, label, { run = tw, into = p } = {}) {
+ const m = G(into, { x: V(v), y, o: 0 });
+ path(m, 'M0 4L-17 30H17Z', { fill: color, stroke: COL.board, 'stroke-width': 2 });
+ if (label) T(m, label, { y: 64 + size, size: 24, fill: color, weight: 600, anchor: 'middle' });
+ run(m, { o: 1 }, t0, .4);
+ return m;
+ },
+ slide: (m, v, t0, run = tw, dur = 1.2) => run(m, { x: V(v) }, t0, dur),
+ // Bracket above the data from a to b at height yb, with a label.
+ span(a, b, yb, label, color, t0, { run = tw, into = p } = {}) {
+ const g = G(into), l = path(g, `M${V(a)} ${yb + 12}V${yb}H${V(b)}V${yb + 12}`, { stroke: color, 'stroke-width': 3 }, { d: 0 });
+ run(l, { d: 1 }, t0, .6);
+ const t = M(g, [label], { x: (V(a) + V(b)) / 2, y: yb - 14, size: 28, fill: color, o: 0 });
+ run(t, { o: 1 }, t0 + .4, .4);
+ return g;
+ },
+ };
+ return D;
+}
+/* ---------- chance: number cubes, coins, spinners (unit 7) ---------- */
+// A number cube face showing n pips, centred on (x, y).
+const PIPS = { 1: [[0, 0]], 2: [[-1, -1], [1, 1]], 3: [[-1, -1], [0, 0], [1, 1]], 4: [[-1, -1], [1, -1], [-1, 1], [1, 1]],
+ 5: [[-1, -1], [1, -1], [0, 0], [-1, 1], [1, 1]], 6: [[-1, -1], [1, -1], [-1, 0], [1, 0], [-1, 1], [1, 1]] };
+function die(p, n, x, y, s = 96, o = 0) {
+ const g = G(p, { x, y, o, s: o ? 1 : .6 });
+ g._box = mk('rect', { x: -s / 2, y: -s / 2, width: s, height: s, rx: s * .18, fill: mix(COL.board, COL.chalk, .1), stroke: COL.chalk, 'stroke-width': 3 }, g);
+ PIPS[n].forEach(([a, b]) => mk('circle', { cx: a * s * .26, cy: b * s * .26, r: s * .085, fill: COL.chalk }, g));
+ return g;
+}
+// Spinner with equal sections; pointer starts straight up. land(k) is the rotation that points at section k.
+const SPIN = [COL.whole, COL.nat, COL.int, COL.whole, COL.irr, COL.nat, COL.whole, COL.int];
+function spinner(p, cx, cy, r, t0, cols = SPIN) {
+ const g = G(p, { x: cx, y: cy, o: 0 }), n = cols.length, secs = [];
+ cols.forEach((c, i) => {
+ const a1 = (-90 + i * 360 / n) * Math.PI / 180, a2 = (-90 + (i + 1) * 360 / n) * Math.PI / 180;
+ secs.push(path(g, `M0 0L${r * Math.cos(a1)} ${r * Math.sin(a1)}A${r} ${r} 0 0 1 ${r * Math.cos(a2)} ${r * Math.sin(a2)}Z`,
+ { fill: mix(COL.board, c, .7), stroke: COL.board, 'stroke-width': 3 }));
+ });
+ mk('circle', { r, fill: 'none', stroke: COL.chalk, 'stroke-width': 3 }, g);
+ const ptr = G(g);
+ path(ptr, `M0 ${r * .12}V${-r * .78}M-14 ${-r * .66}L0 ${-r * .8}L14 ${-r * .66}`, { stroke: COL.chalk, 'stroke-width': 7 });
+ mk('circle', { r: 12, fill: COL.chalk }, g);
+ show(g, t0);
+ return { g, secs, ptr, land: k => (k + .5) * 360 / n };
+}
+// Outline some spinner sections: a bright border that fades in.
+function outline(p, sp, ks, color, t0, run = tw) {
+ return ks.map(k => { const e = sp.secs[k].cloneNode(); e.setAttribute('fill', 'none'); e.setAttribute('stroke', color); e.setAttribute('stroke-width', 7); sp.g.insertBefore(e, sp.ptr); put(e, { o: 0 }); run(e, { o: 1 }, t0, .4); return e; });
+}
+// A coin face.
+function coin(p, side, x, y, t0, r = 34, run = tw) {
+ const g = G(p, { x, y, s: .5, o: 0 });
+ mk('circle', { r, fill: mix(COL.board, side === 'H' ? COL.int : COL.rat, .5), stroke: side === 'H' ? COL.int : COL.rat, 'stroke-width': 3 }, g);
+ T(g, side, { y: r * .36, size: r, fill: COL.chalk, weight: 700, anchor: 'middle' });
+ run(g, { s: 1, o: 1 }, t0, .45, back);
+ return g;
+}
+/* ---------- scaled axes for data and real-world graphs (ch41 onward) ---------- */
+// Axes with a scale on each; returns value -> pixel maps. ybreak draws a zigzag when y does not start at 0.
+function axes(p, { x0, y0, w, h, xs: [xlo, xhi, xst], ys: [ylo, yhi, yst], xl, yl, t0, ybreak }) {
+ const PX = v => x0 + (v - xlo) / (xhi - xlo) * w, PY = v => y0 - (v - ylo) / (yhi - ylo) * h, g = G(p, { o: 0 });
+ let d = '';
+ for (let v = xlo + xst; v <= xhi + 1e-9; v += xst) d += `M${PX(v)} ${y0}V${y0 - h}`;
+ for (let v = ylo + yst; v <= yhi + 1e-9; v += yst) d += `M${x0} ${PY(v)}H${x0 + w}`;
+ mk('path', { d, stroke: COL.chalk, 'stroke-opacity': .1, 'stroke-width': 1.5, fill: 'none' }, g);
+ path(g, `M${x0} ${y0 - h - 20}V${y0}H${x0 + w + 20}`, { stroke: COL.chalk, 'stroke-width': 3 });
+ if (ybreak) path(g, `M${x0 - 10} ${y0 - 22}L${x0 + 10} ${y0 - 30}M${x0 - 10} ${y0 - 34}L${x0 + 10} ${y0 - 42}`, { stroke: COL.chalk, 'stroke-width': 3 });
+ for (let v = xlo; v <= xhi + 1e-9; v += xst) T(g, String(v), { x: PX(v), y: y0 + 30, size: 20, fill: COL.dim, font: MATH, anchor: 'middle' });
+ for (let v = ylo; v <= yhi + 1e-9; v += yst) T(g, String(v), { x: x0 - 14, y: PY(v) + 7, size: 20, fill: COL.dim, font: MATH, anchor: 'end' });
+ T(g, xl, { x: x0 + w / 2, y: y0 + 66, size: 24, fill: COL.dim, anchor: 'middle' });
+ T(g, yl, { x: x0, y: y0 - h - 36, size: 24, fill: COL.dim, anchor: 'middle' });
+ show(g, t0);
+ return { PX, PY };
+}
+/* ---------- area grids for multiplying and factoring polynomials (ch51 onward) ---------- */
+// Area grid from (x0, y0): column widths ws, row heights hs, factor terms along the top and the left side.
+function areaGrid(p, x0, y0, ws, hs, colLab, rowLab, t0, { size = 40 } = {}) {
+ const xs = [x0], ys = [y0];
+ ws.forEach(w => xs.push(xs.at(-1) + w)); hs.forEach(h => ys.push(ys.at(-1) + h));
+ let d = '';
+ xs.forEach(x => { d += `M${x} ${y0}V${ys.at(-1)}`; }); ys.forEach(y => { d += `M${x0} ${y}H${xs.at(-1)}`; });
+ draw(path(p, d, { stroke: COL.chalk, 'stroke-width': 3 }, { d: 0 }), t0, .9);
+ colLab.forEach((l, j) => show(M(p, [].concat(l), { x: (xs[j] + xs[j + 1]) / 2, y: y0 - 22, size, fill: COL.whole, o: 0 }), t0 + .3 + j * .15));
+ rowLab.forEach((l, i) => show(M(p, [].concat(l), { x: x0 - 24, y: (ys[i] + ys[i + 1]) / 2 + size * .35, size, fill: COL.nat, anchor: 'end', o: 0 }), t0 + .3 + i * .15));
+ const box = (i, j, pad) => ({ x: xs[j] + pad, y: ys[i] + pad, width: xs[j + 1] - xs[j] - 2 * pad, height: ys[i + 1] - ys[i] - 2 * pad });
+ return {
+ xs, ys,
+ cell(i, j, parts, t0, { fill = COL.chalk, tint, run = tw, into = p } = {}) {
+ if (tint) { const r = put(mk('rect', { ...box(i, j, 3), fill: tint }, into), { o: 0 }); into.insertBefore(r, into.firstChild); run(r, { o: .3 }, t0, .4); }
+ const e = M(into, [].concat(parts), { x: (xs[j] + xs[j + 1]) / 2, y: (ys[i] + ys[i + 1]) / 2 + size * .35, size, fill, o: 0, s: .6 });
+ run(e, { o: 1, s: 1 }, t0, .4, back);
+ return e;
+ },
+ ring(i, j, color, t0, run = tw, into = p) { const r = put(mk('rect', { ...box(i, j, 8), rx: 12, fill: 'none', stroke: color, 'stroke-width': 4.5 }, into), { o: 0 }); run(r, { o: 1 }, t0, .3); return r; },
+ };
+}
+// A curved arrow from (x1, y1) to (x2, y2) bending up (h < 0) or down (h > 0).
+function arc(p, x1, y1, x2, y2, h, color, t0, run = tw) {
+ const mx = (x1 + x2) / 2, l = path(p, `M${x1} ${y1}Q${mx} ${y1 + h} ${x2} ${y2}`, { stroke: color, 'stroke-width': 3.5 }, { d: 0 });
+ run(l, { d: 1 }, t0, .5);
+ return l;
+}
+
+/* ---------- built-up fractions with math above and below the bar (ch60 onward) ---------- */
+// Width of math parts at a size, without leaving anything on the stage.
+function mathW(parts, size) { const e = M(scene, [].concat(parts), { size, o: 0 }), w = e._w; e.remove(); return w; }
+// A built-up fraction whose top and bottom are math parts (they may hold radicals); bar on y. Returns { g, w, t, b, x0 }.
+function frac(p, top, bot, x, y, t0, { size = 56, fill = COL.chalk, anchor = 'start', topFill, botFill } = {}) {
+ const g = G(p, { o: 0 });
+ const w = Math.max(mathW(top, size), mathW(bot, size)) + size * .3;
+ const x0 = anchor === 'middle' ? x - w / 2 : x;
+ const t = M(g, [].concat(top), { x: x0 + w / 2, y: y - size * .25, size, fill: topFill || fill });
+ const b = M(g, [].concat(bot), { x: x0 + w / 2, y: y + size * 1.05, size, fill: botFill || fill });
+ path(g, `M${x0} ${y}H${x0 + w}`, { stroke: fill, 'stroke-width': size * .05 });
+ if (t0 !== undefined) show(g, t0);
+ return { g, w, t, b, x0 };
+}
+
+/* ---------- coordinate plane (unit 6 onward) ---------- */
+// Grid centred on the origin at (cx, cy); u pixels per unit; x from x0 to x1, y from y0 to y1.
+// Returns { g, PX, PY, u, ... } with helpers to plot points, walk to a point, and draw lines.
+// The grid stays in p; marks go into P.layer (set it to the current panel so marks clear with the step) or opts.into.
+function plane(p, { cx = 800, cy = 450, u = 50, x0 = -6, x1 = 6, y0 = -6, y1 = 6, t0 = .1, labels = true, step = 1 } = {}) {
+ const PX = x => cx + x * u, PY = y => cy - y * u, g = G(p, { o: 0 });
+ let d = '';
+ for (let x = x0; x <= x1; x++) if (x) d += `M${PX(x)} ${PY(y0)}V${PY(y1)}`;
+ for (let y = y0; y <= y1; y++) if (y) d += `M${PX(x0)} ${PY(y)}H${PX(x1)}`;
+ mk('path', { d, stroke: COL.chalk, 'stroke-opacity': .1, 'stroke-width': 1.5, fill: 'none' }, g);
+ const ax = { stroke: COL.chalk, 'stroke-width': 3 };
+ path(g, `M${PX(x0 - .5)} ${cy}H${PX(x1 + .5)}M${PX(x1 + .5) - 14} ${cy - 9}L${PX(x1 + .5)} ${cy}L${PX(x1 + .5) - 14} ${cy + 9}`, ax);
+ path(g, `M${cx} ${PY(y0 - .5)}V${PY(y1 + .5)}M${cx - 9} ${PY(y1 + .5) + 14}L${cx} ${PY(y1 + .5)}L${cx + 9} ${PY(y1 + .5) + 14}`, ax);
+ T(g, 'x', { x: PX(x1 + .5) + 10, y: cy + 30, size: 28, fill: COL.dim, font: MATH, anchor: 'middle' }).setAttribute('font-style', 'italic');
+ T(g, 'y', { x: cx - 26, y: PY(y1 + .5) + 10, size: 28, fill: COL.dim, font: MATH, anchor: 'middle' }).setAttribute('font-style', 'italic');
+ if (labels) {
+ for (let x = x0; x <= x1; x += step) if (x) T(g, num(x), { x: PX(x), y: cy + 26, size: 18, fill: COL.dim, font: MATH, anchor: 'middle' });
+ for (let y = y0; y <= y1; y += step) if (y) T(g, num(y), { x: cx - 12, y: PY(y) + 6, size: 18, fill: COL.dim, font: MATH, anchor: 'end' });
+ }
+ show(g, t0, .5);
+ const P = {
+ g, PX, PY, u, cx, cy, x0, x1, y0, y1, layer: null,
+ dot(x, y, color, t0, { r = 10, label, run = tw, dx = 14, dy = -14, anchor = 'start', into = P.layer || p, open = false } = {}) {
+ const d = G(into, { x: PX(x), y: PY(y), s: 0, o: 0 });
+ mk('circle', open ? { r, fill: COL.board, stroke: color, 'stroke-width': 3.5 } : { r, fill: color, stroke: COL.board, 'stroke-width': 2 }, d);
+ run(d, { s: 1, o: 1 }, t0, .4, back);
+ if (label) { const l = M(into, [label], { x: PX(x) + dx, y: PY(y) + dy, size: 26, fill: color, anchor, o: 0 }); run(l, { o: 1 }, t0 + .2, .3); }
+ return d;
+ },
+ // Walk from the origin: along x, then along y, drawing arrows; then a dot.
+ walk(x, y, t0, { cx: colX = COL.whole, cy: colY = COL.nat, run = tw, color = COL.task, label, into = P.layer || p } = {}) {
+ const a = path(into, `M${PX(0)} ${PY(0)}H${PX(x)}`, { stroke: colX, 'stroke-width': 5 }, { d: 0 });
+ const b = path(into, `M${PX(x)} ${PY(0)}V${PY(y)}`, { stroke: colY, 'stroke-width': 5 }, { d: 0 });
+ run(a, { d: 1 }, t0, .3 + Math.abs(x) * .12, lin);
+ run(b, { d: 1 }, t0 + .4 + Math.abs(x) * .12, .3 + Math.abs(y) * .12, lin);
+ return P.dot(x, y, color, t0 + .8 + (Math.abs(x) + Math.abs(y)) * .12, { run, label, into });
+ },
+ // Arrow from (xa, ya) to (xb, yb) with an optional label beside its middle.
+ arrow(xa, ya, xb, yb, color, t0, { label, run = tw, into = P.layer || p } = {}) {
+ const a = [PX(xa), PY(ya)], b = [PX(xb), PY(yb)], L = Math.hypot(b[0] - a[0], b[1] - a[1]), ux = (b[0] - a[0]) / L, uy = (b[1] - a[1]) / L;
+ const l = path(into, `M${a[0]} ${a[1]}L${b[0]} ${b[1]}M${b[0] - 12 * ux - 8 * uy} ${b[1] - 12 * uy + 8 * ux}L${b[0]} ${b[1]}L${b[0] - 12 * ux + 8 * uy} ${b[1] - 12 * uy - 8 * ux}`, { stroke: color, 'stroke-width': 4 }, { d: 0 });
+ run(l, { d: 1 }, t0, .5);
+ if (label !== undefined) {
+ const vert = Math.abs(uy) > Math.abs(ux);
+ const t = M(into, [label], { x: (a[0] + b[0]) / 2 + (vert ? -24 : 0), y: (a[1] + b[1]) / 2 + (vert ? 9 : -12), size: 26, fill: color, anchor: vert ? 'end' : 'middle', o: 0 });
+ run(t, { o: 1 }, t0 + .3, .3);
+ }
+ return l;
+ },
+ // One slope step from (x, y): rise first (irr green), then run (real violet).
+ stair(x, y, rise, runX, t0, { run = tw, into = P.layer || p, labels = true } = {}) {
+ P.arrow(x, y, x, y + rise, COL.irr, t0, { label: labels ? num(rise) : undefined, run, into });
+ P.arrow(x, y + rise, x + runX, y + rise, COL.real, t0 + .6, { label: labels ? num(runX) : undefined, run, into });
+ },
+ // Shade the region where every a·x + b·y ≥ c in the list holds, clipped to the grid.
+ region(list, color, t0, { run = tw, into = P.layer || p, o = .22 } = {}) {
+ let pts = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]];
+ for (const [a, b, c] of list) {
+ const f = ([x, y]) => a * x + b * y - c, next = [];
+ pts.forEach((v, i) => {
+ const w = pts[(i + 1) % pts.length], fv = f(v), fw = f(w);
+ if (fv >= 0) next.push(v);
+ if (fv * fw < 0) { const t = fv / (fv - fw); next.push([v[0] + t * (w[0] - v[0]), v[1] + t * (w[1] - v[1])]); }
+ });
+ pts = next;
+ }
+ const e = path(into, pts.length ? 'M' + pts.map(([x, y]) => `${PX(x)} ${PY(y)}`).join('L') + 'Z' : '', { fill: color, stroke: 'none' }, { o: 0 });
+ into.insertBefore(e, into.firstChild);
+ run(e, { o }, t0, .6);
+ return e;
+ },
+ half: (a, b, c, color, t0, opts) => P.region([[a, b, c]], color, t0, opts),
+ // Graph of y = f(x) for x from xa to xb, drawn on; the part outside the grid's y range is cut off.
+ fn(f, xa, xb, color, t0, { run = tw, w = 4, into = P.layer || p, n = 160, dur = 1.2 } = {}) {
+ let d = '', pen = false;
+ for (let i = 0; i <= n; i++) {
+ const x = xa + (xb - xa) * i / n, y = f(x), inside = y >= y0 - .5 && y <= y1 + .5;
+ if (inside) { d += `${pen ? 'L' : 'M'}${PX(x).toFixed(1)} ${PY(y).toFixed(1)}`; pen = true; } else pen = false;
+ }
+ const l = path(into, d, { stroke: color, 'stroke-width': w }, { d: 0 });
+ run(l, { d: 1 }, t0, dur);
+ return l;
+ },
+ // Line through two points, extended to the edge of the grid.
+ line(xa, ya, xb, yb, color, t0, { run = tw, w = 4, dash, into = P.layer || p } = {}) {
+ const dx = xb - xa, dy = yb - ya, ts = [];
+ const clip = (t, v, lo, hi) => { if (v >= lo - 1e-9 && v <= hi + 1e-9) ts.push(t); };
+ if (dx) { for (const X of [x0, x1]) { const t = (X - xa) / dx; clip(t, ya + t * dy, y0, y1); } }
+ if (dy) { for (const Y of [y0, y1]) { const t = (Y - ya) / dy; clip(t, xa + t * dx, x0, x1); } }
+ const t1 = Math.min(...ts), t2 = Math.max(...ts);
+ // A dashed line fades in: drawing it on would need the dash array for the reveal.
+ const l = path(into, `M${PX(xa + t1 * dx)} ${PY(ya + t1 * dy)}L${PX(xa + t2 * dx)} ${PY(ya + t2 * dy)}`, { stroke: color, 'stroke-width': w, ...(dash ? { 'stroke-dasharray': dash } : {}) }, dash ? { o: 0 } : { d: 0 });
+ run(l, dash ? { o: 1 } : { d: 1 }, t0, dash ? .6 : 1);
+ return l;
+ },
+ };
+ return P;
+}
+// Question: pick a grid point. ans = [x, y]; no(x, y) explains a wrong pick. Arrows move a cursor, Enter picks.
+// test(x, y), when given, accepts any point it approves; ans is then the point Show answer uses.
+const pickPoint = (P, ans, yes, no, onRight, test) => (body, api) => {
+ const L = qlayer();
+ let cur = [0, 0], locked = false;
+ const cursor = G(L, { x: P.PX(0), y: P.PY(0) });
+ mk('circle', { r: 16, fill: 'none', stroke: COL.task, 'stroke-width': 3 }, cursor);
+ let tag = null;
+ const moveTo = (x, y) => {
+ cur = [Math.max(P.x0, Math.min(P.x1, x)), Math.max(P.y0, Math.min(P.y1, y))];
+ put(cursor, { x: P.PX(cur[0]), y: P.PY(cur[1]) });
+ tag?.remove();
+ tag = M(L, [`(${num(cur[0])}, ${num(cur[1])})`], { x: P.PX(cur[0]) + 22, y: P.PY(cur[1]) - 18, size: 24, fill: COL.task, anchor: 'start' });
+ };
+ moveTo(0, 0);
+ const pick = () => {
+ if (locked) return;
+ const [x, y] = cur;
+ if (test ? test(x, y) : x === ans[0] && y === ans[1]) { P.dot(x, y, COL.good, 0, { run: fx, into: L }); onRight?.(); api.grade(true, typeof yes === 'function' ? yes(x, y) : yes); }
+ else { const d = P.dot(x, y, COL.bad, 0, { run: fx, r: 8, into: L }); fx(d, { o: 0 }, 1.2, .4); shakeFx(cursor); api.grade(false, no(x, y)); }
+ };
+ const hit = mk('rect', { x: P.PX(P.x0 - .5), y: P.PY(P.y1 + .5), width: (P.x1 - P.x0 + 1) * P.u, height: (P.y1 - P.y0 + 1) * P.u, fill: 'transparent' }, L);
+ L.insertBefore(hit, L.firstChild);
+ hit.style.cursor = 'crosshair';
+ hit.addEventListener('click', e => {
+ if (locked) return;
+ const s = $('stage'), pt = s.createSVGPoint(); pt.x = e.clientX; pt.y = e.clientY;
+ const q = pt.matrixTransform(s.getScreenCTM().inverse());
+ moveTo(Math.round((q.x - P.cx) / P.u), Math.round((P.cy - q.y) / P.u));
+ pick();
+ });
+ return {
+ reveal() { moveTo(...ans); P.dot(ans[0], ans[1], COL.good, 0, { run: fx, into: L }); onRight?.(); return typeof yes === 'function' ? yes(...ans) : yes; },
+ lock() { locked = true; },
+ hint: [kbd('←'), kbd('↑'), kbd('↓'), kbd('→'), translate('hintMove'), kbd('Enter'), translate('hintChooseOrClickGrid')],
+ key(e) {
+ if (locked) return false;
+ const d = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, 1], ArrowDown: [0, -1] }[e.key];
+ if (d) { moveTo(cur[0] + d[0], cur[1] + d[1]); return true; }
+ if (e.key === 'Enter') { pick(); return true; }
+ return false;
+ },
+ };
+};
+/* ---------- signed numbers: number-line moves and plus/minus tiles ---------- */
+const POS = COL.whole, NEG = COL.nat; // positive: blue, negative: coral
+// Integer number line from lo to hi with arrows at both ends, drawn into S.line.
+function numberLine(t0 = .1, lo = -8, hi = 8) {
+ const L = S.line;
+ draw(path(L, `M${X(lo - .7)} ${Y0}H${X(hi + .7)}`, { stroke: COL.chalk, 'stroke-width': 3 }, { d: 0 }), t0, .8);
+ for (const [x, d] of [[X(hi + .7), 1], [X(lo - .7), -1]]) {
+ show(path(L, `M${x - 15 * d} ${Y0 - 10}L${x} ${Y0}L${x - 15 * d} ${Y0 + 10}`, { stroke: COL.chalk, 'stroke-width': 3 }, { o: 0 }), t0 + .7, .3);
+ }
+ for (let v = lo; v <= hi; v++) show(tick(v), t0 + .2 + Math.abs(v) * .04, .4);
+}
+// A move along the number line from a to b, drawn as an arrow at height y. run = tw (lesson) or fx (answer).
+function move(p, a, b, y, t0, run = tw) {
+ const x1 = X(a), x2 = X(b), d = Math.sign(b - a), color = d > 0 ? POS : NEG;
+ const dur = .35 + Math.abs(b - a) * .09;
+ const line = path(p, `M${x1} ${y}H${x2}`, { stroke: color, 'stroke-width': 5 }, { d: 0 });
+ const head = path(p, `M${x2 - 15 * d} ${y - 11}L${x2} ${y}L${x2 - 15 * d} ${y + 11}`, { stroke: color, 'stroke-width': 5 }, { o: 0 });
+ const lab = T(p, (d > 0 ? '+' : '−') + Math.abs(b - a), { x: (x1 + x2) / 2, y: y - 16, size: 28, fill: color, font: MATH, anchor: 'middle', o: 0 });
+ const drop = path(p, `M${x2} ${y + 12}V${Y0 - 14}`, { stroke: color, 'stroke-width': 2, 'stroke-dasharray': '5 6' }, { o: 0 });
+ run(line, { d: 1 }, t0, dur, lin); run(head, { o: 1 }, t0 + dur - .1, .15);
+ run(lab, { o: 1 }, t0 + .2, .3); run(drop, { o: .8 }, t0 + dur, .3);
+}
+function landDot(p, v, t0, color = COL.chalk, run = tw) {
+ const g = G(p, { x: X(v), y: Y0, s: 0, o: 0 });
+ mk('circle', { r: 12, fill: color, stroke: COL.board, 'stroke-width': 2 }, g);
+ run(g, { s: 1, o: 1 }, t0, .45, back);
+ return g;
+}
+function tile(p, sign, x, y, o = 0) {
+ const c = sign > 0 ? POS : NEG, g = G(p, { x, y, o, s: o ? 1 : .6 });
+ mk('rect', { x: -27, y: -27, width: 54, height: 54, rx: 10, fill: mix(COL.board, c, .45), stroke: c, 'stroke-width': 2.5 }, g);
+ M(g, [sign > 0 ? '+' : '−'], { y: 13, size: 40 });
+ return g;
+}
+const tiles = (p, n, sign, x0, y, gap = 70) => Array.from({ length: n }, (_, i) => tile(p, sign, x0 + i * gap, y));
+const popAll = (els, t0, step = .08) => els.forEach((e, i) => tw(e, { o: 1, s: 1 }, t0 + i * step, .35, back));
+// Circle each plus/minus pair, then let the pairs vanish: they make zero.
+function cancelPairs(p, tops, bottoms, t0) {
+ tops.forEach((a, i) => {
+ const b = bottoms[i], x = st(a).x, y1 = st(a).y, y2 = st(b).y;
+ const ring = put(mk('rect', { rx: 18, fill: 'none', stroke: COL.dim, 'stroke-width': 2.5, 'stroke-dasharray': '8 6' }, p),
+ { o: 0, a_x: x - 38, a_y: y1 - 38, a_width: 76, a_height: y2 - y1 + 76 });
+ tw(ring, { o: 1 }, t0 + i * .2, .3);
+ for (const e of [a, b, ring]) tw(e, { o: 0, ...(e === ring ? {} : { s: .5 }) }, t0 + 1.4 + i * .1, .4);
+ });
+}
+function brace(p, a, b, y, label, color, t0) {
+ const x1 = X(a), x2 = X(b);
+ draw(path(p, `M${x1} ${y - 10}V${y}H${x2}V${y - 10}`, { stroke: color, 'stroke-width': 3 }, { d: 0 }), t0, .6);
+ show(T(p, label, { x: (x1 + x2) / 2, y: y + 34, size: 26, fill: color, anchor: 'middle', o: 0 }), t0 + .4);
+}
+
+// Inline math for HTML text.
+function mathEl(parts, size = 22) {
+ const svg = mk('svg', { class: 'm', 'font-weight': 400 }); // widths are measured at normal weight, so a bold prompt must not thicken the math
+ const m = M(svg, parts, { size, anchor: 'start', fill: 'currentColor' });
+ let top = size * 1.05, bottom = size * .45, h = size * 1.5;
+ if (m._ascent) { // a TeX formula may reach higher and lower than text
+ top = Math.max(top, m._ascent + size * .1);
+ bottom = Math.max(bottom, m._descent + size * .1);
+ h = top + bottom;
+ }
+ svg.setAttribute('viewBox', `0 ${-top} ${m._w + 2} ${h}`);
+ svg.setAttribute('width', m._w + 2);
+ svg.setAttribute('height', h);
+ svg.style.verticalAlign = `${-bottom}px`; // line up the math baseline with the text baseline
+ return svg;
+}
+
+/* ---------- number map geometry ---------- */
+const RINGS = {
+ real: { cx: 640, cy: 470, rx: 610, ry: 390, lx: 640, ly: 128 },
+ rat: { cx: 500, cy: 480, rx: 400, ry: 320, lx: 500, ly: 202 },
+ int: { cx: 500, cy: 510, rx: 300, ry: 250, lx: 500, ly: 302 },
+ whole: { cx: 500, cy: 540, rx: 210, ry: 180, lx: 500, ly: 400 },
+ nat: { cx: 500, cy: 570, rx: 125, ry: 110, lx: 500, ly: 500 },
+ irr: { cx: 1060, cy: 480, rx: 140, ry: 170, lx: 1060, ly: 360 },
+};
+const CHAIN = { nat: ['nat', 'whole', 'int', 'rat', 'real'], whole: ['whole', 'int', 'rat', 'real'], int: ['int', 'rat', 'real'], rat: ['rat', 'real'], irr: ['irr', 'real'], real: ['real'] };
+const ell = r => `M${r.cx} ${r.cy - r.ry}A${r.rx} ${r.ry} 0 1 1 ${r.cx} ${r.cy + r.ry}A${r.rx} ${r.ry} 0 1 1 ${r.cx} ${r.cy - r.ry}`;
+const inRing = (k, x, y) => { const r = RINGS[k]; return ((x - r.cx) / r.rx) ** 2 + ((y - r.cy) / r.ry) ** 2 <= 1; };
+function regionAt(x, y) {
+ for (const k of ['nat', 'whole', 'int', 'rat', 'irr', 'real']) if (inRing(k, x, y)) return k;
+ return null;
+}
+function buildVenn(parent, hidden) {
+ const out = {};
+ for (const k of ['real', 'rat', 'int', 'whole', 'nat', 'irr']) {
+ const r = RINGS[k], g = G(parent);
+ const fill = path(g, ell(r), { fill: mix(COL.board, COL[k], k === 'real' ? .1 : .16), stroke: 'none' }, { o: hidden ? 0 : 1 });
+ const stroke = path(g, ell(r), { stroke: COL[k], 'stroke-width': 3 }, hidden ? { d: 0, 'a_stroke-width': 3 } : { 'a_stroke-width': 3 });
+ const lab = T(g, NAME[k], { x: r.lx, y: r.ly, size: 26, fill: COL[k], weight: 600, anchor: 'middle', o: hidden ? 0 : 1 });
+ out[k] = { g, fill, stroke, lab };
+ }
+ return out;
+}
+
+/* ---------- timeline ---------- */
+let TW = [];
+const io = p => p < .5 ? 4 * p * p * p : 1 - (-2 * p + 2) ** 3 / 2;
+const out = p => 1 - (1 - p) ** 3;
+const back = p => 1 + 2.2 * (p - 1) ** 3 + 1.2 * (p - 1) ** 2;
+const lin = p => p;
+function tw(e, to, t0, dur = .6, ease = io) { TW.push({ e, to, t0, dur, ease }); }
+function prog(pf, t0, dur, ease = io) { TW.push({ pf, t0, dur, ease }); }
+const show = (e, t0, dur = .5) => tw(e, { o: 1 }, t0, dur);
+const hide = (e, t0, dur = .5) => tw(e, { o: 0 }, t0, dur);
+const draw = (e, t0, dur = .9) => tw(e, { d: 1 }, t0, dur);
+const pop = (e, t0) => tw(e, { s: 1, o: 1 }, t0, .45, back);
+function pulse(e, t0, k = 1.7) { tw(e, { s: k }, t0, .22, out); tw(e, { s: 1 }, t0 + .22, .4); }
+function glow(key, t0) {
+ const s = S.ring[key].stroke;
+ tw(s, { 'a_stroke-width': 9 }, t0, .22, out); tw(s, { 'a_stroke-width': 3 }, t0 + .25, .5);
+}
+function glowRun(key, t0) { CHAIN[key].forEach((k, i) => glow(k, t0 + i * .3)); }
+function stream(t, str, t0, dur) { prog(q => { t.textContent = str.slice(0, Math.round(q * str.length)); }, t0, dur, lin); }
+function mix(a, b, q) {
+ const h = c => [1, 3, 5].map(i => parseInt(c.slice(i, i + 2), 16));
+ const A = h(a), B = h(b);
+ return '#' + A.map((v, i) => Math.round(v + (B[i] - v) * q).toString(16).padStart(2, '0')).join('');
+}
+// A colour or attribute tween with no starting value in the state starts from the element's attribute.
+const fromAttr = (e, k) => k.startsWith('c_') ? e.getAttribute(k.slice(2)) : k.startsWith('a_') ? parseFloat(e.getAttribute(k.slice(2))) : undefined;
+function evalTo(t, list = TW) {
+ for (const w of list) {
+ if (w.done || t < w.t0) continue;
+ if (!w.go) { w.go = 1; if (w.e) { const s = st(w.e); w.from = {}; for (const k in w.to) w.from[k] = s[k] ?? fromAttr(w.e, k); } }
+ const p = w.dur ? Math.min(1, (t - w.t0) / w.dur) : 1, q = w.ease(p);
+ if (w.e) {
+ const s = st(w.e);
+ for (const k in w.to) s[k] = k.startsWith('c_') ? mix(w.from[k], w.to[k], q) : w.from[k] + (w.to[k] - w.from[k]) * q;
+ render(w.e);
+ } else w.pf(q);
+ if (p >= 1) w.done = 1;
+ }
+}
+
+/* ---------- world clock and camera ---------- */
+const soft = p => (1 - Math.cos(Math.PI * p)) / 2; // gentle in-out, for camera moves
+// Continuous motion: f(t) runs on every frame of the beat with t in seconds from its start (0..D).
+// Keep f a pure function of t, so pause, seek and ?beat=N&t=S show the same frame.
+const clockRun = (f, D) => { f(0); prog(q => f(q * D), 0, D, lin); };
+// A camera looks at a world group through the stage (or a box, for split screen and picture-in-picture).
+// The view {x, y, z, r} is the world point at the centre, the zoom (screen px per world px) and the roll in degrees.
+// Moves are keyed on the beat clock: to(view, t0, dur, ease) blends each given key from its value at t0; a key may be a
+// function of t (follow). Unspecified keys keep following the earlier moves. dur 0 is a hard cut.
+let camN = 0;
+function camera(p, D, { box, x = 800, y = 450, z, r = 0, bg = COL.board } = {}) {
+ const [bx, by, bw, bh] = box || [0, 0, 1600, 900];
+ const el = G(p, { x: bx + bw / 2, y: by + bh / 2 });
+ let hold = el;
+ if (box) {
+ const id = 'cam' + (++camN);
+ mk('rect', { x: -bw / 2, y: -bh / 2, width: bw, height: bh, rx: 18 }, mk('clipPath', { id }, mk('defs', {}, el)));
+ hold = G(el); hold.setAttribute('clip-path', `url(#${id})`);
+ mk('rect', { x: -bw / 2, y: -bh / 2, width: bw, height: bh, fill: bg }, hold);
+ }
+ const view = mk('g', {}, hold), world = G(view);
+ if (box) mk('rect', { x: -bw / 2, y: -bh / 2, width: bw, height: bh, rx: 18, fill: 'none', stroke: COL.faint, 'stroke-width': 2 }, el);
+ const v0 = { x, y, z: z ?? (box ? Math.min(bw / 1600, bh / 900) : 1), r };
+ const ops = [], shakes = [], layers = [];
+ const val = (v, t) => typeof v === 'function' ? v(t) : v;
+ // The view at time t after the first n moves; each move remembers the view it starts from.
+ function at(t, n = ops.length) {
+ const s = { ...v0 };
+ for (let i = 0; i < n && ops[i].t0 <= t; i++) {
+ const o = ops[i], a = o.from || (o.from = at(o.t0, i));
+ const q = o.dur ? o.ease(Math.min(1, (t - o.t0) / o.dur)) : 1, b = {};
+ for (const k in o.v) b[k] = val(o.v[k], t);
+ if ('z' in b) s.z = a.z * (b.z / a.z) ** q; // even zoom speed
+ // While zooming, x/y move so that one world point stays put on screen (when start and end allow it).
+ const u = 'z' in b && Math.abs(b.z - a.z) > 1e-6 * a.z ? (1 / s.z - 1 / a.z) / (1 / b.z - 1 / a.z) : q;
+ for (const k of ['x', 'y']) if (k in b) s[k] = a[k] + (b[k] - a[k]) * u;
+ if ('r' in b) s.r = a.r + (b.r - a.r) * q;
+ }
+ return s;
+ }
+ function apply(t) {
+ const s = at(t);
+ let sx = 0, sy = 0;
+ for (const k of shakes) if (t > k.t0 && t < k.t0 + k.dur) {
+ const e = k.amp * Math.min(1, (t - k.t0) / .3, (k.t0 + k.dur - t) / .3), w = 2 * Math.PI * k.hz * t;
+ sx += e * (Math.sin(w) + .5 * Math.sin(2.3 * w + 1)) / 1.5; sy += e * (Math.sin(1.7 * w + 2) + .5 * Math.sin(3.1 * w)) / 1.5;
+ }
+ const tf = `translate(${sx} ${sy}) rotate(${-s.r}) scale(${s.z}) translate(${-s.x} ${-s.y})`;
+ if (tf !== view._tf) view.setAttribute('transform', view._tf = tf);
+ const dx = s.x - v0.x, dy = s.y - v0.y;
+ for (const L of layers) put(L.g, { x: L.wrap ? dx - ((L.k * dx) % L.wrap + L.wrap) % L.wrap : (1 - L.k) * dx, y: (1 - L.k) * dy });
+ }
+ const cam = { el, world, at,
+ to(v, t0, dur = 1, ease = soft) { ops.push({ v, t0, dur, ease }); ops.sort((a, b) => a.t0 - b.t0); ops.forEach(o => delete o.from); return cam; },
+ cut: (v, t0) => cam.to(v, t0, 0),
+ shake(amp, t0, dur, hz = 7) { shakes.push({ amp, t0, dur, hz }); return cam; },
+ // Parallax layer: k < 1 is far (moves slower than the camera), k > 1 near. With wrap = W the layer's content
+ // repeats every W world px: draw one period plus the widest view, and the layer never runs out.
+ layer(k = 1, wrap) { const g = G(world); layers.push({ g, k, wrap }); return g; },
+ // Screen position of a world point at time t (k = 1 layers, no shake): for labels that track an object.
+ screen(wx, wy, t) {
+ const s = at(t), a = -s.r * Math.PI / 180, ux = (wx - s.x) * s.z, uy = (wy - s.y) * s.z;
+ return [bx + bw / 2 + ux * Math.cos(a) - uy * Math.sin(a), by + bh / 2 + ux * Math.sin(a) + uy * Math.cos(a)];
+ },
+ // Put a screen-space label (text, anchor middle, outside the camera) over world point (wx, wy) at time t, kept
+ // inside the frame or box by margin m; it fades out once the point itself leaves. Fade it in with a wrapper group.
+ track(el, wx, wy, t, m = 24) {
+ const [sx, sy] = cam.screen(wx, wy, t), str = el.textContent;
+ if (el._tw?.[0] !== str) el._tw = [str, el.getComputedTextLength() / 2];
+ const h = el._tw[1], away = Math.max(bx - sx, sx - bx - bw, 0);
+ put(el, { x: Math.min(bx + bw - m - h, Math.max(bx + m + h, sx)), y: sy, o: Math.max(0, 1 - away / 80) });
+ },
+ };
+ clockRun(apply, D);
+ return cam;
+}
+
+/* ---------- scene ---------- */
+const scene = document.getElementById('scene');
+const S = {};
+const AXIS = { o: 800, u: 120 }; // number line: x of 0, pixels per unit; a chapter may change it
+const X = v => AXIS.o + AXIS.u * v, Y0 = 610;
+const num = v => (v < 0 ? '−' : '') + String(Math.abs(v)).replace('.', DECIMAL_SIGN);
+function reset() {
+ scene.replaceChildren();
+ for (const k in S) delete S[k];
+ Object.assign(S, { dots: {}, tick: {}, rows: [], chips: [], samples: [], list: G(scene), line: G(scene), venn: G(scene) });
+}
+function tick(v) {
+ const g = G(S.line, { o: 0 });
+ path(g, `M${X(v)} ${Y0 - 11}V${Y0 + 11}`, { stroke: COL.dim, 'stroke-width': 2.5 });
+ T(g, num(v), { x: X(v), y: Y0 + 50, size: 30, fill: COL.dim, font: MATH, anchor: 'middle' });
+ return (S.tick[v] = g);
+}
+function dot(key, v, r = 9, name = v) {
+ const g = G(S.line, { x: X(v), y: Y0, s: 0, o: 0 });
+ mk('circle', { r, fill: COL[key], stroke: COL.board, 'stroke-width': 2 }, g);
+ return (S.dots[name] = g);
+}
+const arrow = (x, dir) => `M${x - 15 * dir} ${Y0 - 10}L${x} ${Y0}L${x - 15 * dir} ${Y0 + 10}`;
+function panel(t0) {
+ if (t0 < .5) S.cleared = true; // the old panel fades, or this is the first panel after the title
+ const old = S.panel;
+ if (old && t0 < .5) retire(old);
+ else if (old) { // a panel change later in the beat stays on the beat clock
+ hide(old, t0, .4);
+ prog(q => { if (q === 1) old.style.display = 'none'; }, t0 + .4, 0, lin);
+ }
+ return (S.panel = G(scene));
+}
+// Take a beat's old picture away on wall time: a 150 ms fade, then out of rendering. On the beat clock the fade would
+// wait for the new clip's audio to start (a few hundred ms in Firefox) with the old, frozen scene still showing.
+// While seeking, the pictures passed on the way were never seen: they go at once.
+let seeking = false;
+function retire(e) {
+ if (seeking) { e.style.display = 'none'; return; }
+ e.style.transition = 'opacity .15s linear';
+ e.style.opacity = '0';
+ setTimeout(() => { e.style.display = 'none'; }, 160);
+}
+function header(p, str, t0, x = 1000, y = 170) {
+ const h = T(p, str, { x, y, size: 30, fill: COL.dim, weight: 600, o: 0 });
+ show(h, t0);
+ return h;
+}
+
+/* ---------- question effects: run on wall time, independent of the lesson clock ---------- */
+let FX = [], clock = 0;
+function fx(e, to, delay = 0, dur = .5, ease = io) { FX.push({ e, to, t0: clock + delay, dur, ease }); }
+function fxp(pf, delay, dur, ease = io) { FX.push({ pf, t0: clock + delay, dur, ease }); }
+function finishFx() { FX.sort((a, b) => a.t0 - b.t0); evalTo(Infinity, FX); FX = []; }
+const pulseFx = (e, k = 1.8) => { if (!e) return; fx(e, { s: k }, 0, .22, out); fx(e, { s: 1 }, .22, .45); };
+const shakeFx = e => { if (!e) return; const x0 = st(e).x; fxp(q => put(e, { x: x0 + Math.sin(q * Math.PI * 6) * (1 - q) * 12 }), 0, .55, lin); };
+const glowFx = (key, delay = 0) => CHAIN[key].forEach((k, i) => {
+ const s = S.ring[k].stroke;
+ fx(s, { 'a_stroke-width': 9 }, delay + i * .28, .22, out); fx(s, { 'a_stroke-width': 3 }, delay + i * .28 + .25, .5);
+});
+function popDotFx(key, v, label) {
+ const L = S.q || qlayer();
+ const g = G(L, { x: X(v), y: Y0, s: 0, o: 0 });
+ mk('circle', { r: 7, fill: COL[key], stroke: COL.board, 'stroke-width': 2 }, g);
+ fx(g, { s: 1, o: 1 }, 0, .45, back);
+ if (label) fx(M(L, label, { x: X(v) + 10, y: Y0 + 56, size: 28, fill: COL[key], o: 0 }), { o: 1 }, .3, .4);
+}
+function floatText(str, x, y, colr) {
+ const t = T(S.q || qlayer(), str, { x, y: y + 14, size: 24, fill: colr, anchor: 'middle', weight: 600, o: 0 });
+ fx(t, { o: 1, y }, 0, .5, out);
+}
+function hopsFx(n) {
+ for (let k = 1; k <= -n; k++) {
+ const a = X(1 - k), b = X(-k);
+ fx(path(S.q, `M${a} ${Y0 - 12}Q${(a + b) / 2} ${Y0 - 84} ${b} ${Y0 - 12}`, { stroke: COL.int, 'stroke-width': 3 }, { d: 0 }), { d: 1 }, (k - 1) * .35, .35, lin);
+ }
+ floatText(translate('stepsLeftOfZero', { n: -n }), X(n / 2), Y0 - 100, COL.int);
+}
+
+/* ---------- shared answer columns ---------- */
+const FAMILIES = ['nat', 'whole', 'int', 'rat', 'irr', 'real'];
+const FAM_COLS = FAMILIES.map(k => [k, k === 'int' ? translate('integerColumn') : NAME[k], COL[k]]);
+const TF = [['t', translate('trueLabel'), null, 'T'], ['f', translate('falseLabel'), null, 'F']];
+function finishCard() {
+ const c = card(SCREEN, 'fin');
+ const sum = pre => Object.entries(SCORE).filter(([k]) => k.startsWith(pre)).reduce((a, [, v]) => [a[0] + v.right, a[1] + v.total], [0, 0]);
+ const line = (name, [r, t]) => h('p', 'fb', t ? translate('firstTryScore', { name, r, t }) : translate('notAttempted', { name }));
+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });
+ const home = h('a', 'btn quiet', translate('allChapters'));
+ home.href = $('bHome').href;
+ const again = h('button', 'btn' + (CHAPTER.next ? ' quiet' : ' go'), [translate('watchAgain'), kbd(CHAPTER.next ? 'R' : 'Enter')]);
+ again.onclick = restart;
+ const next = CHAPTER.next && h('button', 'btn go', [translate('nextChapter'), kbd('Enter')]);
+ if (next) next.onclick = () => { location.href = CHAPTER.next; };
+ P.keys = e => e.key === 'Enter' ? ((next ? next.onclick() : restart()), true)
+ : isShortcut(e, 'r') ? (restart(), true) : false;
+ const guide = mascotEl(240);
+ c.append(h('div', 'finwrap', [guide, h('p', 'kicker', translate('chapterComplete', { n: CHAPTER.label ?? CHAPTER.number })), h('p', 'prompt', CHAPTER.title),
+ line(translate('quickChecks'), sum('c-')), line(translate('chapterPractice'), sum('p-')), h('div', 'acts', next ? [home, again, next] : [home, again])]));
+ setTimeout(() => mood(guide, 'happy'), 400);
+}
+
+/* ---------- in-picture cards ---------- */
+const $ = id => document.getElementById(id);
+// The volume control (volume.js, volume.css) lives in its own files next to this one, the same in every book.
+document.head.append(Object.assign(document.createElement('script'), { src: new URL('volume.js', document.currentScript.src) }));
+const kbd = s => h('kbd', '', s);
+const uiW = (str, size) => { ctx2d.font = `600 ${size}px ${UI}`; return ctx2d.measureText(str).width; };
+const RING_KEYS = ['nat', 'whole', 'int', 'rat', 'irr', 'real']; // number keys 1–6 in sorting questions
+const SCORE = {}; // question id -> first-attempt {right, total}
+
+function h(tag, cls, kids = []) {
+ const e = document.createElement(tag);
+ if (cls) e.className = cls;
+ for (const k of [].concat(kids)) e.append(k);
+ return e;
+}
+// Rich text: strings, DOM nodes, or $m(...) inline math.
+function rich(parts, size = 28) {
+ const s = document.createElement('span');
+ for (const p of [].concat(parts)) s.append(typeof p === 'string' || p instanceof Node ? p : mathEl(p.m, size));
+ return s;
+}
+// A card at pos; a band card keeps its bottom on the stage: when its content grows (a long question, feedback),
+// it moves up rather than running under the player bar.
+function card(pos, cls) {
+ const c = h('div', `card ${pos.cls} ${cls}`);
+ Object.assign(c.style, { left: pos.x + 'px', top: pos.y + 'px', width: pos.w + 'px' });
+ if (pos.maxH) c.style.maxHeight = pos.maxH + 'px';
+ $('ui').append(c);
+ if (pos.cls === 'band') {
+ const fit = () => { c.style.top = Math.max(16, Math.min(pos.y, 900 - 16 - c.offsetHeight)) + 'px'; };
+ const ro = new ResizeObserver(fit);
+ ro.observe(c); fit();
+ P.cleanup.push(() => ro.disconnect());
+ }
+ return c;
+}
+// The guide: an infinity sign whose two loops are its eyes. Drawn in SVG so it can blink, hop and wobble.
+function lemniscate(cx, cy, a, k) {
+ let d = '';
+ for (let i = 0; i <= 96; i++) {
+ const t = i / 96 * 2 * Math.PI, sn = Math.sin(t), q = 1 + sn * sn;
+ d += (i ? 'L' : 'M') + (cx + a * Math.cos(t) / q).toFixed(1) + ' ' + (cy + k * a * sn * Math.cos(t) / q).toFixed(1);
+ }
+ return d + 'Z';
+}
+function mascotEl(size = 100) {
+ const svg = mk('svg', { class: 'mascot', viewBox: '0 0 120 84', width: size, height: size * .7, 'aria-hidden': 'true' });
+ const body = mk('g', { class: 'mbody' }, svg);
+ const line = { fill: 'none', stroke: COL.chalk, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' };
+ mk('path', { d: lemniscate(60, 40, 52, 1.5), ...line, 'stroke-width': 6 }, body);
+ const eyes = mk('g', { class: 'eyes' }, body);
+ for (const x of [33, 87]) {
+ mk('circle', { class: 'pupil', cx: x, cy: 40, r: 6.5, fill: COL.chalk }, eyes);
+ mk('path', { class: 'joy', d: `M${x - 7} 43Q${x} 32 ${x + 7} 43`, ...line, 'stroke-width': 4 }, body);
+ }
+ mk('path', { class: 'smile', d: 'M55 62Q60 67 65 62', ...line, 'stroke-width': 3.5 }, body);
+ mk('path', { class: 'flat', d: 'M55 64H65', ...line, 'stroke-width': 3.5 }, body);
+ return svg;
+}
+function mood(el, m) {
+ el.classList.remove('happy', 'oops');
+ void el.getBoundingClientRect(); // restart the CSS animation
+ if (m) el.classList.add(m);
+}
+// A sequence of questions in one card. Each question: { id, prompt, build(body, api) -> { check?, reveal, lock? } }.
+function quiz(pos, qs, done, label = translate('quickCheck')) {
+ const c = card(pos, 'quiz');
+ let k = 0;
+ const show = () => {
+ const q = qs[k];
+ let first = true, resolved = false;
+ const fb = h('div', 'fb'), body = h('div', 'body'), acts = h('div', 'acts');
+ const bCheck = h('button', 'btn', [translate('check'), kbd('Enter')]), bShow = h('button', 'btn quiet', [translate('showAnswer'), kbd('S')]);
+ const bNext = h('button', 'btn go', [k < qs.length - 1 ? translate('nextQuestion') : translate('continue'), kbd('Enter')]);
+ bShow.hidden = bNext.hidden = true;
+ const guide = pos.cls === 'band' || pos.cls === 'side' ? mascotEl(pos.cls === 'band' ? 108 : 70) : null;
+ const say = (cls, parts) => { fb.className = 'fb ' + cls; fb.replaceChildren(rich(parts, 24)); fb.style.animation = 'none'; void fb.offsetWidth; fb.style.animation = ''; };
+ const resolve = () => {
+ resolved = true;
+ bCheck.hidden = bShow.hidden = true;
+ ctl.lock?.();
+ bNext.hidden = false;
+ bNext.focus({ preventScroll: true });
+ };
+ const api = {
+ grade(ok, msg, score) {
+ if (resolved) return;
+ if (first) { if (!Object.hasOwn(SCORE, q.id)) SCORE[q.id] = score || { right: +ok, total: 1 }; first = false; }
+ say(ok ? 'ok' : 'no', [ok ? translate('correct') : translate('notQuite'), ...[].concat(msg || [])]);
+ if (guide) {
+ mood(guide, ok ? 'happy' : 'oops');
+ if (!ok) setTimeout(() => { if (guide.classList.contains('oops')) mood(guide, null); }, 1600);
+ }
+ if (ok) resolve(); else bShow.hidden = false;
+ },
+ };
+ const ctl = q.build(body, api);
+ if (ctl.check) { bCheck.onclick = () => ctl.check(); acts.append(bCheck); }
+ acts.append(bShow, bNext);
+ bShow.onclick = () => { say('', [translate('answerPrefix'), ...[].concat(ctl.reveal())]); resolve(); };
+ bNext.onclick = () => { if (k < qs.length - 1) { k++; show(); } else done(); };
+ P.keys = e => {
+ if (e.key === 'Enter' && resolved) { bNext.click(); return true; }
+ if (!resolved && ctl.key?.(e)) return true;
+ if (e.key === 'Enter' && !resolved && ctl.check) { bCheck.click(); return true; }
+ if (isShortcut(e, 's') && !bShow.hidden) { bShow.click(); return true; }
+ return false;
+ };
+ const kick = label + (qs.length > 1 ? ' ' + translate('countOf', { k: k + 1, n: qs.length }) : '');
+ const head = h('div', 'head', [h('p', 'kicker', kick), h('p', 'prompt', [rich(q.prompt, pos.cls.startsWith('screen') ? 38 : 28)])]); // match the prompt's type size
+ if (ctl.hint) head.append(h('p', 'keys', [translate('keysPrefix'), ...ctl.hint]));
+ c.replaceChildren(...(guide ? [guide] : []), head, fb, body, acts);
+ };
+ show();
+}
+function qlayer() {
+ S.q?.remove();
+ S.q = G(scene);
+ S.q.classList.add('qlayer');
+ return S.q;
+}
+const keyAct = (el, fn) => el.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); fn(); } });
+
+/* ---------- question builders ---------- */
+// Single answer from buttons; each wrong option has its own explanation.
+const choice = (opts, right, yes, no, onRight) => (body, api) => {
+ const row = h('div', 'opts');
+ const bs = opts.map((o, i) => {
+ const b = h('button', 'opt', [kbd(String(i + 1)), rich(o, 32)]);
+ b.onclick = () => {
+ if (i === right) { b.classList.add('good'); onRight?.(); api.grade(true, yes); }
+ else { b.classList.add('bad'); b.disabled = true; api.grade(false, no[i]); }
+ };
+ row.append(b);
+ return b;
+ });
+ body.append(row);
+ return {
+ reveal() { bs[right].classList.add('good'); onRight?.(); return yes; },
+ lock() { bs.forEach(b => { b.disabled = true; }); },
+ key(e) { const b = bs[+e.key - 1]; if (!b || b.disabled) return false; b.click(); return true; },
+ };
+};
+// The shared body of the stage tap questions: each target ring is a focusable button that answers on click or Enter,
+// and ← / → move the focus between them. targets: [{ g, label, ok, wrong }], wrong() shakes and returns the explanation.
+const stageTap = (api, targets, show, yes, onRight, hint) => {
+ let locked = false, cur = -1;
+ const gs = targets.map(({ g, label, ok, wrong }) => {
+ g.classList.add('hit');
+ g.setAttribute('tabindex', 0);
+ g.setAttribute('role', 'button');
+ g.setAttribute('aria-label', label);
+ const act = () => {
+ if (locked) return;
+ if (ok) { g.classList.add('good'); onRight?.(); api.grade(true, yes); }
+ else { g.classList.add('bad'); api.grade(false, wrong()); }
+ };
+ g.addEventListener('click', act);
+ keyAct(g, act);
+ return g;
+ });
+ return {
+ reveal() { gs[show].classList.add('good'); onRight?.(); return yes; },
+ lock() { locked = true; },
+ hint,
+ key(e) {
+ const d = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;
+ if (!d || locked) return false;
+ cur = cur < 0 ? (d > 0 ? 0 : gs.length - 1) : (cur + d + gs.length) % gs.length;
+ gs[cur].focus();
+ return true;
+ },
+ };
+};
+// Tap a point on the stage number line.
+const tap = (values, right, yes, no, onRight) => (body, api) => {
+ const L = qlayer();
+ const targets = values.map(v => {
+ const g = G(L, { x: X(v), y: Y0 });
+ mk('circle', { r: 30, class: 'ring' }, g);
+ return { g, label: translate('pointLabel', { v: num(v) }), ok: v === right, wrong: () => { shakeFx(S.dots[v]); return no(v); } };
+ });
+ return stageTap(api, targets, values.lastIndexOf(right), yes, onRight,
+ [kbd('←'), kbd('→'), translate('hintMoveAlongLine'), kbd('Enter'), translate('hintChoose')]);
+};
+// Tap one token of a stage token row, e.g. the operation to do first. idx: tappable token indexes.
+const tapEls = (row, idx, right, yes, no, onRight) => (body, api) => {
+ const L = qlayer();
+ const targets = idx.map(i => {
+ const e = row[i], w = e._w + 18, g = G(L, { x: e._px, y: row.y });
+ mk('rect', { class: 'ring', x: -w / 2, y: -row.size * .95, width: w, height: row.size * 1.3, rx: 12 }, g);
+ return { g, label: e.textContent.trim(), ok: i === right, wrong: () => { shakeFx(e); return no(i); } };
+ });
+ return stageTap(api, targets, idx.indexOf(right), yes, onRight,
+ [kbd('←'), kbd('→'), translate('hintMove'), kbd('Enter'), translate('hintChoose')]);
+};
+// Click one of several stage objects (table cells, bars, small graphs). items: [{ el, box: [x, y, w, h], label }].
+const pickEls = (items, right, yes, no, onRight) => (body, api) => {
+ const L = qlayer();
+ const targets = items.map((it, i) => {
+ const [x, y, w, hh] = it.box, g = G(L);
+ mk('rect', { class: 'ring', x, y, width: w, height: hh, rx: 12 }, g);
+ return { g, label: it.label, ok: i === right, wrong: () => { shakeFx(it.el); return no(i); } };
+ });
+ return stageTap(api, targets, right, yes, onRight,
+ [kbd('←'), kbd('→'), translate('hintMove'), kbd('Enter'), translate('hintChooseOrClick')]);
+};
+// Rows of toggles. items: { parts, ans: [keys], why }. parts are math parts (strings, F, R) unless text: true,
+// where they are rich text (strings and $m(...)). cols: [[key, label, colour?, shortcut?]]. multi: several per row.
+const grid = (items, cols, { multi = true, text = false } = {}) => (body, api) => {
+ const wrap = h('div', 'grid' + (text ? ' text' : ''));
+ const hot = cols.map((c, j) => c[3] || String(j + 1));
+ let cur = 0, locked = false;
+ const rows = items.map((it, ri) => {
+ const opts = h('div', 'opts'), mark = h('div', 'mark'), why = h('div', 'why');
+ const bs = cols.map(([key, lab, colr], j) => {
+ const b = h('button', 'opt', [kbd(hot[j]), lab]);
+ if (colr) b.style.setProperty('--c', colr);
+ b.setAttribute('aria-pressed', 'false');
+ b.onclick = () => {
+ const on = b.getAttribute('aria-pressed') !== 'true';
+ if (!multi) bs.forEach(x => x.setAttribute('aria-pressed', 'false'));
+ b.setAttribute('aria-pressed', String(on));
+ };
+ opts.append(b);
+ return b;
+ });
+ const el = h('div', 'row', [h('div', 'num', [text ? rich(it.parts, 26) : mathEl(it.parts, 32)]), opts, mark, why]);
+ el.addEventListener('click', () => { cur = ri; showCur(); });
+ wrap.append(el);
+ const picked = () => cols.filter((c, i) => bs[i].getAttribute('aria-pressed') === 'true').map(c => c[0]);
+ return { it, bs, mark, why, picked, el, played: false };
+ });
+ const single = rows.length === 1;
+ const showCur = () => rows.forEach((r, i) => {
+ const on = !single && !locked && i === cur;
+ r.el.classList.toggle('cur', on);
+ if (on && r.el.isConnected) r.el.scrollIntoView({ block: 'nearest' }); // a long practice list scrolls
+ });
+ showCur();
+ body.append(wrap);
+ const judge = r => {
+ const p = r.picked(), ok = p.length === r.it.ans.length && r.it.ans.every(k => p.includes(k));
+ r.mark.className = 'mark ' + (ok ? 'good' : 'bad');
+ r.mark.textContent = ok ? '✓' : '✗';
+ r.why.replaceChildren(ok || single ? '' : rich(r.it.why, 20));
+ if (ok && !r.played) { r.played = true; r.it.fx?.(); }
+ return ok;
+ };
+ return {
+ check() {
+ const right = rows.filter(judge).length;
+ const all = right === rows.length;
+ api.grade(all, single ? rows[0].it.why : all ? [] : [translate('rowsRight', { r: right, n: rows.length })], { right, total: rows.length });
+ },
+ reveal() {
+ for (const r of rows) {
+ r.bs.forEach((b, i) => b.setAttribute('aria-pressed', String(r.it.ans.includes(cols[i][0]))));
+ judge(r);
+ if (!single) r.why.replaceChildren(rich(r.it.why, 20));
+ }
+ return single ? rows[0].it.why : translate('choicesShown');
+ },
+ lock() { locked = true; showCur(); rows.forEach(r => r.bs.forEach(b => { b.disabled = true; })); },
+ hint: [...(single ? [] : [kbd('↑'), kbd('↓'), translate('hintRow')]), ...(/\d/.test(hot[0]) ? [kbd(hot[0]), '–', kbd(hot[hot.length - 1])] : hot.map(kbd)), translate('hintChoose')],
+ key(e) {
+ if (locked) return false;
+ if ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && !single) {
+ cur = (cur + (e.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
+ showCur();
+ return true;
+ }
+ const j = hot.findIndex(x => isShortcut(e, x));
+ if (j < 0) return false;
+ rows[cur].bs[j].click();
+ if (!multi && cur < rows.length - 1) { cur++; showCur(); }
+ return true;
+ },
+ };
+};
+// Exact value of a typed answer: integer, decimal, fraction a/b or mixed number "w a/b"; returns [num, den] or null.
+// Accepts −, – or - as the sign, and a decimal comma when DECIMAL_SIGN is ','. Never evaluates the text as code.
+function rat(str) {
+ let t = String(str).trim().replace(/^[−–]/, '-').replace(/\s+/g, ' ');
+ if (DECIMAL_SIGN === ',') t = t.replace(/^(-?\d+),(\d+)$/, '$1.$2'); // 0,75 where the decimal sign is a comma
+ let m = t.match(/^(-?)(\d+)(?:\.(\d+))?$/);
+ if (m) { const d = 10 ** (m[3] || '').length, n = (m[1] ? -1 : 1) * (Number(m[2]) * d + Number(m[3] || 0)); return Number.isSafeInteger(n) && Number.isSafeInteger(d) ? [n, d] : null; }
+ m = t.match(/^(-?)(?:(\d+) )?(\d+) ?\/ ?(\d+)$/);
+ if (m && Number(m[4]) > 0) { const d = Number(m[4]), n = (m[1] ? -1 : 1) * (Number(m[2] || 0) * d + Number(m[3])); return Number.isSafeInteger(n) && Number.isSafeInteger(d) ? [n, d] : null; }
+ return null;
+}
+const gcd = (a, b) => { a = Math.abs(a); b = Math.abs(b); while (b) [a, b] = [b, a % b]; return a; };
+const lowest = ([n, d]) => gcd(n, d) === 1;
+// Fill-in boxes inside math. rows: [{ parts: [math parts and { box: '21' }], why, hint?, fx? }].
+// test(values), when given, judges the whole row from the typed numbers (e.g. a factor pair in either order); the boxes' answers are still what Show answer fills in.
+// Answers are exact numbers: "−5", "-5", "0.5", "3/4" and "2 1/4" all work, and equal values match ("6/8" = "3/4")
+// unless the box has lowest: true. hint is shown after a wrong try, why after a right one.
+const blanks = rowsIn => (body, api) => {
+ const all = [];
+ const rows = rowsIn.map(it => {
+ const line = h('div', 'bline'), mark = h('span', 'mark'), why = h('div', 'why');
+ let run = [];
+ const flush = () => { if (run.length) line.append(mathEl(run, 34)); run = []; };
+ const boxes = [];
+ for (const p of it.parts) {
+ if (p && p.box !== undefined) {
+ flush();
+ const b = h('input', 'box');
+ Object.assign(b, { type: 'text', inputMode: 'decimal', autocomplete: 'off', spellcheck: false });
+ b.setAttribute('aria-label', translate('answerBox'));
+ b.dataset.ans = p.box;
+ if (p.lowest) b.dataset.lowest = '1';
+ b.style.width = `${Math.max(2, String(p.box).length) + 2}ch`;
+ line.append(b);
+ boxes.push(b);
+ all.push(b);
+ } else run.push(p);
+ }
+ flush();
+ line.append(mark);
+ body.append(h('div', 'brow', [line, why]));
+ return { it, boxes, mark, why, played: false };
+ });
+ body.classList.add('blanks');
+ const single = rows.length === 1;
+ const judge = r => {
+ let ok = true;
+ if (r.it.test) { // the row is judged as a whole, e.g. two factors in either order
+ const vals = r.boxes.map(b => rat(b.value));
+ ok = vals.every(Boolean) && !!r.it.test(vals.map(([n, d]) => n / d));
+ r.boxes.forEach(b => { b.classList.toggle('good', ok); b.classList.toggle('bad', !ok); });
+ } else for (const b of r.boxes) {
+ const want = rat(b.dataset.ans), got = rat(b.value);
+ const good = !!got && !!want && BigInt(got[0]) * BigInt(want[1]) === BigInt(want[0]) * BigInt(got[1]) && (!b.dataset.lowest || lowest(got));
+ b.classList.toggle('good', good);
+ b.classList.toggle('bad', !good);
+ ok = ok && good;
+ }
+ r.mark.className = 'mark ' + (ok ? 'good' : 'bad');
+ r.mark.textContent = ok ? '✓' : '✗';
+ r.why.replaceChildren(ok || single ? '' : rich(r.it.hint ?? r.it.why, 20));
+ if (ok && !r.played) { r.played = true; r.it.fx?.(); }
+ return ok;
+ };
+ requestAnimationFrame(() => all[0]?.focus({ preventScroll: true }));
+ return {
+ check() {
+ const right = rows.filter(judge).length, done = right === rows.length;
+ const msg = single ? (done ? rows[0].it.why : rows[0].it.hint ?? rows[0].it.why)
+ : done ? [] : [translate('rowsRight', { r: right, n: rows.length })];
+ api.grade(done, msg, { right, total: rows.length });
+ },
+ reveal() {
+ for (const r of rows) {
+ r.boxes.forEach(b => { b.value = b.dataset.ans.replace('-', '−'); }); // shown exactly as authored
+ judge(r);
+ if (!single) r.why.replaceChildren(rich(r.it.why, 20));
+ }
+ return single ? rows[0].it.why : translate('numbersShown');
+ },
+ lock() { all.forEach(b => { b.disabled = true; }); },
+ hint: [translate(all.some(b => b.dataset.ans.includes('/')) ? 'hintTypeFraction' : all.some(b => /[.,]/.test(b.dataset.ans)) ? 'hintTypeDecimal' : 'hintTypeNumber'),
+ kbd('Tab'), translate('hintNextBox'), kbd('Enter'), translate('hintCheck'), kbd('Esc'), translate('hintLeaveBox')],
+ };
+};
+// Drag number chips into the stage number map. items: [parts, smallest ring, explanation].
+const slot = (k, n) => {
+ if (k === 'real') return [[940, 210], [1000, 760], [820, 800]][n % 3]; // inside Real, outside every other ring
+ const r = RINGS[k];
+ return [r.lx + [-72, 72, 0][n % 3], r.ly + 50 + 56 * Math.floor(n / 2)];
+};
+const plain = parts => parts.map(p => typeof p === 'string' ? p : p.ov !== undefined ? p.ov + ' repeating' : p.tex !== undefined ? p.tex : p.f ? p.f.join('/') : p.sup !== undefined ? '^' + p.sup : (p.i ? p.i : '') + '√' + (p.r.f ? p.r.f.join('/') : p.r)).join('');
+const sorter = (items, trayXY) => (body, api) => {
+ const L = qlayer();
+ const bg = mk('rect', { width: 1600, height: 900, fill: 'transparent' }, L);
+ const svg = $('stage');
+ const pt = e => { const p = svg.createSVGPoint(); p.x = e.clientX; p.y = e.clientY; return p.matrixTransform(svg.getScreenCTM().inverse()); };
+ let sel = null, drag = null, locked = false;
+ const label = c => c.setAttribute('aria-label', c.region ? translate('chipPlaced', { x: c.say, ring: NAME[c.region] }) : translate('chipNotPlaced', { x: c.say }));
+ const outline = (c, colr, w = 2.5) => { c._rect.setAttribute('stroke', colr); c._rect.setAttribute('stroke-width', w); };
+ const choose = c => {
+ if (sel) outline(sel, COL.chalk);
+ sel = c;
+ if (sel) { outline(sel, COL.task, 4); L.append(sel); }
+ };
+ const select = c => choose(sel === c ? null : c);
+ // Number badges next to the ring names, for keys 1–6.
+ RING_KEYS.forEach((k, i) => {
+ const r = RINGS[k], g = G(L, { x: r.lx - uiW(NAME[k], 26) / 2 - 24, y: r.ly - 9 });
+ g.style.pointerEvents = 'none';
+ mk('circle', { r: 14, fill: COL.board, stroke: COL[k], 'stroke-width': 1.5 }, g);
+ T(g, String(i + 1), { y: 6.5, size: 18, fill: COL[k], anchor: 'middle', weight: 600 });
+ });
+ const place = (c, x, y) => {
+ c.region = regionAt(x, y);
+ if (!c.region) [x, y] = c.home;
+ put(c, { x, y });
+ outline(c, COL.chalk);
+ c.querySelector('.mark')?.remove();
+ if (sel === c) sel = null;
+ label(c);
+ };
+ const chips = items.map(([parts, answer, why], i) => {
+ const [x, y] = trayXY(i);
+ const c = chip(L, parts, COL.chalk, { x, y, size: 32 });
+ Object.assign(c, { answer, why, home: [x, y], region: null, say: plain(parts) });
+ c.classList.add('tok');
+ c.setAttribute('tabindex', 0);
+ c.setAttribute('role', 'button');
+ label(c);
+ c.addEventListener('pointerdown', e => {
+ if (locked) return;
+ e.preventDefault();
+ const p = pt(e);
+ drag = { dx: p.x - st(c).x, dy: p.y - st(c).y, sx: p.x, sy: p.y, moved: false };
+ L.append(c); // re-parent before capturing: moving a node drops its capture
+ c.setPointerCapture(e.pointerId);
+ });
+ c.addEventListener('pointermove', e => {
+ if (!drag) return;
+ const p = pt(e);
+ if (Math.hypot(p.x - drag.sx, p.y - drag.sy) > 6) drag.moved = true;
+ if (drag.moved) put(c, { x: p.x - drag.dx, y: p.y - drag.dy });
+ });
+ c.addEventListener('pointerup', () => {
+ if (!drag) return;
+ const moved = drag.moved;
+ drag = null;
+ if (moved) place(c, st(c).x, st(c).y); else select(c);
+ });
+ // A cancelled drag (a system gesture, a lost capture) drops the chip where it is instead of leaving it stuck to no pointer.
+ c.addEventListener('lostpointercapture', () => {
+ if (!drag) return;
+ const moved = drag.moved;
+ drag = null;
+ if (moved) place(c, st(c).x, st(c).y);
+ });
+ keyAct(c, () => { if (!locked) select(c); });
+ return c;
+ });
+ bg.addEventListener('pointerup', e => { if (sel && !locked) { const p = pt(e); place(sel, p.x, p.y); } });
+ return {
+ check() {
+ let right = 0;
+ const notes = h('ul');
+ for (const c of chips) {
+ c.querySelector('.mark')?.remove();
+ if (!c.region) { notes.append(h('li', '', translate('notPlacedYet', { x: c.say }))); continue; }
+ const ok = c.region === c.answer;
+ right += ok;
+ outline(c, ok ? COL.good : COL.bad, 4);
+ if (ok) { pulseFx(c, 1.25); glowFx(c.answer, right * .15); } else shakeFx(c);
+ const w = +c._rect.getAttribute('width');
+ T(c, ok ? '✓' : '✗', { x: w / 2 + 4, y: -16, size: 26, fill: ok ? COL.good : COL.bad, weight: 700 }).classList.add('mark');
+ if (!ok) notes.append(h('li', '', c.region === 'real'
+ ? translate('realRingIsEmpty', { x: c.say })
+ : c.why));
+ }
+ const all = right === chips.length;
+ api.grade(all, all ? [] : [translate('ringsRight', { r: right, n: chips.length }), notes], { right, total: chips.length });
+ },
+ reveal() {
+ const count = {};
+ chips.forEach((c, i) => {
+ const n = count[c.answer] = (count[c.answer] ?? -1) + 1;
+ const [x, y] = slot(c.answer, n);
+ c.region = c.answer;
+ c.querySelector('.mark')?.remove();
+ outline(c, COL.good, 4);
+ fx(c, { x, y }, i * .12, .8);
+ });
+ return translate('ringsShown');
+ },
+ lock() { locked = true; choose(null); },
+ hint: [kbd('←'), kbd('→'), translate('hintPickNumber'), kbd('1'), '–', kbd('6'), translate('hintPickRing')],
+ key(e) {
+ if (locked) return false;
+ const d = e.key === 'ArrowRight' || e.key === 'ArrowDown' ? 1 : e.key === 'ArrowLeft' || e.key === 'ArrowUp' ? -1 : 0;
+ if (d) {
+ const i = sel ? chips.indexOf(sel) : d > 0 ? -1 : 0;
+ choose(chips[(i + d + chips.length) % chips.length]);
+ return true;
+ }
+ const ring = RING_KEYS[+e.key - 1];
+ if (!ring || !sel) return false;
+ const c = sel;
+ place(c, ...slot(ring, chips.filter(x => x.region === ring && x !== c).length));
+ choose(chips.find(x => !x.region) || null);
+ return true;
+ },
+ };
+};
+
+/* ---------- player ---------- */
+const P = { i: 0, t: 0, end: 1, playing: false, waiting: false, done: false, started: false, audio: null, afail: false, stall: 0, cleanup: [], rate: 1, nextClip: null };
+function runBeat(i) {
+ TW = [];
+ const b = BEATS[i], tm = TIMINGS[b.id], pre = b.pre || 0; // pre: seconds of picture before the narration starts
+ const m = (k, off = 0) => {
+ if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);
+ return pre + tm.marks[k] + off;
+ };
+ S.cleared = false;
+ b.run(m, pre + tm.dur);
+ if (S.cleared && b.lead !== false && !pre) leadIn();
+ TW.sort((a, c) => a.t0 - c.t0);
+ return Math.max(pre + tm.dur, ...TW.map(w => w.t0 + w.dur)) + .6;
+}
+// A beat that clears the picture must not leave it empty while the narration has started.
+// If nothing appears before LEAD_MAX, the opening group (every tween that starts within LEAD_GROUP s of the
+// first reveal) moves earlier so it begins at LEAD_AT, just after the old panel has faded. Later steps keep their word timing.
+const LEAD_AT = .4, LEAD_MAX = .8, LEAD_GROUP = 1.2;
+function leadIn() {
+ const reveals = TW.filter(w => {
+ if (!w.e) return false;
+ const s = st(w.e), to = w.to;
+ return (to.o > 0 && s.o === 0) || (to.s > 0 && s.s === 0) || (to.d > 0 && (s.d ?? 1) === 0);
+ });
+ if (!reveals.length) return;
+ const first = Math.min(...reveals.map(w => w.t0));
+ if (first <= LEAD_MAX) return;
+ for (const w of TW) if (w.t0 >= first && w.t0 < first + LEAD_GROUP) w.t0 -= first - LEAD_AT;
+}
+function stopAudio() {
+ const a = P.audio;
+ if (!a) return;
+ a.onerror = null; a.pause(); a.removeAttribute('src'); a.load();
+ P.audio = null;
+}
+function clearCards() {
+ $('ui').replaceChildren();
+ P.cleanup.forEach(f => f());
+ P.cleanup = [];
+ finishFx();
+ P.keys = null;
+ S.q?.remove();
+ delete S.q;
+}
+// Rebuild the scene from scratch and fast-forward every earlier beat, so any step starts from its exact picture.
+function seek(i, play = P.playing) {
+ stopAudio(); clearCards(); reset();
+ seeking = true;
+ try {
+ for (let k = 0; k < i; k++) { runBeat(k); evalTo(Infinity); }
+ start(i, play);
+ } finally { seeking = false; }
+}
+// Jump to a point inside beat i (frac of its narration); question beats always start at their beginning.
+function seekInto(i, frac) {
+ seek(i, true);
+ const pre = BEATS[i].pre || 0, t = BEATS[i].ask ? 0 : frac * (pre + TIMINGS[BEATS[i].id].dur);
+ if (t < .3) return;
+ P.t = t;
+ evalTo(t);
+ if (P.audio) P.audio.currentTime = Math.max(0, t - pre);
+}
+function start(i, play) {
+ stopAudio(); clearCards();
+ Object.assign(P, { i, t: 0, waiting: false, done: false, afail: false, stall: 0 });
+ P.end = runBeat(i);
+ evalTo(0);
+ const a = P.audio = beatClip(i, true);
+ a.volume = +($('volume')?.value ?? 1);
+ a.playbackRate = P.rate;
+ // An aborted or superseded load (fast stepping, a reload) is not a failure: only a real error for the current clip
+ // shows the note, and the note goes away as soon as a clip plays.
+ a.onerror = () => { if (P.audio === a && a.error && a.error.code !== MediaError.MEDIA_ERR_ABORTED) soundFailed(); };
+ a.onplaying = () => {
+ if (P.audio !== a) return;
+ $('soundNote').hidden = true;
+ if (P.afail) { P.afail = false; a.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0)); } // sound came back late: rejoin the picture where it is
+ };
+ const b = BEATS[i];
+ if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });
+ setPlaying(play);
+ if (i + 1 < BEATS.length) beatClip(i + 1);
+}
+// The next beat's clip starts loading while this one plays, so a slow connection does not stall between beats.
+function beatClip(i, take) {
+ const src = `audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`;
+ let a = P.nextClip?._src === src ? P.nextClip : null;
+ if (!a) {
+ if (P.nextClip && P.nextClip !== P.audio) { P.nextClip.removeAttribute('src'); P.nextClip.load(); } // abandon a stale preload
+ a = Object.assign(new Audio(src), { preload: 'auto', _src: src });
+ }
+ P.nextClip = take ? null : a;
+ return a;
+}
+// Playback speed: the audio clock drives the picture, so changing the clip's rate keeps them together.
+const SPEEDS = [.75, 1, 1.25, 1.5];
+function setSpeed(r) {
+ P.rate = r;
+ $('bSpeed').textContent = r + '×';
+ if (P.audio) P.audio.playbackRate = r;
+ try { localStorage.setItem('speed', String(r)); } catch {}
+}
+const stepSpeed = d => setSpeed(SPEEDS[Math.max(0, Math.min(SPEEDS.length - 1, SPEEDS.indexOf(P.rate) + d))]);
+function soundFailed() { P.afail = true; $('soundNote').hidden = false; }
+function setPlaying(v) {
+ P.playing = v;
+ const a = P.audio;
+ if (!a) return;
+ const lead = v && P.t < (BEATS[P.i]?.pre || 0);
+ if (v && !P.waiting && !a.ended && !P.afail && !lead) a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); });
+ else if (lead && !a._unlocked) { // the clip starts later, outside this click: play it silently now so the browser allows that
+ a._unlocked = true; a.muted = true;
+ a.play().then(() => { if (P.t < (BEATS[P.i].pre || 0)) { a.pause(); a.currentTime = 0; } a.muted = false; }, () => { a.muted = false; });
+ } else a.pause();
+}
+function beatDone() {
+ evalTo(Infinity);
+ const b = BEATS[P.i];
+ if (b.ask) P.waiting = true;
+ else if (P.i < BEATS.length - 1) start(P.i + 1, true);
+ else { P.done = true; setPlaying(false); }
+}
+let last = performance.now();
+function frame(now) {
+ const dt = Math.min(.1, (now - last) / 1000);
+ last = now;
+ clock += dt;
+ if (FX.length) { evalTo(clock, FX); FX = FX.filter(w => !w.done); }
+ if (P.playing && !P.waiting && !P.done) {
+ const a = P.audio;
+ // While the clip plays, its clock drives the picture; before it starts or after it ends, wall time does.
+ const pre = BEATS[P.i].pre || 0;
+ if (a && P.t < pre) { // the picture's lead before the narration, on wall time; then the clip starts
+ P.t += dt * P.rate;
+ if (P.t >= pre && !P.afail) { a.muted = false; a.currentTime = P.t - pre; a.play().catch(e => { if (P.audio === a && e.name === 'NotAllowedError') soundFailed(); }); }
+ } else if (a && !P.afail && !a.ended) {
+ if (a.currentTime > 0) { P.t = Math.max(P.t, pre + a.currentTime); P.stall = 0; }
+ else if ((P.stall += dt) > (a.readyState < 2 ? 8 : 15)) soundFailed(); // nothing to play after 8 s, or stuck for 15
+ } else P.t += dt * P.rate;
+ evalTo(P.t);
+ if (P.t >= P.end) beatDone();
+ }
+ ui();
+ requestAnimationFrame(frame);
+}
+let segs = [];
+function buildSegs() {
+ segs = BEATS.map((b, i) => {
+ const s = h('button', 'seg' + (b.ask ? ' ask' : ''), [h('i')]);
+ s.style.flex = TIMINGS[b.id].dur + (b.ask ? 12 : 0);
+ s.title = b.title;
+ s.setAttribute('aria-label', translate('goToStep', { n: i + 1, title: b.title }));
+ // A click lands at that point of the step; keyboard activation (no pointer position) starts the step.
+ s.onclick = e => {
+ const r = s.getBoundingClientRect();
+ hideCover(); seekInto(i, e.detail ? (e.clientX - r.left) / r.width : 0);
+ };
+ $('segs').append(s);
+ return s.firstChild;
+ });
+}
+// ui() runs on every frame, paused or not: it writes only what changed, so an idle lesson does no layout work.
+let stepText = '';
+const setWidth = (f, w) => { if (f._w !== w) { f._w = w; f.style.width = w + '%'; } };
+function ui() {
+ segs.forEach((f, k) => setWidth(f, k < P.i || P.done ? 100 : k > P.i ? 0 : Math.min(100, P.t / P.end * 100)));
+ const fr = $('frame');
+ fr.classList.toggle('is-playing', P.playing && !P.done && !P.waiting);
+ fr.classList.toggle('paused', P.started && !P.playing && !P.waiting && !P.done && !BEATS[P.i].ask);
+ const step = `${P.i + 1} / ${BEATS.length} ${BEATS[P.i].title}`;
+ if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
+ const b = BEATS[P.i];
+ let text = '';
+ if (captions && P.started && !b.ask && !P.done) {
+ for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ }
+ if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
+}
+let captions = false, capText = '';
+try { captions = localStorage.getItem('captions') === '1'; } catch {}
+function setCaptions(on) {
+ captions = on;
+ $('bCC').setAttribute('aria-pressed', String(on));
+ try { localStorage.setItem('captions', on ? '1' : '0'); } catch {}
+}
+setCaptions(captions);
+function hideCover() { P.started = true; $('cover').hidden = true; }
+function togglePlay() {
+ if (!P.started) { hideCover(); return setPlaying(true); }
+ if (P.waiting || P.done) return;
+ setPlaying(!P.playing);
+}
+const back1 = () => seek(P.t > 2.5 || P.i === 0 ? P.i : P.i - 1);
+const restart = () => { for (const k in SCORE) delete SCORE[k]; hideCover(); seek(0, true); };
+$('cover').onclick = togglePlay;
+$('stage').addEventListener('click', e => {
+ const b = BEATS[P.i];
+ if (!b.ask && !e.target.closest('.qlayer')) togglePlay();
+});
+$('bPlay').onclick = togglePlay;
+$('bBack').onclick = () => { hideCover(); back1(); };
+$('bRestart').onclick = restart;
+$('bCC').onclick = () => setCaptions(!captions);
+$('bSpeed').onclick = () => setSpeed(SPEEDS[(SPEEDS.indexOf(P.rate) + 1) % SPEEDS.length]);
+try { const r = +localStorage.getItem('speed'); if (SPEEDS.includes(r)) setSpeed(r); } catch {}
+$('bFull').onclick = () => toggleFull();
+const toggleFull = () => document.fullscreenElement ? document.exitFullscreen() : document.documentElement.requestFullscreen?.();
+let helpResume = false;
+function toggleHelp() {
+ const open = $('help').hidden;
+ $('help').hidden = !open;
+ if (open) { helpResume = P.playing; if (P.playing) setPlaying(false); }
+ else if (helpResume) setPlaying(true);
+}
+// Review notes, only with ?review in the URL: N pauses and asks for a note on this moment, Shift+N copies every
+// note of the chapter (one line each, with the ?beat=N&t=S that reopens it) and offers to clear them.
+const REVIEW = new URLSearchParams(location.search).has('review');
+const REVIEW_KEY = 'papermorph:review:' + location.pathname;
+const reviewNotes = () => { try { return JSON.parse(localStorage.getItem(REVIEW_KEY) || '[]'); } catch { return []; } };
+function reviewNote() {
+ if (P.playing) setPlaying(false);
+ const at = `?beat=${P.i}&t=${P.t.toFixed(1)}`, note = prompt(`Note at ${BEATS[P.i].id} ${at}`);
+ if (!note) return;
+ try { localStorage.setItem(REVIEW_KEY, JSON.stringify([...reviewNotes(), `ch${String(CHAPTER.number).padStart(2, '0')} ${at} (${BEATS[P.i].id}): ${note}`])); } catch {}
+}
+function reviewCopy() {
+ const notes = reviewNotes(), text = notes.join('\n');
+ console.log(text);
+ navigator.clipboard?.writeText(text).catch(() => {});
+ if (confirm(`${notes.length} notes copied (also in the console). Clear them?`)) try { localStorage.removeItem(REVIEW_KEY); } catch {}
+}
+// Every action has a key. A question's own keys (P.keys) come first; Shift reaches the player during a question.
+document.addEventListener('keydown', e => {
+ if (e.altKey || e.metaKey || e.ctrlKey) return;
+ const k = e.key;
+ if (!$('help').hidden) { if (k === 'Escape' || k === '?') { e.preventDefault(); toggleHelp(); } return; }
+ if (e.target.matches?.('input')) { // Keep native input keys; only answer boxes use Enter to check.
+ if (k === 'Enter' && e.target.type !== 'range' && P.keys) { e.preventDefault(); P.keys(e); }
+ else if (k === 'Escape') e.target.blur();
+ return;
+ }
+ if (k === '?') { e.preventDefault(); toggleHelp(); return; }
+ if (REVIEW && isShortcut(e, 'n')) { e.preventDefault(); e.shiftKey ? reviewCopy() : reviewNote(); return; }
+ if ((k === 'Enter' || k === ' ') && e.target.closest?.('button, [tabindex], a')) return; // a Tab-focused control acts itself
+ if (!P.started) { if (k === ' ' || k === 'Enter') { e.preventDefault(); togglePlay(); } return; }
+ if (P.keys && !e.shiftKey && P.keys(e)) { e.preventDefault(); return; }
+ const free = e.shiftKey || !P.keys;
+ let used = true;
+ if (k === ' ') togglePlay();
+ else if (k === 'ArrowLeft' && free) back1();
+ else if (k === 'ArrowRight' && free) { if (P.i < BEATS.length - 1) seek(P.i + 1); }
+ else if (k === 'Home') restart();
+ else if (isShortcut(e, 'c')) setCaptions(!captions);
+ else if (k === '<' || k === ',' || isShortcutCode(e, 'Comma')) stepSpeed(-1);
+ else if (k === '>' || k === '.' || isShortcutCode(e, 'Period')) stepSpeed(1);
+ else if (isShortcut(e, 'f')) toggleFull();
+ else used = false;
+ if (used) e.preventDefault();
+});
+// Mouse clicks should not leave focus on a control, so Enter and Space keep meaning "check" and "play".
+$('frame').addEventListener('mousedown', e => { if (e.target.closest('button, [tabindex]')) e.preventDefault(); });
+$('bHelp').onclick = toggleHelp;
+const fit = () => document.documentElement.style.setProperty('--k', Math.min(innerWidth / 1640, (innerHeight - (innerWidth <= 700 ? 120 : 0)) / 1000));
+addEventListener('resize', fit);
+fit();
+
+// Start the lesson once the chapter page has defined CHAPTER and BEATS.
+// ?beat=N&t=S opens a paused frame, for reviewing a single moment.
+// Per-book progress shared with the cover/contents at the parent URL folder.
+const BOOK_PROGRESS_KEY = bookSetting('--progress-key') || 'animebook:progress:' + new URL('../', location.href).pathname;
+function progress(f) {
+ try {
+ const saved = JSON.parse(localStorage.getItem(BOOK_PROGRESS_KEY) || '{}');
+ const p = saved && typeof saved === 'object' && !Array.isArray(saved) ? saved : {};
+ p.done = Array.isArray(p.done) ? p.done.filter(n => Number.isInteger(n) && n > 0) : [];
+ f(p); localStorage.setItem(BOOK_PROGRESS_KEY, JSON.stringify(p));
+ } catch {}
+}
+function boot() {
+ $('coverK').textContent = translate('chapterNumber', { n: CHAPTER.label ?? CHAPTER.number });
+ $('coverT').textContent = CHAPTER.title;
+ $('bHome').href = `../#ch${String(CHAPTER.number).padStart(2, '0')}`;
+ progress(p => { p.last = CHAPTER.number; });
+ document.getElementById('stage').setAttribute('aria-label', translate('stageLabelTitled', { title: CHAPTER.title }));
+ $('coverMeta').textContent = translate('aboutMinutes', { n: num(CHAPTER.minutes) });
+ buildSegs();
+ const qs = new URLSearchParams(location.search);
+ if (qs.has('beat')) {
+ $('cover').hidden = true;
+ seek(+qs.get('beat'), false);
+ P.t = +(qs.get('t') || 0);
+ evalTo(P.t);
+ if (P.audio) P.audio.currentTime = Math.max(0, P.t - (BEATS[P.i].pre || 0));
+ } else seek(0, false);
+ requestAnimationFrame(frame);
+}
diff --git a/site/three-little-pigs/lib/toon.js b/site/three-little-pigs/lib/toon.js
new file mode 100644
index 0000000..f9b2140
--- /dev/null
+++ b/site/three-little-pigs/lib/toon.js
@@ -0,0 +1,399 @@
+// Characters drawn entirely in SVG, built as a rig: every part is a group nested in the part it hangs from, so
+// sleeves turn with arms, hands with forearms, the head on the neck; nothing can come apart. Shapes are drawn in the
+// pixels of the model sheet's side view (the character faces right) and scaled by `k` and SCALE.
+// pose(state) places everything from a plain object, so a frame is a pure function of time. State:
+// x, ground; k [1]; lean [0] (whole body, about the hip); bend [0] (upper body, about the waist); sy [1] breath;
+// drop [0] hips lowered; feet [[x, lift], [x, lift]] (world x, near and far); skirt [0] sway (−1..1);
+// arms [{ up, bend, hand: 'open'|'fist' }] near and far (degrees; up 0 = hanging, + swings back; bend − = forward);
+// head { tilt }, ears [0] flap (−1..1), bow [0] sway, tail [0] wag;
+// face { mouth, smile, blink, gaze [x, y], raise, worry, wide }.
+const TOON = (() => {
+ const NSV = 'http://www.w3.org/2000/svg', INK = '#151314', R = Math.PI / 180;
+ const el = (tag, attrs, p) => { const e = document.createElementNS(NSV, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); p.appendChild(e); return e; };
+ const G = (p, cls) => el('g', cls ? { class: cls } : {}, p);
+ const shape = (p, d, fill, w = 5, extra = {}) => el('path', { d, fill, stroke: INK, 'stroke-width': w, 'stroke-linejoin': 'round', 'stroke-linecap': 'round', ...extra }, p);
+ const at = (e, x, y, r = 0, sx = 1, sy = sx) => e.setAttribute('transform', `translate(${x},${y}) rotate(${r}) scale(${sx},${sy})`);
+ const around = (e, [px, py], r = 0, sx = 1, sy = sx) => e.setAttribute('transform', `translate(${px},${py}) rotate(${r}) scale(${sx},${sy}) translate(${-px},${-py})`);
+ // A limb as one rubbery curve through its joint: ink under skin.
+ function hose(p, w, skin) {
+ const out = el('path', { fill: 'none', stroke: INK, 'stroke-width': w + 9, 'stroke-linecap': 'round' }, p);
+ const fill = el('path', { fill: 'none', stroke: skin, 'stroke-width': w, 'stroke-linecap': 'round' }, p);
+ return (a, k, b) => { const c = [2 * k[0] - (a[0] + b[0]) / 2, 2 * k[1] - (a[1] + b[1]) / 2], d = `M${a}Q${c} ${b}`; out.setAttribute('d', d); fill.setAttribute('d', d); };
+ }
+ // Pig hands: a mitten with a thumb, or a fist; axis along +y from the wrist, thumb toward +x (forward).
+ function hand(p, skin) {
+ const open = G(p), fist = G(p);
+ shape(open, 'M-15 -4C-21 16 -18 36 -7 46C3 54 17 47 19 34C21 20 17 6 14 -4Z', skin);
+ shape(open, 'M13 8C27 4 33 18 22 27', skin, 4.5);
+ shape(open, 'M-6 30L-4 44M3 31L5 46M11 28L13 42', 'none', 3);
+ shape(fist, 'M-16 -2C-22 14 -16 32 0 33C16 34 22 18 18 2C16 -6 -12 -8 -16 -2Z', skin);
+ shape(fist, 'M-9 20Q-6 27 -1 21M0 22Q4 29 9 22M15 6Q22 12 14 18', 'none', 3);
+ return k => { open.style.display = k === 'fist' ? 'none' : ''; fist.style.display = k === 'fist' ? '' : 'none'; };
+ }
+ // A cloven hoof at the ankle, pointing forward.
+ const hoof = (p, skin) => { shape(p, 'M-13 -14L13 -14L13 4L-13 4Z', skin, 0); shape(p, 'M-15 0C-16 -6 -12 -10 -6 -10L14 -10C28 -10 34 4 30 14L-16 14C-19 9 -17 3 -15 0Z', '#4b2c22'); shape(p, 'M10 -9L15 14', 'none', 3.5); };
+ // A face: eyes (white, pupil, shine, closed-lid line), brows, a mouth under the snout (Rhubarb's shapes).
+ const MOUTH = { X: [0, 1], A: [0, .9], B: [7, .8, 1], C: [16, .95], D: [26, 1], E: [20, .7], F: [11, .45], G: [7, .75, 1], H: [17, .9] };
+ function face(p, F) {
+ const eyes = F.eyes.map(([x, y, rx, ry], i) => {
+ const g = G(p), open = G(g);
+ el('ellipse', { rx, ry, fill: '#fff', stroke: INK, 'stroke-width': i ? 3.5 : 4.5 }, open);
+ const pupil = el('ellipse', { rx: rx * .52, ry: ry * .5, fill: INK }, open), shine = el('circle', { r: rx * .17, fill: '#fff' }, open);
+ if (F.lashes && !i) shape(open, `M${rx * .55} ${-ry * .8}l${rx * .5} ${-ry * .3}M${rx * .85} ${-ry * .42}l${rx * .55} ${-ry * .1}`, 'none', 3.5);
+ const shut = shape(g, `M${-rx * 1.1} 0Q0 ${ry * .5} ${rx * 1.1} 0`, 'none', 4.5);
+ return { x, y, rx, ry, g, open, pupil, shine, shut };
+ });
+ const brows = F.brows.map(() => shape(p, '', 'none', 6.5));
+ const mouth = G(p), inside = shape(mouth, '', '#7b2430', 4.5), tongue = el('path', { fill: '#ef7d86' }, mouth), teeth = el('path', { fill: '#fff' }, mouth), line = shape(mouth, '', 'none', 5);
+ return fc => {
+ const [gx, gy] = fc.gaze || [1, 0], blink = fc.blink ?? 0, wide = fc.wide ?? 0, worry = fc.worry ?? 0, raise = fc.raise ?? 0;
+ eyes.forEach(e => {
+ at(e.g, e.x, e.y); e.open.setAttribute('transform', `scale(1,${Math.max(.06, (1 - blink) * (1 + .12 * wide))})`);
+ e.shut.style.opacity = blink > .7 ? 1 : 0; e.open.style.opacity = blink > .7 ? 0 : 1;
+ const px = e.rx * (.15 + .32 * gx), py = e.ry * .3 * gy;
+ at(e.pupil, px, py, 0, 1 - .3 * wide); at(e.shine, px + e.rx * .14, py - e.ry * .2);
+ });
+ F.brows.forEach(([x1, y1, x2, y2], i) => {
+ const up = 9 * raise + 6 * wide, mx = (x1 + x2) / 2, my = (y1 + y2) / 2 - 8 - up;
+ brows[i].setAttribute('d', `M${x1} ${y1 - up + 5 * worry}Q${mx} ${my - 4 * worry} ${x2} ${y2 - up - 9 * worry}`);
+ });
+ const [m0, m1, mw] = F.mouth, [h, wk, th] = MOUTH[fc.mouth || 'X'] || MOUTH.X, w = mw * wk / 2, sm = fc.smile ?? .6;
+ at(mouth, m0 - w, m1); // the front corner stays under the snout
+ const L = [-w, -2 - 9 * sm], Rt = [w, -2];
+ if (!h) { line.setAttribute('d', `M${L}Q${(L[0] + Rt[0]) / 2} ${10 * sm} ${Rt}`); for (const e of [inside, tongue, teeth]) e.setAttribute('d', ''); }
+ else {
+ line.setAttribute('d', '');
+ inside.setAttribute('d', `M${L}Q0 ${-4 + 3 * sm} ${Rt}Q${w * .2} ${h * 1.25} ${L}Z`);
+ tongue.setAttribute('d', h > 12 ? `M${-w * .55} ${h * .55}Q${w * .1} ${h * .3 + (fc.mouth === 'H' ? -8 : 0)} ${w * .6} ${h * .45}Q${w * .1} ${h * 1.05} ${-w * .55} ${h * .55}Z` : '');
+ teeth.setAttribute('d', th ? `M${-w * .6} ${-2 - 4 * sm}L${w * .8} -1L${w * .75} 5L${-w * .55} 4Z` : '');
+ }
+ };
+ }
+
+ // Mother Pig, from the side view of her model sheet (297 × 661 px; ground at y 660).
+ function mother(parent) {
+ const SKIN = '#f6a99a', SKIN2 = '#e98c80', DRESS = '#ab8fd2', DRESS2 = '#957ac0', WHITE = '#f7f5f0';
+ const HIP = [152, 548], WAIST = [160, 330], NECK = [152, 226], SHOULDER = [126, 268];
+ const LEG = [44, 42], ARM = [96, 84];
+ const root = G(parent);
+ const farLegG = G(root), nearLegG = G(root), body = G(root); // legs under the skirt
+ farLegG.style.filter = 'brightness(.88)';
+ // Legs (stage of the root, not leaning): hoses from under the skirt to hooves.
+ const legs = [nearLegG, farLegG].map(g => { const h = hose(g, 30, SKIN), f = G(g); hoof(f, SKIN); return { h, f }; });
+ // Body: skirt (sways at the hem), then the upper body, bending at the waist.
+ const tailG = G(body), bowG = G(body), skirtG = G(body), upper = G(body);
+ const tail = shape(tailG, 'M48 424C30 418 14 428 18 442C22 456 42 452 40 438C38 428 26 430 26 438', 'none', 9);
+ shape(tailG, 'M48 424C30 418 14 428 18 442C22 456 42 452 40 438C38 428 26 430 26 438', 'none', 4, { stroke: SKIN });
+ const skirt = shape(skirtG, '', DRESS), apron = shape(skirtG, '', WHITE, 4.5);
+ shape(bowG, 'M92 332C70 300 34 304 30 330C28 352 62 352 92 340Z', WHITE, 4.5);
+ shape(bowG, 'M92 340C66 352 40 380 52 396C66 404 84 372 96 348Z', WHITE, 4.5);
+ shape(bowG, 'M88 342C70 372 70 410 84 416C92 404 96 372 98 346Z', WHITE, 4.5);
+ shape(bowG, 'M48 326Q66 330 80 334', 'none', 3);
+ const farArmG = G(upper), bodice = G(upper), headG = G(upper), nearArmG = G(upper);
+ farArmG.style.filter = 'brightness(.88)'; const farArm = arm(farArmG);
+ shape(bodice, 'M98 236C74 262 70 302 84 336L244 336C266 300 266 262 240 238C206 252 132 254 98 236Z', DRESS);
+ shape(bodice, 'M150 322L250 322L248 340L150 340Z', WHITE, 4.5); // apron waistband
+ shape(bodice, 'M102 226C116 252 190 258 236 232C240 250 218 264 190 262C160 268 120 260 100 242Z', WHITE, 4.5); // collar
+ el('circle', { cx: 226, cy: 270, r: 6, fill: WHITE, stroke: INK, 'stroke-width': 3 }, bodice);
+ el('circle', { cx: 231, cy: 286, r: 6, fill: WHITE, stroke: INK, 'stroke-width': 3 }, bodice);
+ // Head: back ear, head, snout, face, front ear; ears flop on springs about their roots.
+ const earBack = G(headG), skull = G(headG), faceG = G(headG), earFront = G(headG);
+ shape(earBack, 'M104 72C78 52 46 74 50 110C70 118 104 104 122 90Z', SKIN); shape(earBack, 'M98 80C80 70 62 84 62 102C76 104 96 94 108 88Z', SKIN2, 0);
+ shape(skull, 'M96 206C58 176 54 96 100 60C136 30 198 30 226 70C240 92 244 108 242 122L244 172C234 198 206 214 170 220C140 224 112 220 96 206Z', SKIN);
+ shape(skull, 'M104 200C88 186 80 168 80 150', 'none', 3, { stroke: SKIN2 });
+ const look = face(faceG, { eyes: [[202, 118, 14, 24], [233, 106, 6, 17]], brows: [[184, 84, 212, 78], [228, 74, 242, 72]], lashes: true, mouth: [238, 176, 48] });
+ shape(faceG, 'M258 118C246 118 238 132 238 146C238 162 246 174 258 174C270 174 278 162 278 146C278 132 270 118 258 118Z', '#f7b4a6');
+ el('ellipse', { cx: 252, cy: 141, rx: 3, ry: 7, fill: '#8a3b3b' }, faceG); el('ellipse', { cx: 265, cy: 150, rx: 2.6, ry: 6, fill: '#8a3b3b' }, faceG);
+ shape(earFront, 'M172 46C176 16 206 0 246 8C252 20 234 36 216 48C200 56 184 56 172 46Z', SKIN); shape(earFront, 'M184 42C192 22 214 12 236 14C230 26 214 38 196 44Z', SKIN2, 0);
+ const nearArm = arm(nearArmG);
+ // An arm: shoulder group (turns with the upper arm) holding the arm curve, the puff sleeve and a hand group.
+ function arm(p) {
+ const g = G(p), h = hose(g, 26, SKIN), sleeve = G(g), handG = G(g), grip = G(handG), setHand = hand(handG, SKIN);
+ shape(sleeve, 'M-48 -18C-54 -56 42 -60 52 -18C58 14 42 52 30 60L-28 60C-46 44 -52 14 -48 -18Z', DRESS);
+ shape(sleeve, 'M-32 -30Q-20 -40 -6 -36', 'none', 3, { stroke: DRESS2 });
+ shape(sleeve, 'M-30 54L32 54L32 72L-30 72Z', WHITE, 4.5);
+ return { g, grip, place(up, bend, kind) {
+ const b = bend * R, e = [0, ARM[0]], w = [-ARM[1] * Math.sin(b), ARM[0] + ARM[1] * Math.cos(b)];
+ at(g, SHOULDER[0], SHOULDER[1], up); h([0, 8], e, w); at(handG, w[0], w[1], bend); setHand(kind);
+ return up + bend; // the hand's angle from hanging, in the upper body's frame
+ } };
+ }
+ return {
+ root, grip: nearArm.grip,
+ pose(s) {
+ const k = (s.k ?? 1) * mother.SCALE, lean = s.lean ?? 0, bend = s.bend ?? 0, sy = s.sy ?? 1;
+ const legLen = LEG[0] + LEG[1], hipY = 636 - legLen * .96 + (s.drop ?? 0); // ankle line at 636
+ root.setAttribute('transform', `translate(${s.x},${s.ground}) scale(${k}) translate(${-HIP[0]},${-660})`);
+ // Hip origin: the body hangs from it; lean turns all of it, the upper body adds `bend` at the waist.
+ body.setAttribute('transform', `translate(${HIP[0]},${hipY}) rotate(${lean}) translate(${-HIP[0]},${-HIP[1]})`);
+ const sw = s.skirt ?? 0;
+ skirt.setAttribute('d', `M80 330C60 400 ${36 + 8 * sw} 480 ${22 + 18 * sw} 556C90 ${576 - 4 * sw} 220 578 ${292 + 14 * sw} ${560 - 6 * sw}C278 480 262 400 248 330Z`);
+ apron.setAttribute('d', `M152 330L250 330C262 400 ${278 + 6 * sw} 460 ${288 + 10 * sw} 506Q${274 + 10 * sw} 522 262 508Q250 524 236 510Q222 526 208 510Q194 524 180 510Q166 522 154 506C150 456 148 390 152 330Z`);
+ upper.setAttribute('transform', `translate(${WAIST[0]},${WAIST[1]}) rotate(${bend}) scale(${1 / sy},${sy}) translate(${-WAIST[0]},${-WAIST[1]})`);
+ around(bowG, [92, 336], (s.bow ?? 0) * 12); around(tailG, [48, 424], (s.tail ?? 0) * 20);
+ around(headG, NECK, s.head?.tilt ?? 0);
+ const ear = s.ears ?? 0; around(earFront, [184, 46], -10 * ear); around(earBack, [112, 82], 12 * ear);
+ look(s.face || {});
+ const arms = s.arms || [{}, {}];
+ const ang = nearArm.place(arms[0]?.up ?? 0, arms[0]?.bend ?? -12, arms[0]?.hand); farArm.place(arms[1]?.up ?? 0, arms[1]?.bend ?? -12, arms[1]?.hand);
+ nearArm.handAngle = ang + bend + lean; // from hanging, in the world: a held cloth hangs by counter-rotating this
+ // Legs by IK to world feet, in sheet pixels.
+ const feet = s.feet || [[s.x + 10 * k, 0], [s.x - 10 * k, 0]];
+ const hip = [HIP[0], hipY], toSheet = ([wx, lift]) => [HIP[0] + (wx - s.x) / k, 636 - lift / k];
+ [[legs[0], [hip[0] + 14, hip[1]], feet[0]], [legs[1], [hip[0] - 16, hip[1]], feet[1]]].forEach(([L, h, f]) => {
+ const a = toSheet(f), dx = a[0] - h[0], dy = a[1] - h[1], d = Math.min(Math.hypot(dx, dy), legLen * .999);
+ const th = Math.atan2(dy, dx) - Math.acos((LEG[0] ** 2 + d * d - LEG[1] ** 2) / (2 * LEG[0] * d));
+ L.h(h, [h[0] + LEG[0] * Math.cos(th), h[1] + LEG[0] * Math.sin(th)], a); at(L.f, a[0], a[1], Math.min(25, f[1] * .6 / k));
+ });
+ },
+ get handAngle() { return nearArm.handAngle; },
+ };
+ }
+ mother.SCALE = .62;
+ return { mother };
+})();
+
+// Mother Pig as a vector puppet: parts traced from her rig images (img/mother/rig/*.svg, offsets in rig.json, all
+// in the rig picture's pixels, 1024 × 1536, facing right). The arm between sleeve and hand is an SVG limb in her
+// line weight and skin colour, so it bends without seams. Same pose() state as TOON.mother.
+TOON.vecMother = (parent, R) => {
+ const NSV = 'http://www.w3.org/2000/svg', INK = '#151314';
+ const el = (tag, attrs, p) => { const e = document.createElementNS(NSV, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); p.appendChild(e); return e; };
+ const G = p => el('g', {}, p);
+ const img = (p, n) => { const [x, y, w, h] = R.parts[n]; return el('image', { href: `../img/mother/rig/${n}.svg`, x, y, width: w, height: h }, p); };
+ const about = (e, [px, py], r = 0, sx = 1, sy = sx, dx = 0, dy = 0) => e.setAttribute('transform', `translate(${px + dx},${py + dy}) rotate(${r}) scale(${sx},${sy}) translate(${-px},${-py})`);
+ const FOOT = [468, 1492], WAIST = [470, R.waist], NECK = [505, 505], SHOULDER = [372, 646];
+ const ROOT = [374, 664], ELBOW = [388, 858], WRIST = [392, 952], ARM_W = 90, LINE = 12;
+ const root = G(parent), all = G(root);
+ el('ellipse', { cx: 505, cy: 478, rx: 92, ry: 58, fill: R.skin }, all); // neck, behind the collar
+ img(all, 'lower');
+ const upper = G(all), head = G(upper); // the head behind the bodice: the collar covers its cut edge
+ img(upper, 'upper');
+ const arm = G(upper);
+ // The arm, behind the bodice: limb outline, hand, limb fill (covering the hand's cut top), sleeve over the root.
+ const hose = [el('path', { fill: 'none', stroke: INK, 'stroke-width': ARM_W + LINE, 'stroke-linecap': 'round' }, arm)];
+ const handG = G(arm); img(handG, 'hand');
+ hose.push(el('path', { fill: 'none', stroke: R.skin, 'stroke-width': ARM_W, 'stroke-linecap': 'round' }, arm));
+ img(arm, 'sleeve');
+ img(head, 'head');
+ for (let i = 0; i < R.lines; i++) if (i !== 3) img(head, `line${i}`);
+ const brows = G(head); head.appendChild(brows);
+ // Eyes: the drawn eye and pupil; a skin-coloured lid (the eye's ellipse, clipped to the part above the lid's edge)
+ // slides down over them, its edge drawn as a line.
+ const eyes = [0, 1].map(i => {
+ const g = G(head), [x, y, w, h] = R.parts[`eye${i}`]; img(g, `eye${i}`); const p = img(g, `pupil${i}`);
+ const id = `lid${i}${Math.random().toString(36).slice(2, 7)}`, clip = el('clipPath', { id }, el('defs', {}, head)), cut = el('rect', { x: x - 6, y: y - 6, width: w + 12, height: 0 }, clip);
+ el('ellipse', { cx: x + w / 2, cy: y + h / 2, rx: w / 2 + 3, ry: h / 2 + 3, fill: R.skin, 'clip-path': `url(#${id})` }, head);
+ const edge = el('path', { fill: 'none', stroke: INK, 'stroke-width': LINE * .65, 'stroke-linecap': 'round' }, head);
+ return { g, p, cut, edge, x, y, w, h, c: [x + w / 2, y + h / 2] };
+ });
+ // Brow and lash marks move with the eyes; the smile line is the closed mouth.
+ const marks = [1, 2].map(i => head.querySelector(`image[href$="line${i}.svg"]`));
+ const smile = img(head, 'line3'), [mx, my, mw, mh] = R.parts.line3;
+ const mouth = G(head), inside = el('path', { fill: '#7b2430', stroke: INK, 'stroke-width': LINE * .7, 'stroke-linejoin': 'round' }, mouth);
+ const tongue = el('path', { fill: '#ef7d86' }, mouth), teeth = el('path', { fill: '#fff' }, mouth);
+ const MOUTH = { B: [14, .8, 1], C: [30, .9], D: [48, 1], E: [38, .7], F: [22, .45], G: [14, .75, 1], H: [32, .9] };
+ const front = [mx + mw - 6, my + 14];
+ upper.appendChild(arm); // the arm in front of her head and body
+ const gripAt = G(handG); gripAt.setAttribute('transform', 'translate(400,1012) scale(4)'); // between thumb and fingers
+ return {
+ root, grip: G(gripAt),
+ pose(s) {
+ const k = (s.k ?? 1) * TOON.vecMother.SCALE, lean = s.lean ?? 0, bend = s.bend ?? 0, sy = s.sy ?? 1;
+ root.setAttribute('transform', `translate(${s.x},${s.ground}) scale(${(s.dir ?? 1) * k},${k}) translate(${-FOOT[0]},${-FOOT[1]})`);
+ about(all, FOOT, lean * .5);
+ about(upper, WAIST, bend, 1 / sy, sy);
+ about(head, NECK, s.head?.tilt ?? 0);
+ // Arm: up about the shoulder (sleeve and all), bend about the elbow (forearm and hand).
+ const a = s.arms?.[0] || {}, up = a.up ?? 0, b = a.bend ?? -8, rad = b * Math.PI / 180;
+ about(arm, SHOULDER, up);
+ const v = [WRIST[0] - ELBOW[0], WRIST[1] - ELBOW[1]], w = [ELBOW[0] + v[0] * Math.cos(rad) - v[1] * Math.sin(rad), ELBOW[1] + v[0] * Math.sin(rad) + v[1] * Math.cos(rad)];
+ const c = [2 * ELBOW[0] - (ROOT[0] + w[0]) / 2, 2 * ELBOW[1] - (ROOT[1] + w[1]) / 2], d = `M${ROOT}Q${c} ${w}`;
+ hose.forEach(h => h.setAttribute('d', d)); about(handG, ELBOW, b);
+ this.handAngle = up + b + bend + lean * .5;
+ // Face.
+ const f = s.face || {}, blink = f.blink ?? 0, [gx, gy] = f.gaze || [1, 0], raise = f.raise ?? 0, worry = f.worry ?? 0, wide = f.wide ?? 0;
+ eyes.forEach((e, i) => {
+ const down = Math.min(1, blink) * (e.h * .78), ly = e.y + down; // the lid's edge
+ e.cut.setAttribute('height', down + 6);
+ const half = Math.sqrt(Math.max(0, 1 - ((ly - e.c[1]) / (e.h / 2 + 3)) ** 2)) * (e.w / 2 + 3);
+ e.edge.setAttribute('d', down > 2 ? `M${e.c[0] - half} ${ly}Q${e.c[0]} ${ly + 6} ${e.c[0] + half} ${ly}` : '');
+ about(e.p, e.c, 0, 1 - .25 * wide, 1 - .25 * wide, -16 * (1 - gx) * (i ? .6 : 1), 12 * gy);
+ });
+ marks.forEach((m, i) => about(m, [m.x.baseVal.value + m.width.baseVal.value / 2, m.y.baseVal.value + m.height.baseVal.value], (i ? -1 : 1) * -10 * worry, 1, 1, 0, -14 * raise - 10 * wide));
+ // Mouth: closed, the drawn smile (flipped into a frown when unhappy); open, a shape hinged under the snout.
+ const shape = MOUTH[f.mouth] , sm = f.smile ?? .6;
+ smile.style.display = shape ? 'none' : ''; mouth.style.display = shape ? '' : 'none';
+ if (!shape) about(smile, [mx + mw / 2, my + mh / 2], 0, 1, Math.sign(sm || 1) * Math.max(.25, Math.abs(sm)));
+ else {
+ const [h, wk, th] = shape, L = [front[0] - (mw - 10) * wk, my + 8 - 10 * sm], mid = (L[0] + front[0]) / 2;
+ inside.setAttribute('d', `M${L}Q${mid} ${my + 24 + 10 * sm} ${front}Q${mid} ${my + 30 + h * 1.6} ${L}Z`);
+ tongue.setAttribute('d', h > 25 ? `M${mid - 30} ${my + 28 + h}Q${mid + 10} ${my + 16 + h * .7} ${front[0] - 12} ${my + 26 + h * .6}Q${mid} ${my + 34 + h * 1.4} ${mid - 30} ${my + 28 + h}Z` : '');
+ teeth.setAttribute('d', '');
+ }
+ },
+ };
+};
+TOON.vecMother.SCALE = .26;
+
+// Any character as a vector puppet from its rig parts (img/<name>/rig/*.svg; RIGS.<name> from rig.js, rig-image
+// pixels, facing right). Optional pieces follow the rig: a separate head (tilts on the neck, behind the collar), an
+// upper body bending at the waist, a sleeve turning with the arm, legs as SVG limbs to drawn feet (walking by IK).
+// pose(state): x, ground, k, dir, lean, bend, sy, head { tilt }, arms [{ up, bend }], feet [[x, lift], [x, lift]]
+// (world x of near and far foot), face { mouth, smile, blink, gaze [x, y], raise, worry, wide }.
+TOON.puppet = (parent, name, opts = {}) => {
+ const R = RIGS[name], NSV = 'http://www.w3.org/2000/svg', INK = '#151314', P = R.parts;
+ const el = (tag, attrs, p) => { const e = document.createElementNS(NSV, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); p.appendChild(e); return e; };
+ const G = p => el('g', {}, p);
+ const img = (p, n) => { const [x, y, w, h] = P[n]; return el('image', { href: `../img/${name}/rig/${n}.svg`, x, y, width: w, height: h }, p); };
+ const about = (e, [px, py], r = 0, sx = 1, sy = sx, dx = 0, dy = 0) => e.setAttribute('transform', `translate(${px + dx},${py + dy}) rotate(${r}) scale(${sx},${sy}) translate(${-px},${-py})`);
+ const hoseOf = (p, w, skin) => [el('path', { fill: 'none', stroke: INK, 'stroke-width': w + 12, 'stroke-linecap': 'round' }, p), el('path', { fill: 'none', stroke: skin, 'stroke-width': w, 'stroke-linecap': 'round' }, p)];
+ const curve = (a, k, b) => `M${a}Q${2 * k[0] - (a[0] + b[0]) / 2},${2 * k[1] - (a[1] + b[1]) / 2} ${b}`;
+ const FOOT = [P.body ? P.body[0] + P.body[2] / 2 : 470, R.ground];
+ const root = G(parent), all = G(root);
+ // Legs (behind the body): limb from hip to ankle with a knee by IK, the drawn foot at the ankle.
+ const legs = (R.legs || []).map(L => {
+ const g = G(all), h = hoseOf(g, L.width - 12, R.legSkin), f = G(g); img(f, L.part);
+ const len = Math.hypot(L.ankle[0] - L.hip[0], L.ankle[1] - L.hip[1]);
+ return { L, h, f, len };
+ });
+ const hips = R.legs ? [R.legs.reduce((s, L) => s + L.hip[0], 0) / R.legs.length, R.legs[0].hip[1]] : FOOT;
+ if (R.neck) el('ellipse', { cx: R.neck[0], cy: R.neck[1] - 20, rx: 70, ry: 50, fill: R.lid }, all); // a neck behind the collar
+ if (P.lower) img(all, 'lower');
+ const upper = G(all), head = R.neck ? G(upper) : null;
+ img(upper, P.upper ? 'upper' : 'body');
+ const faceG = head || G(upper);
+ if (head) img(head, 'head');
+ // Arm: limb outline, hand, limb fill (over the hand's cut top), sleeve over the limb's root.
+ const arm = G(upper), AW = Math.max(R.armWidth, 70) - 12, armHose = hoseOf(arm, AW, R.skin), handG = G(arm);
+ arm.insertBefore(handG, armHose[1]); img(handG, 'hand');
+ if (P.sleeve) img(arm, 'sleeve');
+ // Face: eyes with pupils and sliding lids, brows, marks, mouth.
+ const eyes = R.eyes.map((n, i) => {
+ const g = G(faceG), [x, y, w, h] = P[n]; img(g, n); const p = P[`pupil${i}`] ? img(g, `pupil${i}`) : null;
+ const id = `lid${name}${i}${Math.random().toString(36).slice(2, 7)}`, clip = el('clipPath', { id }, el('defs', {}, faceG)), cut = el('rect', { x: x - 6, y: y - 6, width: w + 12, height: 0 }, clip);
+ el('ellipse', { cx: x + w / 2, cy: y + h / 2, rx: w / 2 + 3, ry: h / 2 + 3, fill: R.lid, 'clip-path': `url(#${id})` }, faceG);
+ const edge = el('path', { fill: 'none', stroke: INK, 'stroke-width': 8, 'stroke-linecap': 'round' }, faceG);
+ return { p, cut, edge, x, y, w, h, c: [x + w / 2, y + h / 2] };
+ });
+ for (const n of R.marks) img(faceG, n);
+ const brows = R.brows.map(n => img(faceG, n));
+ const [mx, my, mw, mh] = R.mouth ? P[R.mouth] : [0, 0, 0, 0], smile = R.mouth && img(faceG, R.mouth);
+ const mouth = G(faceG), inside = el('path', { fill: '#7b2430', stroke: INK, 'stroke-width': 8, 'stroke-linejoin': 'round' }, mouth), tongue = el('path', { fill: '#ef7d86' }, mouth);
+ const MOUTH = { B: [.25, .8], C: [.55, .9], D: [.85, 1], E: [.7, .7], F: [.4, .45], G: [.25, .75], H: [.6, .9] };
+ upper.appendChild(arm); // in front of the head and body
+ const gripAt = G(handG); gripAt.setAttribute('transform', `translate(${R.wrist[0] + 8},${R.wrist[1] + 60}) scale(4)`);
+ const self = {
+ root, grip: G(gripAt), R,
+ pose(s) {
+ const k = (s.k ?? 1) * (opts.scale ?? .26), lean = s.lean ?? 0, bend = s.bend ?? 0, sy = s.sy ?? 1;
+ root.setAttribute('transform', `translate(${s.x},${s.ground}) scale(${(s.dir ?? 1) * k},${k}) translate(${-FOOT[0]},${-FOOT[1]})`);
+ about(all, FOOT, lean * .5);
+ about(upper, P.upper ? [FOOT[0], R.waist] : hips, bend, 1 / sy, sy, 0, -(s.bob ?? 0) / k);
+ if (head) about(head, R.neck, s.head?.tilt ?? 0);
+ // Arm.
+ const a = s.arms?.[0] || {}, up = a.up ?? 0, b = a.bend ?? -8, rad = b * Math.PI / 180;
+ about(arm, R.shoulder, up);
+ const v = [R.wrist[0] - R.elbow[0], R.wrist[1] - R.elbow[1]], w = [R.elbow[0] + v[0] * Math.cos(rad) - v[1] * Math.sin(rad), R.elbow[1] + v[0] * Math.sin(rad) + v[1] * Math.cos(rad)];
+ armHose.forEach(h => h.setAttribute('d', curve(R.root, R.elbow, w))); about(handG, R.elbow, b);
+ self.handAngle = up + b + bend + lean * .5;
+ // Legs: feet given in world x (near first) with a lift; knees bend forward. Hips ride with the body's bob.
+ const feet = s.feet, toRig = ([wx, lift]) => [FOOT[0] + (wx - s.x) / ((s.dir ?? 1) * k), R.ground - lift / k];
+ legs.forEach((lg, i) => {
+ const L = lg.L, hip = [L.hip[0], L.hip[1] - (s.bob ?? 0) / k];
+ const ank = feet ? (([fx, fy]) => [fx + L.ankle[0] - FOOT[0], fy - (R.ground - L.ankle[1])])(toRig(feet[legs.length - 1 - i])) : L.ankle;
+ const dx = ank[0] - hip[0], dy = ank[1] - hip[1], l1 = lg.len / 2, d = Math.min(Math.hypot(dx, dy), lg.len * .999);
+ const th = Math.atan2(dy, dx) - Math.acos(d / (2 * l1)), knee = [hip[0] + l1 * Math.cos(th), hip[1] + l1 * Math.sin(th)];
+ lg.h.forEach(h => h.setAttribute('d', curve(hip, knee, ank)));
+ about(lg.f, L.ankle, feet ? Math.min(25, feet[legs.length - 1 - i][1] * .5 / k * .05) : 0, 1, 1, ank[0] - L.ankle[0], ank[1] - L.ankle[1]);
+ });
+ // Face.
+ const f = s.face || {}, blink = f.blink ?? 0, [gx, gy] = f.gaze || [1, 0], raise = f.raise ?? 0, worry = f.worry ?? 0, wide = f.wide ?? 0;
+ eyes.forEach((e, i) => {
+ const down = Math.min(1, blink) * e.h * .8, ly = e.y + down;
+ e.cut.setAttribute('height', down + 6);
+ const half = Math.sqrt(Math.max(0, 1 - ((ly - e.c[1]) / (e.h / 2 + 3)) ** 2)) * (e.w / 2 + 3);
+ e.edge.setAttribute('d', down > 2 ? `M${e.c[0] - half} ${ly}Q${e.c[0]} ${ly + 6} ${e.c[0] + half} ${ly}` : '');
+ if (e.p) about(e.p, e.c, 0, 1 - .25 * wide, 1 - .25 * wide, -e.w * .16 * (1 - gx), e.h * .1 * gy);
+ });
+ brows.forEach((m, i) => about(m, [m.x.baseVal.value + m.width.baseVal.value / 2, m.y.baseVal.value + m.height.baseVal.value], (i % 2 ? 1 : -1) * 8 * worry, 1, 1, 0, -14 * raise - 10 * wide));
+ if (R.mouth) {
+ const shape = MOUTH[f.mouth], sm = f.smile ?? .6, front = [mx + mw - 6, my + mh * .3];
+ smile.style.display = shape ? 'none' : ''; mouth.style.display = shape ? '' : 'none';
+ if (!shape) about(smile, [mx + mw / 2, my + mh / 2], 0, 1, Math.sign(sm || 1) * Math.max(.25, Math.abs(sm)));
+ else {
+ const [h, wk] = shape, H = h * Math.max(60, mw * .45), L = [front[0] - (mw - 10) * wk, my + mh * .2 - 10 * sm], mid = (L[0] + front[0]) / 2;
+ inside.setAttribute('d', `M${L}Q${mid} ${my + mh * .6 + 10 * sm} ${front}Q${mid} ${my + mh * .7 + H * 1.6} ${L}Z`);
+ tongue.setAttribute('d', h > .5 ? `M${mid - 30} ${my + mh * .7 + H}Q${mid + 10} ${my + mh * .5 + H * .7} ${front[0] - 12} ${my + mh * .6 + H * .6}Q${mid} ${my + mh * .8 + H * 1.4} ${mid - 30} ${my + mh * .7 + H}Z` : '');
+ }
+ }
+ },
+ };
+ return self;
+};
+
+// A character from drawn poses (POSES.<name>, img/<name>/pose/): one whole-figure drawing per leg pose, arm
+// drawings laid over it, mouth drawings over the face; eyes, pupils, lids and brows from its rig parts.
+// pose(state): x, ground, k, dir, lean, bob, legs (0 = standing, 1.. walk-cycle drawings), arm (0 rest, 1..),
+// face { mouth (Rhubarb letter), blink, gaze [x, y], raise, wide }.
+TOON.posed = (parent, name, opts = {}) => {
+ const S = POSES[name], R = RIGS[name], NSV = 'http://www.w3.org/2000/svg', INK = '#151314';
+ const el = (tag, attrs, p) => { const e = document.createElementNS(NSV, tag); for (const k in attrs) e.setAttribute(k, attrs[k]); p.appendChild(e); return e; };
+ const G = p => el('g', {}, p);
+ // Every drawing is decoded up front: a picture decoded on its first showing leaves that frame blank (a flicker).
+ const pic = (p, dir, n, [x, y, w, h]) => { const href = `../img/${name}/${dir}/${n}.webp`; TOON.preload(href); return el('image', { href, x, y, width: w, height: h }, p); };
+ const about = (e, [px, py], r = 0, sx = 1, sy = sx, dx = 0, dy = 0) => e.setAttribute('transform', `translate(${px + dx},${py + dy}) rotate(${r}) scale(${sx},${sy}) translate(${-px},${-py})`);
+ const FOOT = [S.parts.fig0[0] + S.parts.fig0[2] / 2, S.ground];
+ const root = G(parent), all = G(root);
+ const back = G(all); // things worn behind the body (a bindle), in rig pixels
+ const figs = Array.from({ length: S.legs + 1 }, (_, i) => pic(all, 'pose', `fig${i}`, S.parts[`fig${i}`]));
+ const face = G(all);
+ pic(face, 'pose', 'faceplate', S.parts.faceplate); // covers the figures' own eyes, brows and mouth
+ const eyes = R.eyes.map((n, i) => {
+ const [x, y, w, h] = R.parts[n]; pic(face, 'rig', n, R.parts[n]); const p = R.parts[`pupil${i}`] ? pic(face, 'rig', `pupil${i}`, R.parts[`pupil${i}`]) : null;
+ const id = `lid${name}${i}${Math.random().toString(36).slice(2, 7)}`, cut = el('rect', { x: x - 6, y: y - 6, width: w + 12, height: 0 }, el('clipPath', { id }, el('defs', {}, face)));
+ el('ellipse', { cx: x + w / 2, cy: y + h / 2, rx: w / 2 + 3, ry: h / 2 + 3, fill: R.lid, 'clip-path': `url(#${id})` }, face);
+ const edge = el('path', { fill: 'none', stroke: INK, 'stroke-width': 8, 'stroke-linecap': 'round' }, face);
+ return { p, cut, edge, x, y, w, h, c: [x + w / 2, y + h / 2] };
+ });
+ const brows = R.brows.map(n => pic(face, 'rig', n, R.parts[n]));
+ R.marks.forEach(n => pic(face, 'rig', n, R.parts[n]));
+ const closed = pic(face, 'rig', R.mouth, R.parts[R.mouth]);
+ const mouths = Array.from({ length: S.mouths }, (_, i) => pic(face, 'pose', `mouth${i + 1}`, S.parts[`mouth${i + 1}`]));
+ const arms = Array.from({ length: S.arms }, (_, i) => pic(all, 'pose', `arm${i}`, S.parts[`arm${i}`]));
+ const wholes = Object.fromEntries((S.wholes || []).map(n => {
+ const e = pic(all, 'pose', n, S.parts[n]);
+ if (n === 'nap') { const [, y, , h] = S.parts[n]; e.setAttribute('y', S.ground - h); } // lying down: on the ground
+ return [n, e];
+ })); // drawings with their own face
+ const show = (list, i) => list.forEach((e, j) => { e.style.visibility = j === i ? '' : 'hidden'; }); // hidden, not display:none, so every drawing loads up front
+ const MOUTH = { B: 0, G: 0, C: 1, H: 1, D: 2, E: 3, F: 3 };
+ return {
+ root, back, R,
+ pose(s) {
+ const k = (s.k ?? 1) * (opts.scale ?? .26);
+ root.setAttribute('transform', `translate(${s.x},${s.ground}) scale(${(s.dir ?? 1) * k},${k}) translate(${-FOOT[0]},${-FOOT[1]})`);
+ about(all, FOOT, s.lean ?? 0, 1, 1, 0, -(s.bob ?? 0) / k);
+ const w = s.whole && wholes[s.whole];
+ for (const n in wholes) wholes[n].style.visibility = wholes[n] === w ? '' : 'hidden';
+ face.style.visibility = w ? 'hidden' : '';
+ show(figs, w ? -1 : s.legs ?? 0);
+ const on = [].concat(s.arm ?? 0); arms.forEach((e, j) => { e.style.visibility = !w && on.includes(j) ? '' : 'hidden'; }); // arm: one index, or several shown together
+ const f = s.face || {}, blink = f.blink ?? 0, [gx, gy] = f.gaze || [1, 0], raise = f.raise ?? 0, wide = f.wide ?? 0;
+ eyes.forEach(e => {
+ const down = Math.min(1, blink) * e.h * .8, ly = e.y + down; e.cut.setAttribute('height', down > 1 ? down + 6 : 0);
+ const half = Math.sqrt(Math.max(0, 1 - ((ly - e.c[1]) / (e.h / 2 + 3)) ** 2)) * (e.w / 2 + 3);
+ e.edge.setAttribute('d', down > 2 ? `M${e.c[0] - half} ${ly}Q${e.c[0]} ${ly + 6} ${e.c[0] + half} ${ly}` : '');
+ if (e.p) about(e.p, e.c, 0, 1 - .25 * wide, 1 - .25 * wide, -e.w * .16 * (1 - gx), e.h * .1 * gy);
+ });
+ const worry = f.worry ?? 0, sm = f.smile ?? .6;
+ brows.forEach((m, i) => { const [x, y, w, h] = R.parts[R.brows[i]]; about(m, [x + w / 2, y + h], (i % 2 ? 1 : -1) * 9 * worry, 1, 1, 0, -14 * raise - 10 * wide); });
+ show(mouths, MOUTH[f.mouth] ?? -1); closed.style.visibility = MOUTH[f.mouth] === undefined ? '' : 'hidden';
+ const [cx, cy, cw, ch] = R.parts[R.mouth]; about(closed, [cx + cw / 2, cy + ch / 2], 0, 1, sm < 0 ? Math.max(-1, sm) : Math.max(.3, sm)); // a frown is the smile flipped
+ },
+ };
+};
+
+// Decoded pictures stay in the browser's cache, so swapping them in later costs nothing and never shows a blank frame.
+TOON.loaded = new Map();
+TOON.preload = href => { if (!TOON.loaded.has(href)) { const im = new Image(); im.src = href; TOON.loaded.set(href, im.decode ? im.decode().catch(() => {}) : null); } };
diff --git a/site/three-little-pigs/lib/units.css b/site/three-little-pigs/lib/units.css
new file mode 100644
index 0000000..e9c62cb
--- /dev/null
+++ b/site/three-little-pigs/lib/units.css
@@ -0,0 +1,79 @@
+/* The unit headers of a book's contents page, the same in every book: a strip of chalkboard per unit, with the unit's
+ label and title and a sketch of its ideas (UNIT_ART, from the book's own unit-art.js) drawn in the unit colour --c.
+ Markup and the scroll observer are in units.js. Uses the contents page's --book, --ui, --chalk and --ease. */
+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }
+.unit h2 { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }
+.unit .grid { position: relative; }
+.unit::before { content: ""; position: absolute; inset: 0 16px auto; height: 208px; border-radius: 22px; pointer-events: none;
+ background: radial-gradient(ellipse 46% 90% at 74% 55%, color-mix(in srgb, var(--c) 11%, transparent), transparent 70%); }
+.unit-art { position: absolute; top: 20px; right: 28px; width: min(580px, 56%); height: auto; overflow: visible; pointer-events: none;
+ color: var(--c); fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: .78; }
+.unit-art text { fill: currentColor; stroke: none; font-family: var(--book); font-style: italic; }
+.unit-art .a { color: var(--chalk); opacity: .55; }
+.unit-art .faint { opacity: .22; }
+.unit-art .d { stroke-dasharray: 1 1; stroke-dashoffset: 1; }
+.unit-art .t { opacity: 0; }
+.seen .unit-art .d { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards; animation-delay: calc(var(--k) * 55ms + 120ms); }
+.seen .unit-art .t { animation: art-fade .6s ease-out forwards; animation-delay: calc(var(--k) * 55ms + 300ms); }
+.seen .unit-art .a.t { animation-name: art-fade-a; }
+@keyframes art-draw { to { stroke-dashoffset: 0; } }
+@keyframes art-fade { to { opacity: 1; } }
+@keyframes art-fade-a { to { opacity: .55; } }
+/* After the drawing, each sketch keeps one small motion that belongs to its topic. */
+.unit-art g { transform-box: fill-box; }
+.seen .unit-art .swap-a { animation: swap-a 6s var(--ease) 2.4s infinite; }
+.seen .unit-art .swap-b { animation: swap-b 6s var(--ease) 2.4s infinite; }
+@keyframes swap-a { 0%, 30%, 100% { transform: none; } 45%, 80% { transform: translate(80px, 0); } 37% { transform: translate(40px, -30px); } 88% { transform: translate(40px, 30px); } }
+@keyframes swap-b { 0%, 30%, 100% { transform: none; } 45%, 80% { transform: translate(-80px, 0); } 37% { transform: translate(-40px, 30px); } 88% { transform: translate(-40px, -30px); } }
+.seen .unit-art .step { animation: art-fade .6s ease-out forwards, step 4s ease-in-out infinite; animation-delay: calc(var(--k) * 55ms + 300ms), calc(var(--k) * 300ms + 2s); }
+@keyframes step { 0%, 20%, 100% { fill-opacity: 1; } 10% { fill-opacity: .3; } }
+.unit-art .hop, .unit-art .ride { offset-rotate: 0deg; }
+.seen .unit-art .hop { animation: art-fade .4s ease-out 2s forwards, along 3.4s linear 2s infinite; }
+.unit-art .orbit { offset-rotate: 0deg; }
+.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s linear 2s infinite; }
+.seen .unit-art .ride { animation: art-fade .4s ease-out 2s forwards, along 4s ease-in-out 2s infinite alternate; }
+@keyframes along { from { offset-distance: 0%; } to { offset-distance: 100%; } }
+.unit-art .pie { stroke: currentColor; stroke-linecap: butt; stroke-dasharray: 0 100; }
+.seen .unit-art .pie { animation: art-fade .4s ease-out 1.6s forwards, pie 5s var(--ease) 1.6s infinite; }
+@keyframes pie { 0% { stroke-dasharray: 0 100; } 35%, 85% { stroke-dasharray: 25 100; } 100% { stroke-dasharray: 0 100; } }
+.seen .unit-art .tilt { transform-box: view-box; transform-origin: 300px 72px; animation: tilt 4.8s ease-in-out 2s infinite; }
+@keyframes tilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-4deg); } 60% { transform: rotate(2deg); } }
+.seen .unit-art .spin { transform-box: view-box; transform-origin: 320px 95px; animation: spin 5s cubic-bezier(.2, .7, .2, 1) 2s infinite; }
+@keyframes spin { from { transform: rotate(0); } 70%, to { transform: rotate(1530deg); } }
+.seen .unit-art .feed-in { animation: feed-in 4s ease-in-out 2s infinite; }
+.seen .unit-art .feed-out { opacity: 0; animation: feed-out 4s ease-in-out 2s infinite; }
+@keyframes feed-in { 0% { transform: none; opacity: 1; } 40% { transform: translate(100px, 0); opacity: 0; } 41%, 100% { transform: none; opacity: 0; } 95% { opacity: 1; } }
+@keyframes feed-out { 0%, 45% { transform: translate(-40px, 0); opacity: 0; } 70%, 90% { transform: none; opacity: 1; } 100% { opacity: 0; } }
+.unit-art .cell { opacity: .25; }
+.seen .unit-art .cell { animation: cell 5s ease-in-out infinite; animation-delay: calc(var(--j) * .5s + 2s); }
+@keyframes cell { 0%, 100% { opacity: .25; } 15%, 60% { opacity: 1; } }
+.unit-art .cut, .unit-art .shade { opacity: 0; }
+.seen .unit-art .cut { animation: cut 4s ease-in-out 2s infinite; }
+@keyframes cut { 0%, 100% { opacity: 0; } 30%, 70% { opacity: .5; } }
+.seen .unit-art .shade { animation: shade 1s ease-out 1.6s forwards; }
+@keyframes shade { to { opacity: .14; } }
+.seen .unit-art .diag { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards, redraw 4s ease-in-out 2.5s infinite; }
+@keyframes redraw { 0%, 15% { stroke-dashoffset: 1; } 50%, 100% { stroke-dashoffset: 0; } }
+.seen .unit-art .root { animation: art-fade .4s ease-out 1.8s forwards, root 2.4s ease-in-out 2.2s infinite; }
+@keyframes root { 0%, 100% { r: 7px; } 50% { r: 11px; } }
+.seen .unit-art .breathe { transform-box: view-box; transform-origin: 380px 140px; animation: breathe 4s ease-in-out 2s infinite alternate; }
+@keyframes breathe { from { transform: scaleY(1); } to { transform: scaleY(.35); } }
+/* The label and the title share a line when they fit; a long title wraps below the label instead of running off. */
+.unit h2 .title { min-width: 0; text-wrap: balance; }
+.unit h2 .label { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
+/* Keep the sketches cheap: each is its own layer, so its loop repaints only itself, and loops pause while their unit is
+ off screen or under the sticky bar (units.js toggles .live), so the bar's blur is not redrawn every frame. */
+.unit-art { will-change: transform; contain: layout style; }
+.unit:not(.live) .unit-art, .unit:not(.live) .unit-art * { animation-play-state: paused; }
+@media (max-width: 560px) {
+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
+ .unit h2 { min-height: 0; padding-top: 104px; font-size: 24px; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .unit-art * { animation: none !important; }
+ .unit-art .d { stroke-dashoffset: 0; }
+ .unit-art .t, .unit-art .cell { opacity: 1; }
+ .unit-art .a.t { opacity: .55; }
+ .unit-art .shade { opacity: .14; }
+ .unit-art .pie { stroke-dasharray: 25 100; }
+}
diff --git a/site/three-little-pigs/lib/units.js b/site/three-little-pigs/lib/units.js
new file mode 100644
index 0000000..e9e8c27
--- /dev/null
+++ b/site/three-little-pigs/lib/units.js
@@ -0,0 +1,26 @@
+// The unit headers of a book's contents page, the same in every book; styled by units.css. The sketches come from
+// the book's own unit-art.js (window.UNIT_ART, one SVG body per unit, viewBox 0 0 600 180).
+// Units.header(u, label, title) the sketch and heading for unit u, as HTML to put first in its <section class="unit">
+// Units.watch() draw each sketch the first time its unit scrolls into view, and run its loop only
+// while the unit is on screen
+'use strict';
+(() => {
+ const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const header = (u, label, title) =>
+ `<svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${window.UNIT_ART?.[u] || ''}</svg>` +
+ `<h2><span class="label">${esc(label)}</span><span class="title">${esc(title)}</span></h2>`;
+
+ function watch(root = document) {
+ const units = root.querySelectorAll('.unit');
+ if (!('IntersectionObserver' in window)) return units.forEach(u => u.classList.add('seen', 'live'));
+ // The first sight draws the sketch; leaving the screen (or sliding under the sticky bar) pauses it.
+ const first = new IntersectionObserver(es => es.forEach(e => {
+ if (e.isIntersecting) { e.target.classList.add('seen'); first.unobserve(e.target); }
+ }), { threshold: .25 });
+ const live = new IntersectionObserver(es => es.forEach(e => e.target.classList.toggle('live', e.isIntersecting)),
+ { rootMargin: '-64px 0px 0px 0px' });
+ units.forEach(u => { first.observe(u); live.observe(u); });
+ }
+
+ window.Units = { header, watch };
+})();
diff --git a/site/three-little-pigs/lib/volume.css b/site/three-little-pigs/lib/volume.css
new file mode 100644
index 0000000..195fe1f
--- /dev/null
+++ b/site/three-little-pigs/lib/volume.css
@@ -0,0 +1,24 @@
+/* Volume control for the player bar (volume.js); imported by engine.css. */
+.volume { display: flex; align-items: center; flex: none; width: 44px; height: 44px; overflow: hidden;
+ border: 1px solid var(--edge); border-radius: 999px; background: var(--panel); color: var(--chalk); transition: width .18s ease; }
+.volume .icon { width: 42px; height: 42px; border: 0; background: transparent; }
+.volume:hover, .volume:focus-within { width: 166px; gap: 10px; padding-right: 12px; }
+.volume:hover { background: #2b3f36; border-color: var(--faint); }
+.volume:has(:focus-visible) { outline: 2px solid var(--task); outline-offset: 3px; }
+.volume .icon:focus-visible { outline: none; }
+.volume input { appearance: none; flex: none; width: 0; height: 42px; margin: 0; opacity: 0; background: transparent; cursor: pointer; }
+.volume:hover input, .volume:focus-within input { width: 100px; opacity: 1; }
+.volume input:focus-visible { outline: none; }
+.volume input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px;
+ background: linear-gradient(to right, var(--chalk) var(--volume, 100%), var(--faint) var(--volume, 100%)); }
+.volume input::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border: 0; border-radius: 50%; background: var(--chalk); }
+.volume input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--faint); }
+.volume input::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--chalk); }
+.volume input::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }
+@media (max-width: 700px) {
+ .volume { width: 36px; height: 40px; }
+ #bar .volume .icon { width: 34px; height: 38px; }
+ .volume:hover, .volume:focus-within { width: 158px; }
+ .volume input { height: 38px; }
+}
+@media (prefers-reduced-motion: reduce) { .volume { transition: none; } }
diff --git a/site/three-little-pigs/lib/volume.js b/site/three-little-pigs/lib/volume.js
new file mode 100644
index 0000000..8616688
--- /dev/null
+++ b/site/three-little-pigs/lib/volume.js
@@ -0,0 +1,20 @@
+/* Volume control for the player bar: a speaker button that opens a slider. engine.js loads this file and reads
+ #volume when it starts each beat's audio, so the control is the same in every book. */
+'use strict';
+{
+ document.getElementById('bHelp').insertAdjacentHTML('beforebegin', `<div class="volume">
+ <button class="icon" id="bVolume" aria-label="${translate('volumeLabel')}" aria-controls="volume" title="${translate('volumeTitle')}">
+ <svg viewBox="0 0 24 24" aria-hidden="true">
+ <path d="M3 9v6h4l5 4V5L7 9z" fill="currentColor"/>
+ <path d="M16 8a6 6 0 0 1 0 8m3-11a10 10 0 0 1 0 14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
+ </svg>
+ </button>
+ <input id="volume" type="range" min="0" max="1" step="0.05" value="1" aria-label="${translate('volumeSlider')}">
+ </div>`);
+ const input = document.getElementById('volume');
+ document.getElementById('bVolume').onclick = () => input.focus();
+ input.oninput = () => {
+ input.style.setProperty('--volume', +input.value * 100 + '%');
+ if (P.audio) P.audio.volume = +input.value;
+ };
+}
diff --git a/site/three-little-pigs/making/bug-wolf-mouth.webp b/site/three-little-pigs/making/bug-wolf-mouth.webp
new file mode 100644
index 0000000..c85edab
Binary files /dev/null and b/site/three-little-pigs/making/bug-wolf-mouth.webp differ
diff --git a/site/three-little-pigs/making/bugs-hands.webp b/site/three-little-pigs/making/bugs-hands.webp
new file mode 100644
index 0000000..51a3ecc
Binary files /dev/null and b/site/three-little-pigs/making/bugs-hands.webp differ
diff --git a/site/three-little-pigs/making/cover.webp b/site/three-little-pigs/making/cover.webp
new file mode 100644
index 0000000..adb223b
Binary files /dev/null and b/site/three-little-pigs/making/cover.webp differ
diff --git a/site/three-little-pigs/making/edits-mother.webp b/site/three-little-pigs/making/edits-mother.webp
new file mode 100644
index 0000000..6b0dff8
Binary files /dev/null and b/site/three-little-pigs/making/edits-mother.webp differ
diff --git a/site/three-little-pigs/making/houses.webp b/site/three-little-pigs/making/houses.webp
new file mode 100644
index 0000000..72ffda7
Binary files /dev/null and b/site/three-little-pigs/making/houses.webp differ
diff --git a/site/three-little-pigs/making/layers-composite.webp b/site/three-little-pigs/making/layers-composite.webp
new file mode 100644
index 0000000..4d7f0f2
Binary files /dev/null and b/site/three-little-pigs/making/layers-composite.webp differ
diff --git a/site/three-little-pigs/making/layers.webp b/site/three-little-pigs/making/layers.webp
new file mode 100644
index 0000000..3e71c02
Binary files /dev/null and b/site/three-little-pigs/making/layers.webp differ
diff --git a/site/three-little-pigs/making/medium-vs-high.webp b/site/three-little-pigs/making/medium-vs-high.webp
new file mode 100644
index 0000000..d3d318b
Binary files /dev/null and b/site/three-little-pigs/making/medium-vs-high.webp differ
diff --git a/site/three-little-pigs/making/mouths-mother.webp b/site/three-little-pigs/making/mouths-mother.webp
new file mode 100644
index 0000000..7cf9f1d
Binary files /dev/null and b/site/three-little-pigs/making/mouths-mother.webp differ
diff --git a/site/three-little-pigs/making/mouths-wolf.webp b/site/three-little-pigs/making/mouths-wolf.webp
new file mode 100644
index 0000000..eca8326
Binary files /dev/null and b/site/three-little-pigs/making/mouths-wolf.webp differ
diff --git a/site/three-little-pigs/making/still-1.webp b/site/three-little-pigs/making/still-1.webp
new file mode 100644
index 0000000..9541e13
Binary files /dev/null and b/site/three-little-pigs/making/still-1.webp differ
diff --git a/site/three-little-pigs/making/still-10.webp b/site/three-little-pigs/making/still-10.webp
new file mode 100644
index 0000000..d819f49
Binary files /dev/null and b/site/three-little-pigs/making/still-10.webp differ
diff --git a/site/three-little-pigs/making/still-11.webp b/site/three-little-pigs/making/still-11.webp
new file mode 100644
index 0000000..3e2bd0a
Binary files /dev/null and b/site/three-little-pigs/making/still-11.webp differ
diff --git a/site/three-little-pigs/making/still-2.webp b/site/three-little-pigs/making/still-2.webp
new file mode 100644
index 0000000..ca1c2c8
Binary files /dev/null and b/site/three-little-pigs/making/still-2.webp differ
diff --git a/site/three-little-pigs/making/still-4.webp b/site/three-little-pigs/making/still-4.webp
new file mode 100644
index 0000000..d0cb6ef
Binary files /dev/null and b/site/three-little-pigs/making/still-4.webp differ
diff --git a/site/three-little-pigs/making/still-5.webp b/site/three-little-pigs/making/still-5.webp
new file mode 100644
index 0000000..7350fad
Binary files /dev/null and b/site/three-little-pigs/making/still-5.webp differ
diff --git a/site/three-little-pigs/making/still-6.webp b/site/three-little-pigs/making/still-6.webp
new file mode 100644
index 0000000..8e423fc
Binary files /dev/null and b/site/three-little-pigs/making/still-6.webp differ
diff --git a/site/three-little-pigs/making/still-7.webp b/site/three-little-pigs/making/still-7.webp
new file mode 100644
index 0000000..b3b6099
Binary files /dev/null and b/site/three-little-pigs/making/still-7.webp differ
diff --git a/site/three-little-pigs/making/still-8.webp b/site/three-little-pigs/making/still-8.webp
new file mode 100644
index 0000000..1003fc6
Binary files /dev/null and b/site/three-little-pigs/making/still-8.webp differ
diff --git a/site/three-little-pigs/making/styles.webp b/site/three-little-pigs/making/styles.webp
new file mode 100644
index 0000000..5f9adce
Binary files /dev/null and b/site/three-little-pigs/making/styles.webp differ
diff --git a/site/three-little-pigs/making/try1-rigid.webp b/site/three-little-pigs/making/try1-rigid.webp
new file mode 100644
index 0000000..5315d8d
Binary files /dev/null and b/site/three-little-pigs/making/try1-rigid.webp differ
diff --git a/site/three-little-pigs/making/try2-hose.webp b/site/three-little-pigs/making/try2-hose.webp
new file mode 100644
index 0000000..ca78ac3
Binary files /dev/null and b/site/three-little-pigs/making/try2-hose.webp differ
diff --git a/site/three-little-pigs/making/try2-slideshow.webp b/site/three-little-pigs/making/try2-slideshow.webp
new file mode 100644
index 0000000..1e863c3
Binary files /dev/null and b/site/three-little-pigs/making/try2-slideshow.webp differ
diff --git a/site/three-little-pigs/making/try3-sheets.webp b/site/three-little-pigs/making/try3-sheets.webp
new file mode 100644
index 0000000..6d49a4a
Binary files /dev/null and b/site/three-little-pigs/making/try3-sheets.webp differ
diff --git a/site/three-little-pigs/making/try4-handdrawn.webp b/site/three-little-pigs/making/try4-handdrawn.webp
new file mode 100644
index 0000000..d026be1
Binary files /dev/null and b/site/three-little-pigs/making/try4-handdrawn.webp differ
diff --git a/site/three-little-pigs/making/vectorize.webp b/site/three-little-pigs/making/vectorize.webp
new file mode 100644
index 0000000..4e84ee2
Binary files /dev/null and b/site/three-little-pigs/making/vectorize.webp differ
diff --git a/site/three-little-pigs/making/walk-wolf.webp b/site/three-little-pigs/making/walk-wolf.webp
new file mode 100644
index 0000000..5ab5e54
Binary files /dev/null and b/site/three-little-pigs/making/walk-wolf.webp differ
diff --git a/site/three-little-pigs/making/whole-poses.webp b/site/three-little-pigs/making/whole-poses.webp
new file mode 100644
index 0000000..c4eea1c
Binary files /dev/null and b/site/three-little-pigs/making/whole-poses.webp differ
diff --git a/site/three-little-pigs/making/wolf-poses.webp b/site/three-little-pigs/making/wolf-poses.webp
new file mode 100644
index 0000000..f336666
Binary files /dev/null and b/site/three-little-pigs/making/wolf-poses.webp differ