An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
fix(science): keep force labels clear of their arrows
yzr5fcfc90a8581
diff --git a/site/science/ch09/index.html b/site/science/ch09/index.htmlindex 033876b..d3bff14 100644--- a/site/science/ch09/index.html+++ b/site/science/ch09/index.html@@ -217,7 +217,7 @@ const BEATS = [const road = phRoad(cam);const you = phPerson(road.side, { x: 760, y: ROAD.side, o: 0 });show(you, m('stand'));- show(phLabel(road.front, 'you', { x: 760, y: 336, fill: PH.you, o: 0 }), m('stand'));+ show(phLabel(road.front, 'you', { x: 760, y: 236, fill: PH.you, o: 0 }), m('stand')); // above the pin: the truck's label passes belowconst truck = phTruck(road.vehicles, { y: ROAD.far });const tl = phLabel(road.front, `truck: ${speedStr(V)}`, { y: 350, fill: PH.truck, o: 0 });fromTag(p, 'you, by the road', m('speed'));@@ -253,7 +253,7 @@ 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); phRoll(car, x + 330);- phText(fl, `friend: ${speedStr(-camV)}`); cam.track(fl, FR, 336, t);+ phText(fl, `friend: ${speedStr(-camV)}`); cam.track(fl, FR, 236, t);phText(tl, `truck: ${speedStr(rel)}`); cam.track(tl, x + 10, 350, t);phText(cl, `your car: ${speedStr(rel)}`); cam.track(cl, x + 10, ROAD.bot + 56, t);}, D);@@ -478,7 +478,7 @@ const BEATS = [path(tot, `M${xm(0)} ${LA + 84}V${LA + 100}H${xm(300)}V${LA + 84}`, { stroke: DIST, 'stroke-width': 4 });T(tot, 'total distance: 300 m', { x: xm(150), y: LA + 134, size: 30, weight: 700, fill: DIST, anchor: 'middle' });show(tot, m('total', .8));- txt(p, 'total time: 30 s', 1460, 320, m('total', 1.6), { size: 28, fill: TIME });+ txt(p, 'total time: 30 s', 1400, 200, m('total', 1.6), { size: 28, fill: TIME, anchor: 'end' }); // beside the clock, clear of the car's speed labelconst y = 100;show(T(p, 'average speed =', { x: 560, y: y + 14, size: 44, weight: 700, anchor: 'end', o: 0 }), m('avg'));show(wfrac(p, 'total distance', 'total time', 730, y, { size: 38, ct: DIST, cb: TIME }), m('avg', .4));@@ -832,7 +832,7 @@ const BEATS = [const ia = Math.atan2(cy - y, cx - x) * 180 / Math.PI; // toward the centre of the turnarrowAt(aa, x, y, onArc ? 120 : 0, ia); arrowAt(feel, x, y, onArc && t > m('feel') ? 110 : 0, ia + 180, 16);cam.track(fl, x - 260 * Math.cos(ia * Math.PI / 180), y - 260 * Math.sin(ia * Math.PI / 180) + 30, t);- const on = onArc && t > tf ? 1 : 0; put(fg, { o: on }); put(ugh, { x: x + 60, y: y - 70, o: on, s: on });+ const on = onArc && t > tf ? 1 : 0; put(fg, { o: on }); put(ugh, { x: x - 110 * Math.cos(r), y: y - 110 * Math.sin(r) + 12, o: on, s: on }); // behind the car, clear of all three arrows}, D);}],['q4', 'Quick check', (m, D) => {diff --git a/site/science/ch10/index.html b/site/science/ch10/index.htmlindex 1113f7f..6eae1a4 100644--- a/site/science/ch10/index.html+++ b/site/science/ch10/index.html@@ -79,7 +79,7 @@ const PICS = {'p-bal': g => { phBlock(g, 260, 800, 1000, 12, PH.walk, { top: 0, ol: 0 }); [[460, 3, 3], [1060, 5, 2]].forEach(([x, a, b]) => { crate(g, { x, y: 800, w: 160, h: 130 }); forceArrow(g, { w: 12 }).set(x + 84, 730, a * 36, 0, ''); forceArrow(g, { w: 12 }).set(x - 84, 730, b * 36, 180, ''); }); },'p-first': g => { phBlock(g, 300, 800, 900, 30, '#cfe8f3', { top: 6, ol: 0 }); const k = G(g, { x: 600, y: 800 }); mk('rect', { x: -50, y: -40, width: 100, height: 40, rx: 12, fill: '#22282a' }, k); arrowAt(path(g, '', { stroke: VEL, 'stroke-width': 10 }), 660, 780, 130, 0, 22); crate(g, { x: 1000, y: 800, w: 150, h: 120 }); },'p-unit': g => { phBlock(g, 400, 800, 800, 12, PH.walk, { top: 0, ol: 0 }); crate(g, { x: 800, y: 800, w: 170, h: 140, label: '1 kg' }); forceArrow(g, { w: 14, size: 34 }).set(530, 730, 180, 0, '1 N'); forceArrow(g, { color: ACC, w: 12, size: 32 }).set(740, 620, 160, 0, '?'); },- 'p-net3': g => { phBlock(g, 300, 800, 900, 12, PH.walk, { top: 0, ol: 0 }); crate(g, { x: 700, y: 800, w: 200, h: 170 }); forceArrow(g, { w: 14, size: 34 }).set(806, 690, 6 * 36, 0, '6 N'); forceArrow(g, { w: 14, size: 34 }).set(806, 760, 4 * 36, 0, '4 N', 0, 56); forceArrow(g, { w: 14, size: 34 }).set(594, 725, 3 * 36, 180, '3 N'); },+ 'p-net3': g => { phBlock(g, 300, 800, 900, 12, PH.walk, { top: 0, ol: 0 }); crate(g, { x: 700, y: 800, w: 200, h: 170 }); forceArrow(g, { w: 14, size: 34 }).set(806, 690, 6 * 36, 0, '6 N'); forceArrow(g, { w: 14, size: 34 }).set(806, 760, 4 * 36, 0, '4 N', 'below'); forceArrow(g, { w: 14, size: 34 }).set(594, 725, 3 * 36, 180, '3 N'); },'p-second': g => { phBlock(g, 400, 800, 800, 12, PH.walk, { top: 0, ol: 0 }); crate(g, { x: 800, y: 800, w: 170, h: 140, label: 'mass' }); forceArrow(g, { w: 14, size: 32 }).set(470, 730, 240, 0, 'net force'); forceArrow(g, { color: ACC, w: 12, size: 32 }).set(720, 620, 200, 0, 'acceleration'); },'p-car': g => { mk('rect', { x: 200, y: 820, width: 1000, height: 40, fill: '#3a4541' }, g); phCar(g, { x: 700, y: 820, s: 2 }); phLabel(g, '2,000 kg', { x: 700, y: 650, size: 38 }); forceArrow(g, { color: ACC, w: 12, size: 34 }).set(600, 600, 200, 0, '3 m/s²'); },'p-third': g => { phBlock(g, 300, 800, 900, 12, PH.walk, { top: 0, ol: 0 }); crate(g, { x: 660, y: 800, w: 140, h: 120 }); crate(g, { x: 800, y: 800, w: 140, h: 120 }); forceArrow(g, { w: 12 }).set(740, 700, 120, 0, ''); forceArrow(g, { w: 12 }).set(720, 700, 120, 180, ''); },@@ -104,7 +104,7 @@ const BEATS = [clockRun(t => {put(a, { x: X(t) }); a.stride('push', (X(t) - x0) / S);const [hx, hy] = a.hand('F'); put(c, { x: hx + W / 2 - 6 });- f.set(hx, hy - 4, t < tp ? 190 : 0, 0, 'push', 0, 62);+ f.set(hx, hy - 4, t < tp ? 190 : 0, 0, 'push', 'below');}, D);thought(p, [150, 96, 910, 256], 430, ['What makes things start, stop,', 'speed up, or turn?'], m('sub')); // your thought, right above you}, { lead: false }],@@ -154,7 +154,7 @@ const BEATS = [cs._in.setAttribute('transform', crushed ? '' : `scale(${sx.toFixed(3)},${sy.toFixed(3)})`);put(cg, { y: 450 + h / 2 }); // its centre stays put while it flattensconst on = t > ts + .4 && t < ts + 2.3;- sq1.set(640, 450 - h / 2 - 150, on ? 130 : 0, 90, 'squeeze', -110, 80); sq2.set(640, 450 + h / 2 + 150, on ? 130 : 0, -90, '');+ sq1.set(640, 450 - h / 2 - 150, on ? 130 : 0, 90, 'squeeze', 'left'); sq2.set(640, 450 + h / 2 + 150, on ? 130 : 0, -90, '');}, D);}],['net', 'Net force', (m, D) => {@@ -209,7 +209,7 @@ const BEATS = [const on = t > .3;FL.set(360 + d + 60, 300, on ? 10 * U : 0, 180, '10 N'); FR.set(1240 + d - 60, 300, on ? pull * U : 0, 0, `${Math.round(pull)} N`);phText(tag, t < tb ? '' : t < tu ? 'balanced' : 'unbalanced'); put(tag, { x: mx }); put(zero, { x: mx });- NF.set(mx - 75, 715, t > tu + .9 ? 150 : 0, 0, 'net force 5 N', 0, -40); // the label clear above the arrow head+ NF.set(mx - 75, 715, t > tu + .9 ? 150 : 0, 0, 'net force 5 N');}, D);}, { lead: false }],['newton', 'The newton', (m, D) => {@@ -235,8 +235,8 @@ const BEATS = [const [hx, hy] = a.hand('F'), x = hx + 30, yh = hy + 4;const y = t < tf ? top : t < ta ? top + (yh - top) * ((t - tf) / .6) ** 2 : yh; // falls, then rests in your handput(ap, { x, y, o: t < tf ? 0 : 1 });- dn.set(x, y + 6, t > tf ? 130 : 0, 90, t > ta ? 'gravity 1 N' : '', 120, 80);- up.set(x, y - 100, t > ta ? 130 : 0, -90, 'hand 1 N', 100, 30);+ dn.set(x, y + 6, t > tf ? 130 : 0, 90, t > ta ? 'gravity 1 N' : '', 'right');+ up.set(x, y - 100, t > ta ? 130 : 0, -90, 'hand 1 N', 'right');}, D);// the definitionconst X0 = 2360, cr = crate(w, { y: Y, w: 240, h: 210, label: '1 kg' }), fp = forceArrow(w, { w: 16, size: 42 }), ac = path(w, '', { stroke: ACC, 'stroke-width': 12 });@@ -299,14 +299,14 @@ const BEATS = [// the words ride above the ballconst say = (lines, t0, t1) => { const g = G(w, { o: 0 }); lines.forEach((s, i) => phLabel(g, s, { y: i * 52, size: i ? 38 : 44, weight: i ? 600 : 700 })); show(g, t0); if (t1) hide(g, t1, .3); return g; };const s1 = say(['at rest:', 'it stays at rest'], m('stay'), tk - .4), s2 = say(['rolling, it would keep rolling…'], m('roll'), m('stop') - .2),- s3 = say(['friction from the grass and air', 'slows it and stops it'], m('stop'));+ s3 = say(['friction from the grass and air', 'slows it and stops it'], m('stop'), ts - .3); // gone before deep space fades inconst bx = t => { const u = Math.min(Math.max(0, t - tk), T0); return X0 + V0 * u - A * u * u / 2; };clockRun(t => {const x = bx(t), u = t - tk, v = u > 0 && u < T0 ? V0 - A * u : 0; // at rest until the kickput(ball, { x }); put(ball._spin, { r: (x - X0) / R * 180 / Math.PI });arrowAt(vA, x + R + 8, Y - R, v * .3, 0, 24);kick.set(X0 - R - 150, Y - R + 20, u > -.1 && u < .15 ? 140 : 0, 0, 'kick'); // the kick force only during contact- fr.set(x - R - 8, Y - 18, v > 0 && u > .3 ? 100 : 0, 180, 'friction', -20, -10); // friction only while it rolls+ fr.set(x - R - 8, Y - 18, v > 0 && u > .3 ? 100 : 0, 180, 'friction'); // friction only while it rollskid.show(u < -.55 || u > .7 ? 'stand' : 'kick', u < -.12 ? 0 : u < .12 ? 1 : 2);[s1, s2, s3].forEach(g => put(g, { x: Math.min(x, 1230), y: Y - 2 * R - 130 })); // kept inside the frame}, D);@@ -387,7 +387,9 @@ const BEATS = [const a = xw(t), b = xr(t), before = t < tHit;put(wb, { x: a, y: 450 }); put(rb, { x: b, y: 450 });arrowAt(vw, a + R + 8, 400, before ? 100 : 0, 0, 22); arrowAt(vr, b + R + 8, 400, before ? 0 : 100, 0, 22);- put(lw, { x: a, y: 540 }); phText(lw, before ? P : '0'); put(lr, { x: b, y: 540 }); phText(lr, before ? '0' : P);+ // the long label reaches away from the other ball, so it never runs into the neighbour's 0+ if (lw._b !== before) { lw._b = before; lw.setAttribute('text-anchor', before ? 'end' : 'middle'); lr.setAttribute('text-anchor', before ? 'middle' : 'start'); }+ put(lw, { x: before ? a + 30 : a, y: 540 }); phText(lw, before ? P : '0'); put(lr, { x: before ? b : b - 30, y: 540 }); phText(lr, before ? '0' : P);}, D);}, { lead: false }],['q2', 'Quick check', (m, D) => {@@ -395,7 +397,7 @@ const BEATS = [ground(p, Y);const ball = phBall(p, R, { y: Y - R }), vA = path(p, '', { stroke: VEL, 'stroke-width': 12 }), fr = forceArrow(p, { w: 14, size: 32 });clockRun(t => { const tt = Math.min(t, 3.6), x = 300 + 300 * tt - 42 * tt * tt, v = Math.max(0, 300 - 84 * t);- put(ball, { x }); put(ball._spin, { r: x / R * 180 / Math.PI }); arrowAt(vA, x + R + 8, Y - R, v * .35, 0, 24); fr.set(x - R - 8, Y - 18, v > 0 ? 90 : 0, 180, 'friction', -20, -10); }, D);+ put(ball, { x }); put(ball._spin, { r: x / R * 180 / Math.PI }); arrowAt(vA, x + R + 8, Y - R, v * .35, 0, 24); fr.set(x - R - 8, Y - 18, v > 0 ? 90 : 0, 180, 'friction'); }, D);}, { ask: done => quiz(Q_CARD, [{ id: 'c-inertia', prompt: ['A bowling ball and a soccer ball are the same size. Which has more ', h('b', '', 'inertia'), '?'],build: choice([['the bowling ball'], ['the soccer ball'], ['they have the same inertia']], 0,@@ -424,7 +426,7 @@ const BEATS = [const a = phActor(w, 'you', { y: Y, s: S, anim: 'push' }), c = phSprite(w, 'cart', { y: Y, s: 2.5 }), f = forceArrow(w, { w: 14, size: 36 }), ac = forceArrow(w, { color: ACC, w: 12, size: 34 });clockRun(t => {put(a, { x: 300 + d(t) }); a.stride('push', d(t) / S); const [hx, hy] = a.hand('F'); put(c, { x: hx + CW / 2 - 6 });- f.set(hx - 6, hy - 6, 200, 0, 'force', 0, 2); ac.set(hx + 40, hy - 120, 160, 0, 'acceleration', 0, 2);+ f.set(hx - 6, hy - 6, 200, 0, 'force'); ac.set(hx + 40, hy - 120, 160, 0, 'acceleration');}, D);opener(p, 1180, 470, 'Part 3', 'The Second Law');thought(p, [60, 70, 860, 230], 330, ['How much does a force change', 'an object’s motion?'], m('q'));@@ -473,11 +475,11 @@ const BEATS = [const u = t - t0, on = u > 0 && u < tc, d1 = dx(1000, t), d2 = dx(20, t);put(A, { x: 260 + Math.min(d1, 1000 * tc * tc / 2) }); if (on) A.stride('push', d1 / S); else A.show(u > 0 ? 'stand' : 'push', 0);const [ha, hya] = A.hand('F'), xa = xa0 + d1; put(cart, { x: xa });- f1.set(ha - 6, hya - 6, on ? 180 : 0, 0, '200 N', 0, -4); arrowAt(v1, xa + 140, LA - 220, u > tc ? 110 : 0, 0, 22);+ f1.set(ha - 6, hya - 6, on ? 180 : 0, 0, '200 N'); arrowAt(v1, xa + 140, LA - 220, u > tc ? 110 : 0, 0, 22);put(m1, { x: xa, y: LA + 50 }); // each mass tag under its objectput(B, { x: 260 + Math.min(d2, 20 * tc * tc / 2) }); if (on) B.stride('push', d2 / S); else B.show(u > 0 ? 'stand' : 'push', 0);const [hb, hyb] = B.hand('F'), xb = xb0 + d2; put(car, { x: xb }); phRoll(car, d2 / 1.6);- f2.set(hb - 6, hyb - 40, on ? 180 : 0, 0, '200 N', 0, -4); put(m2, { x: xb, y: LB + 54 });+ f2.set(hb - 6, hyb - 40, on ? 180 : 0, 0, '200 N'); put(m2, { x: xb, y: LB + 54 });}, D);}, { lead: false }],['calc', 'Net force = mass × acceleration', (m, D) => {@@ -510,9 +512,9 @@ const BEATS = [clockRun(t => {const d = xAt(t), x = 300 + d, sp = v(t), dir = t < ta - .3 ? 1 : -1, windy = t > tw1 - .3;put(bike, { x, y: ROAD.near }); bike.ride(d / 2);- vv.set(x - 80, ROAD.near - 360, sp * 30, 0, `velocity ${sp.toFixed(1)} m/s`, 0, 2);- wf.set(dir > 0 ? x - 330 : x + 330, ROAD.near - 200, windy ? 140 : 0, dir > 0 ? 0 : 180, 'wind', 0, 2);- nf.set(dir > 0 ? x - 60 : x + 100, ROAD.near + 60, windy ? 160 : 0, dir > 0 ? 0 : 180, 'net force', 0, 66);+ vv.set(x - 80, ROAD.near - 360, sp * 30, 0, `velocity ${sp.toFixed(1)} m/s`);+ wf.set(dir > 0 ? x - 330 : x + 330, ROAD.near - 200, windy ? 140 : 0, dir > 0 ? 0 : 180, 'wind');+ nf.set(dir > 0 ? x - 60 : x + 100, ROAD.near + 60, windy ? 160 : 0, dir > 0 ? 0 : 180, 'net force', 'below');phText(tag, !windy ? '' : dir > 0 ? 'same way → speed up' : 'opposite → slow down');sl.forEach((e, i) => { const yy = 200 + 70 * i, xx = ((i * 337 + 900 * t * dir) % 1800 + 1800) % 1800 - 100; e.setAttribute('d', `M${xx} ${yy}h${70 * dir}`); });}, D);@@ -579,8 +581,8 @@ const BEATS = [let bx, by;if (ts < tb) { const [hx, hy] = you.hand('F'); bx = hx + 30; by = hy; } else { bx = rx + 30 + VB * u; by = ry; } // in the hands until release, then straight onput(ball, { x: bx, y: by });- act.set(bx + R + 6, by, contact ? 120 : 0, 0, replay ? '50 N' : 'on the ball', 0, -6);- rea.set(640 - VY * u - 60, Y - 250, contact ? 120 : 0, 180, replay ? '50 N' : 'on you', 0, -6);+ act.set(bx + R + 6, by, contact ? 120 : 0, 0, replay ? '50 N' : 'on the ball');+ rea.set(640 - VY * u - 60, Y - 250, contact ? 120 : 0, 180, replay ? '50 N' : 'on you');arrowAt(vb, bx + R + 8, by - 60, u > 0 ? 110 : 0, 0, 22); arrowAt(vy, 640 - VY * u - 40, Y - 330, u > 0 ? 44 : 0, 180, 16); // velocities after release}, D);}, { lead: false }],@@ -656,7 +658,7 @@ const BEATS = [};clockRun(t => {const j = jump(t); put(you, { y: j.y }); you.show(j.pose);- dn.set(870, G0 - 20, j.push ? 120 : 0, 90, 'you push Earth: 500 N', 150, 80); up.set(730, G0 + 120, j.push ? 120 : 0, -90, 'Earth pushes you: 500 N', -170, 30);+ dn.set(870, G0 - 20, j.push ? 120 : 0, 90, 'you push Earth: 500 N', 'right'); up.set(730, G0 + 120, j.push ? 120 : 0, -90, 'Earth pushes you: 500 N', 'left');}, D);}, { lead: false }],['q4', 'Quick check', (m, D) => {diff --git a/site/science/ch11/index.html b/site/science/ch11/index.htmlindex 7ac3b83..fcbfae7 100644--- a/site/science/ch11/index.html+++ b/site/science/ch11/index.html@@ -151,7 +151,7 @@ function whirl(p, cx, cy, R, P, { release = Infinity, pull = Infinity } = {}) {str.setAttribute('d', u > 0 ? `M${hx} ${hy}l${(R - 60) * .5 * Math.cos(q + .5)} ${(R - 60) * .5 * Math.sin(q + .5)}` : `M${hx} ${hy}L${x} ${y}`);trail.setAttribute('d', u > 0 ? `M${x0} ${y0}L${x} ${y}` : '');v.set(x + 30 * ux, y + 30 * uy, 120, Math.atan2(uy, ux) * 57.3, '');- f.set(x - 30 * Math.cos(q), y - 30 * Math.sin(q), t > pull && u === 0 ? 110 : 0, q * 57.3 + 180, t > pull + 3 ? '' : 'string pull', 0, 0);+ f.set(x - 30 * Math.cos(q), y - 30 * Math.sin(q), t > pull && u === 0 ? 110 : 0, q * 57.3 + 180, t > pull + 3 ? '' : 'string pull', [-ux, -uy]); // label trails behind, away from the velocity arrow} };}// A tub of water seen from the side, centred on x, water surface at y, w wide, depth d.@@ -195,7 +195,7 @@ const BEATS = [const y = t < tf ? top : t < tl ? top + G_PX * (t - tf) ** 2 / 2 : rest, absorb = t > tl && t < tl + .3;a.show(t < tf - .5 ? 'stand' : 'catch', absorb ? 1 : 0);const [hx2, hy2] = a.hand('F'); put(ap, { x: t < tl ? x : hx2 + 22, y: t < tl ? y : hy2 + 6 });- gv.set(x + 70, (t < tl ? y : hy2 + 6) - 40, t > tf ? 110 : 0, 90, t < tl + 1 ? 'gravity' : '', 70, 60);+ gv.set(x + 70, (t < tl ? y : hy2 + 6) - 40, t > tf ? 110 : 0, 90, t < tl + 1 ? 'gravity' : '', 'right');up.set(x - 70, hy2 + 70, t > tl ? 110 : 0, -90, '');}, D);const ttl = G(p, { o: 0, y: 24 });@@ -220,7 +220,7 @@ const BEATS = [clockRun(t => {const d = dAt(t)[0], xa = 800 - d / 2, xb = 800 + d / 2, L = t > tp - .1 ? 70 * (d0 / d) ** 2 : 0; // ≤ 210 px: never reaches the other rockput(A, { x: xa, y: Y }); put(B, { x: xb, y: Y });- fa.set(xa + 60, Y - 24, L, 0, 'pull', 0, -10); fb.set(xb - 60, Y + 24, L, 180, 'pull', 0, 76); // equal pulls, one above, one below+ fa.set(xa + 60, Y - 24, L, 0, 'pull'); fb.set(xb - 60, Y + 24, L, 180, 'pull', 'below'); // equal pulls, one above, one below}, D);}, { lead: false }],['strength', 'Mass and distance', (m, D) => {@@ -237,17 +237,17 @@ const BEATS = [}, [cx - b, -40, 0, V], 0, D);const moon = pixDisc(p, 44, { base: '#a7a59c', craters: 3, seed: 3, o: { x: 520, y: cy } });const planet = pixDisc(p, 120, { base: '#c98a5a', craters: 0, seed: 5, o: { x: 1340, y: cy } });- phLabel(p, 'small moon', { x: 520, y: cy - 80, size: 34 }); phLabel(p, 'planet: much more mass', { x: 1340, y: cy - 156, size: 34 });- const passes = [[520, 2.5e6, 260, ts, COL.dim, 'bends a little'], [1340, 1e7, 260, tb, COL.chalk, 'bends a lot'], [1340, 1e7, 460, tf, COL.int, 'farther: bends less']].map(([cx, GM, b, t0, col, verdict]) => {+ phLabel(p, 'small moon', { x: 520, y: cy - 80, size: 34 }); phLabel(p, 'planet: much more mass', { x: 1190, y: cy - 156, size: 34, anchor: 'start' }); // right of the path in, so the passing rock's pull arrow stays clear+ const passes = [[520, 2.5e6, 260, ts, COL.dim, 'bends a little'], [1340, 1e7, 260, tb, COL.chalk, 'bends a lot'], [1340, 1e7, 460, tf, COL.int, 'bends less']].map(([cx, GM, b, t0, col, verdict]) => {const at = fly(cx, GM, b, t0), trail = path(p, '', { stroke: col, 'stroke-width': 4, 'stroke-dasharray': '10 10', opacity: .8 });const rock = pixDisc(p, 30, { c: 6, base: '#cfc6b2', seed: b, lump: 1 }), f = forceArrow(p, { w: 12, size: 28 });const pts = []; for (let u = t0; u < D; u += 1 / 30) pts.push(at(u));const end = pts.find(([x, y]) => y > 840 || x > 1580 || x < 20) || pts[pts.length - 1];- const vl = phLabel(p, verdict, { x: Math.min(1460, Math.max(140, end[0])), y: 870, size: 32, fill: col, o: 0 }); show(vl, t0 + 2.6);+ const vl = phLabel(p, verdict, { x: end[0] + 30, y: 870, size: 32, fill: col, anchor: 'start', o: 0 }); show(vl, t0 + 2.6); // beside where its trail leaves, not on itreturn { cx, GM, t0, at, trail, rock, f, pts };});const same = phLabel(p, 'same speed, same distance', { x: 800, y: 60, size: 34, fill: COL.dim, weight: 600, o: 0 }); show(same, tb + .3); hide(same, tf - .3, .3);- const farL = phLabel(p, 'same planet, passing farther away', { x: 1200, y: 60, size: 34, fill: COL.int, weight: 600, o: 0 }); show(farL, tf + .1);+ const farL = G(p, { o: 0 }); phLabel(farL, 'same planet,', { x: 1290, y: 60, size: 34, fill: COL.int, weight: 600 }); phLabel(farL, 'passing farther away', { x: 1290, y: 104, size: 34, fill: COL.int, weight: 600 }); show(farL, tf + .1); // right of both trailsclockRun(t => passes.forEach(({ cx, GM, t0, at, trail, rock, f, pts }) => {const on = t >= t0, [x, y] = at(t), dx = cx - x, dy = cy - y, r = Math.hypot(dx, dy), vis = on && y < 940 && x < 1620;put(rock, { x, y, o: vis ? 1 : 0 });@@ -268,7 +268,7 @@ const BEATS = [show(ring, tt); show(tl, tt + .3);const ef = forceArrow(p, { w: 18, size: 36 }), el = G(p, { o: 0 });phLabel(el, 'Earth pulls you:', { y: 0, size: 34, fill: FORCE, anchor: 'start' }); phLabel(el, 'about 500 N', { y: 46, size: 44, fill: FORCE, anchor: 'start' }); show(el, te + .3);- txt(p, 'Earth’s pull is about 5 million times stronger', 560, 860, te + 4, { size: 34, weight: 600 });+ txt(p, 'Earth’s pull is about 5 million times stronger', 560, 180, te + 4, { size: 34, weight: 600 }); // up in the empty sky: Earth's arrow runs to the bottom edgeclockRun(t => {const x = X(t); put(a, { x }); if (t > tw0) a.stride('walk', (x - x0) / S2); else a.show('stand');const cx = x + 8, cyy = Y - 150;@@ -287,11 +287,11 @@ const BEATS = [mk('circle', { cx, cy, r: R, fill: 'none', stroke: COL.faint, 'stroke-width': 2, 'stroke-dasharray': '4 10' }, p);const sun = phSun(p, { x: cx, y: cy, r: 84 }), small = [[150, 4.1, '#b8a48c', 10], [230, 2.4, '#e2b86a', 14]].map(([r, k, col, s]) => [r, k, mk('circle', { r: s, fill: col, ...phLine(2) }, p)]);const earth = phEarthSmall(p, { r: 38 }), g = forceArrow(p, { w: 14, size: 34 }), vv = forceArrow(p, { color: VEL, w: 12, size: 34 });- const ghost = path(p, '', { stroke: COL.chalk, 'stroke-width': 4, 'stroke-dasharray': '14 12' }, { o: 0 }), gl = phLabel(p, 'with no gravity: a straight line', { size: 32, weight: 600, o: 0 });+ const ghost = path(p, '', { stroke: COL.chalk, 'stroke-width': 4, 'stroke-dasharray': '14 12' }, { o: 0 }), gl = G(p, { o: 0 }); phLabel(gl, 'with no gravity:', { size: 32, weight: 600, anchor: 'end' }); phLabel(gl, 'a straight line', { y: 40, size: 32, weight: 600, anchor: 'end' });const ang = t => -Math.PI / 2 - W * t; // counterclockwise on screen, starting at the topconst tg = tb + 2.2, ag = ang(tg), gx = cx + R * Math.cos(ag), gy = cy + R * Math.sin(ag), ux = Math.sin(ag), uy = -Math.cos(ag); // tangent (direction of motion)ghost.setAttribute('d', `M${gx} ${gy}L${gx + 900 * ux} ${gy + 900 * uy}`);- tw(ghost, { o: .8 }, tg, .4); put(gl, { x: gx + 420 * ux + 150, y: gy + 420 * uy }); show(gl, tg + .3);+ tw(ghost, { o: .8 }, tg, .4); put(gl, { x: gx + 110 * ux - 34, y: gy + 110 * uy }); show(gl, tg + .3); // outside the orbit, left of the line: Earth and its arrows never pass thereconst t1 = G(p, { o: 0 }); phLabel(t1, 'The Sun’s gravity pulls on every planet', { x: 800, y: 70, size: 42 }); show(t1, tp); hide(t1, ts - .3, .3);const t2 = G(p, { o: 0 }); phLabel(t2, 'Earth also moves sideways, very fast', { x: 800, y: 70, size: 42, fill: VEL }); show(t2, ts + .2); hide(t2, tb - .3, .3);const t3 = G(p, { o: 0 }); phLabel(t3, 'Gravity keeps bending its path into an orbit', { x: 800, y: 70, size: 42 }); show(t3, tb + .2);@@ -300,7 +300,7 @@ const BEATS = [small.forEach(([r, k, e]) => { const q = -Math.PI / 2 + 1 - W * k * t; e.setAttribute('cx', cx + r * Math.cos(q)); e.setAttribute('cy', cy + r * Math.sin(q)); });const q = ang(t), x = cx + R * Math.cos(q), y = cy + R * Math.sin(q);put(earth, { x, y });- g.set(x - 46 * Math.cos(q), y - 46 * Math.sin(q), t > tp ? 120 : 0, q * 180 / Math.PI + 180, 'gravity', -56 * Math.sin(q), 56 * Math.cos(q) + 12); // label on the side away from the velocity+ g.set(x - 46 * Math.cos(q), y - 46 * Math.sin(q), t > tp ? 120 : 0, q * 180 / Math.PI + 180, 'gravity', [-Math.sin(q), Math.cos(q)]); // label on the side away from the velocityvv.set(x + 46 * Math.sin(q), y - 46 * Math.cos(q), t > ts ? 140 : 0, q * 180 / Math.PI - 90, '');}, D);}, { lead: false }],@@ -311,7 +311,7 @@ const BEATS = [phBlock(p, 300, 60, 1000, 26, '#7d6a5a', { top: 4, ol: 0 });const def = G(p, { o: 0 }); phLabel(def, 'Weight', { x: 220, y: 300, size: 72 }); phLabel(def, 'the force of gravity', { x: 220, y: 360, size: 36, weight: 600 }); phLabel(def, 'on an object', { x: 220, y: 404, size: 36, weight: 600 }); show(def, .3);const rows = [[620, 5, 140, 110, th], [1080, 10, 180, 140, tm]].map(([x, kg, w, h, t0]) => {- const sc = springScale(p, { x, y0: 86, ppn: PPN }), box = crate(p, { w, h, label: `${kg} kg` }), W8 = kg * 9.8;+ const sc = springScale(p, { x, y0: 86, ppn: PPN }), box = crate(p, { w, h, label: `${kg} kg`, labelY: -h + 36 }), W8 = kg * 9.8; // the tag above the centre, where the weight arrow startsconst wf = forceArrow(p, { w: 14, size: 32 }), rd = phLabel(p, '', { size: 36, fill: FORCE, anchor: 'start' });put(box, { o: 0 }); show(box, t0 - .5, .4);return { x, sc, box, wf, rd, W8, t0, h };@@ -320,7 +320,7 @@ const BEATS = [clockRun(t => rows.forEach(({ x, sc, box, wf, rd, W8, t0, h }) => {const u = t - t0, F = u < 0 ? 0 : W8 * (1 - Math.exp(-1.6 * u) * Math.cos(9 * u)); // let go at rest: ring, then settleconst yb = sc.set(F); put(box, { x, y: yb + h });- wf.set(x + 10, yb + h / 2 + 10, u > 0 ? W8 * WPX : 0, 90, '', 0, 0);+ wf.set(x - 7, yb + h / 2, u > 0 ? W8 * WPX : 0, 90, ''); // from the centre (where the planks cross), downphText(rd, u > 1.4 ? `weight ≈ ${Math.round(W8)} N` : ''); put(rd, { x: x + 40, y: yb + h + 50 });}), D);}, { lead: false }],@@ -373,7 +373,7 @@ const BEATS = [if (t < ts - .6) a.show('toss', 0); else if (t < ts) a.show('toss', 1 + ramp(t, ts - .6, ts - .1)); else a.show('toss', 2);const [hx, hy] = a.hand('F'), by = flying ? y : hy - 10; put(ball, { x: hx + 6, y: by });vA.set(hx + 60, by, Math.abs(v) * 9, v >= 0 ? -90 : 90, '');- gA.set(hx - 50, by, flying ? 90 : 0, 90, flying ? 'gravity' : '', -70, 50);+ gA.set(hx - 50, by, flying ? 90 : 0, 90, flying ? 'gravity' : '', 'left');phText(vl, flying ? `${Math.abs(v).toFixed(1)} m/s` : ''); put(vl, { x: hx + 90, y: by + 12 });clk.set(s);}, D);@@ -418,7 +418,7 @@ const BEATS = [const x = sl.x(t), v = sl.v(t), pushing = t > tp - .3 && t < tp + .3;put(a, { x: 220 + (pushing ? 60 * ramp(t, tp - .3, tp + .3) : t > tp ? 60 : 0) }); a.show(t < tp + .5 ? 'push' : 'stand', 0);put(nb, { x, y: tab });- fr.set(x - 20, tab - 8, v > 0 && t > tp + .3 ? 120 : 0, 180, 'friction', -30, 62); vA.set(x + 160, tab - 80, v * .25, 0, '');+ fr.set(x - 20, tab - 8, v > 0 && t > tp + .3 ? 120 : 0, 180, 'friction', 'below'); vA.set(x + 160, tab - 80, v * .25, 0, '');}, D);opener(p, 1180, 400, 'Part 2', 'Friction');thought(p, [100, 40, 960, 200], 270, ['If nothing pushes back, why does', 'a sliding notebook stop?'], m('q'));@@ -439,7 +439,7 @@ const BEATS = [const x = sl.x(t), v = sl.v(t), pushing = t > ts && t < tp + .3;put(a, { x: 220 + (pushing ? 60 * ramp(t, ts, tp + .3) : t > tp ? 60 : 0) }); a.show(t > ts - .6 && t < tp + .5 ? 'push' : 'stand', 0);put(nb, { x, y: tab });- fr.set(x - 20, tab - 8, v > 0 && t > tp + .3 ? 120 : 0, 180, t > tf ? 'friction' : '', -30, 62); vA.set(x + 160, tab - 80, v * .25, 0, '');+ fr.set(x - 20, tab - 8, v > 0 && t > tp + .3 ? 120 : 0, 180, t > tf ? 'friction' : '', 'below'); vA.set(x + 160, tab - 80, v * .25, 0, '');}, D);// up close: a boxed camera on two bumpy surfaces (the cover above, the table below)const box = [880, 60, 640, 360], cam = camera(p, D, { box, x: 800, y: 450, z: 1 }), w = cam.world;@@ -495,13 +495,13 @@ const BEATS = [clockRun(t => {a.show(t < tr ? 'catch' : 'stand', 0);const yb = t < tr ? hy + 4 : t < tb ? hy + 4 + G_PX * (t - tr) ** 2 / 2 : Y - 22;- put(ball, { x: bx, y: yb }); bg.set(bx - 50, yb - 10, t > tr && t < tb ? 100 : 0, 90, 'gravity', -64, 50);+ put(ball, { x: bx, y: yb }); bg.set(bx - 50, yb - 10, t > tr && t < tb ? 100 : 0, 90, 'gravity', 'left');const u = Math.max(0, Math.min(t, tl) - tr), yf = hy - 8 + VF * u, sway = 60 * Math.sin(u * 2.2), tilt = 18 * Math.cos(u * 2.2);put(fe, { x: fx0 + sway, y: yf, r: t > tr && t < tl ? tilt : 0 });const falling = t > tr && t < tl, fxx = fx0 + sway;- fg.set(fxx + 30, yf + 6, falling ? 60 : 0, 90, ''); fa.set(fxx - 30, yf - 20, falling ? 60 : 0, -90, t > tfe ? 'air resistance' : '', 190, 40);+ fg.set(fxx + 30, yf + 6, falling ? 60 : 0, 90, ''); fa.set(fxx - 30, yf - 20, falling ? 60 : 0, -90, t > tfe ? 'air resistance' : '', 'right');}, D);- txt(p, 'the ball falls fast', bx + 160, Y - 40, tr + 1.4, { size: 32, weight: 600, anchor: 'start' });+ txt(p, 'the ball falls fast', bx + 340, Y - 40, tr + 1.4, { size: 32, weight: 600, anchor: 'start' }); // past the feather's swaying air-resistance label}, { lead: false }],['kinds', 'Static, sliding, rolling', (m, D) => {const p = panel(0), Y = Y1, S3 = 3, ts = m('static'), tfr = m('free'), tr = m('roll'), CW = 300, CH = 260;@@ -523,8 +523,8 @@ const BEATS = [put(a, { x: off + d + strain }); if (d > 0) a.stride('push', d / S3); else a.show('push', 0);const [hx, hy] = a.hand('F'), cx = 800 + d; put(cr, { x: cx, y: Y });const P = push(t), Fr = t < tfr ? P : 150;- pf.set(hx - 4, hy - 30, t > ts ? P * U : 0, 0, 'push', 0, -6);- ff.set(cx + 40, Y - 24, t > ts ? Fr * U : 0, 180, t < tfr ? 'static friction' : 'sliding friction', 0, 74);+ pf.set(hx - 4, hy - 30, t > ts ? P * U : 0, 0, 'push');+ ff.set(cx + 40, Y - 24, t > ts ? Fr * U : 0, 180, t < tfr ? 'static friction' : 'sliding friction', 'below');put(umph, { x: cx, y: Y - CH - 50 });}, D);tw(cam.el, { o: 0 }, tr - .1, .4);@@ -540,7 +540,7 @@ const BEATS = [b.show('push', 0); put(b, { x: 0 }); const off2 = 800 - CW / 2 - 10 - b.hand('F')[0] + 6;clockRun(t => {const x = R2(t), d = x - 800; put(b, { x: off2 + d }); b.stride('push', d / S3); put(dolly, { x, y: Y }); wh.forEach(g => put(g, { r: d / 24 * 180 / Math.PI }));- const [hx, hy] = b.hand('F'); rp.set(hx - 4, hy - 60, 30 * U * 1.6, 0, 'push', 0, -6); rf.set(x + 40, Y - 30, 30 * U * 1.6, 180, 'rolling friction', 0, 74);+ const [hx, hy] = b.hand('F'); rp.set(hx - 4, hy - 60, 30 * U * 1.6, 0, 'push'); rf.set(x + 40, Y - 30, 30 * U * 1.6, 180, 'rolling friction', 'below');}, D);// the three frictions compared, kept on screen[['static friction', 220, ts + 1, 70], ['sliding friction', 150, tfr + .6, 120], ['rolling friction', 30, tr + .8, 170]].forEach(([s, L, t0, y]) => {@@ -579,7 +579,7 @@ const BEATS = [const [hx, hy] = a.hand('F'), [bx, by] = a.hand('B');lines.setAttribute('d', t > tc + .3 ? `M${DX - 190 * (.1 + .9 * open)} ${DY - 330}L${bx} ${by}M${DX + 190 * (.1 + .9 * open)} ${DY - 330}L${hx} ${hy}` : '');put(a, { r: t < t0 ? 0 : 0 });- gw.set(DX - 130, DY - 190, t > t0 ? 90 : 0, 90, 'gravity', -70, 50); ga.set(DX + 150, DY - 190, t > t0 ? 90 * D2 : 0, -90, t > t0 + .5 ? 'air resistance' : '', 120, 40);+ gw.set(DX - 130, DY - 190, t > t0 ? 90 : 0, 90, 'gravity', 'left'); ga.set(DX + 150, DY - 190, t > t0 ? 90 * D2 : 0, -90, t > t0 + .5 ? 'air resistance' : '', 'right');phText(spd, `speed ${Math.round(v)} m/s`);const n = Math.floor(t * 10);if (curve._n !== n) { curve._n = n; let d = ''; for (let i = 0; i <= n; i++) { const u = i / 10; d += `${i ? 'L' : 'M'}${gx(u).toFixed(1)} ${gy(st(u)[0]).toFixed(1)}`; } curve.setAttribute('d', d); }@@ -594,7 +594,7 @@ const BEATS = [mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: '#4f7f9c' }, p);const cl = Array.from({ length: 6 }, (_, i) => { const c = G(p); [[0, 0, 160, 30], [30, -24, 90, 26]].forEach(([x, y, w2, h]) => mk('rect', { x, y, width: w2, height: h, fill: '#e9f1f4', opacity: .85 }, c)); return [c, 1600 * phHash(i, 51), 900 * phHash(i, 52)]; });const a = phActor(p, 'you', { x: DX, y: DY, s: 2, anim: 'jump' });- forceArrow(p, { w: 14, size: 30 }).set(DX - 110, DY - 150, 90, 90, 'gravity', -70, 50); forceArrow(p, { w: 14, size: 30 }).set(DX + 130, DY - 150, 90, -90, 'air resistance', 120, 40);+ forceArrow(p, { w: 14, size: 30 }).set(DX - 110, DY - 150, 90, 90, 'gravity', 'left'); forceArrow(p, { w: 14, size: 30 }).set(DX + 130, DY - 150, 90, -90, 'air resistance', 'right');clockRun(t => cl.forEach(([c, x, y0]) => put(c, { x, y: ((y0 - t * 600) % 900 + 900) % 900 - 60 })), D);}, { ask: done => quiz(Q_CARD, [{ id: 'c-rough', prompt: ['A hockey puck slides much farther on ice than on a carpet. Why?'],@@ -705,14 +705,15 @@ const BEATS = [sA.setAttribute('d', `M${PX0} ${PY}L${ax + wob} ${ay - RB}`); sB.setAttribute('d', `M${PX1} ${PY}L${bx + wob} ${by - RB}`);const n = Math.round(Q * 4); if (n !== nA) { nA = n; marks(bA._m, n, '−', COL.nat); marks(bB._m, n, '−', COL.nat); }if (n !== nP) { nP = n; marks(plus, Math.min(n, 3), '+', COL.irr); }- put(plus, { x: hX, y: headY - 40, o: t > tr ? 1 : 0 });// standing hair: strands lean toward the balloon, longer when the pull is strongerconst lift = near ? Math.min(1, attr) : 0, toward = Math.atan2(by - headY, bx - hX);strands.forEach((e, i) => { const len = 20 + 90 * lift, an = (-Math.PI / 2) * (1 - lift) + toward * lift + (i - 2) * .12, sx = hX - 20 + i * 10;e.setAttribute('d', lift > .02 ? `M${sx} ${headY + 8}l${(len * Math.cos(an)).toFixed(1)} ${(len * Math.sin(an)).toFixed(1)}` : ''); });fA.set(ax - RB - 6, ay, !under(t) && rep > .5 ? 90 : 0, 180, ''); fB.set(bx + RB + 6, by, !under(t) && rep > .5 ? 90 : 0, 0, ''); // the balloons push each other apartconst toHead = Math.atan2(headY - by, hX - bx);- fH.set(bx + (RB + 8) * Math.cos(toHead), by + (RB + 8) * Math.sin(toHead), near && lift > .1 ? 50 + 90 * lift : 0, toHead * 57.3, ''); // and your hair pulls the right one+ const sp = Math.min(1, lift / .1); // on the hair; once the pull arrow appears, beside the hair, square to the pull, clear of the arrow+ put(plus, { x: hX - 72 * sp * Math.sin(toHead), y: headY + 12 + sp * (72 * Math.cos(toHead) - 22), o: t > tr ? 1 : 0 });+ fH.set(bx + (RB + 14) * Math.cos(toHead), by + (RB + 14) * Math.sin(toHead), near && lift > .1 ? 40 + 60 * lift : 0, toHead * 57.3, ''); // and your hair pulls the right one}, D);}, { lead: false }],['electromagnet', 'Electromagnets', (m, D) => {@@ -729,7 +730,7 @@ const BEATS = [const midW = G(p); path(midW, mid, { stroke: '#c98a3a', 'stroke-width': 10 }); hide(midW, tc + .3, .5);const cur = path(p, circ, { stroke: COL.int, 'stroke-width': 6, fill: 'none', 'stroke-dasharray': '6 34' }), curM = path(midW, mid, { stroke: COL.int, 'stroke-width': 6, 'stroke-dasharray': '6 34' });const bat = G(p, { x: 650, y: BY }), batIn = G(bat); phBlock(batIn, -130, -45, 260, 90, '#3a4541', { top: 0, ol: 2.5 }); phBlock(batIn, 70, -45, 60, 90, '#c0504d', { top: 0, ol: 0 }); mk('rect', { x: 130, y: -16, width: 14, height: 32, fill: '#9aa5a8' }, batIn);- phLabel(batIn, '+', { x: 100, y: 14, size: 40 }); phLabel(batIn, '−', { x: -100, y: 14, size: 40 }); phLabel(bat, 'battery', { y: 92, size: 30, fill: COL.dim, weight: 600 });+ phLabel(batIn, '+', { x: 100, y: 14, size: 40 }); phLabel(batIn, '−', { x: -100, y: 14, size: 40 }); const batL = phLabel(bat, 'battery', { y: 92, size: 30, fill: COL.dim, weight: 600 });const lever = path(p, '', { stroke: '#c98a3a', 'stroke-width': 10, 'stroke-linecap': 'round' }); mk('circle', { cx: 920, cy: BY, r: 9, fill: COL.chalk }, p); mk('circle', { cx: 1000, cy: BY, r: 9, fill: COL.chalk }, p);const swl = phLabel(p, '', { x: 960, y: BY + 70, size: 30, fill: COL.dim, weight: 600 });const rings = G(p, { o: 0 }), ringEls = [560, 760, 960, 1160].map(x => mk('ellipse', { cx: x, cy: WY, rx: 22, ry: 62, fill: 'none', stroke: COL.irr, 'stroke-width': 4, 'stroke-dasharray': '10 8' }, rings));@@ -752,7 +753,7 @@ const BEATS = [cur.setAttribute('stroke-dashoffset', (-flowAt(t)).toFixed(1)); put(cur, { o: on ? 1 : 0 }); curM.setAttribute('stroke-dashoffset', (-flowAt(t) - 280).toFixed(1)); put(curM, { o: on ? 1 : 0 });lever.setAttribute('d', on ? `M920 ${BY}L1000 ${BY}` : `M920 ${BY}L983 ${BY - 50}`); phText(swl, on ? 'switch on' : 'switch off');ringEls.forEach(e => e.setAttribute('stroke-dashoffset', (-flowAt(t) * .4).toFixed(1)));- put(batIn, { r: 180 * ramp(t, tf, tf + .6) });+ const k = ramp(t, tf, tf + .6); put(batIn, { r: 180 * k }); put(batL, { o: Math.max(0, 3 * Math.abs(1 - 2 * k) - 2) }); // the label steps aside while the battery swings through itconst d = dir(t); phText(nS, mag ? (d > 0 ? 'S' : 'N') : ''); phText(nN, mag ? (d > 0 ? 'N' : 'S') : '');nS.setAttribute('fill', d > 0 ? POLE_S : POLE_N); nN.setAttribute('fill', d > 0 ? POLE_N : POLE_S);put(needle, { r: !mag ? 0 : d > 0 ? 90 : -90 }); // north end away from the north pole@@ -808,7 +809,7 @@ const BEATS = [// tangent in a straight line. From "moon": Earth and the Moon, where gravity is the centripetal force.const s1 = G(p), w = whirl(s1, cx, cy, R, P, { release: tg, pull: tc - .1 });const snap = G(s1, { o: 0 }); for (let k = 0; k < 8; k++) { const q = k * Math.PI / 4, x = cx + R * Math.cos(q), y = cy + R * Math.sin(q); arrowAt(path(snap, '', { stroke: VEL, 'stroke-width': 6, opacity: .35 }), x, y, 80, q * 57.3 + 90, 14); }- show(snap, 3.4);+ show(snap, 3.4); hide(snap, tc - .4, .3); show(snap, tc + 3, .4); // the faint copies step back while 'string pull' rides past themconst t1 = G(s1, { o: 0 }); phLabel(t1, 'same speed, but the direction keeps changing:', { x: 800, y: 70, size: 40 }); phLabel(t1, 'the velocity changes, so it is accelerating', { x: 800, y: 122, size: 36, fill: VEL, weight: 600 }); show(t1, 2.4); hide(t1, tc - .3, .3);const t2 = G(s1, { o: 0 }); phLabel(t2, 'Centripetal force', { x: 800, y: 80, size: 60, fill: FORCE }); phLabel(t2, 'always points toward the center of the circle', { x: 800, y: 132, size: 36, weight: 600 }); show(t2, tc + .2); hide(t2, tg - .3, .3);const t3 = G(s1, { o: 0 }); phLabel(t3, 'Let go: no pull, so it goes straight', { x: 800, y: 80, size: 50 }); show(t3, tg + .2);@@ -822,7 +823,7 @@ const BEATS = [clockRun(t => {w.at(t);const q = -Math.PI / 2 - (t - tm) * 2 * Math.PI / 12, x = cx + 320 * Math.cos(q), y = cy + 320 * Math.sin(q); // counterclockwise, seen from above the North Pole- put(moon, { x, y }); mg.set(x - 44 * Math.cos(q), y - 44 * Math.sin(q), 110, q * 57.3 + 180, 'gravity', 50 * Math.sin(q), -50 * Math.cos(q) + 10);+ put(moon, { x, y }); mg.set(x - 44 * Math.cos(q), y - 44 * Math.sin(q), 110, q * 57.3 + 180, 'gravity', [Math.sin(q), -Math.cos(q)]);mv.set(x + 44 * Math.sin(q), y - 44 * Math.cos(q), 110, q * 57.3 - 90, '');}, D);}, { lead: false }],@@ -842,7 +843,7 @@ const BEATS = [clockRun(t => {const bob = 4 * Math.sin(t * 2.4), dy = WL + sub + bob;put(duck, { x: 700, y: dy });- wA.set(760, dy - 160, t > tu ? 120 : 0, 90, 'weight', 80, 40); bA.set(640, dy + 30, t > tu ? 120 : 0, -90, 'buoyant force', -150, 70);+ wA.set(760, dy - 160, t > tu ? 120 : 0, 90, 'weight', 'right'); bA.set(640, dy + 30, t > tu ? 120 : 0, -90, 'buoyant force', 'left');const k = ramp(t, ta + .6, ta + 2.2); put(ghost, { x: 700 + 600 * k * k * (3 - 2 * k) / 1, y: WL + sub - 150 * Math.sin(Math.PI * k) * (k < 1 ? 1 : 0) + bob * (1 - k) });}, D);hide(s1, tr - .4, .4);@@ -876,7 +877,7 @@ const BEATS = [stream.setAttribute('d', f > .01 && f < .99 && t > tdp ? `M${CX + CW / 2 + 80} ${cb - CH + 55}Q${cupX - 40} ${cb - CH + 60} ${cupX - 30} ${CB0 - wl}` : '');phText(cupL, f > .98 ? '3 N of water' : '');const sy = top + SH / 2;- wF.set(CX + 120, sy - 20, 5 * NPX, 90, '5 N', 50, 40); bF.set(CX - 120, sy + 40, 3 * f * NPX, -90, f > .3 ? `${(3 * f).toFixed(1)} N` : '', -60, 40);+ wF.set(CX + 120, sy - 20, 5 * NPX, 90, '5 N', 'right'); bF.set(CX - 120, sy + 40, 3 * f * NPX, -90, f > .3 ? `${(3 * f).toFixed(1)} N` : '', 'left');}, D);}, { lead: false }],['float', 'Float or sink', (m, D) => {@@ -904,10 +905,10 @@ const BEATS = [clockRun(t => {const [y1] = wy(t), [y2] = sy(t), f1 = Math.min(1, Math.max(0, (y1 - WT) / WH)), f2 = Math.min(1, Math.max(0, (y2 - WT) / SH));put(wood, { x: 480, y: y1, o: t > tw0 - .3 ? 1 : 0 }); put(stone, { x: 1120, y: y2, o: t > ts - .3 ? 1 : 0 });- ww.set(570, y1 - WH / 2, t > tw0 + .3 ? U : 0, 90, 'weight', 70, 40); wb.set(400, y1, f1 > .02 ? U * f1 / .6 : 0, -90, f1 > .3 ? 'buoyant force' : '', -150, 60);+ ww.set(570, y1 - WH / 2, t > tw0 + .3 ? U : 0, 90, 'weight', 'right'); wb.set(400, y1, f1 > .02 ? U * f1 / .6 : 0, -90, f1 > .3 ? 'buoyant force' : '', 'left');const Ws = 1.6 * U, Bs = Ws * f2 / 2.5, onFloor = y2 >= BOT - .5;- sw.set(1210, y2 - SH / 2, t > ts + .3 ? Ws : 0, 90, 'weight', 70, 40); sb.set(1030, y2 - 10, f2 > .02 ? Bs : 0, -90, f2 > .3 ? 'buoyant force' : '', -150, 60);- sf.set(1120, BOT + 60, onFloor ? Ws - Bs : 0, -90, 'floor', -60, 60);+ sw.set(1210, y2 - SH / 2, t > ts + .3 ? Ws : 0, 90, 'weight', 'right'); sb.set(1030, y2 - 10, f2 > .02 ? Bs : 0, -90, f2 > .3 ? 'buoyant force' : '', 'left');+ sf.set(1120, BOT + 60, onFloor ? Ws - Bs : 0, -90, 'floor', 'left');}, D);}, { lead: false }],['q4', 'Quick check', (m, D) => {diff --git a/site/science/lib/physics.js b/site/science/lib/physics.jsindex 1e64f6e..441c5e3 100644--- a/site/science/lib/physics.js+++ b/site/science/lib/physics.js@@ -46,24 +46,46 @@ function arrowAt(el, x, y, len, a, head = 18) {}const ACC = '#ee6fd0'; // acceleration: magenta (velocity stays yellow)const FORCE = '#ff7a45', NETF = COL.chalk; // forces: orange arrows; the net force: a thick white arrow-// A labelled force arrow: f.set(x, y, len, angle, text, dx, dy) draws it from (x, y); the label sits above its middle-// (shifted by dx, dy). len 0 hides it.+// Where a label goes for the arrow from (x, y), len long at angle ang: the baseline point of a middle-anchored label+// whose ink box clears the shaft (and the head, when the label reaches it) by 12 px at any angle. side picks the+// shaft's 'above' / 'below' / 'left' / 'right' side (default: above, or right of a near-vertical arrow), the side a+// direction [dx, dy] points to, or 'tip' to put it just past the head.+const LABW = new Map();+function arrowLabelAt(x, y, len, ang, str, size, w, side) {+ const key = size + str; let tw = LABW.get(key);+ if (tw === undefined) { ctx2d.font = `700 ${size}px ${UI}`; LABW.set(key, tw = ctx2d.measureText(str).width / 2); }+ const r = ang * Math.PI / 180, c = Math.cos(r), s = Math.sin(r), th = .44 * size, head = 12 + w;+ let bx, by, nx, ny, clear;+ if (side === 'tip') { bx = x + len * c; by = y + len * s; nx = c; ny = s; clear = 12; }+ else {+ const [px, py] = Array.isArray(side) ? side : { above: [0, -1], below: [0, 1], left: [-1, 0], right: [1, 0] }[side] || (Math.abs(c) > .3 ? [0, -1] : [1, 0]);+ const m = Math.max(0, len - head) / 2; // beside the middle of the shaft, not counting the head+ bx = x + m * c; by = y + m * s; nx = s; ny = -c;+ if (nx * px + ny * py < 0) { nx = -nx; ny = -ny; }+ const along = Math.abs(c) * tw + Math.abs(s) * th; // the label's half-extent along the shaft+ clear = 12 + (m + along + 12 > len - head ? head * .6 : w / 2);+ }+ const k = clear + Math.abs(nx) * tw + Math.abs(ny) * th;+ return [bx + nx * k, by + ny * k + .28 * size]; // ink centre to baseline+}+// A labelled force arrow: f.set(x, y, len, angle, text, side, dx, dy) draws it from (x, y) with its label beside the+// shaft (see arrowLabelAt for side), nudged by dx, dy. len 0 hides it.function forceArrow(p, { color = FORCE, w = 9, size = 28 } = {}) {const g = G(p), a = path(g, '', { stroke: color, 'stroke-width': w }), lab = phLabel(g, '', { size, fill: color });return Object.assign(g, {- set(x, y, len, ang = 0, text = '', dx = 0, dy = 0) {- const r = ang * Math.PI / 180;+ set(x, y, len, ang = 0, text = '', side, dx = 0, dy = 0) {arrowAt(a, x, y, len, ang, 12 + w); phText(lab, len > 1 ? text : '');- put(lab, { x: x + len / 2 * Math.cos(r) + dx, y: y + len / 2 * Math.sin(r) - 20 + dy });+ const [lx, ly] = arrowLabelAt(x, y, len, ang, text, size, w, side); put(lab, { x: lx + dx, y: ly + dy }); // every frame, so replays match},});}-// A crate (centred on x, sitting on y); returns the group.-function crate(p, { x = 0, y = 0, w = 150, h = 130, label = '' } = {}) {+// A crate (centred on x, sitting on y); returns the group. The label's baseline sits at labelY (from the bottom; default+// the middle), e.g. higher up when a weight arrow starts at the centre.+function crate(p, { x = 0, y = 0, w = 150, h = 130, label = '', labelY = -h / 2 + 10 } = {}) {const g = G(p, { x, y });phBlock(g, -w / 2, -h, w, h, '#a87a4f', { top: 8, right: 14, ol: 0 });path(g, `M${-w / 2 + 10} ${-h + 18}L${w / 2 - 24} -10M${-w / 2 + 10} -10L${w / 2 - 24} ${-h + 18}`, { stroke: '#7d5737', 'stroke-width': 8 });- if (label) phLabel(g, label, { y: -h / 2 + 10, size: 30 });+ if (label) phLabel(g, label, { y: labelY, size: 30 });return g;}