An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
fix(science): trim ch09 scenes and keep labels in frame
yzrbf26f719b6bd
diff --git a/.claude/skills/papermorph/assets/engine/engine.js b/.claude/skills/papermorph/assets/engine/engine.jsindex 3e33e7b..13bfe8e 100644--- a/.claude/skills/papermorph/assets/engine/engine.js+++ b/.claude/skills/papermorph/assets/engine/engine.js@@ -890,6 +890,14 @@ function camera(p, D, { box, x = 800, y = 450, z, r = 0, bg = COL.board } = {})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;diff --git a/.claude/skills/papermorph/references/authoring.md b/.claude/skills/papermorph/references/authoring.mdindex 680e071..cca6239 100644--- a/.claude/skills/papermorph/references/authoring.md+++ b/.claude/skills/papermorph/references/authoring.md@@ -29,8 +29,9 @@ Principles that held up over a whole book:- **Open on the subject.** When a beat clears the picture, the new topic (expression, diagram, question) appears right away; labels and steps then follow the words. The engine moves an opening group forward if nothing appears in the first 0.8 s, but design for it. Normal transitions and short pauses for thought are fine; the picture need not move all the time.- **One new thing at a time.** Don't introduce several objects, colours and texts at once.+- **Balance explanation and decoration.** Favour objects and camera moves that carry the idea (the thing that moves, the reference it moves against, the cut that changes the point of view). Some atmosphere is welcome; keep it light so it never crowds the concept, distracts, or costs smooth playback. Judge each scene as a whole: trim extras (a bystander, dense scenery, stacked parallax layers, a flourish move) rather than strip it bare.- **Same colour, same meaning** within a chapter (and, where it fits, across the book).-- **Be exact.** Number lines, grids and areas are to scale; a deliberately enlarged drawing says "drawn larger" on screen. Approximations are written as approximations (≈ 4.47…, never = 4.47).+- **Be exact where it matters.** Number lines, grids and areas are to scale. Illustrative scenes (planets, people on Earth) need only be clear to the reader; add a scale note only when the size could mislead. Approximations are written as approximations (≈ 4.47…, never = 4.47).- **Teach the chapter's scope.** If the book jumps ahead or uses something not yet taught, leave it out or say so.- **Show the common mistake** where one exists (e.g. squaring the coefficient too), visually crossed out, then the right way.diff --git a/.claude/skills/papermorph/references/engine.md b/.claude/skills/papermorph/references/engine.mdindex 07b798e..ba9a10a 100644--- a/.claude/skills/papermorph/references/engine.md+++ b/.claude/skills/papermorph/references/engine.md@@ -56,7 +56,7 @@ For continuous motion (vehicles, orbits, rolling, scrolling scenery) and camera- `const cam = camera(parent, D, { x, y, z, r, box, bg })` makes a view onto a world group. Draw in `cam.world` in world coordinates. The view `{x, y}` is the world point shown at the centre, `z` the zoom (screen px per world px), `r` the roll in degrees. Defaults: full stage, `(800, 450)`, `z` 1 (identity, so stage coordinates still work). With `box: [x, y, w, h]` the camera draws in a framed, clipped box with background `bg` (split screen, picture-in-picture); its default zoom fits the 1600 × 900 world into the box. `cam.el` is the camera's group (fade, pop or hide it; it scales about the box centre).- Moves, all on the beat clock: `cam.to({x, y, z, r}, t0, dur = 1, ease = soft)` blends only the keys given, from wherever the camera is at `t0`; `cam.cut(view, t0)` is a hard cut (`dur` 0); `cam.shake(amp, t0, dur, hz = 7)` is a subtle, repeatable shake (fades in and out over 0.3 s). Any key may be a function of `t`: that is a follow shot (`cam.to({ x: t => carX(t) }, 2, 1.5)` locks on over 1.5 s; `r: t => spin(t)` rolls with a rotating object). Zoom changes evenly (log scale) and keeps one world point fixed when start and end allow it.- Parallax: `cam.layer(k, wrap)` returns a group inside the world that moves at `k` × the camera's pan (`k` < 1 far, > 1 near; zoom and roll are not scaled per layer). With `wrap = W` the layer's content repeats every `W` world px: draw one period plus the widest view, and the camera can pan any distance. Keep repeating details (dashes, tiles, trees) on a period that divides `W`, and move followed objects by multiples of `W` when they loop, so the loop is invisible.-- `cam.at(t)` returns the view at `t`; `cam.screen(wx, wy, t)` the screen position of a world point (no shake), for screen-space labels that track an object.+- `cam.at(t)` returns the view at `t`; `cam.screen(wx, wy, t)` the screen position of a world point (no shake), for screen-space labels that track an object. `cam.track(label, wx, wy, t)` does that for a text label drawn outside the camera: it follows the point, stays inside the frame (or box), and fades out once the point leaves; fade it in through a wrapper group. Keep tracked labels in the safe frame this way rather than letting them clip at the edge.- Split screen or picture-in-picture: two cameras with boxes, each with its own copy of the world built by the same function and driven by the same clock functions. Cross-fade between shots by fading one camera's `el` out and another's in.- Labels drawn in the world scale with the zoom; put text that must stay readable in screen space (the panel) or give world labels a size for the shot's zoom. A beat whose camera shows a picture from its first frame while its first scheduled reveal is late may need `{ lead: false }`.- Ease `soft` (cosine in-out) suits camera moves; `io`, `out`, `back`, `lin` or any `p => …` work too.diff --git a/site/science/ch09/index.html b/site/science/ch09/index.htmlindex 446bf3d..482aca7 100644--- a/site/science/ch09/index.html+++ b/site/science/ch09/index.html@@ -45,16 +45,15 @@ const groundView = (lift, z) => ({ x: t => EX + (ER + lift) * Math.cos(rimAngle(function earthWorld(cam, D) {const E = phEarthPolar(cam.world, { x: EX, y: EY, R: ER });const rim = deg => G(G(E._spin, { r: deg }), { y: -ER });- phTree(rim(-15), { s: .19, kind: 1 }); phHouse(rim(-9), { s: .17 }); phTree(rim(7), { s: .19 }); phBush(rim(12), { s: .22 });+ phHouse(rim(-9), { s: .17 }); phTree(rim(7), { s: .19 }); // the narration's buildings, trees and youconst you = rim(0);phPerson(you, { s: .17 });clockRun(t => put(E._spin, { r: ESPIN * t }), D);return { E, you };}-// Street for the split screen: truck and car loop round the wrapping street (one loop = ROAD.W, so the follow camera's-// jump at the loop is invisible). The truck enters the roadside view at t = 2.4 s.-// The roadside view needs no wrap, so its truck loops sooner (L = 1850) and is back on screen before the beat ends.-const loopX = (t, L = ROAD.W) => -200 + ((520 + V * (t - 2.4)) % L + L) % L;+// Split screen: the truck and car drive slower than elsewhere (the views are small) so the truck stays inside the roadside+// view for the whole beat; both labels are always visible.+const SPLIT_V = 50, splitX = t => 760 + SPLIT_V * t;/* ---------- beats ---------- */const BEATS = [@@ -64,11 +63,9 @@ const BEATS = [const road = phRoad(cam);const carX = t => -260 + 190 * t;const car = phCar(road.vehicles, { y: ROAD.near });- const jog = phPerson(road.side, { shirt: COL.nat, y: ROAD.side });cam.to({ x: t => carX(t) + 330 }, 2.4, 2); // lock on: from here the camera rides with the carclockRun(t => {const x = carX(t); put(car, { x }); phRoll(car, x);- const jx = 380 + 95 * t; put(jog, { x: jx }); phPose(jog, 'run', jx / 22);}, D);const g = G(p, { o: 0, y: 24 });T(g, 'Unit 3 · Motion, Forces, and Work · Chapter 9', { x: 800, y: 130, size: 28, fill: COL.dim, anchor: 'middle' });@@ -83,9 +80,7 @@ const BEATS = [const w = cam.world;phHills(w, { y: 470, amp: 30, x0: -1400, x1: 3000, fill: PH.hill2, seed: 2 });phBlock(w, -1400, 520, 4400, 1200, PH.grass, { top: 6, ol: 0 });- phTree(w, { x: -300, y: 540, s: 1.3 }); phTree(w, { x: -90, y: 548, kind: 1 }); phBush(w, { x: 40, y: 578 });- phTree(w, { x: 1720, y: 540, s: 1.2, kind: 1 }); phTree(w, { x: 1960, y: 548, s: 1.3 }); phBush(w, { x: 1560, y: 572 });- phPerson(w, { shirt: COL.whole, x: 80, y: 560, s: .9 });+ phTree(w, { x: -200, y: 540, s: 1.3 }); phTree(w, { x: 1820, y: 548, s: 1.2, kind: 1 });const X0 = 200, U = 120, TY = 600, R = 40, xm = v => X0 + U * v;const track = G(w);phBlock(track, X0 - 30, TY, U * 10 + 60, 16, '#8a6f55', { top: 4, ol: 2 });@@ -131,7 +126,6 @@ const BEATS = [mk('circle', { cx: 800, cy: 395, r: 140, fill: 'none', stroke: COL.faint, 'stroke-width': 2, 'stroke-dasharray': '6 10' }, f2);const sun = phSun(f2, { x: 800, y: 395, r: 42 });const earth = phEarthSmall(f2, { r: 22 });- T(f2, 'not to scale', { x: 990, y: 565, size: 20, fill: COL.dim, anchor: 'end' });const f3 = frame(1300, m('you'), 'you, walking');phBlock(f3, 1092, 540, 416, 38, PH.grass, { top: 5, ol: 0 });const you = phPerson(f3, { x: 1160, y: 540, s: .95 });@@ -149,7 +143,6 @@ const BEATS = [['roadside', 'Standing by the road', (m, D) => {const p = panel(0);const cam = camera(p, D);- cam.to({ x: 780, y: 470, z: 1.05 }, 0, D, lin); // fixed roadside shot with a slow push-inconst road = phRoad(cam);const you = phPerson(road.side, { x: 760, y: ROAD.side, o: 0 });show(you, m('stand'));@@ -172,15 +165,15 @@ const BEATS = [const FR = 1100, tc = m('car', .3), r0 = m('ride');const xw = t => -330 + V * Math.max(0, t - tc); // world position of the truck and the car (side by side)// Hard cut at "ride": the camera now rides in the car (locked on it, a little closer, with a light road shake).- cam.cut({ x: t => xw(t) + 10, y: 600, z: 1.15 }, r0).shake(1.6, r0, D - r0, 6);+ cam.cut({ x: t => xw(t) + 10, y: 600, z: 1.15 }, r0);phPerson(road.side, { shirt: PH.friend, x: FR, y: ROAD.side });const truck = phTruck(road.vehicles, { y: ROAD.far, s: .85 });const car = phCar(road.vehicles, { y: ROAD.near });- const fl = phLabel(road.front, '', { x: FR, y: 272, fill: PH.friend, o: 0 });- const tl = phLabel(road.front, '', { y: 380, fill: PH.truck, o: 0 });- const cl = phLabel(road.front, '', { y: ROAD.bot + 56, fill: PH.car, o: 0 });+ // Speed labels live in screen space and are kept inside the frame (cam.track); wrappers fade them in.+ const tag = (fill, t0) => { const g = G(p, { o: 0 }); show(g, t0); return phLabel(g, '', { fill }); };+ const fl = tag(PH.friend, .4), tl = tag(PH.truck, tc + 1.6), cl = tag(PH.car, tc + 1.6);const sl = phLabel(p, 'road and trees: ← 30 mph', { x: 70, y: 862, size: 30, fill: COL.dim, anchor: 'start', o: 0 });- show(fl, .4); show(tl, tc + 1.6); show(cl, tc + 1.6); show(sl, m('back'));+ show(sl, m('back'));const pinA = phPin(road.side, { x: FR, y: 236, o: 0 }), pinB = phPin(car, { x: 30, y: -112, s: 0, o: 0 });show(pinA, .3); hide(pinA, r0, 0); pop(pinB, r0 + .3);const tagA = fromTag(p, 'the roadside', .3);@@ -189,28 +182,27 @@ const BEATS = [const x = xw(t), camV = t < r0 ? 0 : V, rel = t < tc ? 0 : V - camV;put(truck, { x }); put(car, { x: x + 10 });phRoll(truck, (x + 330) / .85); phRoll(car, x + 330);- fl.textContent = `friend: ${speedStr(-camV)}`;- put(tl, { x: x + 10 }); tl.textContent = `truck: ${speedStr(rel)}`;- put(cl, { x: x + 10 }); cl.textContent = `your car: ${speedStr(rel)}`;+ fl.textContent = `friend: ${speedStr(-camV)}`; cam.track(fl, FR, 272, t);+ tl.textContent = `truck: ${speedStr(rel)}`; cam.track(tl, x + 10, 380, t);+ cl.textContent = `your car: ${speedStr(rel)}`; cam.track(cl, x + 10, ROAD.bot + 56, t);}, D);}],['rule', 'Motion is relative', (m, D) => {const p = panel(0);// Split screen: the same street through two cameras at once, one standing by the road, one riding in the car.const view = (box, t0, title, ride) => {- const cam = camera(p, D, { box, x: 1200, y: 560, z: .5 });- const L = ride ? ROAD.W : 1850;- if (ride) cam.cut({ x: t => loopX(t) + 10 }, 0);+ const cam = camera(p, D, { box, x: 1200, y: 560, z: .45 });+ if (ride) cam.cut({ x: t => splitX(t) + 10 }, 0);const r = phRoad(cam, { hills: false });- phPerson(r.scenery, { shirt: PH.friend, x: 850, y: ROAD.side });- if (!ride) phPin(r.scenery, { x: 850, y: 296, s: 1.1 });+ phPerson(r.scenery, { shirt: PH.friend, x: 480, y: ROAD.side });+ if (!ride) phPin(r.scenery, { x: 480, y: 296, s: 1.1 });const truck = phTruck(r.vehicles, { y: ROAD.far, s: .85 }), car = phCar(r.vehicles, { y: ROAD.near });if (ride) phPin(car, { x: 30, y: -112, s: 1.4 });const lab = phLabel(r.front, ride ? 'truck: 0 mph' : 'truck: 30 mph →', { y: 380, size: 56, fill: PH.truck });clockRun(t => {- const x = loopX(t, L), dist = 520 + V * (t - 2.4);+ const x = splitX(t);put(truck, { x }); put(car, { x: x + 10 }); put(lab, { x: x + 10 });- phRoll(truck, dist / .85); phRoll(car, dist);+ phRoll(truck, x / .85); phRoll(car, x);}, D);put(cam.el, { o: 0 }); show(cam.el, t0);show(phLabel(p, title, { x: box[0] + 24, y: box[1] + box[3] - 22, size: 28, fill: PH.ref, anchor: 'start', o: 0 }), t0);@@ -231,7 +223,7 @@ const BEATS = [// Open on the ground, rolling with it (nothing moves), then pull back into space: the spin appears.cam.cut(groundView(26, 6), 0).to({ x: 800, y: 450, z: 1, r: 0 }, m('earth'), 3.4);const stars = cam.layer(.15);- for (let i = 0; i < 110; i++) { const k = 2 + 3 * phHash(i, 5); mk('rect', { x: -1400 + 4400 * phHash(i, 1), y: -1000 + 2900 * phHash(i, 2), width: k, height: k, fill: COL.chalk, opacity: .3 + .5 * phHash(i, 3) }, stars); }+ for (let i = 0; i < 40; i++) { const k = 2 + 3 * phHash(i, 5); mk('rect', { x: -1400 + 4400 * phHash(i, 1), y: -1000 + 2900 * phHash(i, 2), width: k, height: k, fill: COL.chalk, opacity: .3 + .5 * phHash(i, 3) }, stars); }const { you } = earthWorld(cam, D);clockRun(t => { const k = Math.min(1, Math.max(0, (cam.at(t).z - 1.6) / 2)); put(sky, { o: k }); put(stars, { o: 1 - k }); }, D);const rimRing = mk('rect', { x: -16, y: -40, width: 32, height: 44, rx: 6, fill: 'none', stroke: PH.ref, 'stroke-width': 2.5 }, you);@@ -251,7 +243,6 @@ const BEATS = [eq.setAttribute('pathLength', 1); eq.setAttribute('stroke-dasharray', '1 1'); put(eq, { d: 0 }); draw(eq, m('fast'), 1.2);runs(p, [['equator (the rim): ', COL.int], ['more than 1,000 mph', COL.chalk]], { x: EX, y: 818, size: 30, o: 0 });show(p.lastChild, m('fast', .4));- txt(p, 'people and buildings drawn much larger', EX, 860, m('earth', 3.4), { size: 22, fill: COL.dim, weight: 500 });const rx = 1180;txt(p, 'Why can\'t we feel it?', rx, 200, m('why'), { size: 42 });txt(p, 'Everything near you spins along with Earth.', rx, 260, m('along'), { size: 28, fill: COL.dim, weight: 500 });diff --git a/site/science/lib/engine.js b/site/science/lib/engine.jsindex 3e33e7b..13bfe8e 100644--- a/site/science/lib/engine.js+++ b/site/science/lib/engine.js@@ -890,6 +890,14 @@ function camera(p, D, { box, x = 800, y = 450, z, r = 0, bg = COL.board } = {})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;diff --git a/site/science/lib/figures.js b/site/science/lib/figures.jsindex 9926cb7..2d0feec 100644--- a/site/science/lib/figures.js+++ b/site/science/lib/figures.js@@ -238,12 +238,6 @@ function phTree(p, { x = 0, y = 0, s = 1, o = 1, leaf = PH.leaf, kind = 0 } = {}});return g;}-function phBush(p, { x = 0, y = 0, s = 1, leaf = PH.leaf } = {}) {- const g = G(p, { x, y, s });- const rects = [[-34, -30, 68, 30], [-20, -44, 40, 16]];- phMerge(g, rects, dk(leaf, .1), c => { phPixels(c, -34, -44, 34, 0, dk(leaf, .1), 10, 5); mk('rect', { x: 12, y: -44, width: 30, height: 44, fill: dk(leaf, .3), opacity: .6 }, c); });- return g;-}function phLamp(p, { x = 0, y = 0, s = 1 } = {}) {const g = G(p, { x, y, s });phPoly(g, [[34, -213], [56, -213], [92, 0], [0, 0]], PH.light, 0).setAttribute('opacity', .06);@@ -283,12 +277,9 @@ function phHills(p, { y, amp = 40, W = ROAD.W, x0, x1, fill, seed = 1, step = 40// can run for any distance; far hills are parallax layers. Returns the layers to add things to, back to front:// scenery (wraps; for fixed things that should repeat), side (people on the pavement), vehicles, front (labels).const ROAD = { top: 478, far: 566, mid: 640, near: 726, bot: 748, side: 474, W: 2400 };-function phRoad(cam, { trees = [60, 540, 1020, 1500, 1980], lamps = [300, 1500], hills = true, x0 = -1600, x1 = 5600 } = {}) {+function phRoad(cam, { trees = [300, 1100, 1900], lamps = [1500], hills = true, x0 = -1600, x1 = 5600 } = {}) {const W = ROAD.W, rep = xs => xs.flatMap(v => { const out = []; for (let x = v + Math.floor((x0 - v) / W) * W; x < x1; x += W) out.push(x); return out; });- if (hills) {- phHills(cam.layer(.25, W), { y: 330, amp: 50, x0, x1, fill: PH.hill1, seed: 1 });- phHills(cam.layer(.5, W), { y: 400, amp: 34, x0, x1, fill: PH.hill2, seed: 4 });- }+ if (hills) phHills(cam.layer(.3, W), { y: 380, amp: 44, x0, x1, fill: PH.hill1, seed: 1 });const scenery = cam.layer(1, W);phBlock(scenery, x0, 452, x1 - x0, 26, PH.walk, { top: 4, ol: 0 });path(scenery, rep(Array.from({ length: 40 }, (_, i) => i * 60)).map(x => `M${x} 457V478`).join(''), { stroke: dk(PH.walk, .2), 'stroke-width': 2 });