An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat: add the physics book (chapters 9-11) to the bookshelf
yzr40ad9cd155f1
diff --git a/site/index.html b/site/index.htmlindex 80ca145..9e44ee7 100644--- a/site/index.html+++ b/site/index.html@@ -26,7 +26,9 @@<a class="book-hotspot math-book" data-book="math-notebook" href="math-notebook/" aria-label="Open Elementary Mathematics, 22 narrated chapters"><span class="book-caption"><strong>Elementary Mathematics <span aria-hidden="true">↗</span></strong><small>22 narrated chapters</small></span></a>- <span class="physics-pending">Physics · Coming soon</span>+ <a class="book-hotspot physics-book" data-book="science" href="science/" aria-label="Open Elementary Physics, 3 narrated chapters">+ <span class="book-caption"><strong>Elementary Physics <span aria-hidden="true">↗</span></strong><small>3 narrated chapters</small></span>+ </a></section><section class="shelf-tier" aria-labelledby="picture-title"><h2 class="visually-hidden" id="picture-title">Picture books for children · Coming soon</h2>diff --git a/site/lib/bookshelf.css b/site/lib/bookshelf.cssindex 35fbfde..1f31a18 100644--- a/site/lib/bookshelf.css+++ b/site/lib/bookshelf.css@@ -23,15 +23,16 @@ a { color: inherit; }.book-hotspot { position: absolute; display: block; top: 4.9%; height: 23.3%; text-decoration: none; border-radius: 2px; outline-offset: 4px; }.algebra-book { left: 10.1%; width: 26.1%; }.math-book { left: 39.9%; width: 24.5%; }+.physics-book { left: 66.8%; width: 25.3%; }.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; }.math-book .book-caption { background: linear-gradient(110deg, #704732f7, #503721f0); }+.physics-book .book-caption { background: linear-gradient(110deg, #1f2f4ef5, #141d33f0); }.book-caption strong { font-weight: 600; padding-right: 1.5cqw; }.book-caption strong > span { position: absolute; right: 1.2cqw; top: 1.1cqw; color: #e8c68b; }.book-caption small { color: #e2dbca; font-size: 1.03cqw; letter-spacing: .03em; }.resume-label { position: absolute; padding: .46cqw .74cqw; background: #fcf4df; color: #3c4336; box-shadow: 1px 2px 5px #0003; font: 1.03cqw var(--ui); transform: rotate(-3deg); }-.physics-pending { position: absolute; left: 71.4%; top: 25.6%; padding: .46cqw .92cqw; border: 1px solid #edcf73; background: #f1d174; color: #302b1f; font: 1.1cqw var(--ui); transform: rotate(-2deg); box-shadow: 1px 2px 4px #0003; }.github-drawer { position: absolute; left: 9%; top: 87.5%; width: 68%; height: 8.5%; text-decoration: none; }.shelf-noscript { position: absolute; bottom: 0; left: 24px; margin: 0; font: 11px var(--ui); color: #352c21; }.shelf-footer { position: absolute; inset: auto 0 0; display: flex; justify-content: center; align-items: center; gap: 3%; height: 3%; padding: 0 3%; color: #594129; font: 500 clamp(10px, .85vw, 14px)/1.4 var(--ui); text-shadow: 0 1px #ffe6bd66; }diff --git a/site/lib/bookshelf.js b/site/lib/bookshelf.jsindex 7440e7d..77bbdcc 100644--- a/site/lib/bookshelf.js+++ b/site/lib/bookshelf.js@@ -18,6 +18,8 @@{ id: 'elementary-algebra', key: 'progress', chapterBase: 'elementary-algebra/', chapters: 68 },{ id: 'math-notebook', key: 'animebook:progress:' + new URL('math-notebook/', location.href).pathname,chapterBase: 'math-notebook/', chapters: 22 },+ { id: 'science', key: 'animebook:progress:' + new URL('science/', location.href).pathname,+ chapterBase: 'science/', chapters: 11 },];for (const book of books) {const cover = document.querySelector(`[data-book="${book.id}"]`);@@ -29,7 +31,7 @@resume.className = 'resume-label';resume.textContent = `Continue · Chapter ${saved.last} →`;resume.href = `${book.chapterBase}ch${String(saved.last).padStart(2, '0')}/`;- resume.style.left = cover.classList.contains('algebra-book') ? '11%' : '40.8%';+ resume.style.left = { 'elementary-algebra': '11%', 'math-notebook': '40.8%', science: '67.7%' }[book.id];resume.style.top = '5.7%';document.getElementById('shelf-books').append(resume);}diff --git a/site/science/ch09/audio/en/accel.mp3 b/site/science/ch09/audio/en/accel.mp3new file mode 100644index 0000000..ad35e28Binary files /dev/null and b/site/science/ch09/audio/en/accel.mp3 differdiff --git a/site/science/ch09/audio/en/average.mp3 b/site/science/ch09/audio/en/average.mp3new file mode 100644index 0000000..357a637Binary files /dev/null and b/site/science/ch09/audio/en/average.mp3 differdiff --git a/site/science/ch09/audio/en/change.mp3 b/site/science/ch09/audio/en/change.mp3new file mode 100644index 0000000..13c2f84Binary files /dev/null and b/site/science/ch09/audio/en/change.mp3 differdiff --git a/site/science/ch09/audio/en/corner.mp3 b/site/science/ch09/audio/en/corner.mp3new file mode 100644index 0000000..6090511Binary files /dev/null and b/site/science/ch09/audio/en/corner.mp3 differdiff --git a/site/science/ch09/audio/en/earth.mp3 b/site/science/ch09/audio/en/earth.mp3new file mode 100644index 0000000..242616eBinary files /dev/null and b/site/science/ch09/audio/en/earth.mp3 differdiff --git a/site/science/ch09/audio/en/everywhere.mp3 b/site/science/ch09/audio/en/everywhere.mp3new file mode 100644index 0000000..a82b822Binary files /dev/null and b/site/science/ch09/audio/en/everywhere.mp3 differdiff --git a/site/science/ch09/audio/en/final1.mp3 b/site/science/ch09/audio/en/final1.mp3new file mode 100644index 0000000..5da0bf4Binary files /dev/null and b/site/science/ch09/audio/en/final1.mp3 differdiff --git a/site/science/ch09/audio/en/final2.mp3 b/site/science/ch09/audio/en/final2.mp3new file mode 100644index 0000000..2124b3fBinary files /dev/null and b/site/science/ch09/audio/en/final2.mp3 differdiff --git a/site/science/ch09/audio/en/finish.mp3 b/site/science/ch09/audio/en/finish.mp3new file mode 100644index 0000000..cb6a7f2Binary files /dev/null and b/site/science/ch09/audio/en/finish.mp3 differdiff --git a/site/science/ch09/audio/en/formula.mp3 b/site/science/ch09/audio/en/formula.mp3new file mode 100644index 0000000..9f51851Binary files /dev/null and b/site/science/ch09/audio/en/formula.mp3 differdiff --git a/site/science/ch09/audio/en/incar.mp3 b/site/science/ch09/audio/en/incar.mp3new file mode 100644index 0000000..041802aBinary files /dev/null and b/site/science/ch09/audio/en/incar.mp3 differdiff --git a/site/science/ch09/audio/en/instant.mp3 b/site/science/ch09/audio/en/instant.mp3new file mode 100644index 0000000..0fb2b7aBinary files /dev/null and b/site/science/ch09/audio/en/instant.mp3 differdiff --git a/site/science/ch09/audio/en/intro.mp3 b/site/science/ch09/audio/en/intro.mp3new file mode 100644index 0000000..2c4fd86Binary files /dev/null and b/site/science/ch09/audio/en/intro.mp3 differdiff --git a/site/science/ch09/audio/en/part2.mp3 b/site/science/ch09/audio/en/part2.mp3new file mode 100644index 0000000..371840cBinary files /dev/null and b/site/science/ch09/audio/en/part2.mp3 differdiff --git a/site/science/ch09/audio/en/part3.mp3 b/site/science/ch09/audio/en/part3.mp3new file mode 100644index 0000000..87065c9Binary files /dev/null and b/site/science/ch09/audio/en/part3.mp3 differdiff --git a/site/science/ch09/audio/en/part4.mp3 b/site/science/ch09/audio/en/part4.mp3new file mode 100644index 0000000..4aeaedbBinary files /dev/null and b/site/science/ch09/audio/en/part4.mp3 differdiff --git a/site/science/ch09/audio/en/position.mp3 b/site/science/ch09/audio/en/position.mp3new file mode 100644index 0000000..37c974bBinary files /dev/null and b/site/science/ch09/audio/en/position.mp3 differdiff --git a/site/science/ch09/audio/en/q1.mp3 b/site/science/ch09/audio/en/q1.mp3new file mode 100644index 0000000..c9edc2fBinary files /dev/null and b/site/science/ch09/audio/en/q1.mp3 differdiff --git a/site/science/ch09/audio/en/q2.mp3 b/site/science/ch09/audio/en/q2.mp3new file mode 100644index 0000000..7b49404Binary files /dev/null and b/site/science/ch09/audio/en/q2.mp3 differdiff --git a/site/science/ch09/audio/en/q3.mp3 b/site/science/ch09/audio/en/q3.mp3new file mode 100644index 0000000..3d1e810Binary files /dev/null and b/site/science/ch09/audio/en/q3.mp3 differdiff --git a/site/science/ch09/audio/en/q4.mp3 b/site/science/ch09/audio/en/q4.mp3new file mode 100644index 0000000..5ff9d59Binary files /dev/null and b/site/science/ch09/audio/en/q4.mp3 differdiff --git a/site/science/ch09/audio/en/roadside.mp3 b/site/science/ch09/audio/en/roadside.mp3new file mode 100644index 0000000..5c6db81Binary files /dev/null and b/site/science/ch09/audio/en/roadside.mp3 differdiff --git a/site/science/ch09/audio/en/rule.mp3 b/site/science/ch09/audio/en/rule.mp3new file mode 100644index 0000000..62a24baBinary files /dev/null and b/site/science/ch09/audio/en/rule.mp3 differdiff --git a/site/science/ch09/audio/en/sign.mp3 b/site/science/ch09/audio/en/sign.mp3new file mode 100644index 0000000..30321ffBinary files /dev/null and b/site/science/ch09/audio/en/sign.mp3 differdiff --git a/site/science/ch09/audio/en/speed.mp3 b/site/science/ch09/audio/en/speed.mp3new file mode 100644index 0000000..cc5a622Binary files /dev/null and b/site/science/ch09/audio/en/speed.mp3 differdiff --git a/site/science/ch09/audio/en/timings.js b/site/science/ch09/audio/en/timings.jsnew file mode 100644index 0000000..5916151--- /dev/null+++ b/site/science/ch09/audio/en/timings.js@@ -0,0 +1,877 @@+window.TIMINGS = {+ "intro": {+ "dur": 7.944,+ "marks": {+ "sub": 2.083+ },+ "cues": [+ [+ 0.104,+ "Chapter nine."+ ],+ [+ 1.198,+ "Motion."+ ],+ [+ 2.083,+ "In this first part, we answer a simple question: what does it really mean for something to move?"+ ]+ ]+ },+ "position": {+ "dur": 19.944,+ "marks": {+ "pos": 1.68,+ "roll": 4.583,+ "now": 5.898,+ "change": 8.516,+ "rule": 11.263,+ "still": 14.661+ },+ "cues": [+ [+ 0.104,+ "Here is a ball on a track."+ ],+ [+ 1.68,+ "Its position is two meters from the zero mark."+ ],+ [+ 4.583,+ "Now it rolls."+ ],+ [+ 5.898,+ "Its new position is seven meters."+ ],+ [+ 8.516,+ "The position changed by five meters."+ ],+ [+ 11.263,+ "That is what motion is: a change of position."+ ],+ [+ 14.661,+ "If time passes and the position stays the same, the ball is not moving."+ ]+ ]+ },+ "everywhere": {+ "dur": 10.8,+ "marks": {+ "page": 2.096,+ "earth": 4.31,+ "you": 7.161+ },+ "cues": [+ [+ 0.104,+ "Motion is everywhere."+ ],+ [+ 2.096,+ "Turning a page is motion."+ ],+ [+ 4.31,+ "Earth traveling around the Sun is motion."+ ],+ [+ 7.161,+ "And any time your position changes, you are in motion too."+ ]+ ]+ },+ "roadside": {+ "dur": 12.744,+ "marks": {+ "stand": 1.654,+ "truck": 3.177,+ "speed": 6.198+ },+ "cues": [+ [+ 0.065,+ "Now a trickier idea."+ ],+ [+ 1.654,+ "You are standing by a road."+ ],+ [+ 3.177,+ "A truck drives past at thirty miles per hour."+ ],+ [+ 6.198,+ "Measured from where you stand, the truck moves thirty miles per hour down the road."+ ],+ [+ 11.146,+ "Nothing surprising yet."+ ]+ ]+ },+ "incar": {+ "dur": 21.24,+ "marks": {+ "car": 1.289,+ "ride": 8.138,+ "still": 9.883,+ "back": 13.49+ },+ "cues": [+ [+ 0.104,+ "Let's replay it."+ ],+ [+ 1.289,+ "This time, you ride in a car right next to the truck, also at thirty miles per hour, and a friend waits by the road."+ ],+ [+ 8.138,+ "Now watch from inside the car."+ ],+ [+ 9.883,+ "The truck stays right beside you."+ ],+ [+ 11.836,+ "It doesn't seem to move at all."+ ],+ [+ 13.49,+ "Instead, the road, the trees, and your friend all seem to slide backward, at thirty miles per hour."+ ]+ ]+ },+ "rule": {+ "dur": 17.28,+ "marks": {+ "side": 2.643,+ "car": 5.82,+ "both": 7.995,+ "rel": 9.531,+ "refpt": 11.107+ },+ "cues": [+ [+ 0.104,+ "So how fast is the truck really moving?"+ ],+ [+ 2.643,+ "Measured from the roadside, thirty miles per hour."+ ],+ [+ 5.82,+ "Measured from the car, zero."+ ],+ [+ 7.995,+ "Both answers are correct."+ ],+ [+ 9.531,+ "Motion is relative."+ ],+ [+ 11.107,+ "It is always described in relation to a reference point: the place or object you measure from."+ ]+ ]+ },+ "earth": {+ "dur": 25.56,+ "marks": {+ "earth": 2.109,+ "fast": 6.55,+ "why": 11.237,+ "along": 13.346,+ "zoom": 20.534+ },+ "cues": [+ [+ 0.117,+ "Here is a giant example."+ ],+ [+ 2.109,+ "Seen from far above the North Pole, Earth spins counterclockwise."+ ],+ [+ 6.55,+ "At the equator, the ground moves more than a thousand miles per hour."+ ],+ [+ 11.237,+ "So why can't we see or feel it?"+ ],+ [+ 13.346,+ "Because everything around us, the ground, the buildings, the trees, and you, spins along with Earth."+ ],+ [+ 20.534,+ "From where you stand, nothing is moving."+ ],+ [+ 23.398,+ "Your reference point travels with you."+ ]+ ]+ },+ "q1": {+ "dur": 6.24,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.042,+ "A train, a passenger, and a friend on the platform."+ ],+ [+ 4.648,+ "Measure from each one."+ ]+ ]+ },+ "wrap": {+ "dur": 15.048,+ "marks": {+ "w1": 0.964,+ "w2": 3.268,+ "w3": 7.565,+ "end": 11.992+ },+ "cues": [+ [+ 0.091,+ "To sum up."+ ],+ [+ 0.964,+ "Motion is a change of position."+ ],+ [+ 3.268,+ "Motion is relative: it is always described from a reference point."+ ],+ [+ 7.565,+ "Different reference points can give different answers, and each one can be right."+ ],+ [+ 11.992,+ "Next, we'll measure how fast things move."+ ]+ ]+ },+ "part2": {+ "dur": 9.696,+ "marks": {+ "both": 1.953,+ "q": 4.57+ },+ "cues": [+ [+ 0.117,+ "Part two."+ ],+ [+ 1.094,+ "Speed."+ ],+ [+ 1.953,+ "A runner and a car are both moving."+ ],+ [+ 4.57,+ "But how fast?"+ ],+ [+ 5.938,+ "To compare them, we need a number."+ ],+ [+ 8.359,+ "That number is speed."+ ]+ ]+ },+ "speed": {+ "dur": 18.456,+ "marks": {+ "go": 4.688,+ "stop": 7.148,+ "f": 10.677,+ "calc": 13.971,+ "ans": 16.471+ },+ "cues": [+ [+ 0.104,+ "Speed is the distance something travels in a certain amount of time."+ ],+ [+ 4.688,+ "This runner starts at the zero mark."+ ],+ [+ 7.148,+ "After eight seconds, she has gone twenty-four meters."+ ],+ [+ 10.677,+ "To find her speed, divide the distance by the time: twenty-four meters divided by eight seconds is three meters per second."+ ]+ ]+ },+ "units": {+ "dur": 21.168,+ "marks": {+ "s": 3.177,+ "ms": 6.133,+ "each": 9.44,+ "mph": 15.651+ },+ "cues": [+ [+ 0.091,+ "In science, distance is measured in meters, and time is measured in seconds."+ ],+ [+ 6.133,+ "So speed is measured in meters per second."+ ],+ [+ 9.44,+ "Three meters per second means that every second, the runner covers three more meters."+ ],+ [+ 15.651,+ "The miles per hour from part one is a speed unit too."+ ],+ [+ 18.88,+ "It just uses miles and hours."+ ]+ ]+ },+ "average": {+ "dur": 23.904,+ "marks": {+ "go": 3.099,+ "stop": 4.479,+ "again": 5.755,+ "total": 6.979,+ "avg": 10.82,+ "ten": 15.43,+ "ghost": 17.018+ },+ "cues": [+ [+ 0.091,+ "Most things don't keep the same speed the whole time."+ ],+ [+ 3.099,+ "This car speeds along, stops at a red light, then drives on."+ ],+ [+ 6.979,+ "In all, it covers three hundred meters in thirty seconds."+ ],+ [+ 10.82,+ "Its average speed is the total distance divided by the total time: ten meters per second."+ ],+ [+ 17.018,+ "A car driving steadily at ten meters per second would arrive at exactly the same moment."+ ]+ ]+ },+ "instant": {+ "dur": 21.168,+ "marks": {+ "go": 3.398,+ "avg": 5.534,+ "but": 9.076,+ "fast": 13.919,+ "inst": 17.214+ },+ "cues": [+ [+ 0.117,+ "Here is a sprinter in the one hundred meter dash."+ ],+ [+ 3.398,+ "She finishes in ten seconds, so her average speed is ten meters per second."+ ],+ [+ 9.076,+ "But she doesn't run ten meters per second the whole way."+ ],+ [+ 12.435,+ "She starts slowly, and near the finish line she is going much faster."+ ],+ [+ 17.214,+ "The speed at one given moment is called instantaneous speed."+ ]+ ]+ },+ "q2": {+ "dur": 8.544,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.12,+ "A dolphin swims fifty-six meters in eight seconds."+ ],+ [+ 4.935,+ "A walrus swims thirty meters in six seconds."+ ]+ ]+ },+ "wrap2": {+ "dur": 17.712,+ "marks": {+ "w1": 0.977,+ "w2": 3.359,+ "w3": 6.576,+ "w4": 10.716,+ "end": 14.18+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.977,+ "Speed is distance divided by time."+ ],+ [+ 3.359,+ "In science, it is measured in meters per second."+ ],+ [+ 6.576,+ "Average speed is the total distance divided by the total time."+ ],+ [+ 10.716,+ "Instantaneous speed is the speed at one moment."+ ],+ [+ 14.18,+ "Next, we'll give speed a direction: velocity."+ ]+ ]+ },+ "part3": {+ "dur": 7.512,+ "marks": {+ "q": 2.253+ },+ "cues": [+ [+ 0.104,+ "Part three."+ ],+ [+ 1.146,+ "Velocity."+ ],+ [+ 2.253,+ "Speed tells us how fast something moves."+ ],+ [+ 4.831,+ "Velocity also tells us which way."+ ]+ ]+ },+ "velocity": {+ "dur": 26.832,+ "marks": {+ "jog": 3.568,+ "turn": 7.07,+ "same": 11.641,+ "diff": 15.143,+ "plus": 17.201,+ "minus": 19.922,+ "sign": 22.344+ },+ "cues": [+ [+ 0.104,+ "Velocity is speed in a certain direction."+ ],+ [+ 3.568,+ "Say you jog at two meters per second, to the right."+ ],+ [+ 7.07,+ "Then you turn around and jog two meters per second the other way."+ ],+ [+ 11.641,+ "Your speed stays the same: two meters per second."+ ],+ [+ 15.143,+ "But your velocity is different."+ ],+ [+ 17.201,+ "First it was plus two meters per second, then minus two meters per second."+ ],+ [+ 22.344,+ "Same size, opposite direction."+ ],+ [+ 24.753,+ "The sign tells the direction."+ ]+ ]+ },+ "change": {+ "dur": 12.408,+ "marks": {+ "spd": 3.307,+ "dir": 6.706+ },+ "cues": [+ [+ 0.104,+ "So velocity can change in two ways."+ ],+ [+ 3.307,+ "If the speed changes, the velocity changes."+ ],+ [+ 6.706,+ "And if the direction changes, the velocity changes too, even at the same speed."+ ]+ ]+ },+ "corner": {+ "dur": 16.776,+ "marks": {+ "above": 1.94,+ "drive": 3.281,+ "turn": 6.107,+ "still": 8.776,+ "rule": 10.846+ },+ "cues": [+ [+ 0.104,+ "Here is a car turning a corner."+ ],+ [+ 1.94,+ "Let's watch from above."+ ],+ [+ 3.281,+ "The car keeps a steady ten meters per second."+ ],+ [+ 6.107,+ "As it turns, it heads in a new direction, but its speed stays at ten."+ ],+ [+ 10.846,+ "So when a car turns a corner, its velocity changes, even if its speed stays the same."+ ]+ ]+ },+ "q3": {+ "dur": 3.984,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.12,+ "Speed, direction, and velocity."+ ]+ ]+ },+ "wrap3": {+ "dur": 20.928,+ "marks": {+ "w1": 0.964,+ "w2": 4.479,+ "w3": 11.693,+ "end": 16.484+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.964,+ "Velocity is speed in a certain direction."+ ],+ [+ 4.479,+ "The same speed in opposite directions gives different velocities, like plus two and minus two meters per second."+ ],+ [+ 11.693,+ "Velocity changes when the speed changes, or when the direction changes."+ ],+ [+ 16.484,+ "Next: how velocity changes over time."+ ],+ [+ 19.688,+ "Acceleration."+ ]+ ]+ },+ "part4": {+ "dur": 6.624,+ "marks": {+ "q": 2.461+ },+ "cues": [+ [+ 0.104,+ "Part four."+ ],+ [+ 1.133,+ "Acceleration."+ ],+ [+ 2.461,+ "Things don't just move."+ ],+ [+ 3.906,+ "They speed up, slow down, and turn."+ ]+ ]+ },+ "accel": {+ "dur": 14.448,+ "marks": {+ "ways": 4.479,+ "up": 10.677,+ "down": 11.719,+ "turn": 13.06+ },+ "cues": [+ [+ 0.091,+ "Acceleration is the rate at which velocity changes with time."+ ],+ [+ 4.479,+ "Whenever an object's velocity changes, it is accelerating."+ ],+ [+ 8.607,+ "That can happen in three ways: speeding up, slowing down, or changing direction."+ ]+ ]+ },+ "formula": {+ "dur": 26.928,+ "marks": {+ "f": 1.745,+ "t": 5.195,+ "ex": 7.253,+ "calc": 13.281,+ "ans": 18.034,+ "unit": 20.456+ },+ "cues": [+ [+ 0.104,+ "To find an acceleration, subtract the starting velocity from the final velocity, and divide by the time it took."+ ],+ [+ 7.253,+ "This car goes from five meters per second to twenty-five meters per second in four seconds."+ ],+ [+ 13.281,+ "Twenty-five minus five is twenty."+ ],+ [+ 16.12,+ "Twenty divided by four is five meters per second squared."+ ],+ [+ 20.456,+ "Meters per second squared means the velocity grows by five meters per second, every second."+ ]+ ]+ },+ "sign": {+ "dur": 20.712,+ "marks": {+ "gas": 2.591,+ "brake": 10.547,+ "decel": 16.81+ },+ "cues": [+ [+ 0.104,+ "Acceleration has a direction too."+ ],+ [+ 2.591,+ "Press the gas pedal, and the acceleration points the same way the car is moving."+ ],+ [+ 7.839,+ "It is positive, and the car speeds up."+ ],+ [+ 10.547,+ "Press the brake, and the acceleration points the other way."+ ],+ [+ 14.128,+ "It is negative, and the car slows down."+ ],+ [+ 16.81,+ "Negative acceleration is also called deceleration."+ ]+ ]+ },+ "turnfeel": {+ "dur": 12.552,+ "marks": {+ "dir": 3.802,+ "feel": 6.862+ },+ "cues": [+ [+ 0.091,+ "Turning is accelerating too, even at a steady speed, because the direction of the velocity changes."+ ],+ [+ 6.862,+ "That is why, when a car goes around a corner, you feel pushed toward the outside of the turn."+ ]+ ]+ },+ "q4": {+ "dur": 2.376,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.12,+ "Acceleration."+ ]+ ]+ },+ "wrap4": {+ "dur": 24.288,+ "marks": {+ "w1": 0.977,+ "w2": 5.078,+ "w3": 10.312,+ "w4": 16.953+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.977,+ "Acceleration is the rate at which velocity changes."+ ],+ [+ 5.078,+ "Something accelerates when it speeds up, slows down, or changes direction."+ ],+ [+ 10.312,+ "Acceleration equals the change in velocity divided by the time, in meters per second squared."+ ],+ [+ 16.953,+ "Positive acceleration speeds things up; negative acceleration, or deceleration, slows them down."+ ]+ ]+ },+ "final1": {+ "dur": 3.696,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.641,+ "First, motion and speed."+ ]+ ]+ },+ "final2": {+ "dur": 2.856,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Now velocity and acceleration."+ ]+ ]+ },+ "finish": {+ "dur": 2.928,+ "marks": {},+ "cues": [+ [+ 0.104,+ "That's the whole chapter on motion."+ ],+ [+ 2.031,+ "Well done!"+ ]+ ]+ }+};diff --git a/site/science/ch09/audio/en/turnfeel.mp3 b/site/science/ch09/audio/en/turnfeel.mp3new file mode 100644index 0000000..522c1b5Binary files /dev/null and b/site/science/ch09/audio/en/turnfeel.mp3 differdiff --git a/site/science/ch09/audio/en/units.mp3 b/site/science/ch09/audio/en/units.mp3new file mode 100644index 0000000..42a8dddBinary files /dev/null and b/site/science/ch09/audio/en/units.mp3 differdiff --git a/site/science/ch09/audio/en/velocity.mp3 b/site/science/ch09/audio/en/velocity.mp3new file mode 100644index 0000000..a434255Binary files /dev/null and b/site/science/ch09/audio/en/velocity.mp3 differdiff --git a/site/science/ch09/audio/en/wrap.mp3 b/site/science/ch09/audio/en/wrap.mp3new file mode 100644index 0000000..2b622b9Binary files /dev/null and b/site/science/ch09/audio/en/wrap.mp3 differdiff --git a/site/science/ch09/audio/en/wrap2.mp3 b/site/science/ch09/audio/en/wrap2.mp3new file mode 100644index 0000000..e5c6a51Binary files /dev/null and b/site/science/ch09/audio/en/wrap2.mp3 differdiff --git a/site/science/ch09/audio/en/wrap3.mp3 b/site/science/ch09/audio/en/wrap3.mp3new file mode 100644index 0000000..d75d962Binary files /dev/null and b/site/science/ch09/audio/en/wrap3.mp3 differdiff --git a/site/science/ch09/audio/en/wrap4.mp3 b/site/science/ch09/audio/en/wrap4.mp3new file mode 100644index 0000000..1daf9e5Binary files /dev/null and b/site/science/ch09/audio/en/wrap4.mp3 differdiff --git a/site/science/ch09/index.html b/site/science/ch09/index.htmlnew file mode 100644index 0000000..d3bff14--- /dev/null+++ b/site/science/ch09/index.html@@ -0,0 +1,909 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Chapter 9: Motion — Science</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/figures.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+// Chapter 9, one page in book order: part 1 (motion; relative motion), part 2 (speed), part 3 (velocity), part 4 (acceleration).+const CHAPTER = { number: 9, title: 'Motion', minutes: 18, language: 'en', next: '../ch10/' };++/* ---------- chapter helpers ---------- */+const V = 150; // 30 mph on screen, in world px per second (same scale in every road beat)+const MPH = v => Math.round(Math.abs(v) / V * 30);+const speedStr = rel => { const n = MPH(rel); return n === 0 ? '0 mph' : rel > 0 ? `${n} mph →` : `← ${n} mph`; };+const Q_CARD = { x: 96, y: 586, w: 1408, cls: 'band' }; // a band card under the scenes; it moves up by itself when taller+const txt = (p, s, x, y, t0, { size = 32, fill = COL.chalk, anchor = 'middle', weight = 600 } = {}) => { const e = T(p, s, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };+// One line with coloured runs: [[text, colour?], …].+function runs(p, parts, { x, y, size = 40, anchor = 'middle', weight = 600, o = 0 }) {+ const t = T(p, '', { x, y, size, anchor, weight, o });+ parts.forEach(([s, c]) => { const sp = mk('tspan', { fill: c || COL.chalk }, t); sp.textContent = s; });+ return t;+}+function arrowPath(x1, y, x2) { const d = Math.sign(x2 - x1); return `M${x1} ${y}H${x2}M${x2 - 16 * d} ${y - 11}L${x2} ${y}L${x2 - 16 * d} ${y + 11}`; }+// "Measured from: …" tag at the left, top by default (screen space).+function fromTag(p, str, t0, dur = .5, y = 136) {+ const g = G(p, { o: 0 });+ phPin(g, { x: 112, y: y + 14, s: .8 });+ runs(g, [['Measured from: ', COL.dim], [str, PH.ref]], { x: 146, y, size: 34, anchor: 'start', o: 1 });+ show(g, t0, dur);+ return g;+}+// Earth from above the North Pole, in a camera's world. The overview camera (800, 450, z 1) shows it at (EX, EY).+const EX = 430, EY = 450, ER = 200, ESPIN = -14; // spin in degrees per second; negative = counterclockwise+const rimAngle = t => (-90 + ESPIN * t) * Math.PI / 180; // where "you" are on the rim at time t+// A camera locked onto you, rolling with the ground, `lift` world px above it.+const groundView = (lift, z) => ({ x: t => EX + (ER + lift) * Math.cos(rimAngle(t)), y: t => EY + (ER + lift) * Math.sin(rimAngle(t)), z, r: t => ESPIN * t });+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 });+ const gr = ER - 3, ga = .4; // ±23° of smooth ground under the rim scene (the pixel coast is stepped)+ path(E._spin, `M${-gr * Math.sin(ga)} ${-gr * Math.cos(ga)}A${gr} ${gr} 0 0 1 ${gr * Math.sin(ga)} ${-gr * Math.cos(ga)}`, { stroke: PH.land, 'stroke-width': 6, 'stroke-linecap': 'butt' });+ phSprite(rim(-9), 'house', { s: .25 }); phSprite(rim(7), 'tree', { s: .22 }); // the narration's buildings, trees and you+ const you = rim(0);+ phPerson(you, { s: .25 });+ clockRun(t => put(E._spin, { r: ESPIN * t }), D);+ return { E, you };+}+// 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;++/* ---------- section 2 (speed) helpers ---------- */+const DIST = COL.rat, TIME = COL.whole; // distance pink (as "change of position" in part 1), time blue+const walkTo = (r, x, step = 22) => phPose(r, 'walk', x / step * Math.PI); // two frames per stride, from x+// A measured track: a bar with ticks every `every` meters from 0 to `to`, U px per meter.+function meterTrack(p, { x0, U, y, to, every, size = 26 }) {+ const g = G(p);+ phBlock(g, x0 - 20, y, U * to + 40, 14, '#8a6f55', { top: 4, ol: 0 });+ for (let v = 0; v <= to; v += every) {+ mk('rect', { x: x0 + U * v - 2, y: y + 14, width: 4, height: 14, fill: COL.dim }, g);+ T(g, String(v), { x: x0 + U * v, y: y + 56, size, fill: COL.chalk, anchor: 'middle' });+ }+ T(g, 'meters', { x: x0 + U * to + 36, y: y + 56, size: size - 2, fill: COL.dim });+ return g;+}+// A fraction in words or numbers (upright text, no math italics), centred on x with its bar at y.+function wfrac(p, top, bot, x, y, { size = 44, ct = COL.chalk, cb = COL.chalk, o = 0 } = {}) {+ const g = G(p, { x, y, o }), w = Math.max(uiW(top, size), uiW(bot, size)) + 24;+ T(g, top, { y: -size * .32, size, fill: ct, anchor: 'middle', weight: 600 });+ mk('rect', { x: -w / 2, y: -2, width: w, height: 4, rx: 2, fill: COL.chalk }, g);+ T(g, bot, { y: size * 1.02, size, fill: cb, anchor: 'middle', weight: 600 });+ g._w = w;+ return g;+}+// A sim clock: stopwatch plus "N s" under it; set(sec) turns the hand (one turn per minute) and writes whole seconds.+function simClock(p, x, y, r = 46) {+ const sw = phStopwatch(p, { x, y, r }), lab = T(p, '0 s', { x, y: y + r + 48, size: 32, weight: 700, fill: TIME, anchor: 'middle' });+ return { sw, lab, set(sec) { put(sw._hand, { r: sec * 6 }); phText(lab, `${Math.floor(sec + 1e-6)} s`); } };+}+const ramp = (t, a, b) => Math.min(1, Math.max(0, (t - a) / (b - a)));+// Sprint model for the 100 m dash: speed rises quickly and levels off; 100 m at 10 s; about 12 m/s at the finish.+const SK = 1.4, SVM = 100 / (10 - SK * (1 - Math.exp(-10 / SK)));+const sprintX = tau => SVM * (tau - SK * (1 - Math.exp(-tau / SK))), sprintV = tau => SVM * (1 - Math.exp(-tau / SK));+// The stop-and-go car: 15 m/s for 10 s, stopped 8 s at a red light, 12.5 m/s for 12 s: 300 m in 30 s.+const tripX = s => s < 10 ? 15 * s : s < 18 ? 150 : 150 + 12.5 * (Math.min(s, 30) - 18);+const tripV = s => s < 10 ? 15 : s < 18 ? 0 : s < 30 ? 12.5 : 0;++/* ---------- section 3 (velocity) helpers ---------- */+const VEL = COL.int; // velocity arrows and readouts: yellow+// Set path el to an arrow from (x, y), len long, at angle a (degrees; 0 = right, −90 = up).+function arrowAt(el, x, y, len, a, head = 18) {+ const r = a * Math.PI / 180, c = Math.cos(r), s = Math.sin(r), x2 = x + len * c, y2 = y + len * s;+ el.setAttribute('d', len < 2 ? '' : `M${x} ${y}L${x2} ${y2}M${x2 - head * c - head * .6 * s} ${y2 - head * s + head * .6 * c}L${x2} ${y2}L${x2 - head * c + head * .6 * s} ${y2 - head * s - head * .6 * c}`);+ return el;+}+const compassWord = a => a > -22.5 ? 'east' : a > -67.5 ? 'north-east' : 'north';++/* ---------- section 4 (acceleration) helpers ---------- */+const ACC = '#ee6fd0'; // acceleration arrows and readouts: magenta (velocity stays yellow)+// The overhead street with an L-shaped corner (parts 3 and 4). pose(d): [x, y, heading°] at distance d along the road.+function overheadStreet(w) {+ const R0 = 250, L1 = 1050, ARC = Math.PI / 2 * R0;+ mk('rect', { x: -200, y: -200, width: 2000, height: 1300, fill: PH.grass }, w);+ [[180, 260], [420, 260], [660, 260]].forEach(([x, y]) => phBlock(w, x, y, 150, 120, '#a65d4b', { top: 10, right: 12, ol: 0 }));+ [[1320, 560], [1250, 760], [60, 860]].forEach(([x, y]) => phBlock(w, x, y, 64, 64, '#4e9a5a', { top: 8, right: 8, ol: 0 }));+ const route = `M-300 620H850A${R0} ${R0} 0 0 0 1100 370V-400`;+ path(w, route, { stroke: PH.road, 'stroke-width': 130, 'stroke-linecap': 'butt' });+ path(w, route, { stroke: PH.line, 'stroke-width': 4, 'stroke-dasharray': '40 40', opacity: .6 });+ const pose = d => d < L1 ? [-200 + d, 620, 0] : d < L1 + ARC ? (th => [850 + R0 * Math.sin(th), 370 + R0 * Math.cos(th), -th * 180 / Math.PI])((d - L1) / R0) : [1100, 370 - (d - L1 - ARC), -90];+ return { pose, R0, L1, ARC, cx: 850, cy: 370 };+}+// "velocity / acceleration" colour key at the top left.+function vaKey(p, t0, y = 70) {+ const g = G(p, { o: 0 });+ arrowAt(path(g, '', { stroke: VEL, 'stroke-width': 7 }), 70, y, 60, 0, 14); T(g, 'velocity', { x: 146, y: y + 10, size: 28, weight: 700, fill: VEL });+ arrowAt(path(g, '', { stroke: ACC, 'stroke-width': 7 }), 300, y, 60, 0, 14); T(g, 'acceleration', { x: 376, y: y + 10, size: 28, weight: 700, fill: ACC });+ show(g, t0);+ return g;+}++/* ---------- beats ---------- */+const BEATS = [+['intro', 'Motion', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D, { x: 800, y: 285, z: .9 });+ const road = phRoad(cam);+ const carX = t => -260 + 190 * t;+ const car = phCar(road.vehicles, { y: ROAD.near });+ cam.to({ x: t => carX(t) + 330 }, 2.4, 2); // lock on: from here the camera rides with the car+ clockRun(t => {+ const x = carX(t); put(car, { x }); phRoll(car, x);+ }, 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' });+ phLabel(g, 'Motion', { x: 800, y: 250, size: 120, weight: 600 });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ txt(p, 'Part 1 · Motion and relative motion', 800, 320, m('sub'), { size: 36, fill: COL.dim });+}],+['position', 'Motion is a change of position', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D, { x: 800, y: 420, z: .55 });+ cam.to({ x: 800, y: 450, z: 1 }, .1, 1.6); // wide shot of the park, pushing in to the track+ 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 });+ phSprite(w, 'tree', { x: -200, y: 540 }); phSprite(w, 'tree', { x: 1820, y: 548 });+ 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 });+ for (let v = 0; v <= 10; v++) {+ mk('rect', { x: xm(v) - 2, y: TY + 16, width: 4, height: 16, fill: COL.dim }, track);+ T(track, String(v), { x: xm(v), y: TY + 68, size: 28, fill: COL.chalk, anchor: 'middle' });+ }+ T(track, 'meters', { x: xm(10) + 40, y: TY + 68, size: 26, fill: COL.dim });+ T(track, 'zero mark', { x: xm(0), y: TY + 104, size: 24, fill: COL.dim, anchor: 'middle' });+ txt(p, 'Position: where something is, measured from a starting mark', 800, 150, 1.4, { size: 34, fill: COL.dim });+ const ghost = mk('circle', { cx: xm(2), cy: TY - R, r: R, fill: 'none', stroke: COL.dim, 'stroke-width': 3, 'stroke-dasharray': '8 8' }, w);+ put(ghost, { o: 0 });+ const ball = phBall(w, R, { x: xm(2), y: TY - R });+ const at2 = txt(w, 'position: 2 m', xm(2), TY - 110, m('pos'), { size: 32 });+ hide(at2, m('roll'), .4); show(ghost, m('roll'), .4);+ prog(q => { const x = xm(2) + U * 5 * q; put(ball, { x }); put(ball._spin, { r: (x - xm(2)) / R * 180 / Math.PI }); }, m('roll', .1), 2.2, io);+ txt(w, 'position: 7 m', xm(7), TY - 110, m('now'), { size: 32 });+ const ch = G(w, { o: 0 });+ path(ch, arrowPath(xm(2), TY + 150, xm(7)), { stroke: PH.change, 'stroke-width': 5 });+ T(ch, 'change of position: 5 m', { x: xm(4.5), y: TY + 200, size: 32, fill: PH.change, weight: 700, anchor: 'middle' });+ show(ch, m('change'));+ const rule = runs(p, [['Motion', COL.chalk], [' = a ', COL.chalk], ['change of position', PH.change]], { x: 800, y: 270, size: 60 });+ show(rule, m('rule'));+ const sw = phStopwatch(p, { x: 1330, y: 400, r: 52, o: 0 });+ show(sw, m('still'));+ const clockT = txt(p, '0 s later', 1330, 500, m('still'), { size: 28, fill: COL.dim });+ prog(q => { put(sw._hand, { r: 90 * q }); clockT.textContent = `${Math.round(3 * q)} s later`; }, m('still', .3), 3, lin);+ txt(p, 'still at 7 m: not moving', 1330, 540, m('still', 3.4), { size: 28, fill: COL.chalk });+}],+['everywhere', 'Motion is everywhere', (m, D) => {+ const p = panel(0);+ txt(p, 'Motion is everywhere', 800, 140, .2, { size: 48 });+ const frame = (cx, t0, cap) => {+ const g = G(p, { o: 0 });+ mk('rect', { x: cx - 210, y: 210, width: 420, height: 370, rx: 22, fill: '#22332d', stroke: COL.faint, 'stroke-width': 2 }, g);+ T(g, cap, { x: cx, y: 640, size: 32, weight: 600, anchor: 'middle' });+ show(g, t0);+ return g;+ };+ const f1 = frame(300, m('page'), 'turning a page');+ const book = phNotebook(f1, { x: 300, y: 380, s: 1.05 });+ const f2 = frame(800, m('earth'), 'Earth orbiting the Sun');+ 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 });+ 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 });+ const tp = m('page'), te = m('earth'), ty = m('you');+ clockRun(t => {+ const c = Math.max(0, t - tp - .3) % 2.4;+ phFlip(book, 180 * soft(Math.min(1, c / 1.4)));+ const a = (-90 - 40 * Math.max(0, t - te + .5)) * Math.PI / 180; // counterclockwise, seen from above the North Pole+ put(earth, { x: 800 + 140 * Math.cos(a), y: 395 + 140 * Math.sin(a) });+ put(sun._rays, { r: 8 * t });+ const d = Math.min(260, Math.max(0, t - ty) * 85);+ put(you, { x: 1160 + d }); phPose(you, d > 0 && d < 260 ? 'walk' : 'stand', d / 22 * Math.PI);+ }, D);+}],+['roadside', 'Standing by the road', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D);+ 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: 236, fill: PH.you, o: 0 }), m('stand')); // above the pin: the truck's label passes below+ const 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'));+ pop(phPin(road.front, { x: 760, y: 304, s: 0, o: 0 }), m('speed'));+ show(tl, m('speed'));+ const t0 = m('truck', -.3);+ clockRun(t => {+ const x = -250 + V * Math.max(0, t - t0);+ put(truck, { x }); phRoll(truck, x); put(tl, { x: x + 10 });+ }, D);+}],+['incar', 'Riding beside the truck', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D);+ const road = phRoad(cam, { trees: [300, 800, 1900] }); // no tree behind the friend (1100) or the friend's label+ 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);+ phPerson(road.side, { role: 'friend', x: FR, y: ROAD.side });+ const truck = phTruck(road.vehicles, { y: ROAD.far });+ const car = phCar(road.vehicles, { y: ROAD.near });+ // 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(sl, m('back'));+ const pinA = phPin(road.side, { x: FR, y: 304, 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);+ hide(tagA, r0, 0); fromTag(p, 'your car', r0, 0, 800); // bottom: the friend slides through the top+ clockRun(t => {+ 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, 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);+}],+['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: .45 });+ if (ride) cam.cut({ x: t => splitX(t) + 10 }, 0);+ const r = phRoad(cam, { hills: false });+ phPerson(r.scenery, { role: 'friend', x: 480, y: ROAD.side });+ if (!ride) phPin(r.scenery, { x: 480, y: 330, s: 1.1 });+ const truck = phTruck(r.vehicles, { y: ROAD.far }), 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: 340, size: 56, fill: PH.truck });+ clockRun(t => {+ const x = splitX(t);+ put(truck, { x }); put(car, { x: x + 10 }); put(lab, { x: x + 10 });+ phRoll(truck, x); 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);+ };+ view([80, 120, 700, 380], m('side', -.4), 'from the roadside', false);+ view([820, 120, 700, 380], m('car', -.4), 'from the car', true);+ const check = x => { const c = path(p, `M${x} 455l18 18l36 -42`, { stroke: COL.good, 'stroke-width': 9 }, { d: 0 }); draw(c, m('both'), .5); };+ check(700); check(1440);+ txt(p, 'Both are correct.', 800, 560, m('both'), { size: 34, fill: COL.good });+ show(runs(p, [['Motion is ', COL.chalk], ['relative', PH.ref], ['.', COL.chalk]], { x: 800, y: 660, size: 72 }), m('rel'));+ show(runs(p, [['It is always described in relation to a ', COL.chalk], ['reference point', PH.ref], ['.', COL.chalk]], { x: 800, y: 745, size: 40, weight: 500 }), m('refpt'));+ txt(p, 'reference point = the place or object you measure from', 800, 808, m('refpt', 3), { size: 30, fill: COL.dim, weight: 500 });+}],+['earth', 'Why we don\'t feel Earth spin', (m, D) => {+ const p = panel(0);+ const sky = mk('rect', { width: 1600, height: 900, fill: PH.sky }, p);+ const cam = camera(p, D);+ // 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 < 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: -15, y: -36, width: 30, height: 40, rx: 6, fill: 'none', stroke: PH.ref, 'stroke-width': 2.5 }, you);+ put(rimRing, { o: 0 });+ const arcs = G(cam.world, { o: 0 });+ const arc = (a1, a2) => {+ const rr = ER + 92, P = a => [EX + rr * Math.cos(a * Math.PI / 180), EY + rr * Math.sin(a * Math.PI / 180)];+ const [x1, y1] = P(a1), [x2, y2] = P(a2), t = a2 * Math.PI / 180, dx = Math.sin(t), dy = -Math.cos(t);+ path(arcs, `M${x1} ${y1}A${rr} ${rr} 0 0 0 ${x2} ${y2}`, { stroke: COL.chalk, 'stroke-width': 5 });+ path(arcs, `M${x2 - 18 * dx - 10 * dy} ${y2 - 18 * dy + 10 * dx}L${x2} ${y2}L${x2 - 18 * dx + 10 * dy} ${y2 - 18 * dy - 10 * dx}`, { stroke: COL.chalk, 'stroke-width': 5 });+ };+ arc(215, 145); arc(35, -35);+ show(arcs, m('earth', 2.8));+ txt(p, 'Seen from far above the North Pole', 70, 80, m('earth'), { size: 32, fill: COL.dim, anchor: 'start' });+ txt(p, 'counterclockwise', EX, 772, m('earth', 3.2), { size: 30, fill: COL.chalk });+ const eq = mk('circle', { cx: EX, cy: EY, r: ER, fill: 'none', stroke: COL.int, 'stroke-width': 7, transform: `rotate(-90 ${EX} ${EY})` }, cam.world);+ 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));+ 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 });+ show(rimRing, m('along', 1));+ // Picture-in-picture: a second camera that stays with you on the ground.+ const box = [880, 300, 600, 380];+ const pip = camera(p, D, { box, bg: PH.sky });+ pip.cut(groundView(20, 6), 0);+ phPin(earthWorld(pip, D).you, { y: -34, s: .3 });+ put(pip.el, { s: 0, o: 0 }); pop(pip.el, m('zoom'));+ show(phLabel(p, 'from where you stand', { x: box[0] + 24, y: box[1] + box[3] - 22, size: 28, fill: PH.ref, anchor: 'start', o: 0 }), m('zoom', .3));+ txt(p, 'house, tree, ground: 0 mph', rx, 740, m('zoom', .3), { size: 32 });+ txt(p, 'Nothing seems to move.', rx, 790, m('zoom', .3), { size: 32, fill: COL.good });+}, { lead: false }], // the ground shot is on screen from the first frame+['q1', 'Quick check', (m, D) => {+ const p = panel(0);+ const GY = 430;+ phBlock(p, 0, GY + 2, 1600, 10, '#6b5a48', { top: 3, ol: 0 });+ path(p, Array.from({ length: 27 }, (_, i) => `M${i * 60 + 10} ${GY + 12}h34`).join(''), { stroke: '#4a3d31', 'stroke-width': 6 });+ path(p, [0, 40, 80].map(k => `M${720 - 520} ${GY - 120 - k}H${720 - 620}`).join(''), { stroke: COL.chalk, 'stroke-width': 6, opacity: .6 });+ const train = phCarriage(p, { x: 720, y: GY, w: 1000 });+ put(train, { o: 0 }); show(train, .2);+ const wl = train._wins[2], wx = 720 + wl;+ phSprite(train, 'maya_seated', { x: wl - 20, y: -144 });+ phBlock(train, wl - 4, -152, 66, 9, '#8a6a4c', { top: 3, ol: 2 });+ phBlock(train, wl + 32, -186, 14, 34, '#86c9e8', { top: 0, right: 4, ol: 2 });+ phBlock(train, wl + 34, -194, 10, 8, COL.whole, { top: 0, ol: 2 });+ phLabel(p, 'Maya', { x: wx - 22, y: GY - 98, size: 28, fill: COL.int });+ phLabel(p, 'water bottle', { x: wx + 120, y: GY - 300, size: 24, fill: '#86c9e8' });+ path(p, `M${wx + 80} ${GY - 292}L${wx + 42} ${GY - 196}`, { stroke: '#86c9e8', 'stroke-width': 3 });+ phLabel(p, 'train: 60 mph →', { x: 520, y: GY - 300, size: 30, fill: COL.real });+ phBlock(p, 1260, GY + 8, 340, 110, '#4a524f', { top: 6, ol: 2 });+ mk('rect', { x: 1260, y: GY + 8, width: 340, height: 6, fill: COL.int }, p);+ phPerson(p, { role: 'friend', x: 1430, y: GY + 18 });+ phLabel(p, 'Leo, on the platform', { x: 1430, y: GY - 124, size: 26, fill: COL.nat });+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-maya', prompt: ['Measured from ', h('b', '', 'Maya'), ', how fast is the water bottle on her table moving?'],+ build: choice([['0 mph'], ['60 mph'], ['120 mph']], 0,+ 'Maya and the bottle ride together. From Maya, the bottle stays put.',+ [null, 'That is the speed measured from the ground. Maya moves along with the bottle.', 'Nothing here adds up to 120. The bottle rides along with Maya.'],+ () => floatText('0 mph from Maya', 900, 115, COL.int)) },+ { id: 'c-leo', prompt: ['Measured from ', h('b', '', 'Leo'), ', standing on the platform, how fast is the same bottle moving?'],+ build: choice([['0 mph'], ['60 mph'], ['120 mph']], 1,+ 'The bottle rides with the train, so it passes Leo at the train’s speed.',+ ['That is the answer from Maya. Leo stays on the platform; the train carries the bottle past him.', null, 'The bottle only moves as fast as the train carries it.'],+ () => floatText('60 mph → from Leo', 1150, 270, COL.nat)) },+], done) }],+['wrap', 'Summary', (m, D) => {+ const p = panel(0);+ txt(p, 'Motion and relative motion', 800, 150, .2, { size: 40, fill: COL.dim });+ [['Motion is a change of position.', 'w1'],+ ['Motion is relative: it is described from a reference point.', 'w2'],+ ['Different reference points can give different answers, and each can be right.', 'w3']].forEach(([s, mark], i) => {+ const g = G(p, { x: -16, y: 300 + i * 140, o: 0 });+ mk('rect', { x: 144, y: -38, width: 52, height: 52, rx: 6, fill: PH.ref }, g);+ T(g, String(i + 1), { x: 170, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, s, { x: 230, size: 36, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ txt(p, 'Next: how fast things move.', 800, 760, m('end'), { size: 32, fill: COL.dim, weight: 500 });+}],+/* ---------- part 2: speed ---------- */+['part2', 'Part 2 · Speed', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D, { x: 800, y: 285, z: .9 });+ const road = phRoad(cam);+ const car = phCar(road.vehicles, { y: ROAD.near }), run = phPerson(road.side, { role: 'runner', y: ROAD.side });+ const t0 = m('both', -.3);+ clockRun(t => {+ const u = Math.max(0, t - t0), cx = -200 + 300 * u, rx = 80 + 90 * u;+ put(car, { x: cx }); phRoll(car, cx); put(run, { x: rx }); if (u > 0) walkTo(run, rx); else phPose(run);+ }, D);+ const g = G(p, { o: 0, y: 24 });+ T(g, 'Chapter 9 · Motion', { x: 800, y: 130, size: 28, fill: COL.dim, anchor: 'middle' });+ phLabel(g, 'Speed', { x: 800, y: 250, size: 120, weight: 600 });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ txt(p, 'Part 2 · How fast is something moving?', 800, 320, m('q'), { size: 36, fill: COL.dim });+}],+['speed', 'Speed = distance ÷ time', (m, D) => {+ const p = panel(0);+ const X0 = 220, U = 50, TY = 640, xm = v => X0 + U * v, t0 = m('go', .4), t1 = m('f', -.2);+ txt(p, 'Speed: the distance something travels in a certain amount of time', 800, 100, .2, { size: 32, fill: COL.dim });+ meterTrack(p, { x0: X0, U, y: TY, to: 24, every: 3 });+ const run = phPerson(p, { role: 'runner', x: xm(0), y: TY });+ const clk = simClock(p, 1460, 230);+ const dist = G(p, { o: 0 }), arrow = path(dist, '', { stroke: DIST, 'stroke-width': 5 });+ const dLab = T(dist, '', { y: TY + 150, size: 34, weight: 700, fill: DIST, anchor: 'middle' });+ show(dist, t0);+ clockRun(t => {+ const q = ramp(t, t0, t1), sec = 8 * q, d = 3 * sec, x = xm(d);+ put(run, { x }); if (q > 0 && q < 1) walkTo(run, x); else phPose(run);+ clk.set(sec);+ arrow.setAttribute('d', d > .6 ? arrowPath(xm(0), TY + 100, x) : '');+ put(dLab, { x: (xm(0) + x) / 2 }); phText(dLab, `${Math.round(d)} m`);+ }, D);+ const y = 300;+ show(T(p, 'speed =', { x: 520, y: y + 14, size: 52, weight: 700, anchor: 'end', o: 0 }), m('f'));+ show(wfrac(p, 'distance', 'time', 660, y, { ct: DIST, cb: TIME }), m('f', .3));+ show(T(p, '=', { x: 800, y: y + 14, size: 52, weight: 700, anchor: 'middle', o: 0 }), m('calc'));+ show(wfrac(p, '24 m', '8 s', 900, y, { ct: DIST, cb: TIME }), m('calc'));+ const ans = runs(p, [['= ', COL.chalk], ['3 m/s', COL.chalk]], { x: 990, y: y + 16, size: 56, anchor: 'start', weight: 700 });+ pop(put(ans, { s: .6 }), m('ans'));+}],+['units', 'Meters per second', (m, D) => {+ const p = panel(0);+ const X0 = 220, U = 50, TY = 640, xm = v => X0 + U * v, t0 = m('each', .2), t1 = t0 + 4.8;+ runs(p, [['distance → ', COL.dim], ['meters (m)', DIST]], { x: 420, y: 150, size: 40 }); show(p.lastChild, .2);+ runs(p, [['time → ', COL.dim], ['seconds (s)', TIME]], { x: 1180, y: 150, size: 40 }); show(p.lastChild, m('s'));+ const sp = runs(p, [['speed → ', COL.dim], ['meters per second ', COL.chalk], ['(m/s)', COL.chalk]], { x: 800, y: 250, size: 48 });+ show(sp, m('ms'));+ meterTrack(p, { x0: X0, U, y: TY, to: 24, every: 3 });+ const run = phPerson(p, { role: 'runner', x: xm(0), y: TY });+ const clk = simClock(p, 1460, 230);+ const flags = Array.from({ length: 8 }, (_, i) => {+ const g = G(p, { x: xm(3 * (i + 1)), y: TY, o: 0 });+ mk('rect', { x: -2, y: -70, width: 4, height: 70, fill: TIME }, g);+ mk('rect', { x: 2, y: -70, width: 22, height: 14, fill: TIME }, g);+ T(g, `${i + 1} s`, { y: -82, size: 24, weight: 700, fill: TIME, anchor: 'middle' });+ return g;+ });+ const gap = G(p, { o: 0 });+ path(gap, `M${xm(0)} ${TY + 96}V${TY + 112}H${xm(3)}V${TY + 96}`, { stroke: DIST, 'stroke-width': 4 });+ T(gap, '3 m', { x: xm(1.5), y: TY + 150, size: 30, weight: 700, fill: DIST, anchor: 'middle' });+ show(gap, t0 + .7);+ txt(p, 'every second: 3 more meters', 800, 360, t0 + 1.2, { size: 36, fill: COL.chalk });+ clockRun(t => {+ const q = ramp(t, t0, t1), sec = 8 * q, x = xm(3 * sec);+ put(run, { x }); if (q > 0 && q < 1) walkTo(run, x); else phPose(run);+ clk.set(sec);+ flags.forEach((f, i) => put(f, { o: sec >= i + 1 - 1e-6 ? 1 : 0 }));+ }, D);+ txt(p, 'Part 1’s miles per hour (mph) is a speed unit too: miles ÷ hours.', 800, 450, m('mph'), { size: 28, fill: COL.dim, weight: 500 });+}],+['average', 'Average speed', (m, D) => {+ const p = panel(0);+ const X0 = 170, U = 4.2, xm = v => X0 + U * v, LA = 420, LB = 640;+ const lane = y => { phBlock(p, 0, y - 70, 1600, 100, PH.road, { top: 0, ol: 0 }); path(p, `M0 ${y - 66}H1600M0 ${y + 26}H1600`, { stroke: PH.line, 'stroke-width': 3, opacity: .5 }); };+ lane(LA);+ for (let v = 0; v <= 300; v += 50) T(p, `${v}`, { x: xm(v), y: LA + 66, size: 24, fill: COL.chalk, anchor: 'middle' });+ T(p, 'meters', { x: xm(300) + 40, y: LA + 66, size: 22, fill: COL.dim });+ const light = phSprite(p, 'light_red', { x: xm(150) + 92, y: LA - 66 });+ const car = phCar(p, { x: xm(0), y: LA + 18, s: .5 });+ const vLab = phLabel(p, '', { y: LA - 112, size: 28, fill: PH.car });+ const clk = simClock(p, 1460, 190, 40);+ // First run, time-lapse: drive (sim 0–10 s), wait at the light (10–18 s), drive on (18–30 s), timed to the words.+ const go = m('go'), st = m('stop'), ag = m('again'), g0 = m('ghost', .3), g1 = g0 + 5;+ const sim1 = t => t < go ? 0 : t < st ? 10 * ramp(t, go, st) : t < ag ? 10 + 8 * ramp(t, st, ag) : 18 + 12 * ramp(t, ag, ag + 2.2);+ const ghostG = G(p, { o: 0 });+ lane(LB); ghostG.append(p.lastChild.previousSibling, p.lastChild); // the second lane belongs to the replay+ const ghost = phCar(ghostG, { x: xm(0), y: LB + 18, s: .5, o: .55 });+ phLabel(ghostG, 'steady 10 m/s, all the way', { x: 150, y: LB + 74, size: 28, fill: COL.chalk, anchor: 'start' });+ show(ghostG, m('ghost'));+ clockRun(t => {+ const s = t < g0 ? sim1(t) : 30 * ramp(t, g0, g1), x = xm(tripX(s));+ put(car, { x }); phRoll(car, tripX(s) * U / .5); put(vLab, { x });+ phText(vLab, `${tripV(s)} m/s`); put(vLab, { o: t >= go && s < 30 ? 1 : 0 }); // speed now; hidden once arrived+ phFrame(light, s >= 10 && s < 18 ? 'light_red' : s >= 18 ? 'light_green' : 'light_red');+ clk.set(s);+ const gx = xm(10 * (t < g0 ? 0 : s)); put(ghost, { x: gx }); phRoll(ghost, 10 * s * U / .5);+ }, D);+ const tot = G(p, { o: 0 });+ 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', 1400, 200, m('total', 1.6), { size: 28, fill: TIME, anchor: 'end' }); // beside the clock, clear of the car's speed label+ const 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));+ show(T(p, '=', { x: 900, y: y + 14, size: 44, weight: 700, anchor: 'middle', o: 0 }), m('ten'));+ show(wfrac(p, '300 m', '30 s', 990, y, { size: 38, ct: DIST, cb: TIME }), m('ten'));+ const ans = T(p, '= 10 m/s', { x: 1070, y: y + 16, size: 48, weight: 700, anchor: 'start', o: 0 });+ pop(put(ans, { s: .6 }), m('ten', .9));+}, { lead: false }], // road and car are on screen from the first frame+['instant', 'Instantaneous speed', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D), w = cam.world;+ const X0 = 150, U = 12.5, TY = 640, xm = v => X0 + U * v;+ meterTrack(w, { x0: X0, U, y: TY, to: 100, every: 10, size: 24 });+ for (let i = 0; i < 16; i++) for (let j = 0; j < 2; j++) mk('rect', { x: xm(100) - 8 + 8 * j, y: TY - 160 + 10 * i, width: 8, height: 10, fill: (i + j) % 2 ? COL.chalk : PH.out }, w); // finish line+ T(w, 'finish', { x: xm(100), y: TY + 92, size: 26, weight: 700, fill: COL.chalk, anchor: 'middle' });+ const run = phPerson(w, { role: 'runner', x: xm(0), y: TY });+ // Run 1 (time-lapse) after "go"; run 2 from "but" in slower motion, frozen at 90 m for the snapshot, then to the finish.+ const a0 = m('go', .1), a1 = a0 + 3, b0 = m('but', .2), fz = b0 + 9 * .7, f1 = m('inst', 1.8);+ const tau = t => t < b0 ? 10 * ramp(t, a0, a1) : t < fz ? (t - b0) / .7 : t < f1 ? 9 : 9 + ramp(t, f1, f1 + .7);+ const sx = t => xm(sprintX(tau(t)));+ cam.to({ x: t => sx(t), y: TY - 80, z: 1.9 }, m('fast', .2), 1.4).to({ x: 800, y: 450, z: 1 }, f1 + .9, 1.2);+ const clk = simClock(p, 1460, 190, 40);+ const vg = G(p, { o: 0 }), vLab = phLabel(vg, '', { size: 30, fill: COL.task });+ show(vg, b0);+ clockRun(t => {+ const s = tau(t), x = sx(t);+ const still = t >= fz && t < f1; // frozen for the snapshot+ put(run, { x }); if (!still) { if (s > 0 && s < 10) walkTo(run, x, 30); else phPose(run); }+ clk.set(s);+ phText(vLab, `now: ${Math.round(sprintV(s))} m/s`); cam.track(vLab, x, TY - 150, t);+ }, D);+ runs(p, [['average speed = 100 m ÷ 10 s = ', COL.chalk], ['10 m/s', COL.chalk]], { x: 800, y: 100, size: 40, weight: 700 });+ show(p.lastChild, m('avg', .9));+ const snap = G(p, { o: 0 });+ [[700, 330, 1, 1], [900, 330, -1, 1], [700, 610, 1, -1], [900, 610, -1, -1]].forEach(([x, y, dx, dy]) => path(snap, `M${x} ${y + 40 * dy}V${y}H${x + 40 * dx}`, { stroke: COL.task, 'stroke-width': 6 }));+ show(snap, fz, .2); hide(snap, f1, .3);+ runs(p, [['instantaneous speed', COL.task], [': the speed at one moment', COL.chalk]], { x: 800, y: 180, size: 38 });+ show(p.lastChild, m('inst'));+}, { lead: false }], // track and runner are on screen from the first frame+['q2', 'Quick check', (m, D) => {+ const p = panel(0);+ const X0 = 170, U = 20, xm = v => X0 + U * v;+ phBlock(p, 0, 170, 1600, 250, '#2f6f9e', { top: 6, ol: 0 });+ path(p, 'M0 295H1600', { stroke: '#e8eef2', 'stroke-width': 4, 'stroke-dasharray': '18 14', opacity: .7 });+ for (let v = 0; v <= 60; v += 10) { T(p, `${v}`, { x: xm(v), y: 156, size: 24, fill: COL.chalk, anchor: 'middle' }); mk('rect', { x: xm(v) - 2, y: 170, width: 4, height: 250, fill: '#e8eef2', opacity: .18 }, p); }+ T(p, 'meters', { x: xm(60) + 36, y: 156, size: 22, fill: COL.dim });+ const dol = phSprite(p, 'dolphin', { x: xm(0), y: 270 }), wal = phSprite(p, 'walrus', { x: xm(0), y: 405 });+ const dl = phLabel(p, '56 m in 8 s', { y: 200, size: 30, fill: COL.chalk, o: 0 }), wl = phLabel(p, '30 m in 6 s', { y: 325, size: 30, fill: COL.chalk, o: 0 });+ clockRun(t => {+ const s = Math.max(0, t - .5) * 1.4, dx = xm(7 * Math.min(s, 8)), wx = xm(5 * Math.min(s, 6));+ put(dol, { x: dx }); put(wal, { x: wx });+ put(dl, { x: dx, o: s >= 8 ? 1 : 0 }); put(wl, { x: wx, o: s >= 6 ? 1 : 0 });+ }, D);+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-dw-speed', prompt: ['Speed = ', h('b', '', 'distance ÷ time'), '. Find each speed.'],+ build: blanks([+ { parts: ['dolphin: 56 meters ÷ 8 seconds = ', { box: '7' }, ' meters per second'], why: '56 ÷ 8 = 7.', hint: 'Divide the dolphin’s distance by its time: 56 ÷ 8.' },+ { parts: ['walrus: 30 meters ÷ 6 seconds = ', { box: '5' }, ' meters per second'], why: '30 ÷ 6 = 5.', hint: 'Divide the walrus’s distance by its time: 30 ÷ 6.' },+ ]) },+ { id: 'c-dw-faster', prompt: ['Which animal is faster?'],+ build: choice([['the dolphin'], ['the walrus'], ['both are the same']], 0,+ 'The dolphin covers 7 meters every second; the walrus covers 5.',+ [null, 'The walrus’s 30 meters took 6 seconds: 5 meters per second, less than the dolphin’s 7.', 'Compare meters per second: 7 for the dolphin, 5 for the walrus.'],+ () => floatText('dolphin: 7 m/s > 5 m/s', 800, 130, COL.good)) },+ { id: 'c-car-avg', prompt: ['A car drives 150 meters in 12 seconds. What is its ', h('b', '', 'average speed'), '?'],+ build: blanks([{ parts: ['150 meters ÷ 12 seconds = ', { box: '12.5' }, ' meters per second'], why: '150 ÷ 12 = 12.5. The answer can be a decimal.', hint: 'Divide the total distance by the total time: 150 ÷ 12. The answer is a decimal.' }]) },+], done) }],+['wrap2', 'Summary · Speed', (m, D) => {+ const p = panel(0);+ txt(p, 'Speed', 800, 130, .2, { size: 40, fill: COL.dim });+ [['Speed = distance ÷ time.', 'w1'],+ ['In science, speed is measured in meters per second (m/s).', 'w2'],+ ['Average speed = total distance ÷ total time.', 'w3'],+ ['Instantaneous speed is the speed at one moment.', 'w4']].forEach(([s, mark], i) => {+ const g = G(p, { x: -16, y: 260 + i * 120, o: 0 });+ mk('rect', { x: 144, y: -38, width: 52, height: 52, rx: 6, fill: PH.ref }, g);+ T(g, String(i + 1), { x: 170, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, s, { x: 230, size: 36, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ txt(p, 'Next: speed with a direction, velocity.', 800, 780, m('end'), { size: 32, fill: COL.dim, weight: 500 });+}],+/* ---------- part 3: velocity ---------- */+['part3', 'Part 3 · Velocity', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D, { x: 800, y: 285, z: .9 });+ const road = phRoad(cam);+ const a = phCar(road.vehicles, { y: ROAD.near }), b = phCar(road.vehicles, { y: ROAD.far });+ phFace(b, -1);+ const arA = path(road.front, '', { stroke: VEL, 'stroke-width': 8 }), arB = path(road.front, '', { stroke: VEL, 'stroke-width': 8 });+ clockRun(t => {+ const xa = -150 + 200 * t, xb = 1750 - 200 * t;+ put(a, { x: xa }); phRoll(a, xa); put(b, { x: xb }); phRoll(b, -xb);+ arrowAt(arA, xa - 55, ROAD.near - 130, 110, 0); arrowAt(arB, xb + 55, ROAD.far - 222, 110, 180);+ }, D);+ const g = G(p, { o: 0, y: 24 });+ T(g, 'Chapter 9 · Motion', { x: 800, y: 130, size: 28, fill: COL.dim, anchor: 'middle' });+ phLabel(g, 'Velocity', { x: 800, y: 250, size: 120, weight: 600 });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ txt(p, 'Part 3 · Same speed, which way?', 800, 320, m('q'), { size: 36, fill: COL.dim });+}],+['velocity', 'Speed in a direction', (m, D) => {+ const p = panel(0);+ const XL = 260, XR = 1340, TY = 640, j0 = m('jog'), LEG = (m('minus') - j0) / 5; // equal legs: right at "plus", left at "minus"+ txt(p, 'Velocity = speed in a certain direction', 800, 110, .2, { size: 40 });+ phBlock(p, 160, TY, 1280, 14, '#8a6f55', { top: 4, ol: 0 });+ const conv = G(p, { o: 0 });+ path(conv, arrowPath(900, TY + 70, 1400), { stroke: VEL, 'stroke-width': 5 });+ T(conv, '+ direction', { x: 1150, y: TY + 120, size: 30, weight: 700, fill: VEL, anchor: 'middle' });+ path(conv, arrowPath(700, TY + 70, 200), { stroke: VEL, 'stroke-width': 5, opacity: .6 });+ T(conv, '− direction', { x: 450, y: TY + 120, size: 30, weight: 700, fill: VEL, anchor: 'middle', o: 1 });+ show(conv, m('sign'));+ const you = phPerson(p, { x: XL, y: TY });+ const sp = phLabel(p, 'speed: 2 m/s', { size: 30, o: 0 });+ const vg = G(p, { o: 0 }), vl = phLabel(vg, '', { size: 30, fill: VEL }), va = path(vg, '', { stroke: VEL, 'stroke-width': 7 });+ show(sp, j0); show(vg, m('diff'));+ clockRun(t => {+ let x = XL, dir = 1;+ if (t > j0) { const k = Math.floor((t - j0) / LEG), u = (t - j0) / LEG - k; dir = k % 2 ? -1 : 1; x = dir > 0 ? XL + (XR - XL) * u : XR - (XR - XL) * u; }+ put(you, { x }); phFace(you, dir); if (t > j0) walkTo(you, (t - j0) * 300); else phPose(you);+ put(sp, { x, y: TY - 230 }); put(vl, { x, y: TY - 190 });+ phText(vl, dir > 0 ? 'velocity: +2 m/s' : 'velocity: −2 m/s');+ arrowAt(va, x - 55 * dir, TY - 158, 110, dir > 0 ? 0 : 180);+ }, D);+ show(T(p, '+2 m/s →', { x: 560, y: 240, size: 60, weight: 700, fill: VEL, anchor: 'middle', o: 0 }), m('plus'));+ show(T(p, '−2 m/s ←', { x: 1040, y: 240, size: 60, weight: 700, fill: VEL, anchor: 'middle', o: 0 }), m('minus'));+ txt(p, 'same size (2 m/s), opposite directions: the sign tells which way', 800, 315, m('sign'), { size: 32, fill: COL.chalk, weight: 500 });+}],+['change', 'Two ways to change velocity', (m, D) => {+ const p = panel(0);+ const LA = 400, LB = 720, sp0 = m('spd'), dr = m('dir', .6);+ txt(p, 'A change in velocity means a change in…', 800, 110, .2, { size: 40 });+ [LA, LB].forEach(y => { phBlock(p, 0, y - 70, 1600, 100, PH.road, { top: 0, ol: 0 }); path(p, `M0 ${y - 20}H1600`, { stroke: PH.line, 'stroke-width': 4, 'stroke-dasharray': '50 60', opacity: .5 }); });+ const a = phCar(p, { y: LA + 18, s: .6 }), b = phCar(p, { y: LB + 18, s: .6 });+ const arA = path(p, '', { stroke: VEL, 'stroke-width': 8 }), arB = path(p, '', { stroke: VEL, 'stroke-width': 8 });+ const lA = phLabel(p, '', { size: 28, fill: VEL }), lB = phLabel(p, '', { size: 28, fill: VEL });+ const ta = phLabel(p, 'speed', { x: 60, y: LA - 110, size: 44, fill: COL.chalk, anchor: 'start', o: 0 });+ const tb = phLabel(p, 'direction', { x: 60, y: LB - 110, size: 44, fill: COL.chalk, anchor: 'start', o: 0 });+ show(ta, sp0 - .3); show(tb, m('dir', -.3));+ clockRun(t => {+ const u = Math.max(0, t - sp0), acc = Math.min(u, 3), v = 60 + 60 * acc; // px/s: 4 → 16 m/s+ const xa = Math.min(1440, 160 + 60 * t + 30 * acc * acc + 240 * Math.max(0, u - 3));+ put(a, { x: xa }); phRoll(a, xa / .6); arrowAt(arA, xa - v * .3, LA - 80, v * .6, 0);+ put(lA, { x: xa, y: LA - 118 }); phText(lA, `velocity: +${Math.round(v / 15)} m/s`);+ const xb = t < dr ? 300 + 100 * t : 300 + 100 * dr - 100 * (t - dr), db = t < dr ? 1 : -1;+ put(b, { x: xb }); phFace(b, db); phRoll(b, xb / .6 * db); arrowAt(arB, xb - 45 * db, LB - 80, 90, db > 0 ? 0 : 180);+ put(lB, { x: xb, y: LB - 118 }); phText(lB, `velocity: ${db > 0 ? '+' : '−'}6 m/s`);+ }, D);+}],+['corner', 'Turning a corner', (m, D) => {+ const p = panel(0);+ const ab = m('above'), V2 = 150, R0 = 250, L1 = 1050, ARC = Math.PI / 2 * R0, t0 = m('turn') - L1 / V2;+ // Side shot first, then a cross-fade to an overhead camera: only from above can we see the turn.+ const side = camera(p, D, { x: 800, y: 285, z: .9 });+ const road = phRoad(side), sc = phCar(road.vehicles, { y: ROAD.near });+ const sTag = txt(p, 'seen from the side', 70, 80, .2, { size: 30, fill: COL.dim, anchor: 'start' });+ hide(sTag, ab, .4);+ // Only the overhead camera fades (over the side shot), then the side camera stops rendering: one+ // half-transparent full-screen group at a time is much cheaper in Firefox than two.+ prog(q => { if (q === 1) side.el.style.display = 'none'; }, ab + .85, 0, lin);+ const top = camera(p, D);+ put(top.el, { o: 0 }); show(top.el, ab, .8);+ const w = top.world;+ const { pose } = overheadStreet(w);+ // Faint copies of the arrow where the car was: the direction turns, the length (speed) doesn't.+ const marks = [L1 - 1, L1 + ARC / 2, L1 + ARC].map(dd => { const [x, y, a] = pose(dd); return arrowAt(path(w, '', { stroke: VEL, 'stroke-width': 6, opacity: 0 }), x, y, 150, a); });+ const car = phTop(w, 'car_top'), arr = path(w, '', { stroke: VEL, 'stroke-width': 9 });+ const spd = phLabel(p, 'speed: 10 m/s', { x: 70, y: 90, size: 40, anchor: 'start', o: 0 });+ const vg = G(p, { o: 0 }), vl = phLabel(vg, '', { size: 30, fill: VEL });+ show(spd, m('drive')); show(vg, m('drive')); pulse(spd, m('still'), 1.25);+ const cmp = G(p, { x: 1470, y: 760, o: 0 }); // bottom right: the velocity label passes the top+ [[0, -1, 'N'], [1, 0, 'E'], [0, 1, 'S'], [-1, 0, 'W']].forEach(([dx, dy, n]) => {+ path(cmp, `M0 0L${dx * 44} ${dy * 44}`, { stroke: n === 'N' ? COL.chalk : COL.dim, 'stroke-width': 4 });+ T(cmp, n, { x: dx * 70, y: dy * 70 + 10, size: 26, weight: 700, fill: COL.chalk, anchor: 'middle' });+ });+ show(cmp, ab + .4);+ clockRun(t => {+ const xs = -150 + 150 * t; put(sc, { x: xs }); phRoll(sc, xs);+ const d = Math.max(0, V2 * (t - t0)), [x, y, a] = pose(d), r = a * Math.PI / 180;+ put(car, { x, y, r: a });+ const bx = x + 80 * Math.cos(r), by = y + 80 * Math.sin(r);+ arrowAt(arr, bx, by, 150, a);+ marks.forEach((e, i) => put(e, { o: d > [L1 - 1, L1 + ARC / 2, L1 + ARC][i] && t > ab ? .35 : 0 }));+ phText(vl, `velocity: 10 m/s ${compassWord(a)}`);+ top.track(vl, bx + 330 * Math.cos(r), by + 330 * Math.sin(r) - 40 * Math.abs(Math.cos(r)), t);+ }, D);+ runs(p, [['Same speed, new direction: the ', COL.chalk], ['velocity', VEL], [' changes.', COL.chalk]], { x: 800, y: 850, size: 38, weight: 700 });+ show(p.lastChild, m('rule'));+}],+['q3', 'Quick check', (m, D) => {+ const p = panel(0);+ const X0 = 520, X1 = 1080, Y0 = 110, Y1 = 390, per = 2 * (X1 - X0 + Y1 - Y0);+ phBlock(p, X0 - 50, Y0 - 50, X1 - X0 + 100, Y1 - Y0 + 100, PH.walk, { top: 0, ol: 0 });+ phBlock(p, X0 + 30, Y0 + 30, X1 - X0 - 60, Y1 - Y0 - 60, PH.grass, { top: 0, ol: 0 });+ [[X0 + 80, Y0 + 70], [X0 + 250, Y0 + 70], [X0 + 420, Y0 + 130]].forEach(([x, y]) => phBlock(p, x, y, 110, 90, '#a65d4b', { top: 8, right: 10, ol: 0 }));+ T(p, 'one square block', { x: 800, y: Y1 + 40, size: 26, fill: COL.dim, anchor: 'middle' });+ const walker = phTop(p, 'you_top', { s: .9 }), arr = path(p, '', { stroke: VEL, 'stroke-width': 7 });+ const pose = d => { d = ((d % per) + per) % per; const w = X1 - X0, h = Y1 - Y0;+ return d < w ? [X0 + d, Y0, 0] : d < w + h ? [X1, Y0 + d - w, 90] : d < 2 * w + h ? [X1 - (d - w - h), Y1, 180] : [X0, Y1 - (d - 2 * w - h), -90]; };+ clockRun(t => { const [x, y, a] = pose(220 * t); put(walker, { x, y, r: a }); arrowAt(arr, x + 34 * Math.cos(a * Math.PI / 180), y + 34 * Math.sin(a * Math.PI / 180), 70, a, 14); }, D);+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-vel-need', prompt: ['What do you need to know to describe an object’s ', h('b', '', 'velocity'), '?'],+ build: choice([['its speed only'], ['its direction only'], ['its speed and its direction']], 2,+ 'Velocity is speed in a certain direction, so it needs both.',+ ['Speed alone is not velocity: two cars at the same speed can go opposite ways.', 'Direction alone does not say how fast.', null]) },+ { id: 'c-uturn', prompt: ['A truck drives at 30 kilometers per hour, makes a U-turn, then drives 30 kilometers per hour the other way. What changed?'],+ build: choice([['its speed'], ['its velocity'], ['both'], ['neither']], 1,+ 'Same speed, opposite direction: the velocity changed, the speed did not.',+ ['It is 30 kilometers per hour before and after the U-turn: the speed is the same.', null, 'The speed stayed 30 kilometers per hour; only the direction changed.', 'The direction changed, and velocity includes direction.'],+ () => floatText('velocity changed', 800, 470, VEL)) },+ { id: 'c-block', prompt: ['You walk once around a square block at the same pace, turning at each of its four corners.'],+ build: blanks([+ { parts: ['Your velocity changes ', { box: '4' }, ' times'], why: 'Each corner is a new direction: 4 changes.', hint: 'Velocity changes whenever the direction changes. How many times do you turn?' },+ { parts: ['Your speed changes ', { box: '0' }, ' times'], why: 'Same pace the whole way: the speed never changes.', hint: 'You keep the same pace. Does your speed ever change?' },+ ]) },+], done) }],+['wrap3', 'Summary · Velocity', (m, D) => {+ const p = panel(0);+ txt(p, 'Velocity', 800, 130, .2, { size: 40, fill: COL.dim });+ [['Velocity is speed in a certain direction.', 'w1'],+ ['Same speed, opposite directions: different velocities (+2 and −2 m/s).', 'w2'],+ ['Velocity changes when the speed or the direction changes.', 'w3']].forEach(([s, mark], i) => {+ const g = G(p, { x: -16, y: 290 + i * 130, o: 0 });+ mk('rect', { x: 144, y: -38, width: 52, height: 52, rx: 6, fill: PH.ref }, g);+ T(g, String(i + 1), { x: 170, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, s, { x: 230, size: 36, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ txt(p, 'Next: how velocity changes over time, acceleration.', 800, 760, m('end'), { size: 32, fill: COL.dim, weight: 500 });+}],+/* ---------- part 4: acceleration ---------- */+['part4', 'Part 4 · Acceleration', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D, { x: 800, y: 285, z: .9 });+ const road = phRoad(cam), car = phCar(road.vehicles, { y: ROAD.near });+ const av = path(road.front, '', { stroke: VEL, 'stroke-width': 8 }), aa = path(road.front, '', { stroke: ACC, 'stroke-width': 8 });+ clockRun(t => {+ const x = -150 + 40 * t + 30 * t * t, v = 40 + 60 * t; // speeding up from the left+ put(car, { x }); phRoll(car, x); arrowAt(av, x - 40, ROAD.near - 130, v * .35, 0); arrowAt(aa, x - 40, ROAD.near - 160, 90, 0);+ }, D);+ const g = G(p, { o: 0, y: 24 });+ T(g, 'Chapter 9 · Motion', { x: 800, y: 130, size: 28, fill: COL.dim, anchor: 'middle' });+ phLabel(g, 'Acceleration', { x: 800, y: 250, size: 120, weight: 600 });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ txt(p, 'Part 4 · Speeding up, slowing down, turning', 800, 320, m('q'), { size: 36, fill: COL.dim });+}],+['accel', 'Three ways to accelerate', (m, D) => {+ const p = panel(0);+ txt(p, 'Acceleration: the rate at which velocity changes', 800, 140, .2, { size: 40 });+ vaKey(p, m('ways'));+ const W = 460, Y = 230, H = 400, xs = [70, 570, 1070];+ const box = (i, t0, title) => {+ const cam = camera(p, D, { box: [xs[i], Y, W, H], x: i < 2 ? 760 : 800, y: i < 2 ? 470 : 450, z: .5 });+ put(cam.el, { o: 0 }); show(cam.el, m('ways') + .2 * i);+ const lab = phLabel(p, title, { x: xs[i] + W / 2, y: Y + H + 52, size: 34, o: 0 }); show(lab, m('ways') + .2 * i); pulse(lab, t0, 1.25);+ return cam;+ };+ // Each box loops a 3-second clip, so all three keep moving while the narration names them.+ const side = (cam, f) => {+ const w = cam.world;+ phBlock(w, 0, 520, 1600, 120, PH.road, { top: 0, ol: 0 });+ const car = phCar(w, { y: 600 }), av = path(w, '', { stroke: VEL, 'stroke-width': 14 }), aa = path(w, '', { stroke: ACC, 'stroke-width': 14 });+ return t => { const [x, v, dir] = f(t % 3); put(car, { x }); phRoll(car, x); arrowAt(av, x - 60, 440, v, 0, 30); arrowAt(aa, x - 60 + (dir < 0 ? 180 : 0), 360, 180, dir > 0 ? 0 : 180, 30); };+ };+ const up = side(box(0, m('up'), 'speeding up'), u => [380 + 60 * u + 45 * u * u, 60 + 90 * u, 1]);+ const down = side(box(1, m('down'), 'slowing down'), u => [380 + 330 * u - 45 * u * u, 330 - 90 * u, -1]);+ const tc = box(2, m('turn'), 'changing direction'), tw3 = tc.world;+ mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: PH.grass }, tw3);+ mk('circle', { cx: 800, cy: 450, r: 300, fill: 'none', stroke: PH.road, 'stroke-width': 130 }, tw3);+ const car = phTop(tw3, 'car_top', { s: 1.6 }), av = path(tw3, '', { stroke: VEL, 'stroke-width': 14 }), aa = path(tw3, '', { stroke: ACC, 'stroke-width': 14 });+ clockRun(t => {+ up(t); down(t);+ const th = -t * 1.1, x = 800 + 300 * Math.cos(th), y = 450 + 300 * Math.sin(th), hd = th * 180 / Math.PI - 90; // counterclockwise+ put(car, { x, y, r: hd }); arrowAt(av, x, y, 220, hd, 30); arrowAt(aa, x, y, 170, th * 180 / Math.PI + 180, 30);+ }, D);+}],+['formula', 'Acceleration = change in velocity ÷ time', (m, D) => {+ const p = panel(0);+ const X0 = 200, U = 20, TY = 660, xm = v => X0 + U * v, e0 = m('ex', .2), e1 = e0 + 5;+ const y = 170;+ show(T(p, 'acceleration =', { x: 470, y: y + 14, size: 46, weight: 700, anchor: 'end', fill: ACC, o: 0 }), m('f'));+ show(wfrac(p, 'final velocity − starting velocity', 'time', 820, y, { size: 38, ct: VEL, cb: TIME }), m('f', .3));+ show(T(p, '=', { x: 1145, y: y + 14, size: 46, weight: 700, anchor: 'middle', o: 0 }), m('calc'));+ show(wfrac(p, '25 − 5 m/s', '4 s', 1275, y, { size: 38, ct: VEL, cb: TIME }), m('calc'));+ const ans = T(p, '= 5 m/s²', { x: 1150, y: y + 110, size: 52, weight: 700, anchor: 'start', fill: ACC, o: 0 });+ pop(put(ans, { s: .6 }), m('ans'));+ meterTrack(p, { x0: X0, U, y: TY, to: 60, every: 10 });+ const car = phCar(p, { x: xm(0), y: TY, s: .6 }), clk = simClock(p, 1460, 360, 40);+ const vl = phLabel(p, '', { size: 30, fill: VEL, o: 0 }); show(vl, e0 - .3);+ // A flag every second, at the car's position, with its velocity: 5, 10, 15, 20, 25 m/s. The gaps grow.+ const flags = [0, 1, 2, 3, 4].map(k => {+ const g = G(p, { x: xm(5 * k + 2.5 * k * k), y: TY, o: 0 });+ mk('rect', { x: -2, y: -150, width: 4, height: 150, fill: VEL, opacity: .7 }, g);+ T(g, `${5 + 5 * k} m/s`, { y: -160, size: 26, weight: 700, fill: VEL, anchor: 'middle' });+ T(g, `${k} s`, { y: 110, size: 24, weight: 700, fill: TIME, anchor: 'middle' });+ return g;+ });+ txt(p, 'every second: 5 m/s faster', 800, 400, m('unit', .4), { size: 36, fill: ACC });+ clockRun(t => {+ const s = 4 * ramp(t, e0, e1), x = xm(5 * s + 2.5 * s * s);+ put(car, { x }); phRoll(car, (x - X0) / .6); clk.set(s);+ put(vl, { x, y: TY - 80, o: s < 4 ? 1 : 0 }); phText(vl, `${Math.round(5 + 5 * s)} m/s`);+ flags.forEach((f, k) => put(f, { o: t >= e0 && s >= k - 1e-6 ? 1 : 0 }));+ }, D);+}, { lead: false }],+['sign', 'Positive and negative acceleration', (m, D) => {+ const p = panel(0);+ const g0 = m('gas'), b0 = m('brake'), A = 60; // px/s²; 12 px/s = 1 m/s on screen, so A = 5 m/s²+ // Velocity: 60 px/s, gas 3 s up to 240, cruise, brake 4 s down to 0. x(t) is its integral.+ const v = t => t < g0 ? 60 : t < g0 + 3 ? 60 + A * (t - g0) : t < b0 ? 240 : Math.max(0, 240 - A * (t - b0));+ const xAt = t => { const a = Math.min(t, g0), b = Math.min(Math.max(t - g0, 0), 3), c = Math.min(Math.max(t - g0 - 3, 0), b0 - g0 - 3), d = Math.min(Math.max(t - b0, 0), 4);+ return 60 * a + 60 * b + A * b * b / 2 + 240 * c + 240 * d - A * d * d / 2; };+ const cam = camera(p, D, { x: 800, y: 560, z: 1 });+ cam.cut({ x: t => 300 + xAt(t) + 150 }, 0); // follow: the road streams faster or slower behind the car+ const road = phRoad(cam), car = phCar(road.vehicles, { y: ROAD.near });+ const av = path(road.front, '', { stroke: VEL, 'stroke-width': 8 }), aa = path(road.front, '', { stroke: ACC, 'stroke-width': 8 });+ const vg = G(p), vl = phLabel(vg, '', { size: 30, fill: VEL }), ag = G(p), al = phLabel(ag, '', { size: 30, fill: ACC });+ vaKey(p, .2);+ const pedal = (x, label, sign, col) => {+ const g = G(p, { x, y: 820 });+ phBlock(g, -40, -110, 80, 110, '#59625e', { top: 6, right: 8, ol: 0 });+ T(g, label, { y: 44, size: 26, weight: 700, fill: COL.chalk, anchor: 'middle' });+ T(g, sign, { y: -36, size: 54, weight: 700, fill: col, anchor: 'middle' });+ return g;+ };+ const brake = pedal(1300, 'brake', '−', ACC), gas = pedal(1440, 'gas', '+', ACC);+ clockRun(t => {+ const x = 300 + xAt(t), vv = v(t), acc = t >= g0 && t < g0 + 3 ? 1 : t >= b0 && vv > 0 ? -1 : 0;+ put(car, { x }); phRoll(car, x);+ arrowAt(av, x - 60, ROAD.near - 140, vv * .55, 0); arrowAt(aa, acc > 0 ? x - 60 : x + 60, ROAD.near - 180, acc ? 110 : 0, acc > 0 ? 0 : 180);+ phText(vl, `velocity: ${Math.round(vv / 12)} m/s →`); cam.track(vl, x, ROAD.near - 210, t);+ phText(al, acc ? `acceleration: ${acc > 0 ? '+' : '−'}5 m/s²` : 'acceleration: 0'); cam.track(al, x, ROAD.near - 250, t);+ put(gas, { y: acc > 0 ? 832 : 820 }); put(brake, { y: acc < 0 ? 832 : 820 });+ }, D);+ runs(p, [['negative acceleration = ', COL.chalk], ['deceleration', ACC]], { x: 700, y: 870, size: 36, weight: 700 });+ show(p.lastChild, m('decel'));+}],+['turnfeel', 'Turning is accelerating', (m, D) => {+ const p = panel(0);+ const cam = camera(p, D), { pose, L1, ARC, cx, cy } = overheadStreet(cam.world), V3 = 70, t0 = m('dir') - L1 / V3;+ const car = phTop(cam.world, 'car_top'), av = path(cam.world, '', { stroke: VEL, 'stroke-width': 9 }), aa = path(cam.world, '', { stroke: ACC, 'stroke-width': 9 });+ const feel = path(cam.world, '', { stroke: COL.chalk, 'stroke-width': 6, 'stroke-dasharray': '12 10' });+ const fg = G(p, { o: 0 }), fl = phLabel(fg, 'you feel pushed outward', { size: 30 });+ const ugh = phLabel(cam.world, 'UGH!', { size: 34, fill: COL.chalk, o: 0 });+ vaKey(p, .2);+ const sp = phLabel(p, 'speed: steady', { x: 70, y: 140, size: 30, anchor: 'start', o: 0 }); show(sp, m('dir'));+ const tf = m('feel');+ clockRun(t => {+ const d = V3 * (t - t0), [x, y, a] = pose(d), r = a * Math.PI / 180, onArc = d > L1 && d < L1 + ARC;+ put(car, { x, y, r: a }); arrowAt(av, x + 80 * Math.cos(r), y + 80 * Math.sin(r), 140, a);+ const ia = Math.atan2(cy - y, cx - x) * 180 / Math.PI; // toward the centre of the turn+ arrowAt(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 - 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) => {+ const p = panel(0);+ const bee = phTop(p, 'bee', { s: 1.2 }), av = path(p, '', { stroke: VEL, 'stroke-width': 7 });+ mk('circle', { cx: 800, cy: 270, r: 170, fill: 'none', stroke: COL.faint, 'stroke-width': 3, 'stroke-dasharray': '10 12' }, p);+ T(p, 'a bee flying in a circle at a steady speed', { x: 800, y: 500, size: 26, fill: COL.dim, anchor: 'middle' });+ clockRun(t => {+ const th = -.9 * t, x = 800 + 170 * Math.cos(th), y = 270 + 170 * Math.sin(th), hd = th * 180 / Math.PI - 90;+ put(bee, { x, y }); phFace(bee, Math.cos(hd * Math.PI / 180) < 0 ? -1 : 1); arrowAt(av, x, y, 90, hd, 14);+ }, D);+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-bee', prompt: ['A bee flies in a circle at a steady speed. Is it ', h('b', '', 'accelerating'), '?'],+ build: choice([['yes: its direction keeps changing'], ['no: its speed stays the same']], 0,+ 'Its velocity keeps changing direction, so it is accelerating all the time.',+ [null, 'Acceleration is a change in velocity, and velocity includes direction. The bee keeps turning.']) },+ { id: 'c-3ways', prompt: ['Which of these is ', h('b', '', 'not'), ' acceleration?'],+ build: choice([['speeding up'], ['slowing down'], ['changing direction'], ['a steady speed in a straight line']], 3,+ 'Same speed, same direction: the velocity does not change, so there is no acceleration.',+ ['Speeding up changes the velocity: that is acceleration.', 'Slowing down changes the velocity too: negative acceleration.', 'A change of direction changes the velocity: that is acceleration.', null]) },+ { id: 'c-acc', prompt: ['A runner speeds up from 2 to 8 meters per second in 3 seconds.'],+ build: blanks([{ parts: ['acceleration = (8 − 2) ÷ 3 = ', { box: '2' }, ' meters per second squared'], why: '8 − 2 = 6, and 6 ÷ 3 = 2.', hint: 'Subtract the starting velocity from the final one, then divide by the time.' }]) },+], done) }],+['wrap4', 'Summary · Acceleration', (m, D) => {+ const p = panel(0);+ txt(p, 'Acceleration', 800, 120, .2, { size: 40, fill: COL.dim });+ [['Acceleration is the rate at which velocity changes.', 'w1'],+ ['It happens when something speeds up, slows down, or changes direction.', 'w2'],+ ['acceleration = (final velocity − starting velocity) ÷ time, in m/s².', 'w3'],+ ['Positive speeds up; negative (deceleration) slows down.', 'w4']].forEach(([s, mark], i) => {+ const g = G(p, { x: -16, y: 250 + i * 120, o: 0 });+ mk('rect', { x: 144, y: -38, width: 52, height: 52, rx: 6, fill: PH.ref }, g);+ T(g, String(i + 1), { x: 170, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ T(g, s, { x: 230, size: 36, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ });+ txt(p, 'Next: the chapter practice.', 800, 780, m('w4', 5), { size: 32, fill: COL.dim, weight: 500 });+}],+/* ---------- chapter practice and finish (after the last section) ---------- */+['final1', 'Chapter practice: motion and speed', () => { panel(0); }, { ask: done => quiz(SCREEN, [+ { id: 'p-formula', prompt: ['What is the formula for ', h('b', '', 'speed'), '?'],+ build: choice([['distance ÷ time'], ['time ÷ distance'], ['distance × time']], 0,+ 'Speed is the distance traveled in a certain amount of time: distance ÷ time.',+ [null, 'That would give seconds per meter, not meters per second.', 'Speed divides the distance by the time; it does not multiply them.']) },+ { id: 'p-relative', prompt: ['Why is motion ', h('b', '', 'relative'), '?'],+ build: choice([['It is always described from a reference point.'], ['Everything moves at the same speed.'], ['Only things on Earth can move.']], 0,+ 'Motion is measured from a reference point, and different reference points can give different answers.',+ [null, 'Things move at many speeds; the point is that each speed is measured from something.', 'Earth itself moves. Motion is described from a reference point.']) },+ { id: 'p-bus', prompt: ['Sam sits on a bus driving at 40 kilometers per hour. Measured from the ', h('b', '', 'bus driver'), ', how fast is Sam moving?'],+ build: choice([['0 kilometers per hour'], ['40 kilometers per hour'], ['80 kilometers per hour']], 0,+ 'Sam and the driver ride together, so from the driver Sam stays put. From the road, Sam moves 40 kilometers per hour.',+ [null, 'That is Sam’s speed measured from the road, not from the driver.', 'Nothing adds up to 80 here. Sam rides along with the driver.']) },+ { id: 'p-cyclist', prompt: ['A cyclist rides 90 meters in 15 seconds. What is her speed?'],+ build: blanks([{ parts: ['speed = 90 ÷ 15 = ', { box: '6' }, ' meters per second'], why: '90 ÷ 15 = 6.', hint: 'Divide the distance by the time.' }]) },+], done, 'Chapter practice, set 1 of 2 · question') }], // the engine appends "k of n"+['final2', 'Chapter practice: velocity and acceleration', () => { panel(0); }, { ask: done => quiz(SCREEN, [+ { id: 'p-jog', prompt: ['A jogger runs at +3 meters per second, then turns around and jogs at the same pace. What is her new velocity?'],+ build: blanks([{ parts: ['velocity = ', { box: '-3' }, ' meters per second'], why: 'Same speed, opposite direction: the sign flips.', hint: 'The speed stays 3; the direction is opposite, so the sign changes.' }]) },+ { id: 'p-corner', prompt: ['A car drives around a corner at a steady 15 meters per second. Which is true?'],+ build: choice([['its speed changes'], ['its velocity changes'], ['neither changes']], 1,+ 'Its direction changes, so its velocity changes; the speed stays 15 meters per second.',+ ['It keeps a steady 15 meters per second.', null, 'Turning changes the direction, and velocity includes direction.']) },+ { id: 'p-acc', prompt: ['A car speeds up from 4 to 16 meters per second in 3 seconds. What is its acceleration?'],+ build: blanks([{ parts: ['acceleration = (16 − 4) ÷ 3 = ', { box: '4' }, ' meters per second squared'], why: '16 − 4 = 12, and 12 ÷ 3 = 4.', hint: 'Final velocity minus starting velocity, then divide by the time.' }]) },+ { id: 'p-dec', prompt: ['A bike slows down from 8 to 2 meters per second in 3 seconds. What is its acceleration?'],+ build: blanks([{ parts: ['acceleration = (2 − 8) ÷ 3 = ', { box: '-2' }, ' meters per second squared'], why: '2 − 8 = −6, and −6 ÷ 3 = −2: negative, because it slows down.', hint: 'Final minus starting velocity is negative here. Divide it by the time.' }]) },+], done, 'Chapter practice, set 2 of 2 · question') }],+['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/science/ch10/audio/en/balance.mp3 b/site/science/ch10/audio/en/balance.mp3new file mode 100644index 0000000..6d3f884Binary files /dev/null and b/site/science/ch10/audio/en/balance.mp3 differdiff --git a/site/science/ch10/audio/en/calc.mp3 b/site/science/ch10/audio/en/calc.mp3new file mode 100644index 0000000..f9ec120Binary files /dev/null and b/site/science/ch10/audio/en/calc.mp3 differdiff --git a/site/science/ch10/audio/en/cart.mp3 b/site/science/ch10/audio/en/cart.mp3new file mode 100644index 0000000..924c722Binary files /dev/null and b/site/science/ch10/audio/en/cart.mp3 differdiff --git a/site/science/ch10/audio/en/earth.mp3 b/site/science/ch10/audio/en/earth.mp3new file mode 100644index 0000000..efece44Binary files /dev/null and b/site/science/ch10/audio/en/earth.mp3 differdiff --git a/site/science/ch10/audio/en/final1.mp3 b/site/science/ch10/audio/en/final1.mp3new file mode 100644index 0000000..6653dd1Binary files /dev/null and b/site/science/ch10/audio/en/final1.mp3 differdiff --git a/site/science/ch10/audio/en/final2.mp3 b/site/science/ch10/audio/en/final2.mp3new file mode 100644index 0000000..d0df6c4Binary files /dev/null and b/site/science/ch10/audio/en/final2.mp3 differdiff --git a/site/science/ch10/audio/en/finish.mp3 b/site/science/ch10/audio/en/finish.mp3new file mode 100644index 0000000..c731a4eBinary files /dev/null and b/site/science/ch10/audio/en/finish.mp3 differdiff --git a/site/science/ch10/audio/en/force.mp3 b/site/science/ch10/audio/en/force.mp3new file mode 100644index 0000000..bfae528Binary files /dev/null and b/site/science/ch10/audio/en/force.mp3 differdiff --git a/site/science/ch10/audio/en/intro.mp3 b/site/science/ch10/audio/en/intro.mp3new file mode 100644index 0000000..656aaa7Binary files /dev/null and b/site/science/ch10/audio/en/intro.mp3 differdiff --git a/site/science/ch10/audio/en/law1.mp3 b/site/science/ch10/audio/en/law1.mp3new file mode 100644index 0000000..e7b8bc5Binary files /dev/null and b/site/science/ch10/audio/en/law1.mp3 differdiff --git a/site/science/ch10/audio/en/law2.mp3 b/site/science/ch10/audio/en/law2.mp3new file mode 100644index 0000000..cb0ddfeBinary files /dev/null and b/site/science/ch10/audio/en/law2.mp3 differdiff --git a/site/science/ch10/audio/en/law3.mp3 b/site/science/ch10/audio/en/law3.mp3new file mode 100644index 0000000..0b27368Binary files /dev/null and b/site/science/ch10/audio/en/law3.mp3 differdiff --git a/site/science/ch10/audio/en/mass.mp3 b/site/science/ch10/audio/en/mass.mp3new file mode 100644index 0000000..28f7bd0Binary files /dev/null and b/site/science/ch10/audio/en/mass.mp3 differdiff --git a/site/science/ch10/audio/en/momentum.mp3 b/site/science/ch10/audio/en/momentum.mp3new file mode 100644index 0000000..3b52e48Binary files /dev/null and b/site/science/ch10/audio/en/momentum.mp3 differdiff --git a/site/science/ch10/audio/en/net.mp3 b/site/science/ch10/audio/en/net.mp3new file mode 100644index 0000000..f900ef7Binary files /dev/null and b/site/science/ch10/audio/en/net.mp3 differdiff --git a/site/science/ch10/audio/en/newton.mp3 b/site/science/ch10/audio/en/newton.mp3new file mode 100644index 0000000..39ae5a5Binary files /dev/null and b/site/science/ch10/audio/en/newton.mp3 differdiff --git a/site/science/ch10/audio/en/pairs.mp3 b/site/science/ch10/audio/en/pairs.mp3new file mode 100644index 0000000..f835958Binary files /dev/null and b/site/science/ch10/audio/en/pairs.mp3 differdiff --git a/site/science/ch10/audio/en/part2.mp3 b/site/science/ch10/audio/en/part2.mp3new file mode 100644index 0000000..0e04117Binary files /dev/null and b/site/science/ch10/audio/en/part2.mp3 differdiff --git a/site/science/ch10/audio/en/part3.mp3 b/site/science/ch10/audio/en/part3.mp3new file mode 100644index 0000000..d3fc2e0Binary files /dev/null and b/site/science/ch10/audio/en/part3.mp3 differdiff --git a/site/science/ch10/audio/en/part4.mp3 b/site/science/ch10/audio/en/part4.mp3new file mode 100644index 0000000..828254cBinary files /dev/null and b/site/science/ch10/audio/en/part4.mp3 differdiff --git a/site/science/ch10/audio/en/q1.mp3 b/site/science/ch10/audio/en/q1.mp3new file mode 100644index 0000000..12a336bBinary files /dev/null and b/site/science/ch10/audio/en/q1.mp3 differdiff --git a/site/science/ch10/audio/en/q2.mp3 b/site/science/ch10/audio/en/q2.mp3new file mode 100644index 0000000..b5fff51Binary files /dev/null and b/site/science/ch10/audio/en/q2.mp3 differdiff --git a/site/science/ch10/audio/en/q3.mp3 b/site/science/ch10/audio/en/q3.mp3new file mode 100644index 0000000..cf1835bBinary files /dev/null and b/site/science/ch10/audio/en/q3.mp3 differdiff --git a/site/science/ch10/audio/en/q4.mp3 b/site/science/ch10/audio/en/q4.mp3new file mode 100644index 0000000..54c45bdBinary files /dev/null and b/site/science/ch10/audio/en/q4.mp3 differdiff --git a/site/science/ch10/audio/en/rest.mp3 b/site/science/ch10/audio/en/rest.mp3new file mode 100644index 0000000..6d9e9e9Binary files /dev/null and b/site/science/ch10/audio/en/rest.mp3 differdiff --git a/site/science/ch10/audio/en/timings.js b/site/science/ch10/audio/en/timings.jsnew file mode 100644index 0000000..886a4f1--- /dev/null+++ b/site/science/ch10/audio/en/timings.js@@ -0,0 +1,684 @@+window.TIMINGS = {+ "intro": {+ "dur": 6.816,+ "marks": {+ "sub": 3.594+ },+ "cues": [+ [+ 0.104,+ "Chapter ten."+ ],+ [+ 1.25,+ "Force and Newton's laws of motion."+ ],+ [+ 3.594,+ "What makes things start, stop, speed up, or turn?"+ ]+ ]+ },+ "force": {+ "dur": 21.024,+ "marks": {+ "push": 2.344,+ "pull": 4.635,+ "dir": 6.719,+ "shape": 15.182+ },+ "cues": [+ [+ 0.104,+ "A force is a push or a pull."+ ],+ [+ 2.344,+ "Push a cart, and it starts to move."+ ],+ [+ 4.635,+ "Pull it, and it follows you."+ ],+ [+ 6.719,+ "Every force has a size and a direction, so we draw it as an arrow: the longer the arrow, the bigger the force."+ ],+ [+ 15.182,+ "A force can even change an object's shape, like squeezing an empty can until it crumples."+ ]+ ]+ },+ "net": {+ "dur": 22.2,+ "marks": {+ "add": 3.19,+ "sub": 10.417,+ "netw": 18.06+ },+ "cues": [+ [+ 0.104,+ "Often, more than one force acts at once."+ ],+ [+ 3.19,+ "When two forces point the same way, they add up: three newtons plus two newtons is five newtons."+ ],+ [+ 10.417,+ "When they point in opposite directions, they subtract: five newtons against three newtons leaves two newtons."+ ],+ [+ 18.06,+ "The total of all the forces on an object is called the net force."+ ]+ ]+ },+ "balance": {+ "dur": 18.744,+ "marks": {+ "bal": 1.341,+ "unbal": 10.703+ },+ "cues": [+ [+ 0.091,+ "In a tug-of-war, two teams pulling equally hard cancel each other out."+ ],+ [+ 4.974,+ "The net force is zero."+ ],+ [+ 7.161,+ "These are balanced forces, and nothing changes."+ ],+ [+ 10.703,+ "If one side pulls harder, the forces are unbalanced."+ ],+ [+ 14.909,+ "The net force points one way, and the rope starts to move."+ ]+ ]+ },+ "newton": {+ "dur": 14.16,+ "marks": {+ "apple": 4.401,+ "def": 6.966+ },+ "cues": [+ [+ 0.143,+ "Force is measured in newtons, named after Isaac Newton."+ ],+ [+ 4.401,+ "Holding up an apple takes about one newton."+ ],+ [+ 6.966,+ "One newton is the force that gives a one kilogram mass an acceleration of one meter per second squared."+ ]+ ]+ },+ "q1": {+ "dur": 3.216,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.224,+ "Forces and net force."+ ]+ ]+ },+ "wrap1": {+ "dur": 19.2,+ "marks": {+ "w1": 0.99,+ "w2": 5.273,+ "w3": 12.005,+ "end": 16.862+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.99,+ "A force is a push or a pull, with a size and a direction."+ ],+ [+ 5.273,+ "Forces in the same direction add; opposite forces subtract."+ ],+ [+ 9.688,+ "The total is the net force."+ ],+ [+ 12.005,+ "Balanced forces cancel out; unbalanced forces change motion."+ ],+ [+ 16.862,+ "Next: Newton's first law."+ ]+ ]+ },+ "part2": {+ "dur": 4.896,+ "marks": {+ "q": 2.526+ },+ "cues": [+ [+ 0.117,+ "Part two."+ ],+ [+ 1.016,+ "Newton's first law."+ ],+ [+ 2.526,+ "Why do things keep doing what they're already doing?"+ ]+ ]+ },+ "rest": {+ "dur": 17.256,+ "marks": {+ "stay": 2.37,+ "kick": 5.026,+ "roll": 6.029,+ "stop": 7.878,+ "space": 12.24+ },+ "cues": [+ [+ 0.104,+ "A soccer ball lies in a field."+ ],+ [+ 2.37,+ "It stays there, until a force acts on it, like a kick."+ ],+ [+ 6.029,+ "Once it's rolling, it would keep rolling, but friction from the grass and the air pushes against it and stops it."+ ],+ [+ 12.24,+ "Kick a ball in deep space, with nothing to slow it down, and it just keeps going."+ ]+ ]+ },+ "law1": {+ "dur": 17.4,+ "marks": {+ "law": 2.148,+ "inert": 9.479+ },+ "cues": [+ [+ 0.104,+ "This is Newton's first law."+ ],+ [+ 2.148,+ "An object at rest stays at rest, and an object in motion stays in motion, unless a net force acts on it."+ ],+ [+ 9.479,+ "Matter resists changes to its motion."+ ],+ [+ 12.161,+ "This is called inertia, so the first law is also called the law of inertia."+ ]+ ]+ },+ "mass": {+ "dur": 12.504,+ "marks": {+ "catch": 2.878,+ "easy": 6.836,+ "hard": 9.688+ },+ "cues": [+ [+ 0.091,+ "Objects with more mass have more inertia."+ ],+ [+ 2.878,+ "Catch a tennis ball and a basketball moving at the same speed."+ ],+ [+ 6.836,+ "The light tennis ball is easy to stop."+ ],+ [+ 9.688,+ "The heavy basketball is harder to stop."+ ]+ ]+ },+ "momentum": {+ "dur": 20.136,+ "marks": {+ "f": 4.089,+ "pool": 7.513,+ "cons": 12.604+ },+ "cues": [+ [+ 0.091,+ "Momentum measures how hard it is to stop something that's moving."+ ],+ [+ 4.089,+ "Momentum equals mass times velocity."+ ],+ [+ 7.513,+ "When one pool ball hits another, it passes its momentum to the ball it hits."+ ],+ [+ 12.604,+ "The total momentum before and after the collision stays the same."+ ],+ [+ 17.044,+ "This is called the conservation of momentum."+ ]+ ]+ },+ "q2": {+ "dur": 3.048,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.146,+ "Inertia and momentum."+ ]+ ]+ },+ "wrap2": {+ "dur": 21.648,+ "marks": {+ "w1": 1.003,+ "w2": 6.836,+ "w3": 12.969,+ "end": 19.323+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 1.003,+ "Newton's first law: objects keep their state of motion unless a net force acts on them."+ ],+ [+ 6.836,+ "Inertia is matter's resistance to changes in motion; more mass means more inertia."+ ],+ [+ 12.969,+ "Momentum equals mass times velocity, and in a collision the total stays the same."+ ],+ [+ 19.323,+ "Next: Newton's second law."+ ]+ ]+ },+ "part3": {+ "dur": 5.424,+ "marks": {+ "q": 2.63+ },+ "cues": [+ [+ 0.104,+ "Part three."+ ],+ [+ 1.224,+ "Newton's second law."+ ],+ [+ 2.63,+ "How much does a force change an object's motion?"+ ]+ ]+ },+ "law2": {+ "dur": 16.68,+ "marks": {+ "law": 2.24,+ "more": 7.982,+ "rearr": 11.406+ },+ "cues": [+ [+ 0.091,+ "Newton's second law says: the acceleration of an object equals the net force on it, divided by its mass."+ ],+ [+ 7.982,+ "Double the force, and the acceleration doubles."+ ],+ [+ 11.406,+ "We can also write it the other way around: net force equals mass times acceleration."+ ]+ ]+ },+ "cart": {+ "dur": 11.64,+ "marks": {+ "cart": 3.177,+ "car": 4.675,+ "why": 6.406+ },+ "cues": [+ [+ 0.104,+ "Push a shopping cart and a car with the same force."+ ],+ [+ 3.177,+ "The cart zooms off."+ ],+ [+ 4.675,+ "The car hardly moves."+ ],+ [+ 6.406,+ "The car has much more mass, so the same force gives it much less acceleration."+ ]+ ]+ },+ "calc": {+ "dur": 13.992,+ "marks": {+ "ex": 1.107,+ "f": 6.901,+ "ans": 10.417+ },+ "cues": [+ [+ 0.104,+ "Let's use it."+ ],+ [+ 1.107,+ "A two thousand kilogram car accelerates at three meters per second squared."+ ],+ [+ 6.901,+ "Net force equals mass times acceleration: two thousand times three is six thousand newtons."+ ]+ ]+ },+ "wind": {+ "dur": 14.736,+ "marks": {+ "with": 2.721,+ "against": 9.492+ },+ "cues": [+ [+ 0.104,+ "The direction of the net force matters too."+ ],+ [+ 2.721,+ "Coasting on a bike with the wind at your back, the net force points the same way as your velocity, so you speed up."+ ],+ [+ 9.492,+ "Coasting against the wind, the net force points the other way, so you slow down."+ ]+ ]+ },+ "q3": {+ "dur": 4.368,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.159,+ "Force, mass, and acceleration."+ ]+ ]+ },+ "wrap3": {+ "dur": 18.216,+ "marks": {+ "w1": 0.99,+ "w2": 6.81,+ "w3": 10.104,+ "end": 16.185+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.99,+ "Newton's second law: acceleration equals net force divided by mass."+ ],+ [+ 6.81,+ "Net force equals mass times acceleration."+ ],+ [+ 10.104,+ "A net force in the direction of motion speeds things up; against it, things slow down."+ ],+ [+ 16.185,+ "Next: Newton's third law."+ ]+ ]+ },+ "part4": {+ "dur": 4.512,+ "marks": {+ "q": 2.539+ },+ "cues": [+ [+ 0.104,+ "Part four."+ ],+ [+ 1.094,+ "Newton's third law."+ ],+ [+ 2.539,+ "Forces always come in pairs."+ ]+ ]+ },+ "law3": {+ "dur": 15.72,+ "marks": {+ "law": 2.096,+ "bowl": 6.523,+ "equal": 10.859,+ "opp": 13.216+ },+ "cues": [+ [+ 0.091,+ "Newton's third law says: for every action, there is an equal and opposite reaction."+ ],+ [+ 6.523,+ "Throw a heavy bowling ball forward, and it pushes you backward."+ ],+ [+ 10.859,+ "The two forces are the same size, but they point in opposite directions."+ ]+ ]+ },+ "pairs": {+ "dur": 13.032,+ "marks": {+ "tramp": 2.565,+ "run": 7.552+ },+ "cues": [+ [+ 0.104,+ "These are called action-reaction pairs."+ ],+ [+ 2.565,+ "Land on a trampoline, and you push down on it."+ ],+ [+ 5.378,+ "It pushes you back up into the air."+ ],+ [+ 7.552,+ "When you run, your foot pushes back on the ground, and the ground pushes you forward."+ ]+ ]+ },+ "earth": {+ "dur": 15.072,+ "marks": {+ "mass": 2.865,+ "tiny": 9.18+ },+ "cues": [+ [+ 0.104,+ "So if you push on Earth, why doesn't Earth move?"+ ],+ [+ 2.865,+ "Remember the second law: the same force gives a huge mass a tiny acceleration."+ ],+ [+ 9.18,+ "Earth is so massive that its acceleration is far too small to notice."+ ],+ [+ 14.115,+ "But it's there."+ ]+ ]+ },+ "q4": {+ "dur": 2.904,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.107,+ "Action and reaction."+ ]+ ]+ },+ "wrap4": {+ "dur": 20.208,+ "marks": {+ "w1": 0.977,+ "w2": 6.732,+ "w3": 13.086,+ "end": 17.865+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.977,+ "Newton's third law: for every action, there is an equal and opposite reaction."+ ],+ [+ 6.732,+ "The two forces are the same size and point in opposite directions, on two different objects."+ ],+ [+ 13.086,+ "The same force moves a small mass a lot and a huge mass hardly at all."+ ],+ [+ 17.865,+ "Next: the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 3.72,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.602,+ "First, force and the first law."+ ]+ ]+ },+ "final2": {+ "dur": 2.088,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Now the second and third laws."+ ]+ ]+ },+ "finish": {+ "dur": 4.128,+ "marks": {},+ "cues": [+ [+ 0.117,+ "That's the whole chapter on force and Newton's laws."+ ],+ [+ 3.229,+ "Well done!"+ ]+ ]+ }+};diff --git a/site/science/ch10/audio/en/wind.mp3 b/site/science/ch10/audio/en/wind.mp3new file mode 100644index 0000000..13dd2b8Binary files /dev/null and b/site/science/ch10/audio/en/wind.mp3 differdiff --git a/site/science/ch10/audio/en/wrap1.mp3 b/site/science/ch10/audio/en/wrap1.mp3new file mode 100644index 0000000..b3b2107Binary files /dev/null and b/site/science/ch10/audio/en/wrap1.mp3 differdiff --git a/site/science/ch10/audio/en/wrap2.mp3 b/site/science/ch10/audio/en/wrap2.mp3new file mode 100644index 0000000..8dcfcfcBinary files /dev/null and b/site/science/ch10/audio/en/wrap2.mp3 differdiff --git a/site/science/ch10/audio/en/wrap3.mp3 b/site/science/ch10/audio/en/wrap3.mp3new file mode 100644index 0000000..069584fBinary files /dev/null and b/site/science/ch10/audio/en/wrap3.mp3 differdiff --git a/site/science/ch10/audio/en/wrap4.mp3 b/site/science/ch10/audio/en/wrap4.mp3new file mode 100644index 0000000..80002cdBinary files /dev/null and b/site/science/ch10/audio/en/wrap4.mp3 differdiff --git a/site/science/ch10/index.html b/site/science/ch10/index.htmlnew file mode 100644index 0000000..6eae1a4--- /dev/null+++ b/site/science/ch10/index.html@@ -0,0 +1,736 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Chapter 10: Force and Newton's Laws of Motion — Science</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/figures.js"></script>+<script src="../lib/actors.js"></script>+<script src="../lib/physics.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+// Chapter 10, one page in book order: part 1 (force, net force, balanced forces, newtons), part 2 (first law: inertia,+// momentum), part 3 (second law), part 4 (third law), then the chapter practice.+const CHAPTER = { number: 10, title: 'Force and Newton’s Laws of Motion', minutes: 13, language: 'en', next: '../ch11/' };+const Q_CARD = { x: 96, y: 586, w: 1408, cls: 'band' }; // a band card under the scenes; it moves up by itself when taller+const GY = 560; // ground line in side-view scenes+const Y1 = 740; // part 1: a lower ground line under big actors+// A ground band, not a slab: the space below stays free for values and notes.+const ground = (p, y = GY, x = 0, w = 1600) => { phBlock(p, x, y, w, 70, PH.grass, { top: 8, ol: 0 }); mk('rect', { x, y: y + 70, width: w, height: 6, fill: PH.grass, opacity: .5 }, p); };+const TY = { title: 100, rule: 40, value: 40, label: 30, note: 26 }; // the type scale: title, rule, key values, labels, notes+const N = 40; // force arrows: 40 px per newton (scaled per scene where noted)++/* ---------- actors and light context ---------- */+// Light tufts on the grass band: with a following camera they show the motion.+const marks = (p, y, x0, x1) => { for (let x = x0; x < x1; x += 140) mk('rect', { x, y: y + 18, width: 24, height: 8, fill: lt(PH.grass, .2) }, p); };+const park = (p, xs = [90, 1530]) => xs.forEach(x => phSprite(p, 'tree', { x, y: GY + 2 }));+function rink(p, y = GY, x = 0, w = 1600) { // an ice rink: boards behind, a red centre line+ phBlock(p, x, y, w, 110, '#cfe8f3', { top: 8, ol: 0 });+ phBlock(p, x, y - 64, w, 64, '#eef5f7', { top: 0, ol: 0 });+ mk('rect', { x, y: y - 70, width: w, height: 8, fill: '#3f6f9e' }, p);+ mk('rect', { x: 796, y: y + 8, width: 8, height: 102, fill: '#d24b4b', opacity: .5 }, p);+}+function goal(p, x) { // a pixel soccer goal (side view)+ path(p, `M${x} ${GY}V${GY - 150}H${x + 90}`, { stroke: '#ece8dc', 'stroke-width': 10 });+ path(p, `M${x + 10} ${GY - 140}L${x + 90} ${GY}M${x + 30} ${GY - 140}L${x + 90} ${GY - 40}`, { stroke: '#ece8dc', 'stroke-width': 2, opacity: .5 });+}+// A pusher with a cart (or car) that stays on her hands: at(x, dist) walks her and places the load at her hand.+function pusher(p, role, load = 'cart') {+ const a = phActor(p, role, { y: GY, anim: 'push' }), c = load === 'car' ? phCar(p, { y: GY }) : phSprite(p, 'cart', { y: GY });+ return { a, c, at(x, dist, walk = true) {+ put(a, { x }); if (walk) a.stride('push', dist); else a.show('push', 0);+ const [hx] = a.hand('F'); put(c, { x: hx + (load === 'car' ? 126 : 52) }); if (load === 'car') phRoll(c, hx);+ return hx;+ } };+}++// A thought bubble [x0, y0, x1, y1] whose tail points down at x (a head below it), shown at t0.+function thought(p, [x0, y0, x1, y1], x, lines, t0) {+ const q = G(p, { o: 0 });+ mk('rect', { x: x0, y: y0, width: x1 - x0, height: y1 - y0, rx: 40, fill: '#22322d', stroke: COL.dim, 'stroke-width': 3 }, q);+ path(q, `M${x - 30} ${y1 - 2}L${x + 30} ${y1 - 2}L${x} ${y1 + 66}Z`, { fill: COL.dim });+ lines.forEach((s, i) => T(q, s, { x: (x0 + x1) / 2, y: y0 + 70 + i * 56, size: 42, anchor: 'middle' }));+ show(q, t0); return q;+}+// A part title beside its picture: the part over the law's name.+function opener(p, x, y, part, name) {+ const g = G(p, { o: 0, y: 24 });+ phLabel(g, part.toUpperCase(), { x, y: y - 80, size: 30, fill: COL.dim, weight: 600 }); phLabel(g, name, { x, y, size: 84, weight: 600 });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out); return g;+}+// A summary: each takeaway beside a small picture of its moment; icon(g) draws into the row (text baseline at y 0).+function summary(p, m, rows, next) {+ rows.forEach(([lines, icon], i) => {+ const g = G(p, { x: -16, y: 250 + i * 220, o: 0 });+ lines.forEach((s, j) => T(g, s, { x: 430, y: j * 50, size: 38, weight: 600 }));+ icon(g); tw(g, { o: 1, x: 0 }, m(['w1', 'w2', 'w3'][i]), .6);+ });+ txt(p, next, 800, 860, m('end'), { size: 32, fill: COL.dim, weight: 500 });+}++// Under the practice card, a still diagram of the current question's situation (objects only), swapped per question.+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', '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, ''); },+ 'p-mom': g => { phBlock(g, 300, 820, 900, 12, PH.walk, { top: 0, ol: 0 }); phBall(g, 50, { x: 700, y: 770 }); phLabel(g, '0.5 kg', { x: 700, y: 690, size: 34 }); forceArrow(g, { color: VEL, w: 12, size: 34 }).set(760, 770, 200, 0, '8 m/s'); },+};+let PRACTICE; // the practice beat's panel: its question pictures are drawn there+const withPics = qs => qs.map(q => ({ ...q, build(body, api) { const old = PRACTICE.querySelector('.pic'); if (old) old.remove(); const g = G(PRACTICE); g.classList.add('pic'); PICS[q.id]?.(g); return q.build(body, api); } }));++/* ---------- beats ---------- */+const BEATS = [+/* ---------- part 1: force and net force ---------- */+// Part 1 is composed as whole frames (books/science/review/ch10_storyboard): big actors on a low ground line (Y1), each+// value on its arrow, each sentence beside the thing it names.+['intro', 'Force and Newton’s laws', (m, D) => {+ const p = panel(0), Y = Y1, S = 3, W = 760, H = 460, tp = 2.1, x0 = -60, v = 440 / (tp + .2);+ ground(p, Y);+ // You push the title crate into the frame, then let go: it slides a little and stops.+ const a = phActor(p, 'you', { y: Y, s: S, anim: 'push' }), c = crate(p, { y: Y, w: W, h: H }), f = forceArrow(p, { w: 14, size: 34 });+ phLabel(c, 'Unit 3 · Motion, Forces, and Work · Chapter 10', { x: -10, y: -400, size: 26, fill: '#eedec4', weight: 600 });+ phLabel(c, 'Force &', { x: -10, y: -326, size: 70 }); phLabel(c, 'Newton’s Laws', { x: -10, y: -256, size: 70 });+ const X = t => t < tp ? x0 + v * t : t < tp + .4 ? x0 + v * tp + v * ((t - tp) - (t - tp) ** 2 / .8) : x0 + v * (tp + .2);+ 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', '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 }],+['force', 'A push or a pull', (m, D) => {+ const p = panel(0), Y = Y1, S = 3, CS = 2.5, CW = 112 * CS; // the cart handle meets her hands+ const t1 = m('push'), t2 = m('pull'), td = m('dir'), ts = m('shape'), tg = td + 4.6; // tg: "the longer the arrow"+ // One street: you push a cart on the left, your friend pulls one further along. The pushing force is 2 N, then 6 N+ // (it grows on "the longer the arrow"); each cart speeds up only while it is pushed or pulled. At "shape" the+ // street freezes and fades, and a can is squeezed in close-up.+ const c = 7, tk = tg + .5, P0 = 300, Q0 = 3300; // far enough apart that neither cart peeks into the other's frame+ const dP = t => { const u = Math.max(0, Math.min(t, ts) - t1), k = Math.max(0, Math.min(t, ts) - tk); return c * (2 * u * u + 4 * k * k) / 2; };+ const dQ = t => { const u = Math.max(0, Math.min(t, ts) - t2); return 15 * u * u / 2; };+ const cam = camera(p, D), w = cam.world;+ cam.cut({ x: t => Math.max(800, P0 + dP(t) + 500) }, 0).to({ x: t => Q0 + dQ(t) - 300 }, t2 - .15, 1.1).to({ x: t => Math.max(800, P0 + dP(t) + 500) }, td, 1.1);+ // The pushing cart and its labels cover x 450..2450: no tree there, so nothing shows through it. Tufts on the grass show the motion.+ [2650, 4300, 5000].forEach(x => phSprite(w, 'tree', { x, y: Y + 2, s: 1.6 }));+ ground(w, Y, -800, 6400); marks(w, Y, -600, 5600);+ const pa = phActor(w, 'you', { y: Y, s: S, anim: 'push' }), pc = phSprite(w, 'cart', { y: Y, s: CS }), f1 = forceArrow(w, { w: 14 });+ const lab = phLabel(w, '', { size: 36, fill: FORCE, anchor: 'start' }), note = T(w, 'longer arrow = bigger push', { size: 28, fill: COL.dim, weight: 500, o: 0 });+ const qa = phActor(w, 'friend', { y: Y, s: S, anim: 'pull' }), qc = phSprite(w, 'cart', { y: Y, s: CS }), rope = path(w, '', { stroke: '#c9b38d', 'stroke-width': 8 }), f2 = forceArrow(w, { w: 14, size: 36 });+ show(note, tg);+ clockRun(t => {+ const d = dP(t); put(pa, { x: P0 + d }); if (d > 0) pa.stride('push', d / S); else pa.show('push', 0);+ const [hx, hy] = pa.hand('F'); put(pc, { x: hx + CW / 2 - 6 });+ const F = 2 + 4 * ramp(t, tg, tg + 1), len = t > t1 - .1 ? F * 50 : 0;+ f1.set(hx, hy - 6, len, 0, ''); // from the hands, along the top of the cart+ phText(lab, len ? (t < td ? 'push' : `push · ${Math.round(F)} N`) : ''); put(lab, { x: hx + len + 18, y: hy + 6 });+ put(note, { x: hx + len + 18, y: hy + 46 });+ const e = dQ(t); put(qa, { x: Q0 + e }); if (e > 0) qa.stride('pull', e / S); else qa.show('pull', 0);+ const [rx, ry] = qa.hand('F'), cx = rx - 160 - CW / 2; put(qc, { x: cx });+ rope.setAttribute('d', `M${cx + CW / 2 - 8} ${Y - 150}L${rx} ${ry}`);+ f2.set(cx + CW / 2 - 90, Y - 250, t > t2 - .1 ? 150 : 0, 0, 'pull'); // above the rope, short of her body+ }, D);+ // Screen text sits over the actor the camera is showing.+ const s1 = phLabel(p, 'A force is a push…', { x: 150, y: 290, size: 56, anchor: 'start', o: 0 }), s2 = phLabel(p, '…or a pull.', { x: 1100, y: 290, size: 56, o: 0 });+ const s3 = phLabel(p, 'Every force has a size and a direction.', { x: 150, y: 290, size: 48, anchor: 'start', o: 0 });+ show(s1, .3); hide(s1, t2 - .3, .3); show(s2, t2 + .7); hide(s2, td - .1, .3); show(s3, td + 1); hide(s3, ts - .3, .3);+ tw(cam.el, { o: 0 }, ts - .1, .4);+ // The can: squeezed from above and below, it flattens, then keeps its crushed shape. The arrows touch it only+ // while it is squeezed.+ const can = G(p, { o: 0 }), cg = G(can, { x: 640 }), cs = phSprite(cg, 'can', { s: 5 }), sq1 = forceArrow(can, { w: 16, size: 38 }), sq2 = forceArrow(can, { w: 16 });+ show(can, ts + .1, .4);+ txt(p, 'A force can change', 860, 440, ts + .5, { size: 50, weight: 700, anchor: 'start' }); txt(p, 'an object’s shape.', 860, 505, ts + .7, { size: 50, weight: 700, anchor: 'start' });+ clockRun(t => {+ const k = ramp(t, ts + .8, ts + 1.8), crushed = k >= 1, sy = 1 - .375 * k, sx = 1 + .4 * k, h = crushed ? 200 : 320 * sy;+ phFrame(cs, crushed ? 'can_crushed' : 'can');+ cs._in.setAttribute('transform', crushed ? '' : `scale(${sx.toFixed(3)},${sy.toFixed(3)})`);+ put(cg, { y: 450 + h / 2 }); // its centre stays put while it flattens+ const on = t > ts + .4 && t < ts + 2.3;+ 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) => {+ const p = panel(0), FY = 600, ta = m('add'), ts = m('sub'), U = 70;+ // One crate the camera keeps in place (the floor slides): 3 N + 2 N push it from "add"; from "sub", 5 N one way and+ // 3 N the other. It speeds up only while the forces act: 25 px/s² for 5 N, 10 px/s² for 2 N.+ const te = ts - .4, v1 = 25 * (te - ta);+ const dX = t => { const u = Math.min(Math.max(0, t - ta), te - ta), k = Math.max(0, t - ts - .1); return 12.5 * u * u + (t > te ? v1 * (t - te) : 0) + 5 * k * k; };+ const cam = camera(p, D), w = cam.world, fl = cam.layer(1, 160);+ cam.cut({ x: t => 900 + dX(t) }, 0);+ phBlock(fl, 0, FY, 1760, 70, '#44564c', { top: 6, ol: 0 });+ for (let x = 0; x < 1760; x += 160) mk('rect', { x, y: FY + 6, width: 6, height: 64, fill: '#33433a' }, fl);+ const cr = crate(w, { y: FY, w: 320, h: 260 });+ const A = forceArrow(w, { w: 16, size: 40 }), B = forceArrow(w, { w: 16, size: 40 });+ clockRun(t => {+ const X = 800 + dX(t); put(cr, { x: X });+ const g1 = t < te ? ramp(t, ta, ta + .4) : 0, g2 = ramp(t, ts, ts + .4);+ if (t < ts) { A.set(X + 160, 420, 3 * U * g1, 0, '3 N'); B.set(X + 160, 520, 2 * U * g1, 0, '2 N'); }+ else { A.set(X + 160, 470, 5 * U * g2, 0, '5 N'); B.set(X - 160, 470, 3 * U * g2, 180, '3 N'); }+ }, D);+ // The rule above the crate, the sum on one line under it, ending in the net force.+ const h1 = txt(p, 'Same direction: add', 700, 270, ta, { size: 50, weight: 700 }); hide(h1, te, .3);+ txt(p, 'Opposite directions: subtract', 700, 270, ts, { size: 50, weight: 700 });+ const eq1 = runs(p, [['3 N + 2 N = ', COL.chalk], ['5 N', NETF]], { x: 620, y: 780, size: 56, weight: 700 }),+ eq2 = runs(p, [['5 N − 3 N = ', COL.chalk], ['2 N', NETF]], { x: 620, y: 780, size: 56, weight: 700 });+ show(eq1, ta + 1.2); hide(eq1, te, .3); show(eq2, ts + 1.6);+ const NF = forceArrow(p, { color: NETF, w: 18, size: 30 });+ clockRun(t => NF.set(880, 762, t < te ? 5 * 44 * ramp(t, ta + 2.4, ta + 2.8) : t > ts + 3 ? 2 * 44 * ramp(t, ts + 3, ts + 3.4) : 0, 0, 'net force'), D);+ txt(p, 'net force: the total of all the forces on an object', 800, 850, m('netw'), { size: 30, fill: COL.dim, weight: 500 });+}, { lead: false }],+['balance', 'Balanced and unbalanced', (m, D) => {+ const p = panel(0), Y = Y1, S = 3, tb = m('bal'), tu = m('unbal'), U = 16;+ // Equal pulls: nothing moves. From "unbalanced", your pull grows to 15 N and everything speeds up toward you+ // (net 5 N); the camera follows partway, so the flag drifts past the start line.+ const dX = t => { const u = Math.max(0, t - tu - .4); return 4 * u * u; };+ const cam = camera(p, D), w = cam.world; cam.cut({ x: t => 800 + .6 * dX(t) }, 0);+ [70, 2300].forEach(x => phSprite(w, 'tree', { x, y: Y + 2, s: 1.6 }));+ ground(w, Y, -400, 3200);+ path(w, `M800 ${Y + 12}V${Y + 62}`, { stroke: COL.dim, 'stroke-width': 4, 'stroke-dasharray': '6 6' });+ const L = phActor(w, 'friend', { y: Y, s: S, anim: 'strain' }), R = phActor(w, 'you', { y: Y, s: S, anim: 'strain' }).face(-1);+ const rope = path(w, '', { stroke: '#c9b38d', 'stroke-width': 10 }), flag = G(w);+ mk('rect', { x: -9, y: -6, width: 18, height: 50, fill: COL.bad }, flag);+ const FL = forceArrow(w, { w: 16, size: 40 }), FR = forceArrow(w, { w: 16, size: 40 }), NF = forceArrow(w, { color: NETF, w: 18, size: 34 });+ const tag = phLabel(w, '', { y: 470, size: 60 }), zero = phLabel(w, 'net force 0', { y: 700, size: 38, o: 0 });+ show(zero, tb + 1.5); hide(zero, tu, .3);+ clockRun(t => {+ const pull = 10 + 5 * ramp(t, tu, tu + .8), d = dX(t), sh = d ? 0 : Math.sin(t * 31) * 3; // straining: a small shake+ put(L, { x: 360 + d + sh }); put(R, { x: 1240 + d - sh });+ if (d > 0) { L.stride('stumble', d / S); R.stride('backstep', d / S); } else { L.show('strain', t * 3); R.show('strain', t * 3 + 1); }+ const [lx, ly] = L.hand('F'), [rx, ry] = R.hand('F'), mx = (lx + rx) / 2;+ rope.setAttribute('d', `M${lx} ${ly}L${rx} ${ry}`); put(flag, { x: mx, y: (ly + ry) / 2 });+ 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');+ }, D);+}, { lead: false }],+['newton', 'The newton', (m, D) => {+ const p = panel(0), Y = Y1, ta = m('apple'), td = m('def');+ // Two frames in one world: an apple caught in your hand (the camera eases in), then a pan to a 1 kg crate pushed with+ // 1 N, which the camera follows (ticks on the ground show it speeding up). The equation reads under the crate.+ const tp = td + .8, dC = t => { const u = Math.max(0, t - tp); return 20 * u * u; }; // 1 m/s²+ const cam = camera(p, D), w = cam.world;+ cam.to({ x: 900, y: 470, z: 1.12 }, ta + .3, 2.2).to({ x: t => 2400 + dC(t), y: 520, z: 1 }, td, 1.1);+ ground(w, Y, -400, 6000);+ for (let x = 1700; x < 5600; x += 120) mk('rect', { x, y: Y + 14, width: 6, height: 26, fill: lt(PH.grass, .25) }, w);+ // the apple+ const a = phActor(w, 'you', { x: 520, y: Y, s: 3, anim: 'stand' }), ap = phSprite(w, 'apple', { s: 2 });+ const up = forceArrow(w, { w: 16, size: 34 }), dn = forceArrow(w, { w: 16, size: 34 });+ const u1 = phLabel(w, 'Force is measured in', { x: 1160, y: 400, size: 44, weight: 600, o: 0 }), u2 = phLabel(w, 'newtons (N)', { x: 1160, y: 470, size: 66, o: 0 });+ show(u1, .3); show(u2, .6); hide(u1, ta - .3, .3); hide(u2, ta - .3, .3);+ const n1 = phLabel(w, '≈ 1 newton', { x: 1160, y: 450, size: 66, o: 0 }), n2 = phLabel(w, 'to hold up an apple', { x: 1160, y: 510, size: 36, fill: COL.dim, weight: 600, o: 0 });+ show(n1, ta + .3); show(n2, ta + .6);+ const tf = ta - .6, top = -120;+ clockRun(t => {+ const absorb = t > ta && t < ta + .3;+ if (t < tf - .4) a.show('stand'); else a.show('catch', absorb ? 1 : 0);+ 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 hand+ put(ap, { x, y, o: t < tf ? 0 : 1 });+ 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 definition+ const 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 });+ const al = phLabel(w, '1 m/s²', { size: 38, fill: ACC, o: 0 }); show(al, td + 3.6);+ clockRun(t => {+ const X = X0 + dC(t); put(cr, { x: X });+ fp.set(X - 126 - 240, Y - 100, t > tp ? 240 : 0, 0, '1 N');+ arrowAt(ac, X + 60, Y - 270, t > td + 3.6 ? 220 : 0, 0, 26); put(al, { x: X + 170, y: Y - 296 });+ }, D);+ [['1 N', FORCE, 500, 1], ['=', COL.chalk, 620, 2.2], ['1 kg', COL.chalk, 760, 2.2], ['×', COL.chalk, 890, 4], ['1 m/s²', ACC, 1030, 4]]+ .forEach(([s, fill, x, dt]) => txt(p, s, x, 800, td + dt, { size: 64, fill, weight: 700 }));+ txt(p, '1 newton gives 1 kilogram an acceleration of 1 m/s²', 800, 862, td + 5, { size: 28, fill: COL.dim, weight: 500 });+}, { lead: false }],+['q1', 'Quick check', (m, D) => {+ const p = panel(0), Y = 500, S = 2.4, U = 20;+ // The picture fills the top, leaving the band below for the card.+ ground(p, Y);+ const L = phActor(p, 'friend', { y: Y, s: S, anim: 'strain' }), R = phActor(p, 'you', { y: Y, s: S, anim: 'strain' }).face(-1), rope = path(p, '', { stroke: '#c9b38d', 'stroke-width': 8 });+ const fl = forceArrow(p, { w: 14, size: 36 }), fr = forceArrow(p, { w: 14, size: 36 });+ fl.set(430, 150, 10 * U, 180, 'brother: 10 N'); fr.set(1170, 150, 15 * U, 0, 'you: 15 N');+ clockRun(t => { const sh = Math.sin(t * 31) * 2.5; put(L, { x: 380 + sh }); put(R, { x: 1220 - sh }); L.show('strain', t * 3); R.show('strain', t * 3 + 1);+ const [lx, ly] = L.hand('F'), [rx, ry] = R.hand('F'); rope.setAttribute('d', `M${lx} ${ly}L${rx} ${ry}`); }, D);+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-tug', prompt: ['Tug-of-war: you pull with 15 newtons, your brother pulls the other way with 10 newtons. What is the ', h('b', '', 'net force'), '?'],+ build: blanks([{ parts: ['net force = 15 − 10 = ', { box: '5' }, ' newtons'], why: 'Opposite directions subtract: 15 − 10 = 5 newtons, toward you.', hint: 'The forces point in opposite directions, so subtract.' }]) },+ { id: 'c-tugdir', prompt: ['Which way does the rope start to move?'],+ build: choice([['toward you'], ['toward your brother'], ['it does not move']], 0,+ 'The net force (5 newtons) points toward you, the stronger pull.',+ [null, 'Your brother pulls with less force; the net force points toward you.', 'The forces are unbalanced (15 vs 10), so the rope moves.']) },+ { id: 'c-bal', prompt: ['Two teams each pull with 20 newtons in opposite directions. These forces are…'],+ build: choice([['balanced: the net force is 0'], ['unbalanced: the net force is 40 newtons']], 0,+ 'Equal and opposite forces cancel: the net force is 0, so nothing changes.',+ [null, 'They point in opposite directions, so subtract: 20 − 20 = 0.']) },+], done) }],+['wrap1', 'Summary · Force', (m, D) => {+ summary(panel(0), m, [+ [['A force is a push or a pull, with a size and a direction.'], g => { phSprite(g, 'cart', { x: 260, y: 40, s: 1.6 }); forceArrow(g, { w: 10 }).set(40, -85, 120, 0, ''); }],+ [['Same way, forces add; opposite ways, they subtract.', 'Their total is the net force.'], g => { crate(g, { x: 220, y: 50, w: 140, h: 120 }); forceArrow(g, { w: 10 }).set(296, -30, 100, 0, ''); forceArrow(g, { w: 10 }).set(296, 15, 64, 0, ''); }],+ [['Balanced forces cancel; unbalanced forces change motion.'], g => { path(g, 'M150 10H330', { stroke: '#c9b38d', 'stroke-width': 8 }); mk('rect', { x: 234, y: 4, width: 12, height: 44, fill: COL.bad }, g);+ forceArrow(g, { w: 10 }).set(150, -30, 80, 180, ''); forceArrow(g, { w: 10 }).set(330, -30, 80, 0, ''); }],+ ], 'Next: Newton’s first law.');+}],+/* ---------- part 2: Newton's first law ---------- */+['part2', 'Part 2 · The first law', (m, D) => {+ const p = panel(0), Y = Y1;+ ground(p, Y);+ const kid = phActor(p, 'you', { x: 380, y: Y, s: 3, anim: 'stand' }); phBall(p, 64, { x: 640, y: Y - 64 });+ clockRun(t => kid.show('stand'), D);+ opener(p, 1130, 470, 'Part 2', 'The First Law');+ thought(p, [80, 90, 900, 250], 420, ['Why do things keep doing', 'what they’re already doing?'], m('q'));+}, { lead: false }],+['rest', 'At rest, in motion', (m, D) => {+ const p = panel(0), Y = Y1, R = 64, X0 = 640, tk = m('kick'), ts = m('space'), V0 = 360, A = 90, T0 = V0 / A; // grass friction: stops after 4 s, 720 px on+ const field = camera(p, D), w = field.world;+ // push in on the kick (wind-up, contact at the word, follow-through), then pull back to watch the ball roll and stop+ field.to({ x: 600, y: Y - 180, z: 1.6 }, tk - 1.4, .9).to({ x: 800, y: 450, z: 1 }, tk + .7, 1.1);+ ground(w, Y);+ const ball = phBall(w, R, { x: X0, y: Y - R }), kid = phActor(w, 'you', { x: X0 - 214, y: Y, s: 3, anim: 'stand' });+ const vA = path(w, '', { stroke: VEL, 'stroke-width': 12 }), kick = forceArrow(w, { w: 14, size: 30 }), fr = forceArrow(w, { w: 14, size: 32 });+ // the words ride above the ball+ const 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'), ts - .3); // gone before deep space fades in+ const 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 kick+ put(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'); // friction only while it rolls+ kid.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);+ // deep space: the same ball, no friction, the same velocity for as long as we watch+ const sky = camera(p, D, { x: 800, y: 450 });+ put(sky.el, { o: 0 }); show(sky.el, ts, .7);+ prog(q => { if (q === 1) field.el.style.display = 'none'; }, ts + .75, 0, lin);+ const stars = sky.layer(1, 2400);+ for (let i = 0; i < 70; i++) { const k = 2 + 3 * phHash(i, 7); mk('rect', { x: -800 + 4800 * phHash(i, 1), y: 900 * phHash(i, 2), width: k, height: k, fill: COL.chalk, opacity: .3 + .5 * phHash(i, 3) }, stars); }+ const sb = phBall(sky.world, R, { y: 470 }), sv = path(sky.world, '', { stroke: VEL, 'stroke-width': 12 });+ const sx = t => 300 + 220 * (t - ts);+ sky.cut({ x: t => sx(t) + 40 }, 0);+ const sl = G(p, { o: 0 }); phLabel(sl, 'deep space: no friction', { x: 760, y: 330, size: 50 }); phLabel(sl, 'it just keeps going, same speed', { x: 760, y: 384, size: 34, fill: VEL });+ show(sl, ts + .4);+ clockRun(t => { const z = sx(t); put(sb, { x: z }); put(sb._spin, { r: z / R * 180 / Math.PI }); arrowAt(sv, z + R + 8, 470, 150, 0, 24); }, D);+}, { lead: false }],+['law1', 'Newton’s first law', (m, D) => {+ const p = panel(0), tl = m('law'), ti = m('inert');+ // The law is split over its two pictures: rest over the crate, motion over the gliding puck, the condition under both.+ phBlock(p, 60, 560, 680, 40, '#3c4a42', { top: 6, ol: 0 }); crate(p, { x: 400, y: 560, w: 260, h: 210 });+ phBlock(p, 860, 560, 700, 40, '#cfe8f3', { top: 6, ol: 0 });+ const puck = G(p); mk('rect', { x: -50, y: -40, width: 100, height: 40, rx: 12, fill: '#22282a' }, puck); const pv = path(p, '', { stroke: VEL, 'stroke-width': 12 });+ const law = G(p);+ const two = (g, a, b, x, t0) => { const e = G(g, { o: 0 }); phLabel(e, a, { x, y: 230, size: 46 }); phLabel(e, b, { x, y: 290, size: 46 }); show(e, t0); };+ two(law, 'An object at rest', 'stays at rest,', 400, tl); two(law, 'an object in motion', 'stays in motion,', 1210, tl + 2.6);+ txt(law, '…unless a net force acts on it.', 800, 720, tl + 5.2, { size: 50, weight: 700 });+ hide(law, ti - .4, .4);+ const ig = G(p, { o: 0 });+ phLabel(ig, 'inertia', { x: 800, y: 230, size: 96 }); phLabel(ig, 'matter resists changes to its motion', { x: 800, y: 296, size: 36, fill: COL.dim, weight: 600 });+ phLabel(ig, 'the first law is the law of inertia', { x: 800, y: 720, size: 40, weight: 600 });+ show(ig, ti);+ // one slow, steady glide across the whole beat: constant velocity, nothing pushing it+ clockRun(t => { const x = 960 + 26 * t; put(puck, { x, y: 560 }); arrowAt(pv, x + 60, 540, 130, 0, 24); }, D);+}, { lead: false }],+['mass', 'More mass, more inertia', (m, D) => {+ const p = panel(0), S = 2.4, LA = 400, LB = 820, tc = m('catch'), V = 400, X0 = -60;+ // Two lanes, the same speed: the tennis ball is stopped in the hand; the basketball carries the catcher back.+ [LA, LB].forEach(y => phBlock(p, 0, y, 1600, 12, PH.walk, { top: 0, ol: 0 }));+ phLabel(p, 'more mass → more inertia', { x: 800, y: 500, size: 44 });+ const ct = phActor(p, 'friend', { x: 1300, y: LA, s: S, anim: 'catch' }).face(-1), cb = phActor(p, 'friend', { x: 1300, y: LB, s: S, anim: 'catch' }).face(-1);+ const [hx] = ct.hand('F'), tCatch = tc + (hx - X0) / V; // thrown from off-frame left+ const tb = mk('circle', { r: 22, fill: '#d7e24a', ...phLine(2) }, G(p)).parentNode, bb = mk('circle', { r: 52, fill: '#e07a2e', ...phLine(2.5) }, G(p)).parentNode;+ path(bb, 'M-52 0H52M0 -52V52', { stroke: '#7a3a12', 'stroke-width': 4 });+ const vT = path(p, '', { stroke: VEL, 'stroke-width': 10 }), vB = path(p, '', { stroke: VEL, 'stroke-width': 10 }), sT = forceArrow(p, { w: 12 }), sB = forceArrow(p, { w: 12 });+ const nT = phLabel(p, 'tennis ball · light', { size: 34, weight: 600 }), nB = phLabel(p, 'basketball · heavy', { size: 34, weight: 600 });+ hide(nT, tCatch, .3); hide(nB, tCatch, .3);+ txt(p, 'easy to stop', 900, LA - 150, m('easy'), { size: 44, fill: FORCE, weight: 700 });+ const e2 = G(p, { o: 0 }); phLabel(e2, 'harder to stop:', { x: 900, y: LB - 170, size: 44, fill: FORCE }); phLabel(e2, 'it pushes you back', { x: 900, y: LB - 120, size: 38, fill: FORCE, weight: 600 }); show(e2, m('hard'));+ clockRun(t => {+ const u = t - tc, flying = t < tCatch, k = t - tCatch;+ // tennis: caught at the hand, a short absorb, then it rests in the hand+ const absorb = k > 0 && k < .35; ct.show('catch', absorb ? 1 : 0); put(ct, { x: 1300 + (absorb ? 8 * Math.sin(Math.PI * k / .35) : 0) });+ const [ax, ay] = ct.hand('F'), tx = flying ? X0 + V * Math.max(0, u) : ax - 16; put(tb, { x: tx, y: ay + 8 });+ // basketball: it carries the catcher back (slowing) before she stops it+ const slide = k <= 0 ? 0 : k < .9 ? 200 * k - 200 / 1.8 * k * k : 90; // ball and catcher share the speed (200 px/s), then she stops+ put(cb, { x: 1300 + slide }); if (k > 0 && k < .9) cb.stride('backstep', slide / S); else cb.show('catch', k > 0 && k < 1.3 ? 1 : 0);+ const [bx2, by2] = cb.hand('F'), bx = flying ? X0 + V * Math.max(0, u) : bx2 - 46; put(bb, { x: bx, y: by2 + 14 });+ arrowAt(vT, tx + 30, ay + 8, flying && u > 0 ? 110 : 0, 0, 22); arrowAt(vB, bx + 60, by2 + 14, (flying && u > 0) || (k > 0 && k < .9) ? 110 * (flying ? 1 : .5 * (1 - k / .9)) : 0, 0, 22);+ sT.set(tx - 30, ay - 30, absorb ? 70 : 0, 180, ''); sB.set(bx - 60, by2 - 30, k > 0 && k < .9 ? 70 : 0, 180, ''); // the hands' stopping force, while they stop it+ put(nT, { x: tx, y: ay - 40 }); put(nB, { x: bx, y: by2 - 56 });+ }, D);+}, { lead: false }],+['momentum', 'Momentum', (m, D) => {+ const p = panel(0), t0 = m('pool'), V = 90, xHit = 620, R = 44, tHit = t0 + 1;+ // A close overhead table: the white ball rolls in, hits the red one and stops; the red one carries the momentum on.+ const xw = t => t < tHit ? xHit - V * (tHit - t) : xHit, xr = t => t < tHit ? xHit + 2 * R : xHit + 2 * R + V * (t - tHit);+ phBlock(p, 0, 290, 1600, 320, '#6b4a30', { top: 0, ol: 0 }); phBlock(p, 0, 320, 1600, 260, '#2f7d4f', { top: 0, ol: 0 });+ show(runs(p, [['momentum', COL.chalk], [' = mass × ', COL.chalk], ['velocity', VEL]], { x: 800, y: 250, size: 52, weight: 700 }), m('f'));+ const wb = mk('circle', { r: R, fill: '#f4f1e8', ...phLine(2) }, G(p)).parentNode, rb = mk('circle', { r: R, fill: '#d24b4b', ...phLine(2) }, G(p)).parentNode;+ const vw = path(p, '', { stroke: VEL, 'stroke-width': 10 }), vr = path(p, '', { stroke: VEL, 'stroke-width': 10 });+ const lw = phLabel(p, '', { size: 30, weight: 600, o: 0 }), lr = phLabel(p, '', { size: 30, weight: 600, o: 0 }); show(lw, m('f', 1)); show(lr, m('f', 1));+ // the totals read under the table: before, then after, then why they match+ txt(p, 'before: 0.4 + 0 = 0.4 kg·m/s', 800, 690, t0, { size: 44, weight: 700 });+ txt(p, 'after: 0 + 0.4 = 0.4 kg·m/s', 800, 750, tHit + .6, { size: 44, weight: 700 });+ txt(p, 'two balls, no outside forces (friction ignored): the total stays the same', 800, 820, m('cons'), { size: 30, fill: COL.dim, weight: 500 });+ const P = '0.2 kg × 2 m/s = 0.4';+ clockRun(t => {+ 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);+ // 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) => {+ const p = panel(0), Y = 480, R = 56;+ 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'); }, 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,+ 'The bowling ball has much more mass, so it resists changes in motion more.',+ [null, 'The soccer ball is lighter: less mass, less inertia.', 'Inertia depends on mass, not size.']) },+ { id: 'c-friction', prompt: ['A ball rolling on grass slows down and stops. Why?'],+ build: choice([['friction pushes against its motion'], ['it runs out of inertia'], ['no force acts on it']], 0,+ 'Friction from the grass and air is a force against the motion: an unbalanced force that slows it down.',+ [null, 'Inertia is not used up; the ball would keep rolling without friction.', 'With no force at all, it would keep rolling forever (first law).']) },+ { id: 'c-mom', prompt: ['A 2 kilogram ball rolls at 3 meters per second. What is its ', h('b', '', 'momentum'), '?'],+ build: blanks([{ parts: ['momentum = 2 × 3 = ', { box: '6' }, ' kilogram meters per second'], why: 'mass × velocity = 2 × 3 = 6.', hint: 'Momentum = mass × velocity.' }]) },+], done) }],+['wrap2', 'Summary · First law', (m, D) => {+ summary(panel(0), m, [+ [['Objects keep their motion unless a net force acts on them.'], g => { mk('rect', { x: 150, y: -34, width: 90, height: 34, rx: 10, fill: '#22282a' }, g); arrowAt(path(g, '', { stroke: VEL, 'stroke-width': 8 }), 250, -17, 90, 0); }],+ [['Inertia resists changes in motion;', 'more mass, more inertia.'], g => { mk('circle', { cx: 190, cy: -4, r: 14, fill: '#d7e24a', ...phLine(2) }, g); mk('circle', { cx: 280, cy: 4, r: 36, fill: '#e07a2e', ...phLine(2) }, g); }],+ [['Momentum = mass × velocity; with no outside', 'forces, the total stays the same.'], g => { mk('circle', { cx: 200, cy: 0, r: 30, fill: '#f4f1e8', ...phLine(2) }, g); mk('circle', { cx: 290, cy: 0, r: 30, fill: '#d24b4b', ...phLine(2) }, g); }],+ ], 'Next: Newton’s second law.');+}],+/* ---------- part 3: Newton's second law ---------- */+['part3', 'Part 3 · The second law', (m, D) => {+ const p = panel(0), Y = Y1, S = 3, CW = 112 * 2.5, d = t => 16 * t * t;+ // You push the cart and it speeds up; the camera keeps you in place, the grass marks slide back.+ const cam = camera(p, D), w = cam.world; cam.cut({ x: t => 800 + d(t) }, 0);+ ground(w, Y, -400, 2400); marks(w, Y, -400, 2400);+ 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'); 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'));+}, { lead: false }],+['law2', 'a = F ÷ m', (m, D) => {+ const p = panel(0), tl = m('law'), tm = m('more');+ // The law alone and large first; then it moves up as a line and two 2 kg crates show it: 4 N and 8 N, 2 and 4 m/s².+ const big = G(p, { o: 0 });+ T(big, 'acceleration', { x: 560, y: 470, size: 64, weight: 700, fill: ACC, anchor: 'end' }); T(big, '=', { x: 640, y: 470, size: 64, weight: 700, anchor: 'middle' });+ T(big, 'net force', { x: 900, y: 420, size: 60, weight: 700, fill: FORCE, anchor: 'middle' }); mk('rect', { x: 720, y: 446, width: 360, height: 6, fill: COL.chalk }, big);+ T(big, 'mass', { x: 900, y: 520, size: 60, weight: 700, anchor: 'middle' });+ show(big, tl); hide(big, tm - .8, .4);+ show(runs(p, [['acceleration', ACC], [' = ', COL.chalk], ['net force', FORCE], [' ÷ mass', COL.chalk]], { x: 800, y: 110, size: 44, weight: 700 }), tm - .5);+ show(runs(p, [['net force', FORCE], [' = mass × ', COL.chalk], ['acceleration', ACC]], { x: 800, y: 170, size: 40, weight: 700 }), m('rearr'));+ const t0 = tm - .4, U = 2 * 1100 / (4 * (D - t0) ** 2); // the faster crate reaches the far end as the beat ends+ const lanes = [[440, 4, 2], [760, 8, 4]].map(([y, F, a], i) => {+ const g = G(p, { o: 0 }); show(g, tm - .5);+ phBlock(g, 0, y, 1600, 12, PH.walk, { top: 0, ol: 0 });+ txt(g, `${F} N ÷ 2 kg = ${a} m/s²`, 300, y + 70, tm + .8 + i * .8, { size: 36, weight: 600 });+ return { c: crate(g, { y, w: 180, h: 150, label: '2 kg' }), f: forceArrow(g, { w: 14, size: 36 }), aa: forceArrow(g, { color: ACC, w: 12, size: 34 }), F, a, y };+ });+ clockRun(t => lanes.forEach(({ c, f, aa, F, a, y }) => {+ const u = Math.max(0, t - t0), x = 200 + U * a * u * u / 2, on = t > t0;+ put(c, { x }); f.set(x - 96 - F * 30, y - 75, on ? F * 30 : 0, 0, `${F} N`); aa.set(x - 60, y - 190, on ? a * 50 : 0, 0, `${a} m/s²`);+ }), D);+ txt(p, 'double the force → double the acceleration', 1100, 860, m('more', .8), { size: 34, weight: 600 });+}, { lead: false }],+['cart', 'Same force, different mass', (m, D) => {+ const p = panel(0), S = 2.2, LA = 400, LB = 820, t0 = m('cart', -.8), tc = .6;+ // The same 200 N shove for the same 0.6 s on a 20 kg cart and a 1,000 kg car (50 times the mass): the cart leaves+ // at speed, the car barely creeps. The arrows show only while the hands push.+ const dx = (a, t) => { const u = Math.max(0, t - t0), k = Math.min(u, tc); return a * k * k / 2 + a * tc * Math.max(0, u - tc); };+ phBlock(p, 0, LA, 1600, 12, PH.walk, { top: 0, ol: 0 });+ mk('rect', { x: 0, y: LB, width: 1600, height: 80, fill: '#3a4541' }, p);+ [300, 700, 1100, 1500].forEach(x => mk('rect', { x, y: LB + 14, width: 8, height: 52, fill: PH.line, opacity: .5 }, p));+ const A = phActor(p, 'you', { x: 260, y: LA, s: S, anim: 'push' }), cart = phSprite(p, 'cart', { y: LA, s: S });+ const B = phActor(p, 'friend', { x: 260, y: LB, s: S, anim: 'push' }), car = phCar(p, { y: LB, s: 1.6 });+ const f1 = forceArrow(p, { w: 14, size: 36 }), f2 = forceArrow(p, { w: 14, size: 36 }), v1 = path(p, '', { stroke: VEL, 'stroke-width': 10 });+ const m1 = phLabel(p, '20 kg', { size: 36 }), m2 = phLabel(p, '1,000 kg', { size: 36 });+ const why = G(p, { o: 0 }); show(why, m('why'));+ phLabel(why, 'a = 200 N ÷ 20 kg = 10 m/s²', { x: 900, y: 270, size: 44, fill: ACC });+ phLabel(why, 'a = 200 N ÷ 1,000 kg = 0.2 m/s²', { x: 1120, y: 690, size: 44, fill: ACC }); phLabel(why, 'tiny', { x: 1120, y: 740, size: 34, fill: COL.dim, weight: 600 });+ A.show('push', 0); B.show('push', 0);+ const xa0 = A.hand('F')[0] + 112 * S / 2 - 6, xb0 = B.hand('F')[0] + 256 * 1.6 / 2 - 6; // the cart and the car start against the hands+ clockRun(t => {+ 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'); arrowAt(v1, xa + 140, LA - 220, u > tc ? 110 : 0, 0, 22);+ put(m1, { x: xa, y: LA + 50 }); // each mass tag under its object+ put(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'); put(m2, { x: xb, y: LB + 54 });+ }, D);+}, { lead: false }],+['calc', 'Net force = mass × acceleration', (m, D) => {+ const p = panel(0), RY = 560, t0 = m('ex'), aPx = 40, cx = t => { const u = Math.max(0, t - t0); return 600 + aPx * u * u / 2; };+ // The worked example on the car itself: the camera follows it (the lane marks slide back), the sum reads under it.+ const cam = camera(p, D), w = cam.world, road = cam.layer(1, 320); cam.cut({ x: t => cx(t) + 100 }, 0);+ mk('rect', { x: 0, y: RY, width: 2240, height: 80, fill: '#3a4541' }, road);+ for (let x = 0; x < 2240; x += 320) mk('rect', { x, y: RY + 36, width: 120, height: 8, fill: PH.line, opacity: .6 }, road);+ const car = phCar(w, { y: RY, s: 2.4 }), ml = phLabel(w, '2,000 kg', { size: 44 }), aa = forceArrow(w, { color: ACC, w: 12, size: 36 }), f = forceArrow(w, { w: 16, size: 36 });+ show(runs(p, [['net force', FORCE], [' = mass × ', COL.chalk], ['acceleration', ACC]], { x: 700, y: 720, size: 46, weight: 700 }), m('f'));+ show(runs(p, [['= 2,000 kg × 3 ', COL.chalk], ['m/s²', ACC]], { x: 640, y: 790, size: 46, weight: 700 }), m('f', 1.6));+ const ans = T(p, '= 6,000 N', { x: 900, y: 790, size: 56, weight: 700, fill: FORCE, anchor: 'start', o: 0 });+ pop(put(ans, { s: .6 }), m('ans'));+ clockRun(t => {+ const x = cx(t), on = t > t0; put(car, { x }); phRoll(car, (x - 600) / 2.4);+ put(ml, { x, y: 290 }); aa.set(x - 100, 230, on ? 200 : 0, 0, '3 m/s²');+ f.set(x + 330, RY - 120, on ? 160 : 0, 0, t > m('ans') ? '6,000 N' : ''); // the net force pushes the whole time it speeds up+ }, D);+}, { lead: false }],+['wind', 'With and against the wind', (m, D) => {+ const p = panel(0), tw1 = m('with'), ta = m('against');+ // Follow camera on the bike. With the wind: 4 → 8 m/s; against it: 8 → 2 m/s (30 px/s = 1 m/s).+ const v = t => t < ta - .3 ? 4 + 4 * ramp(t, tw1, tw1 + 5) : 8 - 6 * ramp(t, ta, ta + 4.5);+ const xAt = t => { let x = 0; for (let u = 0; u < t; u += .05) x += v(u) * 30 * .05; return x; }; // deterministic sum over fixed steps+ const cam = camera(p, D, { x: 800, y: 560 }); cam.cut({ x: t => 300 + xAt(t) + 300 }, 0);+ const road = phRoad(cam), bike = phBike(road.vehicles, 'you', { s: 2 });+ const vv = forceArrow(road.front, { color: VEL, w: 12, size: 32 }), wf = forceArrow(road.front, { w: 14, size: 32 }), nf = forceArrow(road.front, { color: NETF, w: 18, size: 30 });+ const streaks = G(p, { o: .5 }), sl = Array.from({ length: 9 }, () => path(streaks, '', { stroke: COL.chalk, 'stroke-width': 4 }));+ const tag = phLabel(p, '', { x: 1180, y: 460, size: 48 });+ 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`);+ 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);+}],+['q3', 'Quick check', (m, D) => {+ const p = panel(0), y = 470;+ phBlock(p, 300, y, 1000, 12, PH.walk, { top: 0, ol: 0 });+ crate(p, { x: 800, y, w: 240, h: 200, label: '2 kg' });+ forceArrow(p, { w: 16, size: 40 }).set(434, y - 100, 240, 0, '10 N'); forceArrow(p, { color: ACC, w: 12, size: 38 }).set(720, y - 240, 200, 0, '? m/s²');+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-a', prompt: ['A 10 newton net force pushes a 2 kilogram box. What is its ', h('b', '', 'acceleration'), '?'],+ build: blanks([{ parts: ['acceleration = 10 ÷ 2 = ', { box: '5' }, ' meters per second squared'], why: 'acceleration = net force ÷ mass = 10 ÷ 2 = 5.', hint: 'acceleration = net force ÷ mass.' }]) },+ { id: 'c-fma', prompt: ['A 50 kilogram skater speeds up at 4 meters per second squared. What net force acts on her?'],+ build: blanks([{ parts: ['net force = 50 × 4 = ', { box: '200' }, ' newtons'], why: 'net force = mass × acceleration = 50 × 4 = 200.', hint: 'net force = mass × acceleration.' }]) },+ { id: 'c-more', prompt: ['The same force pushes a bike and a truck. Which accelerates more?'],+ build: choice([['the bike'], ['the truck'], ['both the same']], 0,+ 'Less mass, more acceleration: a = F ÷ m.',+ [null, 'The truck has far more mass, so the same force gives it less acceleration.', 'Same force, different masses: different accelerations.']) },+], done) }],+['wrap3', 'Summary · Second law', (m, D) => {+ summary(panel(0), m, [+ [['acceleration = net force ÷ mass'], g => { crate(g, { x: 220, y: 40, w: 120, h: 100 }); forceArrow(g, { w: 10 }).set(284, -10, 80, 0, ''); forceArrow(g, { color: ACC, w: 8 }).set(180, -90, 70, 0, ''); }],+ [['net force = mass × acceleration', '(newtons = kilograms × m/s²)'], g => { phLabel(g, 'F = m × a', { x: 240, y: 10, size: 36 }); }],+ [['Net force with the motion: speed up;', 'against it: slow down.'], g => { phBike(g, 'you', { x: 230, y: 50, s: .8 }); forceArrow(g, { w: 8 }).set(80, -40, 70, 0, ''); }],+ ], 'Next: Newton’s third law.');+}],+/* ---------- part 4: Newton's third law ---------- */+['part4', 'Part 4 · The third law', (m, D) => {+ const p = panel(0), Y = Y1, S = 3, tp = 1.1;+ // Two skaters push palm to palm, then glide apart (slowly easing on the ice); the pair shows only while they touch.+ rink(p, Y);+ const a = phActor(p, 'you', { y: Y, s: S, anim: 'skate' }), b = phActor(p, 'friend', { y: Y, s: S, anim: 'skate' }).face(-1), fa = forceArrow(p, { w: 14 }), fb = forceArrow(p, { w: 14 });+ clockRun(t => {+ const u = Math.max(0, t - tp), s = 105 * u - 9 * u * u;+ put(a, { x: 640 - s, r: u ? -4 : 0 }); put(b, { x: 960 + s, r: u ? 4 : 0 }); a.show('skate', u ? 0 : 1); b.show('skate', u ? 0 : 1); // arms out, palm to palm+ const on = t < tp;+ fa.set(790, Y - 420, on ? 150 : 0, 180, ''); fb.set(810, Y - 420, on ? 150 : 0, 0, ''); // the pair, over the joined hands+ }, D);+ opener(p, 800, 250, 'Part 4', 'The Third Law');+ txt(p, 'Forces always come in pairs.', 800, 360, m('q'), { size: 42 });+}, { lead: false }],+['law3', 'Action and reaction', (m, D) => {+ const p = panel(0), Y = Y1, S = 3, tb = m('bowl'), tC = tb - .25, tR = m('equal', -.3), R = 44; // contact: wind-up to release, 0.25 s+ // The throw: in close for the contact (the pair only while the hands push the ball), out to watch the light ball fly+ // fast and you slide back slowly. From "equal" a held, labelled replay of the moment of contact.+ const cam = camera(p, D), w = cam.world, close = { x: 760, y: Y - 200, z: 1.6 };+ cam.to(close, tb - 1.3, .8).to({ x: 800, y: 450, z: 1 }, tb + .6, 1).cut(close, tR);+ rink(w, Y, -1200, 4800);+ const you = phActor(w, 'you', { x: 640, y: Y, s: S, anim: 'stand' }), ball = G(w);+ mk('circle', { r: R, fill: '#22282a', ...phLine(2) }, ball); [[-12, -14], [8, -20], [3, 6]].forEach(([x, y]) => mk('circle', { cx: x, cy: y, r: 6, fill: '#5a6266' }, ball));+ const act = forceArrow(w, { w: 12, size: 26 }), rea = forceArrow(w, { w: 12, size: 26 }), vb = path(w, '', { stroke: VEL, 'stroke-width': 10 }), vy = path(w, '', { stroke: VEL, 'stroke-width': 10 });+ you.show('throw', 1); put(you, { x: 640 }); const [rx, ry] = you.hand('F'); // the release point: the hand of the release pose+ const VB = 520, VY = 28;+ const law = G(p, { o: 0 }); phLabel(law, 'For every action, there is an', { x: 800, y: 210, size: 52 }); phLabel(law, 'equal and opposite reaction.', { x: 800, y: 274, size: 52 });+ show(law, m('law')); hide(law, tb - 1.4, .4);+ const tag = G(p, { o: 0 }); mk('rect', { x: 60, y: 56, width: 420, height: 52, rx: 26, fill: 'none', stroke: COL.dim, 'stroke-width': 3 }, tag);+ phLabel(tag, 'replay · the moment of contact', { x: 270, y: 91, size: 24, fill: COL.dim, weight: 600 }); show(tag, tR, .3);+ txt(p, 'same size,', 1250, 200, m('equal'), { size: 50, weight: 700 });+ const op = G(p, { o: 0 }); phLabel(op, 'opposite directions,', { x: 1250, y: 260, size: 44, weight: 600 }); phLabel(op, 'on two objects', { x: 1250, y: 312, size: 44, weight: 600 }); show(op, m('opp'));+ clockRun(t => {+ const replay = t >= tR, ts = replay ? tC + .12 : t, u = Math.max(0, ts - tb), contact = ts >= tC && ts < tb;+ put(you, { x: 640 - VY * u });+ if (ts < tb - .9) you.show('stand'); else if (ts < tC) you.show('throw', 0); else if (ts < tb + .4) you.show('throw', 1); else you.show('throw', 2);+ 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 on+ put(ball, { x: bx, y: by });+ 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 }],+['pairs', 'Action-reaction pairs', (m, D) => {+ const p = panel(0), tt = m('tramp'), tr = m('run'), S = 3, BY = 720;+ // Two full frames in turn: one slow bounce on a trampoline, then a run under a following camera.+ const L = G(p);+ txt(L, 'Action-reaction pairs', 800, 150, .2, { size: 52, weight: 700 });+ path(L, `M300 ${BY}H1300M380 ${BY}V${BY + 110}M1220 ${BY}V${BY + 110}`, { stroke: '#5a6d63', 'stroke-width': 8 });+ const bed = path(L, '', { stroke: '#6f8a96', 'stroke-width': 12 });+ const j = phActor(L, 'you', { x: 800, s: S, anim: 'jump' }), down = forceArrow(L, { w: 16, size: 36 }), up = forceArrow(L, { w: 16, size: 36 });+ const ld = phLabel(L, 'you push it down', { x: 910, y: 700, size: 36, fill: FORCE, anchor: 'start', o: 0 }), lu = phLabel(L, 'it pushes you up', { x: 690, y: 860, size: 36, fill: FORCE, anchor: 'end', o: 0 });+ // a hop up (from tt − 1.8), then the landing on "tramp": compress, hold so the pair can be read, launch, flight, rest+ const bounce = t => {+ const k0 = t - (tt - 1.8);+ if (k0 < 0) return { y: BY, sag: 0, pose: 'stand' };+ if (k0 < .3) return { y: BY + 20 * ramp(k0, 0, .3), sag: ramp(k0, 0, .3) * .4, pose: 'crouch', push: true };+ if (k0 < 1.8) { const q = (k0 - .3) / 1.5; return { y: BY - 280 * 4 * q * (1 - q), sag: 0, pose: 'jump' }; }+ const k = k0 - 1.8;+ if (k < .4) return { y: BY + 50 * ramp(k, 0, .4), sag: ramp(k, 0, .4), pose: 'land', push: true };+ if (k < 1.4) return { y: BY + 50, sag: 1, pose: 'crouch', push: true };+ if (k < 1.7) return { y: BY + 50 - 50 * ramp(k, 1.4, 1.7), sag: 1 - ramp(k, 1.4, 1.7), pose: 'land', push: true };+ if (k < 3) { const q = (k - 1.7) / 1.3; return { y: BY - 280 * 4 * q * (1 - q), sag: 0, pose: 'jump' }; }+ return { y: BY, sag: 0, pose: 'stand' };+ };+ show(ld, tt); show(lu, tt + .4); hide(L, tr - .5, .4);+ // the run+ const rc = camera(p, D); put(rc.el, { o: 0 }); show(rc.el, tr - .2, .4);+ const track = rc.layer(1, 600);+ phBlock(track, 0, Y1, 2200, 30, '#8a6f55', { top: 4, ol: 0 });+ for (let x = 0; x < 2200; x += 120) mk('rect', { x, y: Y1 + 40, width: 60, height: 6, fill: PH.line, opacity: .5 }, track);+ const runner = phActor(rc.world, 'friend', { y: Y1, s: S, anim: 'run' }), back = forceArrow(rc.world, { w: 16 }), fwd = forceArrow(rc.world, { w: 16 });+ const rx = t => 760 + 300 * Math.max(0, t - tr);+ rc.cut({ x: t => rx(t) + 40 }, 0);+ const lb = phLabel(p, 'your foot pushes back on the ground', { x: 760, y: Y1 + 130, size: 36, fill: FORCE, o: 0 }), lf = phLabel(p, 'the ground pushes you forward', { x: 1020, y: 572, size: 36, fill: FORCE, anchor: 'start', o: 0 });+ show(lb, tr + .3); show(lf, tr + 1.2);+ clockRun(t => {+ const b = bounce(t);+ bed.setAttribute('d', `M380 ${BY}Q800 ${BY + 140 * b.sag} 1220 ${BY}`); put(j, { y: b.y }); j.show(b.pose);+ down.set(880, BY - 60 + 50 * b.sag, b.push ? 110 : 0, 90, ''); up.set(720, BY + 160, b.push ? 110 : 0, -90, '');+ const x = rx(t); put(runner, { x }); if (t > tr) runner.stride('run', (x - 760) / S); else runner.show('stand');+ const strike = t > tr && runner._f % 2 === 0; // the push only while a foot is on the ground+ back.set(x, Y1 + 50, strike ? 150 : 0, 180, ''); fwd.set(x + 60, 560, strike ? 170 : 0, 0, '');+ }, D);+}, { lead: false }],+['earth', 'Why Earth doesn’t move', (m, D) => {+ const p = panel(0), ta = m('mass'), tt = m('tiny'), G0 = 560;+ // You on top of a huge Earth. The pair at your feet is equal (500 N each way); what differs is the mass. No+ // acceleration arithmetic for the jumper: on the ground gravity acts too, so the push alone is not the net force.+ phEarthPolar(p, { x: 800, y: G0 + 1000, R: 1000 });+ const you = phActor(p, 'you', { x: 800, y: G0, s: 2.6, anim: 'stand' }), dn = forceArrow(p, { w: 16, size: 32 }), up = forceArrow(p, { w: 16, size: 32 });+ const g1 = G(p, { o: 0 }); phLabel(g1, 'the same 500 N', { x: 580, y: 430, size: 40, fill: FORCE, anchor: 'end' }); phLabel(g1, 'acts on both', { x: 580, y: 480, size: 40, anchor: 'end' }); show(g1, ta);+ txt(p, 'you: about 50 kg', 1020, 450, ta + 1.2, { size: 40, weight: 700, anchor: 'start' });+ const plate = (lines, t0, t1) => {+ const g = G(p, { o: 0 }); mk('rect', { x: 360, y: 700, width: 880, height: 170, rx: 20, fill: '#14201d', opacity: .92 }, g);+ lines.forEach(([s, size, fill], i) => phLabel(g, s, { x: 800, y: 770 + i * 60, size, fill, weight: i ? 600 : 700 })); show(g, t0); if (t1) hide(g, t1, .3);+ };+ plate([['Earth: about 6 × 10²⁴ kg', 44, COL.chalk], ['(a 6 followed by 24 zeros)', 30, COL.dim]], ta + 2.2, tt - .3);+ plate([['huge mass → tiny acceleration', 48, ACC], ['far too small to notice, but it is there', 32, COL.dim]], tt);+ // three separate jumps: crouch, push-off (the pair), flight on a parabola, landing and recovery+ const starts = [.5, ta + .8, tt + 1.2];+ const jump = t => {+ for (const s of starts) {+ const k = t - s;+ if (k < 0 || k > 2.2) continue;+ if (k < .35) return { y: G0, pose: 'crouch' };+ if (k < .5) return { y: G0, pose: 'land', push: true };+ if (k < 1.6) { const q = (k - .5) / 1.1; return { y: G0 - 220 * 4 * q * (1 - q), pose: 'jump' }; }+ if (k < 1.9) return { y: G0, pose: 'land' };+ return { y: G0, pose: 'stand' };+ }+ return { y: G0, pose: 'stand' };+ };+ 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', '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) => {+ const p = panel(0), Y = 500, S = 2.4, WX = 980;+ ground(p, Y);+ phBlock(p, WX, 60, 150, Y - 60, '#7d6a5a', { top: 0, right: 14, ol: 0 });+ for (let y = 100; y < Y; y += 60) mk('rect', { x: WX, y, width: 136, height: 5, fill: '#5e4f42' }, p);+ const a = phActor(p, 'you', { y: Y, s: S, anim: 'push' }).show('push', 0), f1 = forceArrow(p, { w: 14, size: 32 }), f2 = forceArrow(p, { w: 14, size: 32 });+ put(a, { x: 0 }); const off = WX - a.hand('F')[0];+ clockRun(t => { put(a, { x: off + Math.sin(t * 9) * 1.5 }); a.show('push', 0); }, D); // leaning in, straining a little+ put(a, { x: off }); const [hx, hy] = a.hand('F');+ f1.set(WX + 10, hy - 40, 150, 0, ''); f2.set(WX - 10, hy + 60, 150, 180, '');+ phLabel(p, 'you push the wall: 30 N', { x: 1170, y: hy - 28, size: 32, fill: FORCE, anchor: 'start' }); phLabel(p, 'the wall pushes you: ?', { x: 700, y: hy + 72, size: 32, fill: FORCE, anchor: 'end' });+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-wall', prompt: ['You push on a wall with 30 newtons. How hard does the wall push back on you?'],+ build: blanks([{ parts: ['the wall pushes back with ', { box: '30' }, ' newtons'], why: 'Action and reaction are equal in size and opposite in direction.', hint: 'Third law: equal and opposite.' }]) },+ { id: 'c-jump', prompt: ['When you jump, you push down on Earth and Earth pushes up on you with the same force. Why doesn’t Earth move noticeably?'],+ build: choice([['its huge mass gives it a tiny acceleration'], ['it pushes back with a smaller force'], ['forces only act on people']], 0,+ 'Same force, enormous mass: a = F ÷ m is far too small to notice.',+ [null, 'The two forces are equal; the difference is the mass.', 'Earth feels the force too; it just barely accelerates.']) },+ { id: 'c-pair', prompt: ['A swimmer pushes backward on the pool wall. What pushes the swimmer forward?'],+ build: choice([['the wall'], ['the swimmer’s own push'], ['nothing pushes the swimmer']], 0,+ 'The wall pushes back on the swimmer: an action-reaction pair.',+ [null, 'Your own push acts on the wall, not on you. The wall’s push acts on you.', 'Something must push the swimmer to speed her up: the wall does.']) },+], done) }],+['wrap4', 'Summary · Third law', (m, D) => {+ summary(panel(0), m, [+ [['For every action, there is an equal and', 'opposite reaction.'], g => { forceArrow(g, { w: 10 }).set(220, -10, 80, 180, ''); forceArrow(g, { w: 10 }).set(260, -10, 80, 0, ''); }],+ [['The pair: same size, opposite directions,', 'on two different objects.'], g => { mk('circle', { cx: 290, cy: -6, r: 22, fill: '#22282a', ...phLine(2) }, g); forceArrow(g, { w: 10 }).set(318, -6, 70, 0, ''); forceArrow(g, { w: 10 }).set(220, -6, 70, 180, ''); }],+ [['The same force moves a small mass a lot', 'and a huge mass hardly at all.'], g => { phEarthPolar(g, { x: 240, y: 200, R: 160 }); phActor(g, 'you', { x: 240, y: 40, s: .8 }); }],+ ], 'Next: the chapter practice.');+}],+/* ---------- chapter practice and finish ---------- */+['final1', 'Chapter practice: force and the first law', () => { PRACTICE = panel(0); }, { ask: done => quiz(SCREEN, withPics([+ { id: 'p-bal', prompt: ['What is the difference between ', h('b', '', 'balanced'), ' and ', h('b', '', 'unbalanced'), ' forces?'],+ build: choice([['Balanced forces cancel (net force 0); unbalanced forces leave a net force that changes motion.'], ['Balanced forces are always bigger than unbalanced ones.'], ['Unbalanced forces cancel; balanced forces change motion.']], 0,+ 'Balanced: the net force is zero, nothing changes. Unbalanced: there is a net force in one direction.',+ [null, 'It is not about size: it is whether the forces cancel.', 'It is the other way around.']) },+ { id: 'p-first', prompt: ['What is ', h('b', '', 'Newton’s first law'), '?'],+ build: choice([['An object at rest stays at rest and an object in motion stays in motion, unless a net force acts on it.'], ['Acceleration equals net force divided by mass.'], ['For every action there is an equal and opposite reaction.']], 0,+ 'That is the law of inertia.', [null, 'That is the second law.', 'That is the third law.']) },+ { id: 'p-unit', prompt: ['What is the unit of force, and what is one unit equal to?'],+ build: choice([['the newton: 1 N = 1 kg × 1 m/s²'], ['the newton: 1 N = 1 kg × 1 m/s'], ['the kilogram: 1 kg = 1 N × 1 m/s²']], 0,+ 'One newton gives a 1 kilogram mass an acceleration of 1 meter per second squared.',+ [null, 'Close: it is meters per second squared, an acceleration.', 'Force is measured in newtons; the kilogram measures mass.']) },+ { id: 'p-net3', prompt: ['Forces on a box: 6 newtons right, 4 newtons right, and 3 newtons left. What is the net force?'],+ build: blanks([{ parts: ['net force = 6 + 4 − 3 = ', { box: '7' }, ' newtons, to the right'], why: 'Same direction adds (6 + 4 = 10); the opposite force subtracts (10 − 3 = 7).', hint: 'Add the forces to the right, then subtract the one to the left.' }]) },+]), done, 'Chapter practice, set 1 of 2 · question') }],+['final2', 'Chapter practice: the second and third laws', () => { PRACTICE = panel(0); }, { ask: done => quiz(SCREEN, withPics([+ { id: 'p-second', prompt: ['What is ', h('b', '', 'Newton’s second law'), '?'],+ build: choice([['The acceleration of an object equals the net force on it divided by its mass.'], ['Objects keep their motion unless a net force acts.'], ['Forces act in pairs.']], 0,+ 'a = net force ÷ mass, or net force = mass × acceleration.', [null, 'That is the first law.', 'That is the third law.']) },+ { id: 'p-car', prompt: ['A 2,000 kilogram car accelerates at 3 meters per second squared. What force does the engine apply? (Type the number without a comma.)'],+ build: blanks([{ parts: ['net force = 2000 × 3 = ', { box: '6000' }, ' newtons'], why: 'net force = mass × acceleration = 2,000 × 3 = 6,000 newtons.', hint: 'net force = mass × acceleration. Type 6000.' }]) },+ { id: 'p-third', prompt: ['What is ', h('b', '', 'Newton’s third law'), '?'],+ build: choice([['For every action, there is an equal and opposite reaction.'], ['More mass means more inertia.'], ['Momentum equals mass times velocity.']], 0,+ 'Forces act in pairs: equal in size, opposite in direction.', [null, 'That is about inertia (first law).', 'That defines momentum.']) },+ { id: 'p-mom', prompt: ['A 0.5 kilogram ball moves at 8 meters per second. What is its momentum?'],+ build: blanks([{ parts: ['momentum = 0.5 × 8 = ', { box: '4' }, ' kilogram meters per second'], why: 'mass × velocity = 0.5 × 8 = 4.', hint: 'momentum = mass × velocity.' }]) },+]), done, 'Chapter practice, set 2 of 2 · question') }],+['finish', 'Finished', () => {+ // under the card, the chapter in four small pictures with their names+ const p = panel(0);+ [['force', 300, g => { phSprite(g, 'cart', { x: 20, y: 0, s: 1.4 }); forceArrow(g, { w: 8 }).set(-110, -70, 90, 0, ''); }],+ ['first law', 633, g => { mk('rect', { x: -70, y: -34, width: 80, height: 30, rx: 10, fill: '#22282a' }, g); arrowAt(path(g, '', { stroke: VEL, 'stroke-width': 8 }), 20, -20, 80, 0); }],+ ['second law', 966, g => { crate(g, { x: -20, y: 0, w: 110, h: 90 }); forceArrow(g, { w: 8 }).set(40, -40, 70, 0, ''); forceArrow(g, { color: ACC, w: 8 }).set(-70, -110, 70, 0, ''); }],+ ['third law', 1300, g => { forceArrow(g, { w: 8 }).set(-20, -40, 80, 180, ''); forceArrow(g, { w: 8 }).set(20, -40, 80, 0, ''); }]]+ .forEach(([s, x, draw]) => { const g = G(p, { x, y: 800, s: .85 }); draw(g); phLabel(g, s, { y: 56, size: 30, fill: COL.dim, weight: 600 }); });+}, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/science/ch11/audio/en/air.mp3 b/site/science/ch11/audio/en/air.mp3new file mode 100644index 0000000..e463d8bBinary files /dev/null and b/site/science/ch11/audio/en/air.mp3 differdiff --git a/site/science/ch11/audio/en/building.mp3 b/site/science/ch11/audio/en/building.mp3new file mode 100644index 0000000..b96fc41Binary files /dev/null and b/site/science/ch11/audio/en/building.mp3 differdiff --git a/site/science/ch11/audio/en/buoy.mp3 b/site/science/ch11/audio/en/buoy.mp3new file mode 100644index 0000000..7a6e1ddBinary files /dev/null and b/site/science/ch11/audio/en/buoy.mp3 differdiff --git a/site/science/ch11/audio/en/circle.mp3 b/site/science/ch11/audio/en/circle.mp3new file mode 100644index 0000000..4814ec1Binary files /dev/null and b/site/science/ch11/audio/en/circle.mp3 differdiff --git a/site/science/ch11/audio/en/electric.mp3 b/site/science/ch11/audio/en/electric.mp3new file mode 100644index 0000000..a95c42cBinary files /dev/null and b/site/science/ch11/audio/en/electric.mp3 differdiff --git a/site/science/ch11/audio/en/electromagnet.mp3 b/site/science/ch11/audio/en/electromagnet.mp3new file mode 100644index 0000000..fdad6adBinary files /dev/null and b/site/science/ch11/audio/en/electromagnet.mp3 differdiff --git a/site/science/ch11/audio/en/fall.mp3 b/site/science/ch11/audio/en/fall.mp3new file mode 100644index 0000000..40f8d71Binary files /dev/null and b/site/science/ch11/audio/en/fall.mp3 differdiff --git a/site/science/ch11/audio/en/final1.mp3 b/site/science/ch11/audio/en/final1.mp3new file mode 100644index 0000000..323caf0Binary files /dev/null and b/site/science/ch11/audio/en/final1.mp3 differdiff --git a/site/science/ch11/audio/en/final2.mp3 b/site/science/ch11/audio/en/final2.mp3new file mode 100644index 0000000..0977b7fBinary files /dev/null and b/site/science/ch11/audio/en/final2.mp3 differdiff --git a/site/science/ch11/audio/en/finish.mp3 b/site/science/ch11/audio/en/finish.mp3new file mode 100644index 0000000..89afb97Binary files /dev/null and b/site/science/ch11/audio/en/finish.mp3 differdiff --git a/site/science/ch11/audio/en/float.mp3 b/site/science/ch11/audio/en/float.mp3new file mode 100644index 0000000..fdab8eaBinary files /dev/null and b/site/science/ch11/audio/en/float.mp3 differdiff --git a/site/science/ch11/audio/en/friction.mp3 b/site/science/ch11/audio/en/friction.mp3new file mode 100644index 0000000..5c9b450Binary files /dev/null and b/site/science/ch11/audio/en/friction.mp3 differdiff --git a/site/science/ch11/audio/en/gravity.mp3 b/site/science/ch11/audio/en/gravity.mp3new file mode 100644index 0000000..d625bbaBinary files /dev/null and b/site/science/ch11/audio/en/gravity.mp3 differdiff --git a/site/science/ch11/audio/en/intro.mp3 b/site/science/ch11/audio/en/intro.mp3new file mode 100644index 0000000..44fec9fBinary files /dev/null and b/site/science/ch11/audio/en/intro.mp3 differdiff --git a/site/science/ch11/audio/en/kinds.mp3 b/site/science/ch11/audio/en/kinds.mp3new file mode 100644index 0000000..1790c7dBinary files /dev/null and b/site/science/ch11/audio/en/kinds.mp3 differdiff --git a/site/science/ch11/audio/en/magnets.mp3 b/site/science/ch11/audio/en/magnets.mp3new file mode 100644index 0000000..0dfc467Binary files /dev/null and b/site/science/ch11/audio/en/magnets.mp3 differdiff --git a/site/science/ch11/audio/en/moon.mp3 b/site/science/ch11/audio/en/moon.mp3new file mode 100644index 0000000..5d4636dBinary files /dev/null and b/site/science/ch11/audio/en/moon.mp3 differdiff --git a/site/science/ch11/audio/en/orbit.mp3 b/site/science/ch11/audio/en/orbit.mp3new file mode 100644index 0000000..86b4c33Binary files /dev/null and b/site/science/ch11/audio/en/orbit.mp3 differdiff --git a/site/science/ch11/audio/en/part2.mp3 b/site/science/ch11/audio/en/part2.mp3new file mode 100644index 0000000..f665970Binary files /dev/null and b/site/science/ch11/audio/en/part2.mp3 differdiff --git a/site/science/ch11/audio/en/part3.mp3 b/site/science/ch11/audio/en/part3.mp3new file mode 100644index 0000000..daaa753Binary files /dev/null and b/site/science/ch11/audio/en/part3.mp3 differdiff --git a/site/science/ch11/audio/en/part4.mp3 b/site/science/ch11/audio/en/part4.mp3new file mode 100644index 0000000..27763a0Binary files /dev/null and b/site/science/ch11/audio/en/part4.mp3 differdiff --git a/site/science/ch11/audio/en/q1.mp3 b/site/science/ch11/audio/en/q1.mp3new file mode 100644index 0000000..7315809Binary files /dev/null and b/site/science/ch11/audio/en/q1.mp3 differdiff --git a/site/science/ch11/audio/en/q2.mp3 b/site/science/ch11/audio/en/q2.mp3new file mode 100644index 0000000..bf022bbBinary files /dev/null and b/site/science/ch11/audio/en/q2.mp3 differdiff --git a/site/science/ch11/audio/en/q3.mp3 b/site/science/ch11/audio/en/q3.mp3new file mode 100644index 0000000..33978e4Binary files /dev/null and b/site/science/ch11/audio/en/q3.mp3 differdiff --git a/site/science/ch11/audio/en/q4.mp3 b/site/science/ch11/audio/en/q4.mp3new file mode 100644index 0000000..86ea573Binary files /dev/null and b/site/science/ch11/audio/en/q4.mp3 differdiff --git a/site/science/ch11/audio/en/rough.mp3 b/site/science/ch11/audio/en/rough.mp3new file mode 100644index 0000000..e989350Binary files /dev/null and b/site/science/ch11/audio/en/rough.mp3 differdiff --git a/site/science/ch11/audio/en/strength.mp3 b/site/science/ch11/audio/en/strength.mp3new file mode 100644index 0000000..2f7e3c1Binary files /dev/null and b/site/science/ch11/audio/en/strength.mp3 differdiff --git a/site/science/ch11/audio/en/terminal.mp3 b/site/science/ch11/audio/en/terminal.mp3new file mode 100644index 0000000..79bb633Binary files /dev/null and b/site/science/ch11/audio/en/terminal.mp3 differdiff --git a/site/science/ch11/audio/en/timings.js b/site/science/ch11/audio/en/timings.jsnew file mode 100644index 0000000..b00ee99--- /dev/null+++ b/site/science/ch11/audio/en/timings.js@@ -0,0 +1,879 @@+window.TIMINGS = {+ "intro": {+ "dur": 13.104,+ "marks": {+ "q": 6.107+ },+ "cues": [+ [+ 0.104,+ "Chapter eleven."+ ],+ [+ 1.315,+ "Gravity, friction, and more forces in everyday life."+ ],+ [+ 6.107,+ "Everywhere you look, forces are at work."+ ],+ [+ 8.854,+ "Why do things fall, slow down, stick together, or float?"+ ]+ ]+ },+ "gravity": {+ "dur": 16.776,+ "marks": {+ "pull": 4.857,+ "never": 10.026,+ "close": 13.281+ },+ "cues": [+ [+ 0.104,+ "Gravity is the force of attraction between all things that have mass."+ ],+ [+ 4.857,+ "Any two masses pull on each other, even two rocks floating in space."+ ],+ [+ 10.026,+ "Gravity is always a pull, never a push."+ ],+ [+ 13.281,+ "And as the rocks get closer, the pull gets stronger."+ ]+ ]+ },+ "strength": {+ "dur": 20.472,+ "marks": {+ "small": 4.05,+ "big": 7.969,+ "far": 15.456+ },+ "cues": [+ [+ 0.117,+ "The strength of gravity depends on mass and on distance."+ ],+ [+ 4.05,+ "A rock flies past a small moon."+ ],+ [+ 6.25,+ "Its path bends a little."+ ],+ [+ 7.969,+ "Past a planet with much more mass, at the same distance, the pull is stronger, and the path bends much more."+ ],+ [+ 15.456,+ "Pass the same planet farther away, and the pull is weaker again."+ ]+ ]+ },+ "building": {+ "dur": 17.472,+ "marks": {+ "walk": 1.992,+ "tiny": 4.831,+ "earth": 9.635+ },+ "cues": [+ [+ 0.104,+ "If all masses attract, why aren't you pulled toward a building as you walk past it?"+ ],+ [+ 4.831,+ "Its pull on you is real, but tiny: about a ten-thousandth of a newton."+ ],+ [+ 9.635,+ "Earth has so much mass that it pulls you down with about five hundred newtons."+ ],+ [+ 14.753,+ "Next to that, you'd never feel the building."+ ]+ ]+ },+ "orbit": {+ "dur": 22.728,+ "marks": {+ "pull": 3.646,+ "side": 7.617,+ "bend": 13.906+ },+ "cues": [+ [+ 0.104,+ "Gravity also keeps Earth in orbit around the Sun."+ ],+ [+ 3.646,+ "The Sun has so much mass that it pulls on every planet."+ ],+ [+ 7.617,+ "So why doesn't Earth fall into the Sun?"+ ],+ [+ 9.766,+ "Because Earth is also moving sideways, very fast."+ ],+ [+ 13.906,+ "Without gravity, it would fly off in a straight line."+ ],+ [+ 17.63,+ "Gravity keeps bending its path, so Earth goes around and around."+ ]+ ]+ },+ "weight": {+ "dur": 15.912,+ "marks": {+ "hang": 3.724,+ "more": 9.479+ },+ "cues": [+ [+ 0.117,+ "Weight is a measure of the force of gravity on an object."+ ],+ [+ 3.724,+ "Hang a five kilogram box from a spring scale: it weighs about forty-nine newtons."+ ],+ [+ 9.479,+ "Hang a ten kilogram box, and the spring stretches twice as far."+ ],+ [+ 13.984,+ "More mass, more weight."+ ]+ ]+ },+ "moon": {+ "dur": 21.384,+ "marks": {+ "earth": 3.555,+ "moon": 8.737,+ "jump": 17.839+ },+ "cues": [+ [+ 0.091,+ "Your mass doesn't depend on where you are, but your weight does."+ ],+ [+ 3.555,+ "On Earth, a fifty kilogram student weighs about four hundred ninety newtons."+ ],+ [+ 8.737,+ "The Moon has less mass than Earth, so its gravity is weaker."+ ],+ [+ 13.411,+ "On the Moon, the same student weighs about one-sixth as much."+ ],+ [+ 17.839,+ "The same jump goes much higher, and lasts much longer."+ ]+ ]+ },+ "fall": {+ "dur": 24.336,+ "marks": {+ "up": 7.148,+ "top": 15.573,+ "down": 18.06+ },+ "cues": [+ [+ 0.091,+ "Near Earth, gravity makes falling things speed up by about nine point eight meters per second, every second."+ ],+ [+ 7.148,+ "Throw a ball straight up."+ ],+ [+ 8.516,+ "On the way up, it slows down by nine point eight meters per second each second."+ ],+ [+ 13.516,+ "That's a negative acceleration."+ ],+ [+ 15.573,+ "At the top, it stops for an instant."+ ],+ [+ 18.06,+ "Then it falls, speeding up by nine point eight meters per second each second, until it lands."+ ]+ ]+ },+ "q1": {+ "dur": 2.712,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.185,+ "Gravity and weight."+ ]+ ]+ },+ "wrap1": {+ "dur": 21.168,+ "marks": {+ "w1": 0.99,+ "w2": 7.708,+ "w3": 13.177,+ "end": 19.622+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.99,+ "Gravity is a pull between all masses: stronger with more mass, weaker with more distance."+ ],+ [+ 7.708,+ "Weight is the force of gravity on you; your mass stays the same everywhere."+ ],+ [+ 13.177,+ "Near Earth, falling things speed up by nine point eight meters per second, every second."+ ],+ [+ 19.622,+ "Next: friction."+ ]+ ]+ },+ "part2": {+ "dur": 5.52,+ "marks": {+ "q": 1.914+ },+ "cues": [+ [+ 0.117,+ "Part two."+ ],+ [+ 1.081,+ "Friction."+ ],+ [+ 1.914,+ "If nothing pushes back, why does a sliding notebook stop?"+ ]+ ]+ },+ "friction": {+ "dur": 20.616,+ "marks": {+ "slide": 6.367,+ "fric": 8.021,+ "zoom": 15.208+ },+ "cues": [+ [+ 0.091,+ "Newton's first law says a moving object keeps moving, unless a net force acts on it."+ ],+ [+ 6.367,+ "So what stops the notebook?"+ ],+ [+ 8.021,+ "Friction: the force that opposes motion between touching surfaces."+ ],+ [+ 12.357,+ "It always acts against the direction of motion."+ ],+ [+ 15.208,+ "Up close, even smooth surfaces are bumpy, and the bumps catch on each other."+ ]+ ]+ },+ "rough": {+ "dur": 23.568,+ "marks": {+ "go": 2.695,+ "sand": 9.74,+ "grease": 12.279,+ "knee": 17.435+ },+ "cues": [+ [+ 0.104,+ "Rougher surfaces have more friction."+ ],+ [+ 2.695,+ "Give three blocks the same push: one on sandpaper, one on paper, one on a greased surface."+ ],+ [+ 9.74,+ "On rough sandpaper, it stops quickly."+ ],+ [+ 12.279,+ "On paper it slides farther, and on grease it glides the farthest."+ ],+ [+ 17.435,+ "Your body reduces friction too: fluid in your knees helps the joints move smoothly."+ ]+ ]+ },+ "air": {+ "dur": 20.328,+ "marks": {+ "drop": 6.224,+ "feather": 9.948,+ "area": 16.029+ },+ "cues": [+ [+ 0.091,+ "There's friction with air and water too."+ ],+ [+ 2.773,+ "Friction with the air is called air resistance."+ ],+ [+ 6.224,+ "Drop a ball and a feather."+ ],+ [+ 8.164,+ "The ball falls fast."+ ],+ [+ 9.948,+ "The feather drifts from side to side, because air resistance pushes up against its fall."+ ],+ [+ 16.029,+ "Objects with more surface area meet more air resistance."+ ]+ ]+ },+ "kinds": {+ "dur": 22.872,+ "marks": {+ "static": 2.044,+ "slide": 8.581,+ "free": 9.544,+ "roll": 15.0+ },+ "cues": [+ [+ 0.117,+ "There are different kinds of friction."+ ],+ [+ 2.044,+ "Push gently on a heavy box, and it doesn't move: static friction holds it, matching your push."+ ],+ [+ 8.581,+ "Push harder, and it breaks free."+ ],+ [+ 10.859,+ "Now sliding friction acts, and it's weaker than static friction."+ ],+ [+ 15.0,+ "Put the box on wheels, and rolling friction is weaker still."+ ],+ [+ 19.492,+ "That's why things on wheels are so much easier to move."+ ]+ ]+ },+ "terminal": {+ "dur": 30.72,+ "marks": {+ "speed": 7.878,+ "equal": 11.758,+ "chute": 21.771+ },+ "cues": [+ [+ 0.104,+ "A falling object has two forces on it: gravity pulling down, and air resistance pushing up."+ ],+ [+ 7.878,+ "As a skydiver speeds up, air resistance grows."+ ],+ [+ 11.758,+ "When it equals gravity, the forces are balanced."+ ],+ [+ 15.312,+ "With no net force, she stops speeding up and falls at a steady speed, called her terminal velocity."+ ],+ [+ 21.771,+ "Open a parachute, and its big surface area means much more air resistance."+ ],+ [+ 26.602,+ "She slows down to a new, much lower terminal velocity."+ ]+ ]+ },+ "q2": {+ "dur": 3.672,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.185,+ "Friction and air resistance."+ ]+ ]+ },+ "wrap2": {+ "dur": 22.392,+ "marks": {+ "w1": 1.042,+ "w2": 7.083,+ "w3": 13.06,+ "end": 19.427+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 1.042,+ "Friction opposes motion between touching surfaces; rougher surfaces have more."+ ],+ [+ 7.083,+ "Static friction is stronger than sliding friction, and rolling friction is the weakest."+ ],+ [+ 13.06,+ "When air resistance equals gravity, a falling object reaches terminal velocity."+ ],+ [+ 19.427,+ "Next: magnetic and electric forces."+ ]+ ]+ },+ "part3": {+ "dur": 7.008,+ "marks": {+ "q": 3.503+ },+ "cues": [+ [+ 0.104,+ "Part three."+ ],+ [+ 1.159,+ "Magnetic and electric forces."+ ],+ [+ 3.503,+ "How can two things push or pull without even touching?"+ ]+ ]+ },+ "magnets": {+ "dur": 21.864,+ "marks": {+ "clips": 4.258,+ "poles": 7.396,+ "attract": 11.888,+ "repel": 16.198+ },+ "cues": [+ [+ 0.065,+ "A magnet attracts iron, steel, and other magnets."+ ],+ [+ 4.258,+ "Hold one over some paper clips, and they jump up to it."+ ],+ [+ 7.396,+ "Every magnet has two ends, called its north and south poles."+ ],+ [+ 11.888,+ "Opposite poles attract: north and south pull together."+ ],+ [+ 16.198,+ "Like poles repel: bring two north poles together, and they push each other away."+ ]+ ]+ },+ "electric": {+ "dur": 26.64,+ "marks": {+ "rub": 5.039,+ "repel": 9.036,+ "attract": 12.604,+ "close": 20.091+ },+ "cues": [+ [+ 0.104,+ "Electric forces come from electric charges, which can be positive or negative."+ ],+ [+ 5.039,+ "Rub two balloons on your hair, and both pick up negative charge."+ ],+ [+ 9.036,+ "Like charges repel, so the balloons push apart."+ ],+ [+ 12.604,+ "Your hair is left with positive charge, and opposite charges attract: your hair rises toward a balloon."+ ],+ [+ 20.091,+ "Electric and magnetic forces get stronger when the charge is stronger, and when the charges are closer together."+ ]+ ]+ },+ "electromagnet": {+ "dur": 22.416,+ "marks": {+ "wire": 2.526,+ "coil": 8.958,+ "on": 13.607,+ "off": 16.914,+ "flip": 18.867+ },+ "cues": [+ [+ 0.091,+ "Moving charges make magnetism."+ ],+ [+ 2.526,+ "An electric current is charge flowing through a wire, and any current has a magnetic field around it."+ ],+ [+ 8.958,+ "Wrap the wire around an iron nail, and you've made an electromagnet."+ ],+ [+ 13.607,+ "With the current on, the nail picks up paper clips."+ ],+ [+ 16.914,+ "Switch it off, and they drop."+ ],+ [+ 18.867,+ "Reverse the current, and the north and south poles swap."+ ]+ ]+ },+ "q3": {+ "dur": 3.456,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.12,+ "Magnetic and electric forces."+ ]+ ]+ },+ "wrap3": {+ "dur": 18.528,+ "marks": {+ "w1": 0.977,+ "w2": 7.161,+ "w3": 11.146,+ "end": 15.469+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.977,+ "Opposite poles and opposite charges attract; like poles and like charges repel."+ ],+ [+ 7.161,+ "These forces get stronger with more charge and less distance."+ ],+ [+ 11.146,+ "A current in a coil around iron makes an electromagnet."+ ],+ [+ 15.469,+ "Next: moving in circles, and floating."+ ]+ ]+ },+ "part4": {+ "dur": 7.752,+ "marks": {+ "q": 3.737+ },+ "cues": [+ [+ 0.104,+ "Part four."+ ],+ [+ 1.094,+ "Moving in circles, and floating."+ ],+ [+ 3.737,+ "What keeps a ball swinging in a circle, or a duck afloat?"+ ]+ ]+ },+ "circle": {+ "dur": 28.464,+ "marks": {+ "center": 9.648,+ "let": 15.664,+ "go": 20.534,+ "moon": 23.724+ },+ "cues": [+ [+ 0.091,+ "Velocity includes direction, so anything moving in a circle keeps changing its velocity."+ ],+ [+ 6.641,+ "It's accelerating, and that takes a force."+ ],+ [+ 9.648,+ "This force always points toward the center of the circle."+ ],+ [+ 13.542,+ "It's called centripetal force."+ ],+ [+ 15.664,+ "When you swing a ball on a string, the string's pull is the centripetal force."+ ],+ [+ 20.534,+ "Let go, and the ball flies off in a straight line."+ ],+ [+ 23.724,+ "For the Moon going around Earth, the centripetal force is gravity."+ ]+ ]+ },+ "buoy": {+ "dur": 27.0,+ "marks": {+ "up": 1.862,+ "arch": 7.083,+ "rock": 14.466,+ "dip": 17.201,+ "aside": 19.023+ },+ "cues": [+ [+ 0.104,+ "What keeps a rubber duck afloat?"+ ],+ [+ 1.862,+ "The water pushes up on it."+ ],+ [+ 3.594,+ "This upward push from a fluid is called the buoyant force."+ ],+ [+ 7.083,+ "The buoyant force equals the weight of the fluid the object pushes aside."+ ],+ [+ 12.578,+ "That's Archimedes' principle."+ ],+ [+ 14.466,+ "A rock weighs five newtons on a scale."+ ],+ [+ 17.201,+ "Lower it into water: it pushes aside three newtons of water, so the water pushes up with three newtons, and the scale reads only two."+ ]+ ]+ },+ "float": {+ "dur": 20.928,+ "marks": {+ "wood": 5.104,+ "stone": 12.8+ },+ "cues": [+ [+ 0.078,+ "An object floats if it's less dense than the fluid, and sinks if it's denser."+ ],+ [+ 5.104,+ "Wood is less dense than water."+ ],+ [+ 7.227,+ "It sinks only until it has pushed aside its own weight of water, then it floats."+ ],+ [+ 12.8,+ "A stone is denser than water."+ ],+ [+ 14.896,+ "Even fully under, the water it pushes aside weighs less than the stone, so it sinks."+ ]+ ]+ },+ "q4": {+ "dur": 2.928,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Quick check."+ ],+ [+ 1.159,+ "Circles and floating."+ ]+ ]+ },+ "wrap4": {+ "dur": 17.784,+ "marks": {+ "w1": 0.99,+ "w2": 6.471,+ "w3": 11.003,+ "end": 15.482+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.99,+ "Centripetal force points to the center and keeps things moving in a circle."+ ],+ [+ 6.471,+ "The buoyant force equals the weight of the fluid pushed aside."+ ],+ [+ 11.003,+ "Less dense than the fluid, it floats; denser, it sinks."+ ],+ [+ 15.482,+ "Next: the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 3.96,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Chapter practice."+ ],+ [+ 1.576,+ "First, gravity and friction."+ ]+ ]+ },+ "final2": {+ "dur": 4.488,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Now terminal velocity, magnets, circles, and floating."+ ]+ ]+ },+ "finish": {+ "dur": 5.424,+ "marks": {},+ "cues": [+ [+ 0.117,+ "That's the whole chapter on gravity, friction, and more forces."+ ],+ [+ 4.557,+ "Well done!"+ ]+ ]+ }+};diff --git a/site/science/ch11/audio/en/weight.mp3 b/site/science/ch11/audio/en/weight.mp3new file mode 100644index 0000000..cf1b76aBinary files /dev/null and b/site/science/ch11/audio/en/weight.mp3 differdiff --git a/site/science/ch11/audio/en/wrap1.mp3 b/site/science/ch11/audio/en/wrap1.mp3new file mode 100644index 0000000..f61f740Binary files /dev/null and b/site/science/ch11/audio/en/wrap1.mp3 differdiff --git a/site/science/ch11/audio/en/wrap2.mp3 b/site/science/ch11/audio/en/wrap2.mp3new file mode 100644index 0000000..59279d3Binary files /dev/null and b/site/science/ch11/audio/en/wrap2.mp3 differdiff --git a/site/science/ch11/audio/en/wrap3.mp3 b/site/science/ch11/audio/en/wrap3.mp3new file mode 100644index 0000000..70e89c1Binary files /dev/null and b/site/science/ch11/audio/en/wrap3.mp3 differdiff --git a/site/science/ch11/audio/en/wrap4.mp3 b/site/science/ch11/audio/en/wrap4.mp3new file mode 100644index 0000000..dfa7bf5Binary files /dev/null and b/site/science/ch11/audio/en/wrap4.mp3 differdiff --git a/site/science/ch11/index.html b/site/science/ch11/index.htmlnew file mode 100644index 0000000..fcbfae7--- /dev/null+++ b/site/science/ch11/index.html@@ -0,0 +1,977 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>Chapter 11: Gravity, Friction, and More Forces in Everyday Life — Science</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/figures.js"></script>+<script src="../lib/actors.js"></script>+<script src="../lib/physics.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+// Chapter 11, one page in book order: part 1 (gravity, weight, falling), part 2 (friction, air resistance, terminal+// velocity), part 3 (magnetic and electric forces, electromagnets), part 4 (centripetal force, buoyancy), then the+// chapter practice. Notes and storyboard intents: books/science/chapters/ch11.md.+const CHAPTER = { number: 11, title: 'Gravity, Friction, and More Forces in Everyday Life', minutes: 15, language: 'en' };+const Q_CARD = { x: 96, y: 586, w: 1408, cls: 'band' }; // a band card under the scenes; it moves up by itself when taller+const GY = 560; // ground line in quick-check pictures+const Y1 = 740; // ground line under big actors+Object.assign(PH_SPR, { building: [16, 31], feather: [10, 4], duck: [12, 10], stone: [9, 6] }); // books/science/images/ch11.py+const ground = (p, y = GY, x = 0, w = 1600) => { phBlock(p, x, y, w, 70, PH.grass, { top: 8, ol: 0 }); mk('rect', { x, y: y + 70, width: w, height: 6, fill: PH.grass, opacity: .5 }, p); };+const marks = (p, y, x0, x1) => { for (let x = x0; x < x1; x += 140) mk('rect', { x, y: y + 18, width: 24, height: 8, fill: lt(PH.grass, .2) }, p); };+const AIR = '#9fd3e6'; // air resistance and buoyant force are forces too (orange); this tint is for air streaks only+const SKY = '#0c1418'; // deep space+const POLE_N = '#d9534f', POLE_S = '#4a7fc1';+const G_PX = 1400; // gravity in px/s² for quick everyday drops (apple, notebook scenes)++/* ---------- shared pictures ---------- */+// The same shapes as ch10: a thought bubble over a head, a part title, and a three-row summary with small pictures.+function thought(p, [x0, y0, x1, y1], x, lines, t0) {+ const q = G(p, { o: 0 });+ mk('rect', { x: x0, y: y0, width: x1 - x0, height: y1 - y0, rx: 40, fill: '#22322d', stroke: COL.dim, 'stroke-width': 3 }, q);+ path(q, `M${x - 30} ${y1 - 2}L${x + 30} ${y1 - 2}L${x} ${y1 + 66}Z`, { fill: COL.dim });+ lines.forEach((s, i) => T(q, s, { x: (x0 + x1) / 2, y: y0 + 70 + i * 56, size: 42, anchor: 'middle' }));+ show(q, t0); return q;+}+function opener(p, x, y, part, name, name2) {+ const g = G(p, { o: 0, y: 24 });+ phLabel(g, part.toUpperCase(), { x, y: y - 80, size: 30, fill: COL.dim, weight: 600 }); phLabel(g, name, { x, y, size: 80, weight: 600 });+ if (name2) phLabel(g, name2, { x, y: y + 86, size: 80, weight: 600 });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out); return g;+}+function summary(p, m, rows, next) {+ rows.forEach(([lines, icon], i) => {+ const g = G(p, { x: -16, y: 250 + i * 220, o: 0 });+ lines.forEach((s, j) => T(g, s, { x: 430, y: j * 50, size: 38, weight: 600 }));+ icon(g); tw(g, { o: 1, x: 0 }, m(['w1', 'w2', 'w3'][i]), .6);+ });+ txt(p, next, 800, 860, m('end'), { size: 32, fill: COL.dim, weight: 500 });+}+// Deep space: a dark field with fixed pixel stars.+function space(p, n = 80, seed = 1) {+ mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: SKY }, p);+ let d = '';+ for (let i = 0; i < n; i++) { const k = 2 + Math.round(3 * phHash(i, seed + 3)); d += `M${Math.round(1600 * phHash(i, seed))} ${Math.round(900 * phHash(i, seed + 1))}h${k}v${k}h${-k}Z`; }+ path(p, d, { fill: COL.chalk, opacity: .55 });+}+// A pixel disc (rock, moon, planet) of radius r in cells of c px: lit from the top left, a few craters. One path per+// colour keeps it cheap. lump > 0 makes an uneven rock.+function pixDisc(p, r, { c = 10, base = '#8d8a80', craters = 0, seed = 1, lump = 0, o = {} } = {}) {+ const g = G(p, o), ds = { [lt(base, .25)]: '', [base]: '', [dk(base, .3)]: '', [dk(base, .5)]: '' }, ks = Object.keys(ds);+ const cr = Array.from({ length: craters }, (_, i) => [(phHash(i, seed) - .5) * 1.2 * r, (phHash(i, seed + 1) - .5) * 1.2 * r, r * (.1 + .12 * phHash(i, seed + 2))]);+ for (let y = -r; y < r; y += c) for (let x = -r; x < r; x += c) {+ const cx = x + c / 2, cy = y + c / 2, a = Math.atan2(cy, cx), rr = r * (1 + lump * (.12 * Math.sin(3 * a + seed) + .08 * Math.sin(5 * a + 2 * seed)));+ if (Math.hypot(cx, cy) > rr) continue;+ const lit = (-cx - cy) / (r * 1.4), hole = cr.some(([hx, hy, hr]) => Math.hypot(cx - hx, cy - hy) < hr);+ const k = hole ? 3 : lit > .35 ? 0 : lit > -.35 ? 1 : 2;+ ds[ks[k]] += `M${x} ${y}h${c}v${c}h${-c}Z`;+ }+ ks.forEach(col => { if (ds[col]) path(g, ds[col], { fill: col }); });+ return g;+}+// A hanging spring scale marked in newtons, its top hook at (x, y0). set(F) stretches it to F newtons; it returns the+// y of the bottom hook. ppn: px of stretch per newton.+function springScale(p, { x, y0, max = 100, every = 10, ppn = 2, label = 'N' }) {+ const g = G(p), H = max * ppn + 90, top = y0 + 30;+ path(g, `M${x} ${y0}V${top}`, { stroke: COL.dim, 'stroke-width': 6 });+ phBlock(g, x - 40, top, 80, H, '#c8ccc4', { top: 6, right: 8, ol: 2.5 });+ mk('rect', { x: x - 14, y: top + 14, width: 28, height: H - 28, fill: '#e9ebe4' }, g);+ for (let v = 0; v <= max; v += every) {+ const yy = top + 40 + v * ppn;+ path(g, `M${x - 36} ${yy}H${x - 18}`, { stroke: PH.out, 'stroke-width': 2.5 });+ if (v % (every * 2) === 0) T(g, String(v), { x: x - 50, y: yy + 8, size: 22, fill: COL.chalk, anchor: 'end', weight: 600 });+ }+ T(g, label, { x: x - 50, y: top + 10, size: 22, fill: COL.dim, anchor: 'end', weight: 600 });+ const spring = path(g, '', { stroke: '#6a7570', 'stroke-width': 4, fill: 'none' }), ptr = path(g, '', { stroke: COL.bad, 'stroke-width': 5 });+ const rod = path(g, '', { stroke: '#6a7570', 'stroke-width': 6 }), hook = path(g, '', { stroke: '#6a7570', 'stroke-width': 5, fill: 'none' });+ return Object.assign(g, {+ set(F) {+ const yp = top + 40 + F * ppn, z = 8;+ let d = `M${x} ${top + 14}`;+ for (let i = 1; i <= z; i++) d += `L${x + (i % 2 ? 10 : -10)} ${top + 14 + (yp - top - 14) * (i - .5) / z}`;+ spring.setAttribute('d', d + `L${x} ${yp}`); ptr.setAttribute('d', `M${x - 34} ${yp}H${x + 34}`);+ const yb = top + H + 40 + F * ppn;+ rod.setAttribute('d', `M${x} ${yp}V${yb - 16}`); hook.setAttribute('d', `M${x} ${yb - 16}v10a10 10 0 1 1 -10 10`);+ return yb + 10;+ },+ });+}+// A thrown or dropped ball (SVG, so it can be any size): a plain coloured disc with a highlight.+function ballEl(p, r, fill = '#e07a2e') { const g = G(p); mk('circle', { r, fill, ...phLine(2) }, g); mk('circle', { cx: -r * .35, cy: -r * .35, r: r * .25, fill: '#fff', opacity: .45 }, g); return g; }+// Fixed-step integration (deterministic, so pause and seek show the same frame): returns state(t) by interpolation.+function integrate(step, s0, T0, T1, dt = 1 / 240) {+ const out = [s0.slice()]; let s = s0.slice();+ for (let t = T0; t < T1; t += dt) { s = step(s, t, dt); out.push(s.slice()); }+ return t => { const k = Math.max(0, Math.min(out.length - 1.001, (t - T0) / dt)), i = Math.floor(k), f = k - i; return out[i].map((v, j) => v + (out[i + 1][j] - v) * f); };+}++// A table top at y from x0 to x1 (legs down to the floor y1); returns the top y.+function table(p, y, x0, x1, y1) {+ phBlock(p, x0, y, x1 - x0, 26, '#a87a4f', { top: 6, ol: 0 });+ [x0 + 30, x1 - 60].forEach(x => phBlock(p, x, y + 26, 30, y1 - y - 26, '#7d5737', { top: 0, ol: 0 }));+ return y;+}+// A closed notebook seen from the side (bottom centre at the origin).+function notebook(p) { const g = G(p); phBlock(g, -150, -50, 300, 50, '#c0504d', { top: 0, ol: 2.5 }); mk('rect', { x: -144, y: -40, width: 288, height: 26, fill: '#f4f1e8' }, g); return g; }+// Something shoved to speed v0 at t0 that slows at a (px/s²) until it stops: x(t) and v(t) from x0.+function slider(x0, v0, a, t0) {+ const T1 = v0 / a;+ return { a, x: t => { const u = Math.min(Math.max(0, t - t0), T1); return x0 + v0 * u - a * u * u / 2; }, v: t => { const u = t - t0; return u > 0 && u < T1 ? v0 - a * u : 0; } };+}++// A bar magnet centred on the origin, 260 × 70; poles 'SN' = south on the left, north on the right.+function magnet(p, poles = 'SN') {+ const g = G(p);+ [...poles].forEach((k, i) => { phBlock(g, -130 + i * 130, -35, 130, 70, k === 'N' ? POLE_N : POLE_S, { top: 8, ol: 2.5 }); phLabel(g, k, { x: -65 + i * 130, y: 14, size: 40 }); });+ return g;+}+// A paper clip lying flat (origin at its middle).+function clip(p) { const g = G(p); path(g, 'M-22 -6H18A6 6 0 0 1 18 6H-16A4 4 0 0 1 -16 -2H12', { stroke: '#c3ccce', 'stroke-width': 3.5, fill: 'none' }); return g; }+const HAIR_C = '#3e4751';++// A ball whirled on a string, seen from above, around you at (cx, cy): w.at(t) draws the frame. The ball keeps the+// same speed; its velocity (yellow) is tangent; the string's pull (orange, from t = pull) points to the centre. After+// release it flies on along the tangent at the same speed.+function whirl(p, cx, cy, R, P, { release = Infinity, pull = Infinity } = {}) {+ const W = 2 * Math.PI / P, you = phTop(p, 'you_top', { x: cx, y: cy, s: 3.2 }), str = path(p, '', { stroke: COL.chalk, 'stroke-width': 3 });+ const ball = ballEl(p, 24), v = forceArrow(p, { color: VEL, w: 12, size: 30 }), f = forceArrow(p, { w: 14, size: 30 }), trail = path(p, '', { stroke: COL.chalk, 'stroke-width': 3, 'stroke-dasharray': '10 10', opacity: .6 });+ mk('circle', { cx, cy, r: R, fill: 'none', stroke: COL.faint, 'stroke-width': 2, 'stroke-dasharray': '4 10' }, p);+ p.appendChild(str); p.appendChild(you); p.appendChild(ball); p.appendChild(v); p.appendChild(f);+ return { at(t) {+ const tt = Math.min(t, release), q = W * tt, x0 = cx + R * Math.cos(q), y0 = cy + R * Math.sin(q), ux = -Math.sin(q), uy = Math.cos(q), u = Math.max(0, t - release);+ const x = x0 + W * R * ux * u, y = y0 + W * R * uy * u;+ put(ball, { x, y }); put(you, { r: q * 57.3 });+ const hx = cx + 40 * Math.cos(q), hy = cy + 40 * Math.sin(q);+ 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', [-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.+function tubScene(p, x, y, w, d) {+ const g = G(p);+ mk('rect', { x: x - w / 2, y, width: w, height: d, fill: '#3f7fb0', opacity: .6 }, g);+ path(g, `M${x - w / 2} ${y}H${x + w / 2}`, { stroke: '#9fd3e6', 'stroke-width': 4 });+ path(g, `M${x - w / 2 - 8} ${y - 60}V${y + d + 8}H${x + w / 2 + 8}V${y - 60}`, { stroke: '#c3ccce', 'stroke-width': 12, fill: 'none' });+ // call front() after adding what floats in it: a see-through layer of water over their underwater parts+ g.front = () => { const e = mk('rect', { x: x - w / 2, y, width: w, height: d, fill: '#3f7fb0', opacity: .45 }, p); return e; };+ return g;+}+let PRACTICE; // the practice beat's panel: its question pictures are drawn there+const PICS = {+ 'p-grav': g => { pixDisc(g, 60, { seed: 2, lump: 1, o: { x: 560, y: 760 } }); pixDisc(g, 60, { seed: 7, lump: 1, o: { x: 1040, y: 760 } }); forceArrow(g, { w: 12 }).set(620, 740, 120, 0, ''); forceArrow(g, { w: 12 }).set(980, 780, 120, 180, ''); },+ 'p-bowl': g => { const b = G(g, { x: 620, y: 760 }); mk('circle', { r: 70, fill: '#22282a', ...phLine(2) }, b); phBall(g, 70, { x: 980, y: 760 }); },+ 'p-dist': g => { pixDisc(g, 50, { seed: 2, lump: 1, o: { x: 400, y: 760 } }); pixDisc(g, 50, { seed: 7, lump: 1, o: { x: 1200, y: 760 } }); path(g, 'M470 840H1130', { stroke: COL.dim, 'stroke-width': 4, 'stroke-dasharray': '10 8' }); },+ 'p-cart': g => { phBlock(g, 300, 840, 1000, 12, PH.walk, { top: 0, ol: 0 }); phSprite(g, 'cart', { x: 800, y: 840, s: 2 }); forceArrow(g, { w: 12 }).set(760, 830, 90, 180, ''); },+ 'p-feather': g => { phSprite(g, 'feather', { x: 800, y: 770, s: 3 }); forceArrow(g, { w: 12 }).set(720, 760, 80, -90, ''); forceArrow(g, { w: 12 }).set(880, 770, 80, 90, ''); },+ 'p-term': g => { phActor(g, 'you', { x: 800, y: 860, s: 1.4, anim: 'jump' }); forceArrow(g, { w: 12 }).set(720, 760, 80, 90, ''); forceArrow(g, { w: 12 }).set(880, 760, 80, -90, ''); },+ 'p-like': g => { const a = magnet(g, 'SN'), b = magnet(g, 'NS'); put(a, { x: 600, y: 780 }); put(b, { x: 1000, y: 780 }); forceArrow(g, { w: 12 }).set(600, 720, 90, 180, ''); forceArrow(g, { w: 12 }).set(1000, 720, 90, 0, ''); },+ 'p-cent': g => { mk('circle', { cx: 800, cy: 760, r: 90, fill: 'none', stroke: COL.faint, 'stroke-width': 3 }, g); put(ballEl(g, 18), { x: 890, y: 760 }); forceArrow(g, { w: 10 }).set(866, 760, 56, 180, ''); },+ 'p-boat': g => { tubScene(g, 800, 780, 500, 90); phSprite(g, 'duck', { x: 800, y: 820, s: 1.6 }); },+ 'p-dog': g => { tubScene(g, 800, 780, 500, 90); phSprite(g, 'duck', { x: 800, y: 820, s: 1.6 }); },+};+const withPics = qs => qs.map(q => ({ ...q, build(body, api) { const old = PRACTICE.querySelector('.pic'); if (old) old.remove(); const g = G(PRACTICE); g.classList.add('pic'); PICS[q.id]?.(g); return q.build(body, api); } }));++/* ---------- beats ---------- */+const BEATS = [+/* ---------- part 1: gravity and weight ---------- */+['intro', 'Gravity, friction, and more forces', (m, D) => {+ const p = panel(0), Y = Y1, tq = m('q'), tf = 1.1;+ // An apple drops from the tree into your hands: gravity acts on it the whole time (the hands push up once it rests).+ ground(p, Y);+ const a = phActor(p, 'you', { x: 470, y: Y, s: 3, anim: 'catch' }), [hx, hy] = a.hand('F');+ phSprite(p, 'tree', { x: hx - 250, y: Y + 2, s: 4.6 }); // a big tree behind you; its canopy reaches over your hands+ p.appendChild(a); // you in front of the trunk+ const ap = phSprite(p, 'apple', { s: 1.6 }), x = hx + 22, top = Y - 300, rest = hy + 6, tl = tf + Math.sqrt(2 * (rest - top) / G_PX);+ const gv = forceArrow(p, { w: 14, size: 32 }), up = forceArrow(p, { w: 14, size: 32 });+ clockRun(t => {+ 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' : '', 'right');+ up.set(x - 70, hy2 + 70, t > tl ? 110 : 0, -90, '');+ }, D);+ const ttl = G(p, { o: 0, y: 24 });+ phLabel(ttl, 'Unit 3 · Motion, Forces, and Work · Chapter 11', { x: 1150, y: 330, size: 26, fill: COL.dim, weight: 600 });+ phLabel(ttl, 'Gravity, Friction,', { x: 1150, y: 420, size: 76 }); phLabel(ttl, 'and More Forces', { x: 1150, y: 500, size: 76 });+ tw(ttl, { o: 1, y: 0 }, .3, 1.1, out);+ thought(p, [70, 60, 930, 220], 510, ['Why do things fall, slow down,', 'stick together, or float?'], tq);+}, { lead: false }],+['gravity', 'Gravity', (m, D) => {+ const p = panel(0), tp = m('pull'), tn = m('never'), tc = m('close'), Y = 520, d0 = 900, R0 = 100;+ // Two equal rocks start at rest and pull each other together: each feels the same pull, growing as 1/d².+ space(p);+ const run = K => integrate(([d, v], t, dt) => { const a = t < tp ? 0 : -K / (d * d); return [d + v * dt, v + a * dt]; }, [d0, 0], 0, D);+ let lo = 0, hi = 1e8;+ for (let i = 0; i < 40; i++) { const k = (lo + hi) / 2; if (run(k)(D)[0] > 520) lo = k; else hi = k; }+ const dAt = run(lo);+ const A = pixDisc(p, R0, { base: '#8d8a80', craters: 4, seed: 2, lump: 1 }), B = pixDisc(p, R0, { base: '#9a8f7e', craters: 3, seed: 7, lump: 1 });+ const fa = forceArrow(p, { w: 14, size: 34 }), fb = forceArrow(p, { w: 14, size: 34 });+ const def = G(p, { o: 0 }); phLabel(def, 'Gravity', { x: 800, y: 150, size: 80 }); phLabel(def, 'the force of attraction between all things that have mass', { x: 800, y: 214, size: 36, weight: 600 }); show(def, .3);+ txt(p, 'always a pull, never a push', 800, 790, tn, { size: 46, weight: 700 });+ const cl = phLabel(p, 'closer → stronger pull', { x: 800, y: 340, size: 40, fill: FORCE, o: 0 }); show(cl, tc);+ 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 rock+ put(A, { x: xa, y: Y }); put(B, { x: xb, y: Y });+ 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) => {+ const p = panel(0), ts = m('small'), tb = m('big'), tf = m('far'), V = 350, cy = 470;+ // Two panels with the same rock speed and the same miss distance: a small moon on the left bends the path a little,+ // a planet with far more mass on the right bends it a lot; then the same planet, missed by more, bends it less.+ // Paths come from integrating a = GM/r² (deterministic steps); each arrow is the pull at that moment.+ space(p, 90, 4);+ mk('rect', { x: 796, y: 0, width: 8, height: 900, fill: COL.board }, p);+ const fly = (cx, GM, b, t0) => integrate(([x, y, vx, vy], t, dt) => {+ if (t < t0) return [x, y, vx, vy];+ const dx = cx - x, dy = cy - y, r = Math.hypot(dx, dy), a = GM / (r * r);+ return [x + vx * dt, y + vy * dt, vx + a * dx / r * dt, vy + a * dy / r * dt];+ }, [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: 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: 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 it+ return { 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 = 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 trails+ clockRun(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 });+ const L = .6 * GM / (r * r) + 30; f.set(x + 34 * dx / r, y + 34 * dy / r, vis ? L : 0, Math.atan2(dy, dx) * 180 / Math.PI, ''); // from the rock's edge+ const n = on ? Math.floor((t - t0) * 30) : -1;+ if (trail._n !== n) { trail._n = n; trail.setAttribute('d', n > 0 ? 'M' + pts.slice(0, n + 1).map(([a, b]) => `${a.toFixed(1)} ${b.toFixed(1)}`).join('L') : ''); }+ }), D);+}, { lead: false }],+['building', 'Why not the building?', (m, D) => {+ const p = panel(0), Y = Y1, S2 = 2, tw0 = m('walk'), tt = m('tiny'), te = m('earth'), v = 55, x0 = 120;+ // You stroll toward a huge apartment block (it runs off the top of the frame). Its pull on you is real but far too+ // small to draw (≈ 0.0001 N); Earth's pull on you is about 500 N, straight down.+ ground(p, Y); marks(p, Y, 0, 1600);+ phSprite(p, 'building', { x: 1330, y: Y + 2, s: 3.4 });+ const a = phActor(p, 'you', { y: Y, s: S2, anim: 'walk' }), X = t => x0 + v * Math.max(0, t - tw0);+ const ring = G(p, { o: 0 }); mk('circle', { r: 40, fill: 'none', stroke: FORCE, 'stroke-width': 4, 'stroke-dasharray': '8 7' }, ring); mk('circle', { r: 4, fill: FORCE }, ring);+ const tl = G(p, { o: 0 }); phLabel(tl, 'the building pulls you:', { y: 0, size: 34, fill: FORCE }); phLabel(tl, 'about 0.0001 N, too small to draw', { y: 42, size: 30, fill: FORCE, weight: 600 });+ 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, 180, te + 4, { size: 34, weight: 600 }); // up in the empty sky: Earth's arrow runs to the bottom edge+ clockRun(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;+ put(ring, { x: cx + 90, y: cyy }); // beside you, on the side the building is+ put(tl, { x: Math.min(cx + 60, 800), y: Y - 360 });+ ef.set(cx, cyy, t > te ? 300 : 0, 90, '');+ put(el, { x: cx + 40, y: Y + 60 });+ }, D);+}, { lead: false }],+['orbit', 'Orbits', (m, D) => {+ const p = panel(0), tp = m('pull'), ts = m('side'), tb = m('bend'), cx = 800, cy = 470, R = 330, W = 2 * Math.PI / 14;+ // Seen from above: Earth goes round the Sun counterclockwise. The Sun's pull (orange) always points at the Sun; the+ // velocity (yellow) is sideways. From "bend", a dashed line shows where Earth would go with no gravity.+ space(p, 90, 6);+ [150, 230].forEach(r => mk('circle', { cx, cy, r, fill: 'none', stroke: COL.faint, 'stroke-width': 2 }, p));+ 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 = 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 top+ const 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 + 110 * ux - 34, y: gy + 110 * uy }); show(gl, tg + .3); // outside the orbit, left of the line: Earth and its arrows never pass there+ const 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);+ clockRun(t => {+ put(sun._rays, { r: t * 6 });+ 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', [-Math.sin(q), Math.cos(q)]); // label on the side away from the velocity+ vv.set(x + 46 * Math.sin(q), y - 46 * Math.cos(q), t > ts ? 140 : 0, q * 180 / Math.PI - 90, '');+ }, D);+}, { lead: false }],+['weight', 'Weight', (m, D) => {+ const p = panel(0), th = m('hang'), tm = m('more'), PPN = 2, WPX = 1.2; // 2 px of stretch per newton; weight arrows 1.2 px per newton+ // Two spring scales hang from a beam. Each box is hooked on at rest and let go: the spring overshoots, rings and+ // settles where its pull equals the weight. Weight (orange) is the same the whole time; only the spring changes.+ 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`, labelY: -h + 36 }), W8 = kg * 9.8; // the tag above the centre, where the weight arrow starts+ const 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 };+ });+ txt(p, 'more mass →', 220, 600, tm + 3, { size: 44, weight: 700 }); txt(p, 'more weight', 220, 656, tm + 3.2, { size: 44, weight: 700 });+ 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 settle+ const yb = sc.set(F); put(box, { x, y: yb + h });+ wf.set(x - 7, yb + h / 2, u > 0 ? W8 * WPX : 0, 90, ''); // from the centre (where the planks cross), down+ phText(rd, u > 1.4 ? `weight ≈ ${Math.round(W8)} N` : ''); put(rd, { x: x + 40, y: yb + h + 50 });+ }), D);+}, { lead: false }],+['moon', 'Mass and weight on the Moon', (m, D) => {+ const p = panel(0), te = m('earth'), tm = m('moon'), tj = m('jump'), Y = 800, S2 = 2.3;+ // Earth on the left, the Moon on the right; the same student, the same takeoff speed. Weight arrows at 0.4 px per+ // newton (490 N vs 82 N). Earth hops land after 0.5 s and 50 px; the Moon jump lasts 6× as long and goes 6× as high.+ mk('rect', { x: 800, y: 0, width: 800, height: 900, fill: SKY }, p);+ for (let i = 0; i < 40; i++) mk('rect', { x: 820 + 760 * phHash(i, 9), y: 500 * phHash(i, 10), width: 4, height: 4, fill: COL.chalk, opacity: .6 }, p);+ phEarthSmall(p, { x: 1480, y: 130, r: 34 });+ ground(p, Y, 0, 800); phBlock(p, 800, Y, 800, 100, '#9a9890', { top: 8, ol: 0 });+ [[900, 20], [1150, 30], [1420, 16]].forEach(([x, r]) => mk('ellipse', { cx: x, cy: Y + 40, rx: r * 2, ry: r * .5, fill: '#7a7870' }, p));+ mk('rect', { x: 796, y: 0, width: 8, height: 900, fill: COL.board }, p);+ phLabel(p, 'Earth', { x: 400, y: 80, size: 50 }); phLabel(p, 'Moon', { x: 1200, y: 80, size: 50 });+ const hop = (k, dur, h) => k < 0 ? { y: 0, pose: 'stand' } : k < .25 ? { y: 0, pose: 'crouch' } : k < .35 ? { y: 0, pose: 'land' } : k < .35 + dur ? { y: -h * 4 * ((k - .35) / dur) * (1 - (k - .35) / dur), pose: 'jump' } : k < .55 + dur ? { y: 0, pose: 'land' } : { y: 0, pose: 'stand' };+ const sides = [[400, 490, te, k => { const c = 1.15; return k < 0 ? hop(-1) : hop(k % c, .5, 50); }], [1200, 82, tm, k => hop(k, 3, 300)]].map(([x, Wn, t0, jump]) => {+ const a = phActor(p, 'you', { x, y: Y, s: S2, anim: 'stand' }), wf = forceArrow(p, { w: 16, size: 34 });+ const info = G(p, { o: 0 }); phLabel(info, 'mass 50 kg', { x: x - 110, y: 520, size: 38, anchor: 'end' });+ phLabel(info, `weight ≈ ${Wn} N`, { x: x - 110, y: 570, size: 38, fill: FORCE, anchor: 'end' }); show(info, t0);+ return { a, wf, Wn, t0, jump, x };+ });+ const same = phLabel(p, 'same mass, about one-sixth the weight', { x: 1200, y: 250, size: 34, fill: COL.dim, weight: 600, o: 0 }); show(same, tm + 4);+ clockRun(t => sides.forEach(({ a, wf, Wn, t0, jump, x }) => {+ const j = jump(t - (tj - .2)); put(a, { y: Y + j.y }); a.show(j.pose);+ wf.set(x + 110, Y + j.y - 200, t > t0 ? Wn * .5 : 0, 90, ''); // beside the body, from its middle+ }), D);+}, { lead: false }],+['fall', 'Falling: 9.8 m/s every second', (m, D) => {+ const p = panel(0), tu = m('up'), ttop = m('top'), Y = 820, S2 = 2.2, g = 9.8, v0 = 19.6;+ // Slow motion: 2 s of real flight up, 2 s down, each played over ttop − tu. 28 px per meter (19.6 m ≈ 550 px).+ // The ledger writes the speed at each whole second; the live label is the same v(s).+ const k = 2 / (ttop - tu - .25), ts = tu + .25, sAt = t => Math.max(0, Math.min(4, (t - ts) * k)), PXM = 28;+ ground(p, Y);+ const a = phActor(p, 'you', { x: 560, y: Y, s: S2, anim: 'toss' }); a.show('toss', 2); const [, hy0] = a.hand('F'); a.show('toss', 0); // released from, and caught in, the raised hands+ const ball = ballEl(p, 26), vA = forceArrow(p, { color: VEL, w: 12, size: 32 }), gA = forceArrow(p, { w: 14, size: 32 });+ const vl = phLabel(p, '', { size: 34, fill: VEL, anchor: 'start' }), clk = simClock(p, 1460, 160, 50);+ const slow = phLabel(p, 'slow motion', { x: 1460, y: 300, size: 28, fill: COL.dim, weight: 600, o: 0 }); show(slow, ts);+ const rule = G(p, { o: 0 }); phLabel(rule, 'Falling things speed up by', { x: 1100, y: 380, size: 46, weight: 600 }); phLabel(rule, '9.8 m/s every second', { x: 1100, y: 450, size: 64 });+ show(rule, .4); hide(rule, tu - .3, .3);+ const led = [0, 1, 2, 3, 4].map(sec => {+ const v = v0 - g * sec, s = v > 0 ? `${v.toFixed(1)} m/s up` : v < 0 ? `${(-v).toFixed(1)} m/s down` : '0 m/s: stopped';+ const e = runs(p, [[`${sec} s: `, TIME], [s, VEL]], { x: 900, y: 330 + sec * 64, size: 40, anchor: 'start', weight: 700 }); show(e, ts + sec / k, .3); return e;+ });+ txt(p, 'going up: −9.8 m/s each second', 900, 680, tu + 3.5, { size: 32, fill: ACC, weight: 600, anchor: 'start' });+ txt(p, '(a negative acceleration)', 900, 718, tu + 4, { size: 28, fill: ACC, weight: 500, anchor: 'start' });+ txt(p, 'coming down: +9.8 m/s each second', 900, 770, m('down') + 1, { size: 32, fill: ACC, weight: 600, anchor: 'start' });+ clockRun(t => {+ const s = sAt(t), flying = t > ts && s < 4, v = flying ? v0 - g * s : 0;+ const y = flying ? hy0 - 10 - PXM * (v0 * s - g * s * s / 2) : null;+ 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' : '', 'left');+ phText(vl, flying ? `${Math.abs(v).toFixed(1)} m/s` : ''); put(vl, { x: hx + 90, y: by + 12 });+ clk.set(s);+ }, D);+}, { lead: false }],+['q1', 'Quick check', (m, D) => {+ const p = panel(0), Y = 520;+ // On the Moon: a slow toss, up and down, again and again (one-sixth gravity).+ mk('rect', { x: 0, y: 0, width: 1600, height: Y, fill: SKY }, p);+ for (let i = 0; i < 30; i++) mk('rect', { x: 1600 * phHash(i, 21), y: (Y - 40) * phHash(i, 22), width: 4, height: 4, fill: COL.chalk, opacity: .6 }, p);+ phEarthSmall(p, { x: 1300, y: 120, r: 40 });+ phBlock(p, 0, Y, 1600, 60, '#9a9890', { top: 6, ol: 0 });+ const a = phActor(p, 'you', { x: 700, y: Y, s: 2, anim: 'toss' }), ball = ballEl(p, 20), vA = path(p, '', { stroke: VEL, 'stroke-width': 10 });+ clockRun(t => { const c = (t % 3.4) / 3.4, h = 250 * 4 * c * (1 - c); a.show('toss', c < .08 || c > .92 ? 1 : 2); const [hx, hy] = a.hand('F'); put(ball, { x: hx + 6, y: hy - 8 - h }); arrowAt(vA, hx + 46, hy - 8 - h, Math.abs(1 - 2 * c) * 90, c < .5 ? -90 : 90, 20); }, D);+ phLabel(p, 'on the Moon', { x: 400, y: 120, size: 40, fill: COL.dim, weight: 600 });+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-dist', prompt: ['The pull of gravity between two objects gets ', h('b', '', 'weaker'), ' when…'],+ build: choice([['they move farther apart'], ['their masses get bigger'], ['they move closer together']], 0,+ 'More distance, weaker gravity.',+ [null, 'More mass makes gravity stronger, not weaker.', 'Closer objects pull on each other more strongly.']) },+ { id: 'c-mass', prompt: ['An astronaut has a mass of 60 kilograms on Earth. What is her ', h('b', '', 'mass'), ' on the Moon?'],+ build: blanks([{ parts: ['mass on the Moon = ', { box: '60' }, ' kilograms'], why: 'Mass doesn’t depend on where you are. Her weight on the Moon is about one-sixth, but her mass is still 60 kilograms.', hint: 'Mass stays the same everywhere; weight changes.' }]) },+ { id: 'c-top', prompt: ['You throw a ball straight up. At the very top, it stops for an instant. Is gravity still pulling on it?'],+ build: choice([['yes, gravity pulls it down the whole time'], ['no, gravity is zero at the top'], ['only once it starts falling again']], 0,+ 'Gravity never switches off: that steady pull is what turned the ball around.',+ [null, 'If gravity were zero there, the ball would just stay up.', 'Gravity also slowed it on the way up.']) },+], done) }],+['wrap1', 'Summary · Gravity', (m, D) => {+ summary(panel(0), m, [+ [['Gravity pulls all masses together: stronger with', 'more mass, weaker with more distance.'], g => { pixDisc(g, 30, { c: 6, seed: 2, lump: 1, o: { x: 150, y: 0 } }); pixDisc(g, 30, { c: 6, seed: 7, lump: 1, o: { x: 330, y: 0 } }); forceArrow(g, { w: 8 }).set(180, -10, 60, 0, ''); forceArrow(g, { w: 8 }).set(300, 10, 60, 180, ''); }],+ [['Weight is the force of gravity on you;', 'your mass is the same everywhere.'], g => { crate(g, { x: 240, y: 60, w: 110, h: 90, label: '5 kg' }); forceArrow(g, { w: 8 }).set(300, 20, 70, 90, ''); }],+ [['Falling things speed up by about', '9.8 m/s every second.'], g => { put(ballEl(g, 20), { x: 240, y: -10 }); forceArrow(g, { w: 8 }).set(200, -10, 70, 90, ''); }],+ ], 'Next: friction.');+}],+/* ---------- part 2: friction ---------- */+['part2', 'Part 2 · Friction', (m, D) => {+ const p = panel(0), Y = Y1, tp = .4;+ // You flick a notebook along a table: it slides, slows and stops. Friction shows only while it slides.+ const a = phActor(p, 'you', { x: 220, y: Y, s: 2.6, anim: 'push' }), [hx0, hy0] = a.hand('F');+ const tab = table(p, hy0 + 8, 330, 1560, Y), nb = notebook(p), sl = slider(hx0 + 8 + 150, 650, 260, tp + .3);+ const fr = forceArrow(p, { w: 14, size: 32 }), vA = forceArrow(p, { color: VEL, w: 12, size: 30 });+ clockRun(t => {+ 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', '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'));+}, { lead: false }],+['friction', 'Friction', (m, D) => {+ const p = panel(0), Y = Y1, ts = m('slide'), tf = m('fric'), tz = m('zoom'), tp = ts + .3;+ // The same table: at "slide" you push the notebook; it slows down and stops. From "zoom", a magnified replay of+ // the contact: the bumps of the two surfaces catch on each other while the cover slides, slows and stops.+ const a = phActor(p, 'you', { x: 220, y: Y, s: 2.6, anim: 'push' }), [hx0, hy0] = a.hand('F');+ const tab = table(p, hy0 + 8, 330, 1560, Y), nb = notebook(p), sl = slider(hx0 + 8 + 150, 650, 260, tp + .3);+ const fr = forceArrow(p, { w: 14, size: 32 }), vA = forceArrow(p, { color: VEL, w: 12, size: 30 });+ const law = G(p, { o: 0 }); phLabel(law, 'A moving object keeps moving…', { x: 800, y: 130, size: 50 }); phLabel(law, '…unless a net force acts on it.', { x: 800, y: 200, size: 50 });+ show(law, .3); hide(law, tf - .2, .3);+ const def = G(p, { o: 0 }); phLabel(def, 'Friction', { x: 420, y: 130, size: 72, fill: FORCE });+ phLabel(def, 'opposes motion between touching surfaces,', { x: 420, y: 190, size: 32, weight: 600 }); phLabel(def, 'always against the direction of motion', { x: 420, y: 232, size: 32, weight: 600 });+ show(def, tf + .2);+ clockRun(t => {+ 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' : '', '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;+ put(cam.el, { o: 0 }); show(cam.el, tz, .5);+ const bumps = (seed, y0, dir) => { let d = `M300 ${y0 + 400 * dir}`; for (let x = 300; x <= 1600; x += 40) d += `L${x} ${y0 - dir * (14 + 46 * phHash(x, seed))}`; return d + `L1600 ${y0 + 400 * dir}Z`; };+ path(w, bumps(3, 480, 1), { fill: '#a87a4f', ...phLine(3) });+ const top = G(w); path(top, bumps(8, 420, -1), { fill: '#c0504d', ...phLine(3) });+ const rl = phLabel(p, 'up close (replay)', { x: 1200, y: 400, size: 28, fill: COL.chalk, weight: 600, o: 0 }); show(rl, tz + .3);+ const lens = G(p, { o: 0 }); show(lens, tz); mk('circle', { cx: sl.x(D) - 120, cy: tab, r: 26, fill: 'none', stroke: COL.chalk, 'stroke-width': 3, 'stroke-dasharray': '6 5' }, lens);+ path(lens, `M${sl.x(D) - 120} ${tab - 26}L${box[0] + 40} ${box[1] + box[3]}`, { stroke: COL.chalk, 'stroke-width': 2, 'stroke-dasharray': '6 6' });+ const cap = phLabel(p, 'the bumps catch on each other', { x: 1200, y: 460, size: 34, o: 0 }); show(cap, tz + 1.4);+ const rp = slider(0, 160, 64, tz + .4);+ const rf = forceArrow(cam.world, { w: 14, size: 30 });+ clockRun(t => { const dx = rp.x(t), lift = 8 * Math.abs(Math.sin(dx / 12.7)); put(top, { x: dx, y: -lift }); rf.set(1000, 330, rp.v(t) > 0 ? 120 : 0, 180, 'friction'); }, D);+}, { lead: false }],+['rough', 'Rough and smooth', (m, D) => {+ const p = panel(0), tg = m('go'), tk = m('knee'), t0 = m('sand') - 1.2, V0 = 520;+ // Three lanes, the same shove (same starting speed) at t0. Friction (deceleration) is set by the surface:+ // stopping distances 200, 620 and 1150 px. The friction arrow is drawn while each block slides.+ const lanes = [['sandpaper', 300, 200, '#b48a55', 'stops quickly', tg + .9], ['paper', 530, 620, '#ece8dc', 'slides farther', tg + 2.3], ['greased', 760, 1150, '#6f8a96', 'glides the farthest', tg + 3.6]].map(([name, y, d, col, verdict, tl]) => {+ phBlock(p, 0, y, 1600, 34, col, { top: 0, ol: 0 });+ if (name === 'sandpaper') { let s = ''; for (let i = 0; i < 260; i++) s += `M${Math.round(1600 * phHash(i, 31))} ${y + 4 + Math.round(26 * phHash(i, 32))}h5v5h-5Z`; path(p, s, { fill: '#6e5131' }); }+ if (name === 'greased') for (let x = 60; x < 1600; x += 170) mk('rect', { x, y: y + 6, width: 60, height: 5, fill: '#e3f1f6', opacity: .7 }, p);+ const lab = phLabel(p, name, { x: 40, y: y + 80, size: 34, anchor: 'start', o: 0 }); show(lab, tl);+ const sl = slider(220, V0, V0 * V0 / (2 * d), t0), c = crate(p, { w: 140, h: 110 }), f = forceArrow(p, { w: 14, size: 30 }), sh = forceArrow(p, { w: 14, size: 30 });+ const vd = phLabel(p, verdict, { size: 34, fill: COL.int, o: 0 }); show(vd, t0 + V0 / sl.a + .2);+ return { y, sl, c, f, sh, vd };+ });+ txt(p, 'the same push', 220, 200, t0 - .2, { size: 30, weight: 600 });+ clockRun(t => lanes.forEach(({ y, sl, c, f, sh, vd }) => {+ const x = sl.x(t), v = sl.v(t); put(c, { x, y });+ f.set(x - 70, y - 14, v > 0 ? 20 + sl.a * .16 : 0, 180, '');+ sh.set(x - 230, y - 55, t > t0 - .4 && t < t0 ? 150 : 0, 0, '');+ put(vd, { x, y: y - 140 });+ }), D);+ const knee = G(p, { o: 0 }); show(knee, tk);+ phBlock(knee, 960, 92, 110, 40, '#ffe0bb', { top: 0, ol: 2 }); phBlock(knee, 1062, 110, 40, 110, '#ffe0bb', { top: 0, ol: 2 }); // a bent leg: thigh, shin+ mk('circle', { cx: 1078, cy: 112, r: 18, fill: '#6fb7e0', stroke: PH.out, 'stroke-width': 2 }, knee);+ phLabel(knee, 'fluid in your knee joints', { x: 1150, y: 130, size: 32, anchor: 'start', fill: '#6fb7e0' }); phLabel(knee, 'reduces friction', { x: 1150, y: 172, size: 32, anchor: 'start', fill: '#6fb7e0' });+}, { lead: false }],+['air', 'Air resistance', (m, D) => {+ const p = panel(0), Y = 860, td = m('drop'), tfe = m('feather'), ta = m('area'), tr = td + .5;+ // You on a roof drop a ball and a feather at tr. The ball falls fast (gravity); the feather reaches its slow+ // terminal speed at once, so air resistance (up) matches its small weight (down), and it sways as it falls.+ phBlock(p, 0, Y, 1600, 40, PH.grass, { top: 8, ol: 0 });+ const bd = phSprite(p, 'building', { x: 420, y: Y + 2, s: 1.6 }), roof = Y + 2 - 31 * PX * 1.6 + PX * 1.6;+ const a = phActor(p, 'you', { x: 480, y: roof, s: 2, anim: 'catch' }), [hx, hy] = a.hand('F');+ const ball = ballEl(p, 22), fe = phSprite(p, 'feather', { s: 2 });+ const bg = forceArrow(p, { w: 12, size: 30 }), fg = forceArrow(p, { w: 10, size: 28 }), fa = forceArrow(p, { w: 10, size: 28 });+ const bx = hx + 26, fx0 = hx + 70, tb = tr + Math.sqrt(2 * (Y - 22 - hy) / G_PX), VF = 52, tl = tr + (Y - hy) / VF;+ const def = G(p, { o: 0 }); phLabel(def, 'air resistance', { x: 1100, y: 200, size: 66 }); phLabel(def, 'friction with the air', { x: 1100, y: 260, size: 36, weight: 600 }); show(def, 2);+ const ar = G(p, { o: 0 }); phLabel(ar, 'more surface area →', { x: 1050, y: 600, size: 40 }); phLabel(ar, 'more air resistance', { x: 1050, y: 650, size: 40 }); show(ar, ta + .3);+ 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', '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' : '', 'right');+ }, D);+ 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;+ // One push in three stages. Static: your push grows and static friction matches it (no motion). At "free" it gives+ // way: sliding friction is smaller, the box speeds up for 1 s, then you push just as hard as friction (steady speed).+ // At "roll": the same box on a wheeled dolly; rolling friction is tiny, and so is the push that keeps it rolling.+ const U = 0.9; // px per arrow unit+ const push = t => t < ts ? 0 : t < tfr ? 60 + 160 * ramp(t, ts, tfr) : t < tfr + 1 ? 220 : 150;+ const dX = t => { const u = Math.max(0, t - tfr); return u < 1 ? 60 * u * u : 60 + 120 * (u - 1); };+ const cam = camera(p, D), w = cam.world; cam.cut({ x: t => 800 + dX(t) }, 0);+ ground(w, Y, -400, 4000); marks(w, Y, -400, 4000);+ const a = phActor(w, 'you', { y: Y, s: S3, anim: 'push' }), cr = crate(w, { w: CW, h: CH });+ const pf = forceArrow(w, { w: 16, size: 34 }), ff = forceArrow(w, { w: 16, size: 34 });+ const nm = phLabel(w, 'no motion', { x: 800, y: Y + 110, size: 38, fill: COL.dim, o: 0 }); show(nm, ts + 1.2); hide(nm, tfr, .2);+ const umph = phLabel(w, 'UMPH!', { size: 60, fill: COL.int, o: 0 }); tw(umph, { o: 1 }, tfr, .15); hide(umph, tfr + 1.2, .4);+ a.show('push', 0); put(a, { x: 0 }); const off = 800 - CW / 2 - a.hand('F')[0] + 6;+ clockRun(t => {+ const d = dX(t), strain = t > ts && t < tfr ? Math.sin(t * 30) * 2 : 0;+ 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');+ 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);+ // the dolly+ const roll = camera(p, D); put(roll.el, { o: 0 }); show(roll.el, tr, .4);+ const R2 = t => 800 + 160 * Math.max(0, t - tr); roll.cut({ x: t => R2(t) }, 0);+ ground(roll.world, Y, -400, 6000); marks(roll.world, Y, -400, 6000);+ const b = phActor(roll.world, 'you', { y: Y, s: S3, anim: 'push' }), dolly = G(roll.world);+ phBlock(dolly, -CW / 2 - 10, -70, CW + 20, 24, '#6a5a4a', { top: 4, ol: 2 });+ const wh = [-100, 100].map(x => { const g = G(dolly, { x, y: -24 }); mk('circle', { r: 24, fill: '#59646a', ...phLine(2.5) }, g); path(g, 'M-16 0H16M0 -16V16', { stroke: '#c3ccce', 'stroke-width': 4 }); return g; });+ crate(dolly, { y: -70, w: CW, h: CH });+ const rp = forceArrow(roll.world, { w: 16, size: 34 }), rf = forceArrow(roll.world, { w: 16, size: 34 });+ 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'); 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]) => {+ const g = G(p, { o: 0 }); phLabel(g, s, { x: 330, y: y + 10, size: 30, anchor: 'end', weight: 600 }); mk('rect', { x: 350, y: y - 12, width: L * 1.4, height: 24, rx: 4, fill: FORCE }, g); show(g, t0);+ });+}, { lead: false }],+['terminal', 'Terminal velocity', (m, D) => {+ const p = panel(0), tsp = m('speed'), te = m('equal'), tc = m('chute'), t0 = .8, g = 9.8, VT = 55, VP = 5, DX = 560, DY = 520;+ // Real time, g = 9.8 m/s². Air resistance = weight × (v / 55)² until the chute opens; while it opens (1.5 s) it+ // blends to weight × (v / 5)², capped at 4 × weight (a reefed canopy opens gently). Arrows: weight 90 px.+ const k = t => ramp(t, tc + .3, tc + 1.8), drag = (v, t) => (1 - k(t)) * (v / VT) ** 2 + k(t) * Math.min(4, (v / VP) ** 2);+ const st = integrate(([v, y], t, dt) => { if (t < t0) return [0, 0]; const a = g * (1 - drag(v, t)); return [v + a * dt, y + v * dt]; }, [0, 0], 0, D + .1, 1 / 120);+ mk('rect', { x: 0, y: 0, width: 1600, height: 900, fill: '#4f7f9c' }, p);+ const clouds = G(p), cl = Array.from({ length: 7 }, (_, i) => { const c = G(clouds); [[0, 0, 160, 30], [30, -24, 90, 26], [-40, 14, 90, 22]].forEach(([x, y, w2, h]) => mk('rect', { x, y, width: w2, height: h, fill: '#e9f1f4', opacity: .85 }, c)); return [c, 1600 * phHash(i, 41), 1300 * phHash(i, 42)]; });+ const can = G(p, { x: DX, y: DY - 330 }), canopy = G(can);+ path(canopy, 'M-200 0Q-200 -150 0 -150Q200 -150 200 0Z', { fill: '#f08a3c', ...phLine(3) });+ path(canopy, 'M-70 -146Q-80 -60 -70 0H70Q80 -60 70 -146Q0 -154 -70 -146Z', { fill: '#f4f1e8' });+ const lines = path(p, '', { stroke: '#dfe6e8', 'stroke-width': 3 });+ const a = phActor(p, 'you', { x: DX, y: DY, s: 2.4, anim: 'jump' });+ const gw = forceArrow(p, { w: 16, size: 32 }), ga = forceArrow(p, { w: 16, size: 32 });+ const spd = phLabel(p, '', { x: 1230, y: 360, size: 52, fill: VEL });+ // the speed graph+ const GX = 980, GY0 = 800, GW = 520, GH = 330, gx = t => GX + GW * t / D, gy = v => GY0 - GH * v / 60;+ path(p, `M${GX} ${GY0 - GH - 10}V${GY0}H${GX + GW + 10}`, { stroke: COL.chalk, 'stroke-width': 4 });+ phLabel(p, 'speed', { x: GX - 14, y: GY0 - GH + 6, size: 26, anchor: 'end', weight: 600 }); phLabel(p, 'time', { x: GX + GW, y: GY0 + 36, size: 26, weight: 600 });+ const curve = path(p, '', { stroke: VEL, 'stroke-width': 5, fill: 'none' });+ const l55 = G(p, { o: 0 }); path(l55, `M${GX} ${gy(VT)}H${GX + GW}`, { stroke: COL.chalk, 'stroke-width': 2, 'stroke-dasharray': '8 8' }); phLabel(l55, 'terminal velocity ≈ 55 m/s', { x: GX + 10, y: gy(VT) - 14, size: 26, anchor: 'start' }); show(l55, te + 1.5);+ const l5 = G(p, { o: 0 }); path(l5, `M${GX} ${gy(VP)}H${GX + GW}`, { stroke: COL.chalk, 'stroke-width': 2, 'stroke-dasharray': '8 8' }); phLabel(l5, 'with the parachute ≈ 5 m/s', { x: GX + GW, y: gy(VP) - 14, size: 26, anchor: 'end' }); show(l5, tc + 5);+ const bal = G(p, { o: 0 }); phLabel(bal, 'balanced: no net force', { x: DX, y: 800, size: 40 }); phLabel(bal, 'so a steady speed', { x: DX, y: 846, size: 34, weight: 600 }); show(bal, te + .3); hide(bal, tc, .3);+ const bal2 = G(p, { o: 0 }); phLabel(bal2, 'balanced again, much slower', { x: DX, y: 820, size: 40 }); show(bal2, tc + 5.5);+ let pts = '';+ clockRun(t => {+ const [v, y] = st(t), D2 = drag(v, t), open = k(t);+ cl.forEach(([c, x, y0]) => put(c, { x, y: ((y0 - y * 14) % 1300 + 1300) % 1300 - 200 }));+ put(can, { o: t > tc + .3 ? 1 : 0 }); put(canopy, { s: .1 + .9 * open });+ 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', '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); }+ }, D);+ const two = G(p, { o: 0 }); phLabel(two, 'two forces on a falling object', { x: 1230, y: 150, size: 40 }); show(two, 1); hide(two, tsp - .3, .3);+ const gr = phLabel(p, 'faster → more air resistance', { x: 1230, y: 150, size: 40, o: 0 }); show(gr, tsp + .3); hide(gr, tc - .3, .3);+ const big = G(p, { o: 0 }); phLabel(big, 'big surface area →', { x: 1230, y: 130, size: 40 }); phLabel(big, 'much more air resistance', { x: 1230, y: 180, size: 40 }); show(big, tc + 1);+}, { lead: false }],+['q2', 'Quick check', (m, D) => {+ const p = panel(0), DX = 800, DY = 470;+ // A skydiver at terminal velocity: the two arrows equal, the clouds streaming past at a steady rate.+ 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', '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?'],+ build: choice([['the carpet is rougher, so there is more friction'], ['the puck has more mass on the carpet'], ['there is no gravity on ice']], 0,+ 'Rougher surfaces have more friction, so the puck slows down sooner.',+ [null, 'Its mass doesn’t change; the surface does.', 'Gravity acts on the puck everywhere.']) },+ { id: 'c-static', prompt: ['To get a heavy box moving, you push harder than you need to keep it sliding. Which friction is ', h('b', '', 'stronger'), '?'],+ build: choice([['static friction'], ['sliding friction'], ['they are always equal']], 0,+ 'Static friction holds a still box more strongly than sliding friction resists a moving one.',+ [null, 'Once it slides, the friction is weaker: that’s why it gets easier.', 'Starting is harder than keeping it going, so they differ.']) },+ { id: 'c-term', prompt: ['A skydiver falls at ', h('b', '', 'terminal velocity'), '. What is the net force on her?'],+ build: choice([['zero: air resistance equals gravity'], ['downward, so she keeps speeding up'], ['upward, so she slows down']], 0,+ 'Balanced forces: no net force, so her speed stays the same.',+ [null, 'If she were still speeding up, she would not be at terminal velocity yet.', 'That happens only just after a parachute opens.']) },+], done) }],+['wrap2', 'Summary · Friction', (m, D) => {+ summary(panel(0), m, [+ [['Friction opposes motion between touching surfaces;', 'rougher surfaces have more friction.'], g => { const n = notebook(g); put(n, { x: 260, y: 30 }); phBlock(g, 120, 30, 300, 14, '#a87a4f', { top: 0, ol: 0 }); forceArrow(g, { w: 8 }).set(240, 20, 70, 180, ''); }],+ [['Static friction is stronger than sliding friction;', 'rolling friction is the weakest.'], g => { [90, 62, 14].forEach((L, i) => mk('rect', { x: 150, y: -50 + i * 34, width: L * 2.4, height: 22, rx: 4, fill: FORCE }, g)); }],+ [['When air resistance equals gravity, a falling', 'object reaches terminal velocity.'], g => { phActor(g, 'you', { x: 270, y: 60, s: .9, anim: 'jump' }); forceArrow(g, { w: 8 }).set(200, -40, 60, 90, ''); forceArrow(g, { w: 8 }).set(340, -40, 60, -90, ''); }],+ ], 'Next: magnetic and electric forces.');+}],+/* ---------- part 3: magnetic and electric forces ---------- */+['part3', 'Part 3 · Magnetic and electric forces', (m, D) => {+ const p = panel(0), Y = 640, tq = m('q'), d0 = 640, W = 260;+ // Two bar magnets on a table, north facing south: they pull each other together (equal pulls, growing as they+ // close in) and click at the middle.+ table(p, Y, 120, 1480, 900);+ const run = K => integrate(([d, v], t, dt) => d <= W ? [W, 0] : [d + v * dt, v - (t < .4 ? 0 : K / (d * d)) * dt], [d0, 0], 0, D);+ let lo = 0, hi = 1e9; for (let i = 0; i < 40; i++) { const k = (lo + hi) / 2; const at = run(k); if (at(2.2)[0] > W + 1) lo = k; else hi = k; }+ const dAt = run(hi), A = magnet(p, 'SN'), B = magnet(p, 'SN'), fa = forceArrow(p, { w: 14, size: 30 }), fb = forceArrow(p, { w: 14, size: 30 });+ const click = phLabel(p, 'click!', { x: 800, y: Y - 130, size: 44, fill: COL.int, o: 0 });+ clockRun(t => {+ const d = dAt(t)[0], on = d > W + 1 && t > .4, L = Math.min(150, 40 * (d0 / d) ** 2);+ put(A, { x: 800 - d / 2, y: Y - 40 }); put(B, { x: 800 + d / 2, y: Y - 40 });+ fa.set(800 - d / 2, Y - 100, on ? L : 0, 0, ''); fb.set(800 + d / 2, Y - 130, on ? L : 0, 180, '');+ put(click, { o: d <= W + 1 && t < 3.4 ? 1 : 0 });+ }, D);+ opener(p, 800, 250, 'Part 3', 'Magnetic and Electric Forces');+ thought(p, [380, 300, 1220, 460], 800, ['How can things push or pull', 'without even touching?'], tq);+}, { lead: false }],+['magnets', 'Magnets', (m, D) => {+ const p = panel(0), Y = Y1, tc = m('clips'), tp = m('poles'), ta = m('attract'), tr = m('repel'), S3 = 2.6;+ // Scene 1: you hold a magnet over paper clips; at "clips" they jump up to it, the nearest first. Its ends are named+ // at "poles". Scene 2 (from "attract"): you walk a magnet toward one lying on the floor: south faces north and+ // the lying one jumps to it; then (from "repel") north faces north and the lying one is pushed ahead of yours.+ const s1 = G(p); ground(s1, Y);+ const a = phActor(s1, 'you', { x: 380, y: Y, s: S3, anim: 'catch' }), [hx, hy] = a.hand('F'), mg = magnet(s1, 'SN'); put(mg, { x: hx + 100, y: hy });+ const clips = [-110, -60, -10, 40, 90, 140].map((dx, i) => { const c = clip(s1); const x = hx + 100 + dx, y0 = Y - 4, y1 = hy + 46 + 14 * (i % 2), t0 = tc + .2 + .18 * Math.abs(i - 2.5); return { c, x, y0, y1, t0 }; });+ const s1t = G(s1, { o: 0 }); phLabel(s1t, 'A magnet attracts iron, steel,', { x: 1100, y: 170, size: 46 }); phLabel(s1t, 'and other magnets', { x: 1100, y: 230, size: 46 }); show(s1t, .3);+ const poles = G(s1, { o: 0 }); phLabel(poles, 'south pole', { x: hx + 35, y: hy - 60, size: 36, fill: POLE_S, anchor: 'end' }); phLabel(poles, 'north pole', { x: hx + 165, y: hy - 60, size: 36, fill: POLE_N, anchor: 'start' }); show(poles, tp + .2);+ clockRun(t => clips.forEach(({ c, x, y0, y1, t0 }) => { const u = Math.max(0, t - t0), y = Math.max(y1, y0 - 1600 * u * u); put(c, { x, y, r: u > 0 ? 90 : 0 }); }), D);+ hide(s1, ta - .4, .4);+ // scene 2+ const s2 = G(p, { o: 0 }); show(s2, ta - .2, .4); ground(s2, Y);+ const b = phActor(s2, 'you', { y: Y, s: S3, anim: 'push' }); b.show('push', 0); put(b, { x: 0 });+ const [hx0, hy0] = b.hand('F'), MY = hy0 + 4, X0 = 120; // magnets ride at hand height; the lying one on a table+ table(s2, MY + 35, 820, 1560, Y);+ const A = magnet(s2, 'NS'), A2 = magnet(s2, 'SN'), B = magnet(s2, 'NS');+ const fA = forceArrow(s2, { w: 14, size: 30 }), fB = forceArrow(s2, { w: 14, size: 30 });+ const lab = phLabel(s2, '', { x: 800, y: 200, size: 56 });+ const B0 = 1150, GAP = 150, tipAt = x => x + hx0 + 260; // the right end of the magnet in your hands+ const xStop = B0 - 130 - GAP - hx0 - 260, t1 = ta + .3, t2 = t1 + (xStop - X0) / 140, tR = tr - .3;+ const walk = t => t < tR ? X0 + Math.min(xStop - X0, 140 * Math.max(0, t - t1)) : X0 + Math.min(520, 120 * Math.max(0, t - tR - .3));+ clockRun(t => {+ const rep = t > tR, x = walk(t), d = x - X0; put(b, { x }); if ((rep ? t > tR + .3 : t > t1) && (rep ? d < 520 : x < xStop)) b.stride('push', d / S3); else b.show('push', 0);+ const tip = tipAt(x); put(A, { x: tip - 130, y: MY, o: rep ? 0 : 1 }); put(A2, { x: tip - 130, y: MY, o: rep ? 1 : 0 });+ let bx;+ if (!rep) { const k = ramp(t, t2, t2 + .35); bx = B0 - GAP * k * k; } // it jumps the last gap and clicks on+ else bx = Math.max(B0, tip + 130 + GAP); // it is pushed ahead, never touched+ put(B, { x: bx, y: MY });+ const gap = bx - 130 - tip, L = gap > 1 && gap < 260 ? 70 + 260 * (1 - gap / 260) * .4 : 0;+ fA.set(tip - 60, MY - 64, L, rep ? 180 : 0, ''); fB.set(bx - 70, MY - 104, L, rep ? 0 : 180, ''); // one row each, so they never overlap+ phText(lab, t < ta ? '' : rep ? 'Like poles repel' : 'Opposite poles attract');+ }, D);+}, { lead: false }],+['electric', 'Electric forces', (m, D) => {+ const p = panel(0), tr = m('rub'), tp = m('repel'), ta = m('attract'), tc = m('close'), Y = 860, L = 330, PX0 = 690, PX1 = 830, PY = 70, RB = 62;+ // Two balloons on strings. You rub your head on both (they gain −, your hair +), step out: they swing apart. Then+ // you come back beside the right one: your hair rises toward it and it leans toward you; closer, both get stronger.+ const q = t => ramp(t, tr + .3, tr + 3); // charge on each balloon, 0..1+ const you = t => t < tr ? 1250 - 500 * ramp(t, 1, tr - .2) : t < tp - .3 ? 750 + 70 * Math.sin((t - tr) * 7.8) : t < ta ? 750 + 500 * ramp(t, tp - .3, tp + 1.2) : t < tc ? 1250 - 160 * ramp(t, ta, ta + 1.5) : 1090 - 70 * ramp(t, tc + .5, tc + 2);+ const under = t => t > tr - .2 && t < tp + .2;+ phBlock(p, 560, PY - 16, 400, 18, '#7d6a5a', { top: 4, ol: 0 });+ const sA = path(p, '', { stroke: COL.chalk, 'stroke-width': 3 }), sB = path(p, '', { stroke: COL.chalk, 'stroke-width': 3 });+ const balloon = col => { const g = G(p); mk('ellipse', { rx: RB - 6, ry: RB, fill: col, ...phLine(2.5) }, g); mk('ellipse', { cx: -18, cy: -22, rx: 10, ry: 16, fill: '#fff', opacity: .45 }, g); path(g, `M-8 ${RB}h16l-8 12Z`, { fill: col }); g._m = G(g); return g; };+ const bA = balloon('#e8a0c8'), bB = balloon('#f3c95c');+ const SPOTS = [[-20, -18], [20, -18], [0, 14], [-24, 40], [24, 40]];+ const marks = (g, n, sign, col) => { g.replaceChildren(); for (let i = 0; i < n; i++) phLabel(g, sign, { x: SPOTS[i][0], y: SPOTS[i][1] + 10, size: 34, fill: col }); };+ const a = phActor(p, 'you', { y: Y, s: 2.4, anim: 'stand' }), hair = G(p), strands = Array.from({ length: 5 }, () => path(hair, '', { stroke: '#6a7682', 'stroke-width': 8, 'stroke-linecap': 'square' })), plus = G(p);+ const fA = forceArrow(p, { w: 12, size: 28 }), fB = forceArrow(p, { w: 12, size: 28 }), fH = forceArrow(p, { w: 12, size: 28 });+ const say = (s, t0, t1, y = 250, x = 330) => { const e = phLabel(p, s, { x, y, size: 44, o: 0 }); show(e, t0); if (t1) hide(e, t1, .3); return e; };+ const c1 = G(p, { o: 0 }); phLabel(c1, 'Charges can be', { x: 300, y: 300, size: 40 }); phLabel(c1, '+ positive', { x: 300, y: 360, size: 44, fill: COL.irr }); phLabel(c1, '− negative', { x: 300, y: 416, size: 44, fill: COL.nat }); show(c1, .3); hide(c1, tp - .3, .3);+ say('Like charges repel', tp + .4, ta - .3); say('Opposite charges', ta + .4, tc - .3, 250); say('attract', ta + .6, tc - .3, 306);+ const st = G(p, { o: 0 }); phLabel(st, 'more charge, or closer', { x: 330, y: 250, size: 44 }); phLabel(st, '→ a stronger force', { x: 330, y: 306, size: 44 }); show(st, tc + .3);+ let nA = -1, nP = -1;+ clockRun(t => {+ const Q = q(t), x = you(t), headY = Y - 17 * PX * 2.4, hX = x + 4;+ a.show(t > tr - .2 && t < tp ? 'stand' : 'walk', 0); put(a, { x });+ const near = t > ta; // your charged hair near the right balloon+ const dH = Math.max(140, hX - (PX1 + 60));+ const rep = under(t) ? 0 : Q; // held together while you are under them+ const thA = -rep * .36, attr = near ? Q * 1.0 * (180 / dH) ** 2 : 0, thB = rep * .36 + Math.min(.32, attr * .2);+ const pos = (px, th) => [px + (L + RB) * Math.sin(th), PY + (L + RB) * Math.cos(th)];+ const [ax, ay] = pos(PX0, thA), [bx, by] = pos(PX1, thB);+ const wob = under(t) ? 6 * Math.sin((t - tr) * 7.8 + 1) : 0;+ put(bA, { x: ax + wob, y: ay, r: -thA * 57.3 }); put(bB, { x: bx + wob, y: by, r: -thB * 57.3 });+ 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); }+ // standing hair: strands lean toward the balloon, longer when the pull is stronger+ const 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 apart+ const toHead = Math.atan2(headY - by, hX - bx);+ 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) => {+ const p = panel(0), tw0 = m('wire'), tc = m('coil'), ton = m('on'), toff = m('off'), tf = m('flip'), WY = 330, BY = 720;+ // A circuit: battery and switch on the bottom wire, the top wire over where the nail will go. Moving dashes are+ // the current; when it flows, rings around the wire show its magnetic field. With the coil round the nail: on, the+ // nail is a magnet (clips jump up, the compass swings); off, the clips drop; battery reversed, the poles swap.+ const closed = t => (t > tw0 + .5 && t < tc) || (t > ton && t < toff) || t > tf + .8;+ const dir = t => t > tf ? -1 : 1;+ const flowAt = t => { let s = 0; for (const [a, b, k] of [[tw0 + .5, tc, 1], [ton, toff, 1], [tf + .8, D, -1]]) s += k * Math.max(0, Math.min(t, b) - a); return s * 90; };+ // the top wire's middle (over the nail) is its own piece: it gives way to the coil+ const circ = `M520 ${BY}H360V${WY}H640M1080 ${WY}H1300V${BY}H1000M920 ${BY}H780`, mid = `M640 ${WY}H1080`;+ path(p, circ, { stroke: '#c98a3a', 'stroke-width': 10, fill: 'none', 'stroke-linejoin': 'round' });+ 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 }); 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));+ const rl = phLabel(rings, 'magnetic field', { x: 760, y: WY - 90, size: 32, fill: COL.irr });+ show(rings, tw0 + .8); hide(rings, tc + .2, .3);+ // the nail and the coil+ const nail = G(p, { o: 0 }); phBlock(nail, 600, WY + 34, 520, 30, '#9aa5a8', { top: 6, ol: 2.5 }); phBlock(nail, 584, WY + 18, 22, 62, '#9aa5a8', { top: 0, ol: 2.5 }); path(nail, `M1120 ${WY + 34}L1150 ${WY + 49}L1120 ${WY + 64}Z`, { fill: '#9aa5a8', ...phLine(2.5) });+ tw(nail, { o: 1 }, tc, .5);+ const coil = G(p); const loops = Array.from({ length: 12 }, (_, i) => { const x = 660 + i * 36, e = path(coil, `M${x} ${WY + 22}Q${x + 26} ${WY + 49} ${x + 18} ${WY + 76}`, { stroke: '#c98a3a', 'stroke-width': 9, fill: 'none' }, { o: 0 }); show(e, tc + .4 + i * .08, .2); return e; });+ phBlock(p, 560, 600, 640, 20, '#7d6a5a', { top: 4, ol: 0 }); // a shelf under the nail+ const clips = [690, 760, 830, 900, 970, 1040].map((x, i) => ({ c: clip(p), x, d: .06 * i }));+ const nS = phLabel(p, '', { x: 600, y: WY + 140, size: 52 }), nN = phLabel(p, '', { x: 1130, y: WY + 140, size: 52 });+ const comp = G(p, { x: 1225, y: WY + 49 }); mk('circle', { r: 44, fill: '#f4f1e8', ...phLine(2.5) }, comp); const needle = G(comp); path(needle, 'M0 -34L9 0H-9Z', { fill: COL.bad }); path(needle, 'M0 34L9 0H-9Z', { fill: '#9aa5a8' });+ phLabel(p, 'compass', { x: 1225, y: WY + 130, size: 26, fill: COL.dim, weight: 600 });+ const say = (s, t0, t1, fill = COL.chalk) => { const e = phLabel(p, s, { x: 800, y: 110, size: 44, fill, o: 0 }); show(e, t0); if (t1) hide(e, t1, .3); };+ say('A current has a magnetic field around it', tw0 + .6, tc - .2, COL.irr); say('Wire coiled around iron: an electromagnet', tc + .3, ton - .2);+ say('Current on: the nail is a magnet', ton + .3, toff - .2); say('Current off: not a magnet', toff + .2, tf - .2); say('Reverse the current: the poles swap', tf + .3);+ clockRun(t => {+ const on = closed(t), mag = on && t > tc;+ 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)));+ 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 it+ const 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+ const tOn = t < toff ? ton : tf + .8;+ clips.forEach(({ c, x, d: dl }) => {+ let y = 600;+ if (mag) { const u = Math.max(0, t - tOn - dl); y = Math.max(WY + 74, 600 - 2400 * u * u); }+ else if (t > toff && t < tf + .8) { const u = Math.max(0, t - toff); y = Math.min(600, WY + 74 + 2400 * u * u / 2); }+ put(c, { x, y, r: y < 590 ? 90 : 0 });+ });+ }, D);+}, { lead: false }],+['q3', 'Quick check', (m, D) => {+ const p = panel(0), Y = 470;+ // Two magnets, north facing north: the right one is pushed away and slides, the pair of arrows pointing apart.+ table(p, Y, 200, 1400, 900);+ const A = magnet(p, 'SN'), B = magnet(p, 'NS'), fa = forceArrow(p, { w: 14, size: 30 }), fb = forceArrow(p, { w: 14, size: 30 });+ put(A, { x: 560, y: Y - 40 });+ put(B, { x: 1040, y: Y - 40 }); fa.set(560, Y - 110, 110, 180, 'repel'); fb.set(1040, Y - 110, 110, 0, 'repel');+ clockRun(t => put(B, { x: 1040 + 3 * Math.sin(t * 20) }), D); // north faces north: held apart, trembling+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-poles', prompt: ['You push the ', h('b', '', 'north'), ' pole of one magnet toward the ', h('b', '', 'north'), ' pole of another. What happens?'],+ build: choice([['they push each other away'], ['they pull together'], ['nothing happens']], 0,+ 'Like poles repel.', [null, 'Only opposite poles (north and south) attract.', 'Magnets push or pull each other even without touching.']) },+ { id: 'c-charge', prompt: ['Two balloons both have a ', h('b', '', 'negative'), ' charge. What do they do?'],+ build: choice([['push apart'], ['pull together']], 0,+ 'Like charges repel.', [null, 'Opposite charges attract; these are both negative.']) },+ { id: 'c-emag', prompt: ['How can you make an ', h('b', '', 'electromagnet'), '?'],+ build: choice([['wrap a wire carrying a current around an iron core'], ['rub an iron nail on your hair'], ['cool a magnet in water']], 0,+ 'A current in a coil around iron makes a magnet you can switch on and off.',+ [null, 'Rubbing gives things an electric charge; it doesn’t make an electromagnet.', 'An electromagnet needs a current.']) },+], done) }],+['wrap3', 'Summary · Magnetic and electric forces', (m, D) => {+ summary(panel(0), m, [+ [['Opposite poles and charges attract;', 'like poles and charges repel.'], g => { const a = magnet(g, 'SN'), b = magnet(g, 'SN'); put(a, { x: 190, y: -10, s: .5 }); put(b, { x: 330, y: -10, s: .5 }); }],+ [['Electric and magnetic forces are stronger with', 'more charge and less distance.'], g => { mk('ellipse', { cx: 210, cy: -10, rx: 34, ry: 40, fill: '#e8a0c8', ...phLine(2) }, g); mk('ellipse', { cx: 310, cy: -10, rx: 34, ry: 40, fill: '#f3c95c', ...phLine(2) }, g); }],+ [['A current in a coil around iron makes', 'an electromagnet.'], g => { phBlock(g, 150, -20, 220, 20, '#9aa5a8', { top: 4, ol: 2 }); for (let i = 0; i < 6; i++) path(g, `M${180 + i * 30} -30Q${200 + i * 30} -10 ${192 + i * 30} 10`, { stroke: '#c98a3a', 'stroke-width': 6, fill: 'none' }); }],+ ], 'Next: moving in circles, and floating.');+}],+/* ---------- part 4: circles and floating ---------- */+['part4', 'Part 4 · Circles and floating', (m, D) => {+ const p = panel(0), tq = m('q');+ // Two small loops side by side: a ball whirled on a string (seen from above) and a duck bobbing in a tub.+ const w = whirl(p, 430, 560, 190, 2.2), tub = tubScene(p, 1170, 560, 520, 300), duck = phSprite(p, 'duck', { s: 2.2 }); tub.front();+ clockRun(t => { w.at(t); put(duck, { x: 1170, y: 560 + 70 + 5 * Math.sin(t * 2.6) }); }, D);+ opener(p, 800, 170, 'Part 4', 'Circles and Floating');+ txt(p, 'What keeps a ball swinging in a circle, or a duck afloat?', 800, 280, tq, { size: 40, weight: 600 });+}, { lead: false }],+['circle', 'Centripetal force', (m, D) => {+ const p = panel(0), tc = m('center'), tl = m('let'), tg = m('go'), tm = m('moon'), cx = 800, cy = 490, R = 300, P = 3.2;+ // From above: you whirl a ball on a string. Its speed stays the same; the velocity arrow (yellow) keeps turning.+ // From "center" the string's pull (orange) points to the centre. At "go" you let go: the ball leaves along the+ // 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); hide(snap, tc - .4, .3); show(snap, tc + 3, .4); // the faint copies step back while 'string pull' rides past them+ const 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);+ hide(s1, tm - .5, .4);+ // the Moon around Earth+ const s2 = G(p, { o: 0 }); show(s2, tm - .3, .5); space(s2, 70, 12);+ phEarthPolar(s2, { x: cx, y: cy, R: 120 }); const moon = pixDisc(s2, 36, { c: 8, base: '#b9b7ae', craters: 3, seed: 4 });+ mk('circle', { cx, cy, r: 320, fill: 'none', stroke: COL.faint, 'stroke-width': 2, 'stroke-dasharray': '4 10' }, s2);+ const mg = forceArrow(s2, { w: 14, size: 32 }), mv = forceArrow(s2, { color: VEL, w: 12, size: 30 });+ phLabel(s2, 'For the Moon, gravity is the centripetal force', { x: 800, y: 80, size: 46 });+ 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', [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 }],+['buoy', 'Buoyant force', (m, D) => {+ const p = panel(0), tu = m('up'), ta = m('arch'), tr = m('rock'), tdp = m('dip'), tas = m('aside');+ // Scene 1: a duck floats; weight (down) and the buoyant force (up) are equal. At "arch" the water it pushes aside+ // (the shape of its underwater part) lifts out beside it: it weighs as much as the duck.+ const s1 = G(p), WL = 520;+ const tb = tubScene(s1, 700, WL, 760, 300);+ const duck = phSprite(s1, 'duck', { s: 3 }), sub = 90; tb.front(); // 90 px of the duck below the waterline+ const wA = forceArrow(s1, { w: 16, size: 32 }), bA = forceArrow(s1, { w: 16, size: 32 });+ const ghost = G(s1, { o: 0 }); mk('rect', { x: -150, y: -sub, width: 300, height: sub, rx: 24, fill: '#7fc3e6', opacity: .85, stroke: COL.chalk, 'stroke-width': 3, 'stroke-dasharray': '8 6' }, ghost);+ const gl = G(s1, { o: 0 }); phLabel(gl, 'the water it pushes aside', { x: 1300, y: 300, size: 34 }); phLabel(gl, 'weighs as much as the duck', { x: 1300, y: 344, size: 34, fill: FORCE });+ show(ghost, ta + .2); show(gl, ta + 2.2);+ const d1 = G(s1, { o: 0 }); phLabel(d1, 'buoyant force', { x: 800, y: 90, size: 60, fill: FORCE }); phLabel(d1, 'the upward push of a fluid on an object in it', { x: 800, y: 142, size: 34, weight: 600 }); show(d1, tu + .3); hide(d1, ta - .3, .3);+ const d2 = G(s1, { o: 0 }); phLabel(d2, 'buoyant force = weight of the fluid pushed aside', { x: 800, y: 90, size: 46 }); phLabel(d2, 'Archimedes’ principle', { x: 800, y: 142, size: 34, fill: COL.dim, weight: 600 }); show(d2, ta + .3);+ 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', '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);+ // Scene 2: a 5 N stone hangs from a spring scale. From "dip" a full overflow can is raised around it on a stand;+ // the water it pushes aside spills into a cup. Reading = 5 − 3 × (fraction under water); cup water ∝ that fraction.+ const s2 = G(p, { o: 0 }); show(s2, tr - .2, .5);+ const CX = 640, CW = 300, CH = 250, PPN = 16, LIFT = 312, CB0 = 870, SH = 6 * PX * 2.4;+ const lift = t => LIFT * soft(ramp(t, tdp, tdp + 3.2));+ phBlock(s2, 420, 30, 440, 22, '#7d6a5a', { top: 4, ol: 0 });+ const sc = springScale(s2, { x: CX, y0: 52, max: 6, every: 1, ppn: PPN }), stone = phSprite(s2, 'stone', { s: 2.4 });+ phBlock(s2, 0, CB0 + 14, 1600, 30, '#7d6a5a', { top: 4, ol: 0 }); // the bench+ const can = G(s2), stand = mk('rect', { x: CX - 60, width: 120, fill: '#5e4f42' }, s2);+ phBlock(can, -CW / 2 - 12, -CH, 12, CH, '#9aa5a8', { top: 0, ol: 2 }); phBlock(can, CW / 2, -CH, 12, CH, '#9aa5a8', { top: 0, ol: 2 }); phBlock(can, -CW / 2 - 12, 0, CW + 24, 14, '#9aa5a8', { top: 0, ol: 2 });+ path(can, `M${CW / 2 + 12} ${-CH + 31}L${CW / 2 + 80} ${-CH + 55}`, { stroke: '#9aa5a8', 'stroke-width': 14 });+ const cupX = 1010, cupW = 160, cup = G(s2);+ path(cup, `M${cupX - cupW / 2} ${CB0 - 180}V${CB0}H${cupX + cupW / 2}V${CB0 - 180}`, { stroke: '#c3ccce', 'stroke-width': 6, fill: 'none' });+ const cupW8 = mk('rect', { x: cupX - cupW / 2 + 3, width: cupW - 6, fill: '#3f7fb0', opacity: .8 }, cup), stream = path(s2, '', { stroke: '#5fa3d0', 'stroke-width': 8, fill: 'none' });+ const water = G(s2); mk('rect', { x: -CW / 2, y: -CH + 25, width: CW, height: CH - 25, fill: '#3f7fb0', opacity: .6 }, water); // in front of the stone+ const rd = phLabel(s2, '', { x: CX - 70, y: 190, size: 48, anchor: 'end' }), cupL = phLabel(s2, '', { x: cupX, y: CB0 - 200, size: 32 });+ const wF = forceArrow(s2, { w: 14, size: 30 }), bF = forceArrow(s2, { w: 14, size: 30 }), NPX = 30;+ const exp = G(s2, { o: 0 }); [['in air: 5 N', COL.chalk], ['in water: 2 N', COL.chalk], ['buoyant force: 3 N', FORCE]].forEach(([s3, f], i) => phLabel(exp, s3, { x: 1180, y: 360 + i * 60, size: 40, fill: f, anchor: 'start' })); show(exp, tas + 2.5);+ clockRun(t => {+ const L = lift(t), cb = CB0 - L, sp = cb - CH + 25; // can bottom and spout (water) level+ put(can, { x: CX, y: cb }); put(water, { x: CX, y: cb }); stand.setAttribute('y', cb + 14); stand.setAttribute('height', CB0 + 14 - cb - 14);+ // the stone's top is the hook; solve F = 5 − 3 f with f from where the stone sits (two passes settle it)+ let F = 5; for (let k = 0; k < 3; k++) { const top = sc.set(F), f = Math.min(1, Math.max(0, (top + SH - sp) / SH)); F = 5 - 3 * f; }+ const top = sc.set(F), f = (5 - F) / 3;+ put(stone, { x: CX, y: top + SH });+ phText(rd, `${F.toFixed(1)} N`);+ const wl = 160 * f; cupW8.setAttribute('y', CB0 - wl); cupW8.setAttribute('height', wl);+ 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', '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) => {+ const p = panel(0), tw0 = m('wood'), ts = m('stone'), WT = 420, BOT = 740, g = 900;+ // A tank. Wood (density 0.6 of water) is dropped at "wood": it sinks in only until the water it pushes aside weighs+ // as much as it does, bobs and floats. Stone (2.5 × water) dropped at "stone": even fully under, the buoyant force is+ // only 0.4 of its weight, so it sinks to the floor, which then holds up the rest. Arrows: weight and buoyant force.+ const tank = tubScene(p, 800, WT, 1200, BOT - WT);+ const fall = (rho, h, t0, y0, c) => integrate(([y, v], t, dt) => {+ if (t < t0) return [y, 0];+ const f = Math.min(1, Math.max(0, (y - WT) / h)), a = g * (1 - f / rho) - (f > 0 ? c * v : 0);+ let ny = y + v * dt, nv = v + a * dt; if (ny >= BOT) { ny = BOT; nv = 0; }+ return [ny, nv];+ }, [y0, 0], 0, D);+ const WH = 120, wood = G(p); phBlock(wood, -110, -WH, 220, WH, '#c99a5a', { top: 10, right: 12, ol: 2.5 }); for (let i = 0; i < 3; i++) path(wood, `M-96 ${-WH + 30 + i * 30}H${80 - i * 20}`, { stroke: '#a87a4f', 'stroke-width': 4 });+ const SH = 6 * PX * 2.2, stone = phSprite(p, 'stone', { s: 2.2 });+ const wy = fall(.6, WH, tw0 + .3, 300, 3.2), sy = fall(2.5, SH, ts + .3, 300, 4);+ tank.front();+ const arrows = () => [forceArrow(p, { w: 14, size: 30 }), forceArrow(p, { w: 14, size: 30 }), forceArrow(p, { w: 14, size: 30 })];+ const [ww, wb] = arrows(), [sw, sb, sf] = arrows();+ const rule = G(p, { o: 0 }); phLabel(rule, 'less dense than the fluid: it floats', { x: 800, y: 110, size: 44 }); phLabel(rule, 'denser than the fluid: it sinks', { x: 800, y: 170, size: 44 }); show(rule, .4);+ const lw = G(p, { o: 0 }); phLabel(lw, 'wood: less dense', { x: 480, y: 280, size: 38, fill: COL.int }); phLabel(lw, 'floats', { x: 480, y: 326, size: 38, fill: COL.int }); show(lw, tw0 + 3.5);+ const ls = G(p, { o: 0 }); phLabel(ls, 'stone: denser', { x: 1120, y: 280, size: 38, fill: COL.int }); phLabel(ls, 'sinks', { x: 1120, y: 326, size: 38, fill: COL.int }); show(ls, ts + 3.5);+ const U = 80; // the wood's weight arrow; the stone's is 1.6 × longer (heavier block)+ 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', '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', '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) => {+ const p = panel(0), w = whirl(p, 430, 300, 190, 2.2, { pull: 0 }), tub = tubScene(p, 1150, 330, 520, 200), duck = phSprite(p, 'duck', { s: 2.2 }); tub.front();+ clockRun(t => { w.at(t); put(duck, { x: 1150, y: 330 + 70 + 5 * Math.sin(t * 2.6) }); }, D);+}, { ask: done => quiz(Q_CARD, [+ { id: 'c-cent', prompt: ['You whirl a ball on a string. Which way does the ', h('b', '', 'centripetal force'), ' on the ball point?'],+ build: choice([['toward the center of the circle'], ['away from the center'], ['the way the ball is moving']], 0,+ 'The string pulls the ball inward, toward the center.',+ [null, 'Let go and the ball flies off straight, not outward: nothing pulls it outward.', 'That is the velocity; the force points to the center.']) },+ { id: 'c-boat', prompt: ['A toy boat pushes aside 4 newtons of water. What is the ', h('b', '', 'buoyant force'), ' on it?'],+ build: blanks([{ parts: ['buoyant force = ', { box: '4' }, ' newtons'], why: 'Archimedes’ principle: the buoyant force equals the weight of the water pushed aside.', hint: 'Buoyant force = weight of the fluid pushed aside.' }]) },+ { id: 'c-dense', prompt: ['An object is ', h('b', '', 'denser'), ' than water. In water, it…'],+ build: choice([['sinks'], ['floats']], 0, 'Denser than the fluid: it sinks.', [null, 'Only objects less dense than the fluid float.']) },+], done) }],+['wrap4', 'Summary · Circles and floating', (m, D) => {+ summary(panel(0), m, [+ [['Centripetal force points to the center and keeps', 'things moving in a circle.'], g => { mk('circle', { cx: 260, cy: -10, r: 60, fill: 'none', stroke: COL.faint, 'stroke-width': 3 }, g); put(ballEl(g, 14), { x: 320, y: -10 }); forceArrow(g, { w: 8 }).set(304, -10, 40, 180, ''); }],+ [['The buoyant force equals the weight of the', 'fluid pushed aside.'], g => { phBlock(g, 150, 0, 220, 50, '#3f7fb0', { top: 0, ol: 0 }); phSprite(g, 'duck', { x: 260, y: 30, s: 1 }); }],+ [['Less dense than the fluid: it floats;', 'denser: it sinks.'], g => { phBlock(g, 150, -10, 220, 70, '#3f7fb0', { top: 0, ol: 0 }); phBlock(g, 170, -26, 70, 36, '#c99a5a', { top: 4, ol: 2 }); phSprite(g, 'stone', { x: 320, y: 60, s: 1 }); }],+ ], 'Next: the chapter practice.');+}],+/* ---------- chapter practice and finish ---------- */+['final1', 'Chapter practice: gravity and friction', () => { PRACTICE = panel(0); }, { ask: done => quiz(SCREEN, withPics([+ { id: 'p-grav', prompt: ['What is the force that attracts masses together?'],+ build: choice([['gravity'], ['friction'], ['the buoyant force']], 0, 'Gravity is the attraction between all things with mass.', [null, 'Friction opposes motion between touching surfaces.', 'The buoyant force pushes up on things in a fluid.']) },+ { id: 'p-bowl', prompt: ['Why does a bowling ball have more gravity than a soccer ball?'],+ build: choice([['it has more mass, and more mass means a stronger pull'], ['it is rounder'], ['it is closer to the ground']], 0,+ 'As mass increases, so does the force of gravity.', [null, 'Shape doesn’t set gravity; mass does.', 'Both sit on the same ground; the difference is mass.']) },+ { id: 'p-dist', prompt: ['The force of gravity decreases as the ___ between masses increases.'],+ build: choice([['distance'], ['mass'], ['speed']], 0, 'Farther apart, weaker gravity.', [null, 'More mass makes gravity stronger.', 'Speed doesn’t change the pull of gravity.']) },+ { id: 'p-cart', prompt: ['When you push a shopping cart, the friction that opposes its motion is mainly ___ friction.'],+ build: choice([['rolling'], ['static'], ['sliding']], 0, 'The cart rolls on wheels: rolling friction.', [null, 'Static friction acts only while it is still.', 'Its wheels roll; nothing slides.']) },+ { id: 'p-feather', prompt: ['Why does a feather drift back and forth as it falls?'],+ build: choice([['air resistance pushes up against its fall'], ['gravity doesn’t act on feathers'], ['it has no mass']], 0,+ 'A feather has a big surface for its tiny weight, so air resistance nearly balances gravity.', [null, 'Gravity pulls on everything with mass, feathers too.', 'It has a little mass; that’s why it does fall.']) },+]), done, 'Chapter practice, set 1 of 2 · question') }],+['final2', 'Chapter practice: more forces', () => { PRACTICE = panel(0); }, { ask: done => quiz(SCREEN, withPics([+ { id: 'p-term', prompt: ['When air resistance equals the force of gravity, a falling object…'],+ build: choice([['reaches terminal velocity: it falls at a steady speed'], ['stops in midair'], ['speeds up faster']], 0,+ 'Balanced forces, no net force: a steady speed called terminal velocity.', [null, 'Balanced forces keep its speed the same; they don’t stop it.', 'With no net force it can’t speed up.']) },+ { id: 'p-like', prompt: ['In magnetic and electric forces, likes ___ and opposites attract.'],+ build: choice([['repel'], ['attract']], 0, 'Like poles and like charges repel.', [null, 'Opposites attract; likes push each other away.']) },+ { id: 'p-cent', prompt: ['What is ', h('b', '', 'centripetal force'), '?'],+ build: choice([['the force that keeps an object moving in a circle; it points toward the center'], ['a force that pushes objects away from the center'], ['the upward push of a fluid']], 0,+ 'Centripetal force always points toward the center of the circular path.', [null, 'It points inward, toward the center.', 'That is the buoyant force.']) },+ { id: 'p-boat', prompt: ['What is the name of the upward force that water exerts on a boat?'],+ build: choice([['the buoyant force'], ['centripetal force'], ['friction']], 0, 'Buoyancy: the upward push of a fluid.', [null, 'That keeps things moving in circles.', 'Friction opposes motion; it doesn’t hold boats up.']) },+ { id: 'p-dog', prompt: ['A dog swimming in a lake pushes aside 10 pounds of water. What is the buoyant force on the dog?'],+ build: blanks([{ parts: ['buoyant force = ', { box: '10' }, ' pounds'], why: 'It equals the weight of the water pushed aside: 10 pounds.', hint: 'Archimedes’ principle.' }]) },+]), done, 'Chapter practice, set 2 of 2 · question') }],+['finish', 'Finished', () => {+ // under the card, the chapter in four small pictures with their names+ const p = panel(0);+ [['gravity', 300, g => { pixDisc(g, 26, { c: 6, seed: 2, lump: 1, o: { x: -60, y: -40 } }); pixDisc(g, 26, { c: 6, seed: 7, lump: 1, o: { x: 60, y: -40 } }); }],+ ['friction', 633, g => { crate(g, { x: 0, y: 0, w: 110, h: 90 }); forceArrow(g, { w: 8 }).set(10, -12, 70, 180, ''); }],+ ['magnets', 966, g => { const a = magnet(g, 'SN'), b = magnet(g, 'SN'); put(a, { x: -70, y: -40, s: .5 }); put(b, { x: 70, y: -40, s: .5 }); }],+ ['circles and floating', 1300, g => { phBlock(g, -90, -40, 180, 40, '#3f7fb0', { top: 0, ol: 0 }); phSprite(g, 'duck', { y: -14, s: 1 }); }]]+ .forEach(([s, x, draw]) => { const g = G(p, { x, y: 800, s: .85 }); draw(g); phLabel(g, s, { y: 56, size: 30, fill: COL.dim, weight: 600 }); });+}, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/science/img/CREDITS.md b/site/science/img/CREDITS.mdnew file mode 100644index 0000000..b746caa--- /dev/null+++ b/site/science/img/CREDITS.md@@ -0,0 +1,12 @@+# Image credits++| File | Source | Author | Licence | Changes |+| --- | --- | --- | --- | --- |+| car.png | [Pixel Vehicle Pack](https://opengameart.org/content/pixel-vehicle-pack) (`rounded_green`) | Kenney ([kenney.nl](https://www.kenney.nl)) | [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/) | Scaled ×8 (nearest neighbour) |+| truck.png | [Pixel Vehicle Pack](https://opengameart.org/content/pixel-vehicle-pack) (`truckdelivery`) | Kenney | CC0 1.0 | Cab recoloured blue, scaled ×8 |+| you*.png, friend*.png | [Pixel Vehicle Pack](https://opengameart.org/content/pixel-vehicle-pack) (`man`, `man_walk1`, `man_walk2`) | Kenney | CC0 1.0 | Shirt recoloured (lilac, coral), scaled ×8 |+| maya_seated.png | [Pixel Vehicle Pack](https://opengameart.org/content/pixel-vehicle-pack) (`woman_convertible`) | Kenney | CC0 1.0 | Top recoloured yellow, scaled ×8 |+| lamp.png | [Pixel Vehicle Pack](https://opengameart.org/content/pixel-vehicle-pack) (`light`) | Kenney | CC0 1.0 | Scaled ×8 |+| earth.png | [North Pole (orthographic projection with shade)](https://commons.wikimedia.org/wiki/File:North_Pole_(orthographic_projection_with_shade).svg) | Ecrusized (Wikimedia Commons) | Public domain | Land outline only (borders, graticule, rivers and shade removed), turned 160°, reduced to 96 × 96 cells, recoloured (ocean, land, Greenland and polar ice), scaled ×8 |+| runner*.png | [Pixel Vehicle Pack](https://opengameart.org/content/pixel-vehicle-pack) (`woman`, `woman_walk1`, `woman_walk2`) | Kenney | CC0 1.0 | Top recoloured orange, scaled ×8 |+| tree.png, house.png, dolphin.png, walrus.png, light_red.png, light_green.png, building.png, feather.png, duck.png, stone.png | Papermorph (drawn for this book) | — | Same as the project | — |diff --git a/site/science/img/actor_friend.png b/site/science/img/actor_friend.pngnew file mode 100644index 0000000..bf87261Binary files /dev/null and b/site/science/img/actor_friend.png differdiff --git a/site/science/img/actor_you.png b/site/science/img/actor_you.pngnew file mode 100644index 0000000..abe631dBinary files /dev/null and b/site/science/img/actor_you.png differdiff --git a/site/science/img/apple.png b/site/science/img/apple.pngnew file mode 100644index 0000000..8c742e0Binary files /dev/null and b/site/science/img/apple.png differdiff --git a/site/science/img/bee.png b/site/science/img/bee.pngnew file mode 100644index 0000000..45dd0c3Binary files /dev/null and b/site/science/img/bee.png differdiff --git a/site/science/img/bicycle.png b/site/science/img/bicycle.pngnew file mode 100644index 0000000..1036557Binary files /dev/null and b/site/science/img/bicycle.png differdiff --git a/site/science/img/bike.png b/site/science/img/bike.pngnew file mode 100644index 0000000..de91389Binary files /dev/null and b/site/science/img/bike.png differdiff --git a/site/science/img/building.png b/site/science/img/building.pngnew file mode 100644index 0000000..a4f9a46Binary files /dev/null and b/site/science/img/building.png differdiff --git a/site/science/img/can.png b/site/science/img/can.pngnew file mode 100644index 0000000..54a5d24Binary files /dev/null and b/site/science/img/can.png differdiff --git a/site/science/img/can_crushed.png b/site/science/img/can_crushed.pngnew file mode 100644index 0000000..8baed62Binary files /dev/null and b/site/science/img/can_crushed.png differdiff --git a/site/science/img/car.png b/site/science/img/car.pngnew file mode 100644index 0000000..b9fd7c3Binary files /dev/null and b/site/science/img/car.png differdiff --git a/site/science/img/car_top.png b/site/science/img/car_top.pngnew file mode 100644index 0000000..d7ce7bfBinary files /dev/null and b/site/science/img/car_top.png differdiff --git a/site/science/img/cart.png b/site/science/img/cart.pngnew file mode 100644index 0000000..d33e804Binary files /dev/null and b/site/science/img/cart.png differdiff --git a/site/science/img/dolphin.png b/site/science/img/dolphin.pngnew file mode 100644index 0000000..8c13b47Binary files /dev/null and b/site/science/img/dolphin.png differdiff --git a/site/science/img/duck.png b/site/science/img/duck.pngnew file mode 100644index 0000000..daefc17Binary files /dev/null and b/site/science/img/duck.png differdiff --git a/site/science/img/earth.png b/site/science/img/earth.pngnew file mode 100644index 0000000..3875220Binary files /dev/null and b/site/science/img/earth.png differdiff --git a/site/science/img/feather.png b/site/science/img/feather.pngnew file mode 100644index 0000000..6f427b2Binary files /dev/null and b/site/science/img/feather.png differdiff --git a/site/science/img/friend.png b/site/science/img/friend.pngnew file mode 100644index 0000000..d00f5fbBinary files /dev/null and b/site/science/img/friend.png differdiff --git a/site/science/img/friend_point.png b/site/science/img/friend_point.pngnew file mode 100644index 0000000..164aa80Binary files /dev/null and b/site/science/img/friend_point.png differdiff --git a/site/science/img/friend_walk1.png b/site/science/img/friend_walk1.pngnew file mode 100644index 0000000..51c75caBinary files /dev/null and b/site/science/img/friend_walk1.png differdiff --git a/site/science/img/friend_walk2.png b/site/science/img/friend_walk2.pngnew file mode 100644index 0000000..2c7f19aBinary files /dev/null and b/site/science/img/friend_walk2.png differdiff --git a/site/science/img/house.png b/site/science/img/house.pngnew file mode 100644index 0000000..25a26ccBinary files /dev/null and b/site/science/img/house.png differdiff --git a/site/science/img/lamp.png b/site/science/img/lamp.pngnew file mode 100644index 0000000..dec9e62Binary files /dev/null and b/site/science/img/lamp.png differdiff --git a/site/science/img/light_green.png b/site/science/img/light_green.pngnew file mode 100644index 0000000..3db5f34Binary files /dev/null and b/site/science/img/light_green.png differdiff --git a/site/science/img/light_red.png b/site/science/img/light_red.pngnew file mode 100644index 0000000..2b366d4Binary files /dev/null and b/site/science/img/light_red.png differdiff --git a/site/science/img/maya_seated.png b/site/science/img/maya_seated.pngnew file mode 100644index 0000000..5ec6a5dBinary files /dev/null and b/site/science/img/maya_seated.png differdiff --git a/site/science/img/rider.png b/site/science/img/rider.pngnew file mode 100644index 0000000..fd1b85cBinary files /dev/null and b/site/science/img/rider.png differdiff --git a/site/science/img/runner.png b/site/science/img/runner.pngnew file mode 100644index 0000000..96a5ac8Binary files /dev/null and b/site/science/img/runner.png differdiff --git a/site/science/img/runner_walk1.png b/site/science/img/runner_walk1.pngnew file mode 100644index 0000000..b646dcdBinary files /dev/null and b/site/science/img/runner_walk1.png differdiff --git a/site/science/img/runner_walk2.png b/site/science/img/runner_walk2.pngnew file mode 100644index 0000000..1abbe67Binary files /dev/null and b/site/science/img/runner_walk2.png differdiff --git a/site/science/img/stone.png b/site/science/img/stone.pngnew file mode 100644index 0000000..8cff86fBinary files /dev/null and b/site/science/img/stone.png differdiff --git a/site/science/img/tree.png b/site/science/img/tree.pngnew file mode 100644index 0000000..79110d5Binary files /dev/null and b/site/science/img/tree.png differdiff --git a/site/science/img/truck.png b/site/science/img/truck.pngnew file mode 100644index 0000000..8451122Binary files /dev/null and b/site/science/img/truck.png differdiff --git a/site/science/img/walrus.png b/site/science/img/walrus.pngnew file mode 100644index 0000000..74357aaBinary files /dev/null and b/site/science/img/walrus.png differdiff --git a/site/science/img/you.png b/site/science/img/you.pngnew file mode 100644index 0000000..e9f2748Binary files /dev/null and b/site/science/img/you.png differdiff --git a/site/science/img/you_down.png b/site/science/img/you_down.pngnew file mode 100644index 0000000..2e74201Binary files /dev/null and b/site/science/img/you_down.png differdiff --git a/site/science/img/you_point.png b/site/science/img/you_point.pngnew file mode 100644index 0000000..e5d4fe3Binary files /dev/null and b/site/science/img/you_point.png differdiff --git a/site/science/img/you_top.png b/site/science/img/you_top.pngnew file mode 100644index 0000000..657213eBinary files /dev/null and b/site/science/img/you_top.png differdiff --git a/site/science/img/you_walk1.png b/site/science/img/you_walk1.pngnew file mode 100644index 0000000..5791773Binary files /dev/null and b/site/science/img/you_walk1.png differdiff --git a/site/science/img/you_walk2.png b/site/science/img/you_walk2.pngnew file mode 100644index 0000000..ee72ed0Binary files /dev/null and b/site/science/img/you_walk2.png differdiff --git a/site/science/index.html b/site/science/index.htmlnew file mode 100644index 0000000..d0cb091--- /dev/null+++ b/site/science/index.html@@ -0,0 +1,328 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<script>+// Observe aborted incoming transitions before the first rendering opportunity.+addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));+</script>+<title>Ace Science · Physics</title>+<meta name="description" content="ONE SENTENCE ABOUT THE BOOK.">+<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%231d2b27'/%3E%3Ctext x='32' y='45' text-anchor='middle' font-size='48' fill='%23f0b45a'%3E∞%3C/text%3E%3C/svg%3E">+<script src="unit-art.js"></script>+<link rel="expect" href="#ch01" blocking="render">+<style>+: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);+ 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: rgba(22, 33, 29, .86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid #2a3b35; }+.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; }+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }+.unit h2 { position: relative; display: flex; align-items: baseline; gap: 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }+.unit .grid { position: relative; }+/* Each unit header is a strip of chalkboard with a sketch of its mathematics, drawn in the unit colour. */+.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; }+.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); } }+.unit h2 span { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }+.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 rgba(0, 0, 0, .3); }+.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: "✓ Finished · "; color: var(--good); font-weight: 600; }+.ch.last small::after { content: " · 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); }++.back-shelf { color: var(--dim); font: 13px var(--ui); text-decoration: none; white-space: nowrap; }+.back-shelf:hover { color: var(--chalk); }+.cover-back { position: absolute; top: 24px; left: 24px; }+.contents-back { margin-left: 16px; }++/* ---------- page-to-page motion ---------- */+@view-transition { navigation: auto; }+::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-back { margin-left: 0; font-size: 11px; }+ #contents .top { flex-wrap: wrap; gap: 8px 12px; }+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }+ .unit h2 { min-height: 0; padding-top: 104px; }+ .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; }+ .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; }+ .chalk span { opacity: .075; }+}+</style>+</head>+<body>+<section id="cover">+ <div class="chalk" aria-hidden="true"><!-- a few faint formulas or phrases from the book, drawn in chalk -->+ <span style="left:7%;top:13%;--d:1.6">speed = distance ÷ time</span>+ <span style="right:8%;top:17%;--d:1.9">motion is relative</span>+ <span style="left:5%;bottom:20%;--d:2.2">+2 m/s → −2 m/s</span>+ <span style="right:6%;bottom:15%;--d:2.5">5 m/s²</span>+ </div>+ <svg class="mascot draw" id="guide" width="210" height="147"></svg>+ <p class="kicker">An animated science book · physics</p>+ <h1>Motion <i>&</i> Forces</h1>+ <p class="lede">The physics chapters of a middle-school science notebook, as short narrated animations with quick checks. Chapters 9 to 11 are ready.</p>+ <div class="acts">+ <a class="btn go" href="#contents">Open the book<svg viewBox="0 0 16 16"><path d="M6 2.5 11.5 8 6 13.5 4.6 12.1 8.7 8 4.6 3.9z"/></svg></a>+ <a class="btn quiet" id="resume" hidden></a>+ </div>+ <p class="meta" id="meta"></p>+ <a class="back-shelf cover-back" href="../">← Back to the bookshelf</a>+</section>++<main id="contents">+ <header class="top">+ <a class="home" href="#book" aria-label="Back to the cover"><svg class="mascot" id="guideSmall" width="52" height="36"></svg><strong>Motion <i>&</i> Forces</strong></a>+ <span class="prog" id="prog"></span>+ <a class="back-shelf contents-back" href="../">← Bookshelf</a>+ </header>+ <div id="units"></div>+</main>++<script>+'use strict';+// Physics only: the book's chapters 9–17 (units 3–4) keep their original numbers. START gives the first unit and+// chapter numbers; chapters are numbered in order from there. Add a chapter here when its lesson is ready.+const START = { unit: 3, chapter: 9 };+const UNITS = [ // [unit title, [[chapter title, minutes], ...]]+ ['Motion, Forces, and Work', [['Motion', 18], ['Force and Newton’s Laws of Motion', 13], ['Gravity, Friction, and More Forces in Everyday Life', 15]]],+];+const HUES = ['#f4a48c', '#86c9e8', '#f3c95c', '#e8a0c8', '#8fd6b0', '#bba8ee', '#f0b45a'];+const id = n => 'ch' + String(n).padStart(2, '0');+let P = {};+const BOOK_PROGRESS_KEY = 'animebook:progress:' + new URL('.', location.href).pathname;+try {+ const saved = JSON.parse(localStorage.getItem(BOOK_PROGRESS_KEY) || '{}');+ if (saved && typeof saved === 'object' && !Array.isArray(saved)) P = saved;+} catch {}+const done = new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger(n) && n > 0) : []);++// Contents.+let n = START.chapter - 1, total = 0, i = 0; // i staggers the entrance, in reading order+const esc = s => s.replace(/&/g, '&').replace(/</g, '<');+document.getElementById('units').innerHTML = UNITS.map(([name, chs], u) => {+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}"><svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${UNIT_ART[u] || ''}</svg><h2><span>Unit ${u + START.unit}</span>${esc(name)}</h2><div class="grid">` ++ chs.map(([t, min]) => { n++; total++;+ const cls = 'ch' + (done.has(n) ? ' done' : '') + (P.last === n ? ' last' : '');+ return `<a class="${cls}" id="${id(n)}" href="${id(n)}/" style="--i:${i++}"><b>${n}</b><span>${esc(t)}</span><small>${min} min</small></a>`;+ }).join('') + '</div></section>';+}).join('');+// A unit's sketch draws itself the first time the unit scrolls into view.+const seen = new IntersectionObserver(es => es.forEach(e => { if (e.isIntersecting) { e.target.classList.add('seen'); seen.unobserve(e.target); } }), { threshold: .25 });+document.querySelectorAll('.unit').forEach(u => seen.observe(u));+const finished = [...done].filter(k => k >= START.chapter && k <= n).length;+document.getElementById('prog').innerHTML = finished ? `<b>${finished}</b> of ${total} finished` : `${total} chapter${total === 1 ? '' : 's'}`;+const pl = (k, w) => `${k} ${w}${k === 1 ? '' : 's'}`;+document.getElementById('meta').textContent = `${pl(total, 'chapter')} · ${pl(UNITS.length, 'unit')} · with sound`;+const last = Number.isInteger(P.last) && document.getElementById(id(P.last));+if (last) {+ const r = document.getElementById('resume');+ r.hidden = false;+ r.href = last.getAttribute('href');+ r.textContent = `Continue · Chapter ${P.last}`;+}++// The guide, drawn the same way as in the lessons.+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';+}+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="#ece8dc" 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="#ece8dc"/><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.+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 ? document.getElementById(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) {+ 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 && document.getElementById(location.hash.slice(1))?.closest('.ch')) || (named?.offsetParent && named);+ name(e.viewTransition && target ? target : null);+ e.viewTransition?.finished.then(() => name(null), () => name(null));+});+</script>+</body>+</html>diff --git a/site/science/lib/actors.js b/site/science/lib/actors.jsnew file mode 100644index 0000000..c0e530e--- /dev/null+++ b/site/science/lib/actors.js@@ -0,0 +1,3 @@+// Generated by books/science/images/actors.py: actor sprite-sheet layout and hand positions.+'use strict';+const ACTORS = {"W":22,"H":19,"K":8,"X0":11,"anims":{"stand":{"row":0,"n":1,"hands":[{"B":[-0.83,-4.81],"F":[1.05,-4.86]}]},"walk":{"row":1,"n":6,"hands":[{"B":[-0.25,-4.83],"F":[0.75,-4.83]},{"B":[1.09,-4.96],"F":[-0.63,-4.74]},{"B":[1.09,-4.96],"F":[-0.63,-4.74]},{"B":[-0.25,-4.83],"F":[0.75,-4.83]},{"B":[-1.63,-4.74],"F":[2.09,-4.96]},{"B":[-1.63,-4.74],"F":[2.09,-4.96]}]},"run":{"row":2,"n":4,"hands":[{"B":[2.31,-7.33],"F":[3.31,-7.33]},{"B":[3.41,-8.2],"F":[0.78,-5.14]},{"B":[2.31,-7.33],"F":[3.31,-7.33]},{"B":[-0.22,-5.14],"F":[4.41,-8.2]}]},"push":{"row":3,"n":6,"hands":[{"B":[4.94,-7.37],"F":[6.11,-7.86]},{"B":[4.94,-7.19],"F":[6.11,-7.68]},{"B":[4.94,-7.19],"F":[6.11,-7.68]},{"B":[4.94,-7.37],"F":[6.11,-7.86]},{"B":[4.94,-7.19],"F":[6.11,-7.68]},{"B":[4.94,-7.19],"F":[6.11,-7.68]}]},"pull":{"row":4,"n":6,"hands":[{"B":[-1.64,-5.23],"F":[-1.12,-5.56]},{"B":[-1.64,-5.05],"F":[-1.12,-5.38]},{"B":[-1.64,-5.05],"F":[-1.12,-5.38]},{"B":[-1.64,-5.23],"F":[-1.12,-5.56]},{"B":[-1.64,-5.05],"F":[-1.12,-5.38]},{"B":[-1.64,-5.05],"F":[-1.12,-5.38]}]},"strain":{"row":5,"n":2,"hands":[{"B":[1.71,-7.14],"F":[2.77,-7.44]},{"B":[1.51,-7.04],"F":[2.56,-7.34]}]},"stumble":{"row":6,"n":4,"hands":[{"B":[5.01,-7.86],"F":[6.08,-8.3]},{"B":[5.01,-7.66],"F":[6.08,-8.09]},{"B":[5.01,-7.86],"F":[6.08,-8.3]},{"B":[5.01,-7.66],"F":[6.08,-8.09]}]},"backstep":{"row":7,"n":4,"hands":[{"B":[2.0,-7.86],"F":[3.05,-8.15]},{"B":[2.0,-7.69],"F":[3.05,-7.98]},{"B":[2.0,-7.86],"F":[3.05,-8.15]},{"B":[2.0,-7.69],"F":[3.05,-7.98]}]},"kick":{"row":8,"n":3,"hands":[{"B":[2.85,-6.3],"F":[-1.14,-5.29]},{"B":[-3.32,-5.57],"F":[2.48,-5.55]},{"B":[-5.1,-6.48],"F":[2.75,-6.46]}]},"throw":{"row":9,"n":3,"hands":[{"B":[1.51,-7.84],"F":[2.64,-8.02]},{"B":[4.79,-8.39],"F":[5.81,-8.83]},{"B":[2.16,-7.22],"F":[3.37,-7.77]}]},"skate":{"row":10,"n":2,"hands":[{"B":[-1.02,-4.4],"F":[5.54,-6.4]},{"B":[-4.0,-7.35],"F":[4.87,-7.74]}]},"crouch":{"row":11,"n":1,"hands":[{"B":[-1.0,-2.93],"F":[0.66,-2.68]}]},"jump":{"row":12,"n":1,"hands":[{"B":[3.0,-11.15],"F":[3.57,-11.74]}]},"land":{"row":13,"n":1,"hands":[{"B":[3.73,-5.63],"F":[5.04,-6.29]}]},"catch":{"row":14,"n":2,"hands":[{"B":[3.84,-8.46],"F":[4.88,-8.75]},{"B":[2.01,-7.96],"F":[3.08,-8.38]}]},"toss":{"row":15,"n":3,"hands":[{"B":[2.52,-6.56],"F":[3.66,-6.62]},{"B":[3.39,-10.03],"F":[4.3,-10.38]},{"B":[0.33,-13.0],"F":[0.97,-13.09]}]},"pedal":{"row":16,"n":8,"hands":[{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]},{"B":[3.46,-9.44],"F":[4.62,-9.78]}]}},"bike":{"wheels":[[-5,-1.5],[6.5,-1.5]],"r":3.1,"crank":[0.5,-3.5999999999999996]}};diff --git a/site/science/lib/engine.css b/site/science/lib/engine.cssnew file mode 100644index 0000000..4fcc2ff--- /dev/null+++ b/site/science/lib/engine.css@@ -0,0 +1,216 @@+: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); }+/* Band card: prompt and buttons on top, answers below at full width, feedback last. A prompt beside the answers+ lost the width race to long choices or answer rows (it was squeezed to a word per line, worst in Firefox). */+.card.band { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "pic head acts" "pic body body" "pic fb fb"; column-gap: 28px; row-gap: 12px; align-items: center; align-content: center; min-height: 150px; }+.band .mascot { grid-area: pic; }+.band .head { grid-area: head; }+.band .fb { grid-area: fb; margin-top: 0; }+.band .body { grid-area: body; min-width: 0; }+.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; }++/* 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; }+.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 "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 */+.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 .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; }diff --git a/site/science/lib/engine.js b/site/science/lib/engine.jsnew file mode 100644index 0000000..47fdd22--- /dev/null+++ b/site/science/lib/engine.js@@ -0,0 +1,1736 @@+// 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(() => {}));+document.body.insertAdjacentHTML('afterbegin', `<div id="frame">+ <svg id="stage" viewBox="0 0 1600 900" role="img" aria-label="Lesson animation">+ <g id="scene"></g>+ </svg>+ <div id="ui"></div>+ <div class="paused-mark"><div>Paused. Press space or click to continue.</div></div>+ <div class="caption" id="caption" hidden></div>+ <div class="help" id="help" hidden role="dialog" aria-label="Keyboard shortcuts">+ <div class="help-box">+ <h2>Keyboard shortcuts</h2>+ <div class="help-cols">+ <div><h3>Lesson</h3><dl>+ <dt><kbd>Space</kbd></dt><dd>Play or pause</dd>+ <dt><kbd>←</kbd><kbd>→</kbd></dt><dd>Previous or next step</dd>+ <dt><kbd>Shift</kbd><kbd>←</kbd><kbd>→</kbd></dt><dd>Change step during a question</dd>+ <dt><kbd>Home</kbd></dt><dd>Start over</dd>+ <dt><kbd>C</kbd></dt><dd>Captions on or off</dd>+ <dt><kbd>F</kbd></dt><dd>Full screen</dd>+ <dt><kbd>?</kbd></dt><dd>Show this list</dd>+ </dl></div>+ <div><h3>Questions</h3><dl>+ <dt><kbd>1</kbd>–<kbd>6</kbd></dt><dd>Choose an answer or a ring</dd>+ <dt><kbd>T</kbd><kbd>F</kbd></dt><dd>True or false</dd>+ <dt><kbd>↑</kbd><kbd>↓</kbd></dt><dd>Move between rows</dd>+ <dt><kbd>←</kbd><kbd>→</kbd></dt><dd>Move along the number line, or pick a number to sort</dd>+ <dt><kbd>Enter</kbd></dt><dd>Check, then continue</dd>+ <dt><kbd>S</kbd></dt><dd>Show the answer</dd>+ <dt><kbd>Esc</kbd></dt><dd>Leave an answer box</dd>+ </dl></div>+ </div>+ <p class="help-close">Press <kbd>Esc</kbd> to close.</p>+ </div>+ </div>+ <p class="sound-note" id="soundNote" hidden>Sound could not play. The lesson continues with the on-screen text.</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>Start lesson</span>+ <small><span id="coverMeta"></span> Press <kbd>Space</kbd> to start, <kbd>?</kbd> for shortcuts.</small>+ </div></button>+ <div id="bar">+ <a class="icon" id="bHome" href="../" aria-label="All chapters" title="All chapters">+ <svg viewBox="0 0 18 18"><path d="M2 2h6v6H2zM10 2h6v6h-6zM2 10h6v6H2zM10 10h6v6h-6z"/></svg>+ </a>+ <button class="icon" id="bPlay" aria-label="Play or pause (space)">+ <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="Previous step (left arrow)">+ <svg viewBox="0 0 18 18"><path d="M3 2h2.5v14H3zM16 2v14L6.5 9z"/></svg>+ </button>+ <button class="icon" id="bRestart" aria-label="Restart lesson">+ <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="Keyboard shortcuts (?)" title="Keyboard shortcuts (?)">?</button>+ <button class="icon cc" id="bCC" aria-pressed="false" aria-label="Captions (C)" title="Captions (C)">CC</button>+ <button class="icon" id="bFull" aria-label="Full screen">+ <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, s % 36], 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';+const MATH = UI; // science book: one face for numbers and formulas in demos and questions+const NAME = { nat: 'Natural', whole: 'Whole', int: 'Integers', rat: 'Rational', irr: 'Irrational', real: '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+// Math expression from parts: 'text' | F(n,d) | R(x) | E(exp). Baseline at y; anchor start/middle/end.+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;+ for (const p of parts) {+ if (typeof p === 'string') cx += text(p, cx, 0, size);+ 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;+ }+ }+ const dx = anchor === 'middle' ? -cx / 2 : anchor === 'end' ? -cx : 0;+ inner.setAttribute('transform', `translate(${dx},0)`);+ g._w = cx;+ 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), h = size * (parts.some(p => p.f) ? 1.75 : 1.45);+ 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;+ const box = put(mk('rect', { rx: 10, fill: 'none', stroke: color, 'stroke-width': 3 }, p),+ { o: 0, a_x: left - 8, a_y: y - size * .95, a_width: right - left + 16, a_height: size * 1.3 });+ 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('→'), ' move, ', kbd('Enter'), ' choose, or click the grid'],+ 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' });+ const top = size * 1.05, h = size * 1.5;+ svg.setAttribute('viewBox', `0 ${-top} ${m._w + 2} ${h}`);+ svg.setAttribute('width', m._w + 2);+ svg.setAttribute('height', h);+ svg.style.verticalAlign = `${-size * .45}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 ? '−' : '') + Math.abs(v);+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.+function retire(e) {+ 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(`${-n} steps left of 0`, 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' ? 'Integer' : NAME[k], COL[k]]);+const TF = [['t', 'True', null, 'T'], ['f', 'False', 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 ? `${name}: ${r} of ${t} right on the first try.` : `${name}: not attempted.`);+ progress(p => { p.done = [...new Set([...(p.done || []), CHAPTER.number])]; });+ const home = h('a', 'btn quiet', 'All chapters');+ home.href = $('bHome').href;+ const again = h('button', 'btn' + (CHAPTER.next ? ' quiet' : ' go'), ['Watch again', kbd(CHAPTER.next ? 'R' : 'Enter')]);+ again.onclick = restart;+ const next = CHAPTER.next && h('button', 'btn go', ['Next chapter', kbd('Enter')]);+ if (next) next.onclick = () => { location.href = CHAPTER.next; };+ P.keys = e => e.key === 'Enter' ? ((next ? next.onclick() : restart()), true)+ : (e.key === 'r' || e.key === 'R') ? (restart(), true) : false;+ const guide = mascotEl(240);+ c.append(h('div', 'finwrap', [guide, h('p', 'kicker', `Chapter ${CHAPTER.number} complete`), h('p', 'prompt', CHAPTER.title),+ line('Quick checks', sum('c-')), line('Chapter practice', sum('p-')), h('div', 'acts', next ? [home, again, next] : [home, again])]));+ setTimeout(() => mood(guide, 'happy'), 400);+}++/* ---------- in-picture cards ---------- */+const $ = id => document.getElementById(id);+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 = 'Quick check') {+ 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', ['Check', kbd('Enter')]), bShow = h('button', 'btn quiet', ['Show answer', kbd('S')]);+ const bNext = h('button', 'btn go', [k < qs.length - 1 ? 'Next question' : '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 ? 'Correct. ' : 'Not quite. ', ...[].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('', ['Answer: ', ...[].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 ((e.key === 's' || e.key === 'S') && !bShow.hidden) { bShow.click(); return true; }+ return false;+ };+ const kick = label + (qs.length > 1 ? ` ${k + 1} of ${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', ['Keys: ', ...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; },+ };+};+// Tap a point on the stage number line.+const tap = (values, right, yes, no, onRight) => (body, api) => {+ const L = qlayer(), hits = {};+ let locked = false;+ for (const v of values) {+ const g = G(L, { x: X(v), y: Y0 });+ g.classList.add('hit');+ g.setAttribute('tabindex', 0);+ g.setAttribute('role', 'button');+ g.setAttribute('aria-label', `The point ${num(v)}`);+ mk('circle', { r: 30, class: 'ring' }, g);+ const act = () => {+ if (locked) return;+ if (v === right) { g.classList.add('good'); onRight?.(); api.grade(true, yes); }+ else { g.classList.add('bad'); shakeFx(S.dots[v]); api.grade(false, no(v)); }+ };+ g.addEventListener('click', act);+ keyAct(g, act);+ hits[v] = g;+ }+ const gs = values.map(v => hits[v]);+ let cur = -1;+ return {+ reveal() { hits[right].classList.add('good'); onRight?.(); return yes; },+ lock() { locked = true; },+ hint: [kbd('←'), kbd('→'), ' move along the line, ', kbd('Enter'), ' choose'],+ 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 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();+ let locked = false, cur = -1;+ const hits = idx.map(i => {+ const e = row[i], w = e._w + 18, g = G(L, { x: e._px, y: row.y });+ g.classList.add('hit');+ g.setAttribute('tabindex', 0);+ g.setAttribute('role', 'button');+ g.setAttribute('aria-label', e.textContent.trim());+ mk('rect', { class: 'ring', x: -w / 2, y: -row.size * .95, width: w, height: row.size * 1.3, rx: 12 }, g);+ const act = () => {+ if (locked) return;+ if (i === right) { g.classList.add('good'); onRight?.(); api.grade(true, yes); }+ else { g.classList.add('bad'); shakeFx(e); api.grade(false, no(i)); }+ };+ g.addEventListener('click', act);+ keyAct(g, act);+ return g;+ });+ return {+ reveal() { hits[idx.indexOf(right)].classList.add('good'); onRight?.(); return yes; },+ lock() { locked = true; },+ hint: [kbd('←'), kbd('→'), ' move, ', kbd('Enter'), ' choose'],+ key(e) {+ const d = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;+ if (!d || locked) return false;+ cur = cur < 0 ? (d > 0 ? 0 : hits.length - 1) : (cur + d + hits.length) % hits.length;+ hits[cur].focus();+ return true;+ },+ };+};+// 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();+ let locked = false, cur = -1;+ const hits = items.map((it, i) => {+ const [x, y, w, hh] = it.box, g = G(L);+ g.classList.add('hit');+ g.setAttribute('tabindex', 0);+ g.setAttribute('role', 'button');+ g.setAttribute('aria-label', it.label);+ mk('rect', { class: 'ring', x, y, width: w, height: hh, rx: 12 }, g);+ const act = () => {+ if (locked) return;+ if (i === right) { g.classList.add('good'); onRight?.(); api.grade(true, yes); }+ else { g.classList.add('bad'); shakeFx(it.el); api.grade(false, no(i)); }+ };+ g.addEventListener('click', act);+ keyAct(g, act);+ return g;+ });+ return {+ reveal() { hits[right].classList.add('good'); onRight?.(); return yes; },+ lock() { locked = true; },+ hint: [kbd('←'), kbd('→'), ' move, ', kbd('Enter'), ' choose, or click'],+ key(e) {+ const d = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;+ if (!d || locked) return false;+ cur = cur < 0 ? (d > 0 ? 0 : hits.length - 1) : (cur + d + hits.length) % hits.length;+ hits[cur].focus();+ return true;+ },+ };+};+// 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) => r.el.classList.toggle('cur', !single && !locked && i === cur));+ 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 ? [] : [`${right} of ${rows.length} right. Fix the rows marked ✗ and check again.`], { 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 : 'the correct choices are now selected.';+ },+ lock() { locked = true; showCur(); rows.forEach(r => r.bs.forEach(b => { b.disabled = true; })); },+ hint: [...(single ? [] : [kbd('↑'), kbd('↓'), ' row, ']), ...(/\d/.test(hot[0]) ? [kbd(hot[0]), '–', kbd(hot[hot.length - 1])] : hot.map(kbd)), ' choose'],+ 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 => x.toLowerCase() === e.key.toLowerCase());+ 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. Never evaluates the text as code.+function rat(str) {+ const t = String(str).trim().replace(/^[−–]/, '-').replace(/\s+/g, ' ');+ 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', 'Answer');+ 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 ? [] : [`${right} of ${rows.length} right. Fix the rows marked ✗ and check again.`];+ 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 : 'the correct numbers are filled in.';+ },+ lock() { all.forEach(b => { b.disabled = true; }); },+ hint: [all.some(b => b.dataset.ans.includes('/')) ? 'type numbers like 3/4 or −2 1/4, ' : 'type the number, ', kbd('Tab'), ' next box, ', kbd('Enter'), ' check, ', kbd('Esc'), ' leave the box'],+ };+};+// 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.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.say}, ${c.region ? 'placed in ' + NAME[c.region] : 'not placed'}`);+ 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);+ });+ 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', '', `${c.say} is not placed yet.`)); 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'+ ? `${c.say}: every real number is rational or irrational, so that space has no numbers of its own.`+ : c.why));+ }+ const all = right === chips.length;+ api.grade(all, all ? [] : [`${right} of ${chips.length} in the right ring.`, 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 'every number is now in its smallest ring.';+ },+ lock() { locked = true; choose(null); },+ hint: [kbd('←'), kbd('→'), ' pick a number, ', kbd('1'), '–', kbd('6'), ' choose its ring'],+ 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: [] };+function runBeat(i) {+ TW = [];+ const b = BEATS[i], tm = TIMINGS[b.id];+ const m = (k, off = 0) => {+ if (!(k in tm.marks)) throw new Error(`${b.id}: missing mark ${k}`);+ return tm.marks[k] + off;+ };+ S.cleared = false;+ b.run(m, tm.dur);+ if (S.cleared && b.lead !== false) leadIn();+ TW.sort((a, c) => a.t0 - c.t0);+ return Math.max(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();+ for (let k = 0; k < i; k++) { runBeat(k); evalTo(Infinity); }+ start(i, play);+}+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 = new Audio(`audio/${CHAPTER.language || 'en'}/${BEATS[i].id}.mp3`);+ a.preload = 'auto';+ // 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) $('soundNote').hidden = true; };+ const b = BEATS[i];+ if (b.ask) b.ask(() => { if (P.i === i) { evalTo(Infinity); start(i + 1, true); } });+ setPlaying(play);+}+function soundFailed() { P.afail = true; $('soundNote').hidden = false; }+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();+}+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.+ if (a && !P.afail && !a.ended) {+ if (a.currentTime > 0) { P.t = Math.max(P.t, a.currentTime); P.stall = 0; }+ else if ((P.stall += dt) > 8 && a.readyState < 2) soundFailed(); // still nothing to play after 8 s+ } else P.t += dt;+ 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', `Go to step ${i + 1}: ${b.title}`);+ s.onclick = () => { hideCover(); seek(i, true); };+ $('segs').append(s);+ return s.firstChild;+ });+}+function ui() {+ segs.forEach((f, k) => { f.style.width = (k < P.i || P.done ? 100 : k > P.i ? 0 : Math.min(100, P.t / P.end * 100)) + '%'; });+ $('frame').classList.toggle('is-playing', P.playing && !P.done && !P.waiting);+ $('frame').classList.toggle('paused', P.started && !P.playing && !P.waiting && !P.done && !BEATS[P.i].ask);+ $('stepName').textContent = `${P.i + 1} / ${BEATS.length} ${BEATS[P.i].title}`;+ 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; }+ }+ 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);+$('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);+}+// 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')) { // typing an answer: only Enter (check) and Escape (leave the box) are ours+ if (k === 'Enter' && P.keys) { e.preventDefault(); P.keys(e); }+ else if (k === 'Escape') e.target.blur();+ return;+ }+ if (k === '?') { e.preventDefault(); toggleHelp(); 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 (k === 'c' || k === 'C') setCaptions(!captions);+ else if (k === 'f' || k === '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 / 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 = '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 = `Chapter ${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', `Lesson animation: ${CHAPTER.title}`);+ $('coverMeta').textContent = `About ${CHAPTER.minutes} minutes, with sound and quick checks.`;+ 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);+ } else seek(0, false);+ requestAnimationFrame(frame);+}diff --git a/site/science/lib/figures.js b/site/science/lib/figures.jsnew file mode 100644index 0000000..9207113--- /dev/null+++ b/site/science/lib/figures.js@@ -0,0 +1,226 @@+// Papermorph science book: the scene set. Load after engine.js.+// Style: pixel art. Vehicles, people, lamps, trees, houses and Earth are sprites in ../img/ (Kenney CC0 sprites and our+// own pixel art; credits in img/CREDITS.md), drawn at PX world px per sprite pixel with image-rendering: pixelated.+// Shapes that animate or teach stay SVG: road, wheel hubs, pins, labels, arrows, ball, stopwatch, notebook, Sun.+// Every figure is drawn around its own origin with the ground at y = 0, facing right (+x); place it with+// put(e, {x, y, s}) and animate it with the engine's tweens.+'use strict';+const PH = {+ out: '#14201c', road: '#3a4541', walk: '#55625b', grass: '#2d4636', line: '#ece8dc', hill1: '#22352d', hill2: '#283f34',+ glass: '#c8e0ff', metal: '#7d8a86', ocean: '#3f7fb0', land: '#4ea05a', sky: '#4f7f9c',+ you: COL.real, friend: COL.nat, truck: COL.whole, car: COL.irr, ref: COL.task, change: COL.rat,+};+const OL = 2.5;+const dk = (c, k = .22) => mix(c, '#0e1714', k), lt = (c, k = .3) => mix(c, '#ffffff', k);+const phLine = (w = OL) => ({ stroke: PH.out, 'stroke-width': w, 'stroke-linejoin': 'round' });+const phHash = (i, j) => { const v = Math.sin(i * 127.1 + j * 311.7) * 43758.5453; return v - Math.floor(v); };++/* ---------- building blocks ---------- */+// A flat block with an optional lighter top band and darker right/bottom bands (and outline, ol = 0 for none).+function phBlock(p, x, y, w, h, c, { top = 4, right = 0, bottom = 0, ol = OL } = {}) {+ mk('rect', { x, y, width: w, height: h, fill: c }, p);+ if (top) mk('rect', { x, y, width: w, height: Math.min(top, h / 2), fill: lt(c) }, p);+ if (right) mk('rect', { x: x + w - right, y, width: right, height: h, fill: dk(c) }, p);+ if (bottom) mk('rect', { x, y: y + h - bottom, width: w, height: bottom, fill: dk(c) }, p);+ if (ol) mk('rect', { x, y, width: w, height: h, fill: 'none', ...phLine(ol) }, p);+}++// Text with a thin dark outline, so it stays legible when something passes behind it.+function phLabel(p, str, { x = 0, y = 0, size = 30, fill = COL.chalk, anchor = 'middle', weight = 700, o = 1 } = {}) {+ const t = T(p, str, { x, y, size, fill, anchor, weight, o });+ // A thin, capped outline keeps small labels legible over pictures; titles (72 px and up) sit on clean board and get none.+ if (size < 72) { t.setAttribute('stroke', COL.board); t.setAttribute('stroke-width', Math.min(5, size * .16)); t.setAttribute('paint-order', 'stroke'); }+ t.setAttribute('stroke-linejoin', 'round');+ return t;+}+const phText = (t, s) => { if (t.textContent !== s) t.textContent = s; }; // per-frame text: write only on change+// Reference-point pin (an on-screen marker): the tip touches (0, 0).+function phPin(p, o = {}) {+ const g = G(p, o);+ path(g, 'M0 0C-5 -12 -19 -22 -19 -37A19 19 0 1 1 19 -37C19 -22 5 -12 0 0Z', { fill: PH.ref, ...phLine() });+ path(g, 'M-11 -44A12 12 0 0 1 -2 -53', { stroke: lt(PH.ref, .5), 'stroke-width': 3.5 });+ mk('circle', { cx: 0, cy: -37, r: 7, fill: COL.board }, g);+ return g;+}++/* ---------- sprites ---------- */+const PX = 8; // world px per sprite pixel+const PH_SPR = { car: [32, 13], truck: [44, 24], lamp: [7, 27], tree: [16, 20], house: [18, 14], maya_seated: [7, 7],+ you: [9, 15], you_walk1: [7, 15], you_walk2: [11, 15], friend: [9, 15], friend_walk1: [7, 15], friend_walk2: [11, 15],+ runner: [7, 15], runner_walk1: [6, 15], runner_walk2: [11, 15], dolphin: [25, 8], walrus: [20, 11], light_red: [6, 21], light_green: [6, 21],+ car_top: [18, 8], you_top: [7, 7], bee: [9, 5],+ you_point: [13, 15], friend_point: [13, 15], rider: [8, 15], bike: [16, 10], cart: [14, 11], can: [5, 8], can_crushed: [7, 5], apple: [6, 6], you_down: [15, 5] }; // *_top: seen from above, facing east; their origin is the centre (phTop)+function phSprite(p, name, { x = 0, y = 0, s = 1, o = 1 } = {}) {+ const g = G(p, { x, y, s, o });+ g._in = mk('g', {}, g); // mirrored by phFace+ g._img = mk('image', { style: 'image-rendering: pixelated' }, g._in);+ phFrame(g, name);+ return g;+}+// Show another picture (animation frame) in a sprite; its bottom centre stays at the origin.+function phFrame(g, name) {+ if (g._name === name) return;+ const [w, h] = PH_SPR[name], a = { href: `../img/${name}.png`, x: -w * PX / 2, y: -h * PX, width: w * PX, height: h * PX };+ for (const k in a) g._img.setAttribute(k, a[k]);+ g._name = name;+}+// Face right (dir > 0) or left (dir < 0): mirrors the picture (and a vehicle's hubs) about the origin.+function phFace(g, dir) {+ const left = dir < 0;+ if (g._left !== left) { g._left = left; if (left) g._in.setAttribute('transform', 'scale(-1,1)'); else g._in.removeAttribute('transform'); }+}+// A sprite seen from above, centred on its origin, facing east; turn it with put(g, {r: degrees}) (−90 = north).+function phTop(p, name, o) { const g = phSprite(p, name, o), [, h] = PH_SPR[name]; g._img.setAttribute('y', -h * PX / 2); return g; }+// People (120 px tall): role 'you' (lilac), 'friend' (coral) or 'runner'. Poses: stand, walk (two frames per stride; phase in radians).+const PH_PERSON_H = 120;+const phPerson = (p, { role = 'you', ...o } = {}) => Object.assign(phSprite(p, role, o), { _role: role });+const phPose = (person, pose = 'stand', phase = 0) =>+ phFrame(person, pose === 'walk' ? `${person._role}_walk${((Math.floor(phase / Math.PI) % 2) + 2) % 2 + 1}` : person._role);++// Vehicles. Each wheel's 2×2 hub gets one light pixel that steps round it as the vehicle rolls (see phRoll).+const PH_HUBS = { car: [[3, 9], [17, 9]], truck: [[5, 20], [11, 20], [30, 20]] }; // hub top-left, in sprite px+function phVehicle(p, name, o) {+ const g = phSprite(p, name, o), [w, h] = PH_SPR[name];+ g._hubs = PH_HUBS[name].map(([hx, hy]) => {+ const x = -w * PX / 2 + hx * PX, y = -h * PX + hy * PX;+ mk('rect', { x, y, width: 2 * PX, height: 2 * PX, fill: '#3e4751' }, g._in);+ return Object.assign(mk('rect', { x, y, width: PX, height: PX, fill: PH.glass }, g._in), { _x: x, _y: y });+ });+ return g;+}+const phCar = (p, o) => phVehicle(p, 'car', o), phTruck = (p, o) => phVehicle(p, 'truck', o);+// Wheels turn with the distance rolled: a quarter turn per quarter of the wheel's circumference (radius 24), clockwise going right.+function phRoll(v, dist) {+ const k = ((Math.floor(dist / 24 / (Math.PI / 2)) % 4) + 4) % 4;+ if (k === v._k) return;+ const [dx, dy] = [[0, 0], [1, 0], [1, 1], [0, 1]][v._k = k];+ v._hubs.forEach(r => { r.setAttribute('x', r._x + dx * PX); r.setAttribute('y', r._y + dy * PX); });+}+// Passenger railway carriage in flat pixel blocks, `w` long, 278 px tall; g._wins holds window centres (x).+function phCarriage(p, { x = 0, y = 0, w = 960, color = COL.real } = {}) {+ const g = G(p, { x, y });+ const x0 = -w / 2;+ phBlock(g, x0, -262, w, 222, color, { top: 0, bottom: 32, ol: 0 });+ phBlock(g, x0 + 16, -278, w - 32, 16, dk(color, .35), { top: 0, ol: 0 });+ mk('rect', { x: x0, y: -118, width: w, height: 8, fill: lt(color, .45) }, g);+ g._wins = [];+ for (let wx = x0 + 110; wx < w / 2 - 60; wx += 170) {+ mk('rect', { x: wx - 64, y: -232, width: 128, height: 96, fill: dk(color, .35) }, g);+ mk('rect', { x: wx - 56, y: -224, width: 112, height: 80, fill: PH.glass }, g);+ mk('rect', { x: wx + 16, y: -224, width: 16, height: 80, fill: '#ffffff', opacity: .5 }, g);+ g._wins.push(wx);+ }+ mk('rect', { x: w / 2 - 40, y: -250, width: 32, height: 200, fill: dk(color, .2) }, g);+ [x0 + 110, w / 2 - 110].forEach(bx => {+ mk('rect', { x: bx - 80, y: -48, width: 160, height: 16, fill: '#3b4744' }, g);+ [-46, 46].forEach(o => mk('rect', { x: bx + o - 16, y: -40, width: 32, height: 32, fill: '#3e4751' }, g));+ });+ return g;+}++/* ---------- scenery ---------- */+// Stepped (voxel) hills repeating every W px, ridge around y, filled down to y + depth.+function phHills(p, { y, amp = 40, W = ROAD.W, x0, x1, fill, seed = 1, step = 40, q = 16, depth = 700 }) {+ const f = x => y - amp * (.55 * Math.sin(2 * Math.PI * 2 * x / W + seed) + .3 * Math.sin(2 * Math.PI * 5 * x / W + 2 * seed) + .15 * Math.sin(2 * Math.PI * 11 * x / W + 3 * seed));+ let d = `M${x0} ${y + depth}`;+ for (let x = x0; x < x1; x += step) d += `V${Math.round(f(x) / q) * q}H${x + step}`;+ return path(p, d + `V${y + depth}Z`, { fill, stroke: 'none' });+}+// Side-view street on a camera (see camera() in the engine). Fixed scenery wraps every ROAD.W world px, so follow shots+// can run for any distance. 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 = [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(.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 });+ rep(trees).forEach(x => phSprite(scenery, 'tree', { x, y: ROAD.side }));+ rep(lamps).forEach(x => phSprite(scenery, 'lamp', { x, y: ROAD.side }));+ const side = G(cam.world), surface = cam.layer(1, W);+ mk('rect', { x: x0, y: ROAD.top, width: x1 - x0, height: ROAD.bot - ROAD.top, fill: PH.road }, surface);+ path(surface, `M${x0} ${ROAD.top + 12}H${x1}M${x0} ${ROAD.bot - 8}H${x1}`, { stroke: PH.line, 'stroke-width': 4, opacity: .65 });+ path(surface, rep(Array.from({ length: 15 }, (_, i) => i * 160)).map(x => `M${x} ${ROAD.mid - 4}h72v8h-72Z`).join(''), { fill: PH.line });+ phBlock(surface, x0, ROAD.bot, x1 - x0, 700, PH.grass, { top: 8, ol: 0 });+ path(surface, rep(Array.from({ length: 10 }, (_, i) => i * 240)).map(x => {+ const k = Math.round((((x % W) + W) % W) / 240), gx = x + 60 + (k % 2) * 70, gy = ROAD.bot + 56 + (k % 3) * 32;+ return `M${gx} ${gy}h8v-8h8v-8h8v16h8v-8h8v8Z`;+ }).join(''), { fill: lt(PH.grass, .14) });+ return { scenery, side, vehicles: G(cam.world), front: G(cam.world) };+}++/* ---------- objects ---------- */+// Soccer ball of radius r, centred on the origin: move the group, rotate ball._spin; highlight and shadow stay put.+function phBall(p, r = 40, o = {}) {+ const g = G(p, o);+ mk('ellipse', { cy: r, rx: r * .9, ry: r * .12, fill: '#000', opacity: .25 }, g);+ const sp = G(g);+ mk('circle', { r, fill: '#f4f1e8' }, sp);+ const pent = (cx, cy, k, rot) => Array.from({ length: 5 }, (_, i) => { const a = rot + i * 72 * Math.PI / 180; return `${i ? 'L' : 'M'}${(cx + k * Math.cos(a)).toFixed(1)} ${(cy + k * Math.sin(a)).toFixed(1)}`; }).join('') + 'Z';+ path(sp, pent(0, 0, r * .3, -Math.PI / 2), { fill: '#2a3532' });+ [0, 72, 144, 216, 288].forEach(a => {+ const t = (a - 90) * Math.PI / 180, cx = Math.cos(t) * r * .9, cy = Math.sin(t) * r * .9;+ path(sp, pent(cx, cy, r * .24, t + Math.PI), { fill: '#2a3532' });+ path(sp, `M${(Math.cos(t) * r * .3).toFixed(1)} ${(Math.sin(t) * r * .3).toFixed(1)}L${(Math.cos(t) * r * .68).toFixed(1)} ${(Math.sin(t) * r * .68).toFixed(1)}`, { stroke: '#2a3532', 'stroke-width': 2 });+ });+ mk('circle', { cx: -r * .38, cy: -r * .42, r: r * .2, fill: '#fff', opacity: .55 }, g);+ mk('circle', { r, fill: 'none', ...phLine(3) }, g);+ g._spin = sp;+ return g;+}+// Stopwatch; returns the group with ._hand to rotate.+function phStopwatch(p, { x = 0, y = 0, r = 60, o = 1 } = {}) {+ const g = G(p, { x, y, o });+ phBlock(g, -12, -r - 24, 24, 18, PH.metal, { top: 4, ol: 2 });+ mk('circle', { r: r + 9, fill: PH.metal, ...phLine() }, g);+ mk('circle', { r, fill: '#f4f1e8' }, g);+ for (let i = 0; i < 12; i++) { const a = i * Math.PI / 6; path(g, `M${Math.sin(a) * r * .8} ${-Math.cos(a) * r * .8}L${Math.sin(a) * r * .92} ${-Math.cos(a) * r * .92}`, { stroke: PH.out, 'stroke-width': 3 }); }+ g._hand = path(g, `M0 8V${-r * .78}`, { stroke: COL.bad, 'stroke-width': 4 });+ mk('circle', { r: 5, fill: PH.out }, g);+ return g;+}+// Open notebook; g._page flips about the spine with phFlip(book, angle in degrees, 0 = lying right, 180 = lying left).+function phNotebook(p, { x = 0, y = 0, s = 1 } = {}) {+ const g = G(p, { x, y, s });+ const page = (dx, parent) => {+ const e = mk('g', {}, parent);+ mk('rect', { x: dx, y: -70, width: 130, height: 170, fill: '#f4f1e8', ...phLine() }, e);+ for (let ly = -40; ly < 95; ly += 20) path(e, `M${dx + 14} ${ly}H${dx + 116}`, { stroke: '#86c9e8', 'stroke-width': 2 });+ return e;+ };+ phBlock(g, -142, -78, 284, 186, '#a65d4b', { top: 0, bottom: 8 });+ page(-132, g); page(2, g);+ g._page = page(0, g);+ return g;+}+function phFlip(book, deg) {+ const k = Math.cos(deg * Math.PI / 180), e = book._page;+ e.setAttribute('transform', `scale(${Math.abs(k) < .02 ? .02 * Math.sign(k || 1) : k},1) skewY(${-8 * Math.sin(deg * Math.PI / 180)})`);+ e.firstChild.setAttribute('fill', k < 0 ? '#e2ddcf' : '#f4f1e8');+}+// The Sun with block rays (g._rays turns).+function phSun(p, { x = 0, y = 0, r = 54 } = {}) {+ const g = G(p, { x, y });+ const rays = G(g);+ for (let i = 0; i < 12; i++) mk('rect', { x: r + 8, y: -4, width: 18, height: 8, fill: '#f6c445', transform: `rotate(${i * 30})` }, rays);+ mk('circle', { r, fill: '#f6c445', ...phLine() }, g);+ mk('circle', { cx: -r * .2, cy: -r * .2, r: r * .62, fill: '#f9d978', opacity: .7 }, g);+ g._rays = rays;+ return g;+}+// Small Earth seen from the side (for orbits).+function phEarthSmall(p, { x = 0, y = 0, r = 26 } = {}) {+ const g = G(p, { x, y });+ mk('circle', { r, fill: PH.ocean, ...phLine(2) }, g);+ [[-.55, -.45, .45, .35], [.05, .1, .5, .4], [-.45, .25, .3, .25]].forEach(([lx, ly, w, h]) => mk('rect', { x: lx * r, y: ly * r, width: w * r, height: h * r, fill: PH.land }, g));+ return g;+}+// Earth seen from far above the North Pole: the rim is the equator. One pixel image (img/earth.png, ocean included,+// turned so land is at the top of the rim); no SVG disc, which is slow in Firefox at close-up zoom.+// Rotate g._spin (degrees; negative = counterclockwise on screen).+function phEarthPolar(p, { x = 0, y = 0, R = 220 } = {}) {+ const g = G(p, { x, y }), spin = G(g);+ mk('image', { href: '../img/earth.png', x: -R, y: -R, width: 2 * R, height: 2 * R, style: 'image-rendering: pixelated' }, spin);+ g._spin = spin;+ return g;+}diff --git a/site/science/lib/physics.js b/site/science/lib/physics.jsnew file mode 100644index 0000000..441c5e3--- /dev/null+++ b/site/science/lib/physics.js@@ -0,0 +1,130 @@+// Papermorph science book: shared lesson helpers for physics chapters (load after engine.js and figures.js).+// Copied from ch09's chapter-local helpers (ch09 keeps its own copies, unchanged).+'use strict';+const txt = (p, s, x, y, t0, { size = 32, fill = COL.chalk, anchor = 'middle', weight = 600 } = {}) => { const e = T(p, s, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };+// One line with coloured runs: [[text, colour?], …].+function runs(p, parts, { x, y, size = 40, anchor = 'middle', weight = 600, o = 0 }) {+ const t = T(p, '', { x, y, size, anchor, weight, o });+ parts.forEach(([s, c]) => { const sp = mk('tspan', { fill: c || COL.chalk }, t); sp.textContent = s; });+ return t;+}+function arrowPath(x1, y, x2) { const d = Math.sign(x2 - x1); return `M${x1} ${y}H${x2}M${x2 - 16 * d} ${y - 11}L${x2} ${y}L${x2 - 16 * d} ${y + 11}`; }+const DIST = COL.rat, TIME = COL.whole; // distance pink (as "change of position" in part 1), time blue+const walkTo = (r, x, step = 22) => phPose(r, 'walk', x / step * Math.PI); // two frames per stride, from x+// A measured track: a bar with ticks every `every` meters from 0 to `to`, U px per meter.+function meterTrack(p, { x0, U, y, to, every, size = 26 }) {+ const g = G(p);+ phBlock(g, x0 - 20, y, U * to + 40, 14, '#8a6f55', { top: 4, ol: 0 });+ for (let v = 0; v <= to; v += every) {+ mk('rect', { x: x0 + U * v - 2, y: y + 14, width: 4, height: 14, fill: COL.dim }, g);+ T(g, String(v), { x: x0 + U * v, y: y + 56, size, fill: COL.chalk, anchor: 'middle' });+ }+ T(g, 'meters', { x: x0 + U * to + 36, y: y + 56, size: size - 2, fill: COL.dim });+ return g;+}+// A fraction in words or numbers (upright text, no math italics), centred on x with its bar at y.+function wfrac(p, top, bot, x, y, { size = 44, ct = COL.chalk, cb = COL.chalk, o = 0 } = {}) {+ const g = G(p, { x, y, o }), w = Math.max(uiW(top, size), uiW(bot, size)) + 24;+ T(g, top, { y: -size * .32, size, fill: ct, anchor: 'middle', weight: 600 });+ mk('rect', { x: -w / 2, y: -2, width: w, height: 4, rx: 2, fill: COL.chalk }, g);+ T(g, bot, { y: size * 1.02, size, fill: cb, anchor: 'middle', weight: 600 });+ g._w = w;+ return g;+}+// A sim clock: stopwatch plus "N s" under it; set(sec) turns the hand (one turn per minute) and writes whole seconds.+function simClock(p, x, y, r = 46) {+ const sw = phStopwatch(p, { x, y, r }), lab = T(p, '0 s', { x, y: y + r + 48, size: 32, weight: 700, fill: TIME, anchor: 'middle' });+ return { sw, lab, set(sec) { put(sw._hand, { r: sec * 6 }); phText(lab, `${Math.floor(sec + 1e-6)} s`); } };+}+const ramp = (t, a, b) => Math.min(1, Math.max(0, (t - a) / (b - a)));+const VEL = COL.int; // velocity arrows and readouts: yellow+// Set path el to an arrow from (x, y), len long, at angle a (degrees; 0 = right, −90 = up).+function arrowAt(el, x, y, len, a, head = 18) {+ const r = a * Math.PI / 180, c = Math.cos(r), s = Math.sin(r), x2 = x + len * c, y2 = y + len * s;+ el.setAttribute('d', len < 2 ? '' : `M${x} ${y}L${x2} ${y2}M${x2 - head * c - head * .6 * s} ${y2 - head * s + head * .6 * c}L${x2} ${y2}L${x2 - head * c + head * .6 * s} ${y2 - head * s - head * .6 * c}`);+ return el;+}+const ACC = '#ee6fd0'; // acceleration: magenta (velocity stays yellow)+const FORCE = '#ff7a45', NETF = COL.chalk; // forces: orange arrows; the net force: a thick white arrow+// 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 = '', side, dx = 0, dy = 0) {+ arrowAt(a, x, y, len, ang, 12 + w); phText(lab, len > 1 ? text : '');+ 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. 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: labelY, size: 30 });+ return g;+}++/* ---------- pixel actors (lib/actors.js, img/actor_<role>.png) ---------- */+// One sprite sheet per role; a frame is chosen by the viewBox of a nested <svg>, so swapping frames never refetches+// an image. The origin is the feet centre; face(-1) mirrors. Stride tables keep feet from skating: STEP is the+// distance (world px) the body moves per frame of each gait.+const STEP = { walk: 11, run: 26, push: 10, pull: 10, stumble: 14, backstep: 13 };+function phActor(p, role = 'you', { x = 0, y = 0, s = 1, o = 1, anim = 'stand' } = {}) {+ const A = ACTORS, w = A.W * PX, h = A.H * PX, rows = Object.keys(A.anims).length, cols = Math.max(...Object.values(A.anims).map(a => a.n));+ const g = G(p, { x, y, s, o }), inner = mk('g', {}, g);+ const sv = mk('svg', { x: -A.X0 * PX, y: -h, width: w, height: h, viewBox: `0 0 ${w} ${h}` }, inner);+ mk('image', { href: `../img/actor_${role}.png`, width: w * cols, height: h * rows, style: 'image-rendering: pixelated' }, sv);+ return Object.assign(g, {+ _dir: 1,+ // Show frame k (wrapped) of an animation.+ show(name, k = 0) {+ const a = A.anims[name], f = ((Math.floor(k) % a.n) + a.n) % a.n, vb = `${f * w} ${a.row * h} ${w} ${h}`;+ g._anim = name; g._f = f;+ if (sv._vb !== vb) sv.setAttribute('viewBox', sv._vb = vb);+ return g;+ },+ // A gait frame from the distance travelled, so the feet keep pace with the ground.+ stride(name, dist) { return g.show(name, Math.abs(dist) / STEP[name]); },+ face(dir) { if (dir !== g._dir) { g._dir = dir; if (dir < 0) inner.setAttribute('transform', 'scale(-1,1)'); else inner.removeAttribute('transform'); } return g; },+ // World position of a hand ('F' front, 'B' back) in the current frame.+ hand(which = 'F') { const st = g._st, [hx, hy] = A.anims[g._anim].hands[g._f][which]; return [st.x + hx * PX * st.s * g._dir, st.y + hy * PX * st.s]; },+ }).show(anim);+}+// Our bicycle with spinning SVG wheels and a pedalling rider: bike.ride(dist) turns wheels and cranks.+function phBike(p, role = 'you', o = {}) {+ const g = G(p, o), B = ACTORS.bike, w = ACTORS.W * PX, h = ACTORS.H * PX;+ const wheels = B.wheels.map(([wx, wy]) => {+ const wg = G(g, { x: wx * PX + PX / 2, y: wy * PX }), r = B.r * PX;+ mk('circle', { r, fill: 'none', stroke: '#2c3337', 'stroke-width': 7 }, wg);+ path(wg, `M${-r} 0H${r}M0 ${-r}V${r}`, { stroke: '#9aa5a8', 'stroke-width': 3 });+ return wg;+ });+ mk('image', { href: '../img/bicycle.png', x: -ACTORS.X0 * PX, y: -h, width: w, height: h, style: 'image-rendering: pixelated' }, g);+ const rider = phActor(g, role, { anim: 'pedal' });+ return Object.assign(g, { ride(dist) { const r = B.r * PX; wheels.forEach(wg => put(wg, { r: dist / r * 180 / Math.PI })); rider.show('pedal', dist / (2 * Math.PI * r * 1.5) * 8); return g; } });+}diff --git a/site/science/unit-art.js b/site/science/unit-art.jsnew file mode 100644index 0000000..a4cebf0--- /dev/null+++ b/site/science/unit-art.js@@ -0,0 +1,23 @@+// Chalk sketches for the unit headers on the contents page, one per unit, drawn in the unit's colour.+// Each entry is the inside of an SVG with viewBox 0 0 600 180; keep the left ~200 px light (the unit title sits there+// on narrow screens). Classes, styled in book.html:+// d a stroke that draws itself in when the unit scrolls into view (--k orders the strokes)+// t text or a filled shape that fades in+// a faint chalk white instead of the unit colour; faint even fainter+// A sketch may add one looping motion after it is drawn: give an element a class and add a .seen .unit-art .NAME+// rule with its keyframes in book.html (see the examples there: swap-a, hop, spin, tilt, breathe, ...).+'use strict';+(() => {+ let k = 0;+ const P = (d, cls = '', extra = '') => `<path class="d ${cls}" pathLength="1" style="--k:${k++}" d="${d}" ${extra}/>`;+ const Tx = (x, y, s, size = 24, cls = '', anchor = 'start') => `<text class="t ${cls}" style="--k:${k++}" x="${x}" y="${y}" font-size="${size}" text-anchor="${anchor}">${s}</text>`;+ const C = (cx, cy, r, cls = '') => `<circle class="d ${cls}" pathLength="1" style="--k:${k++}" cx="${cx}" cy="${cy}" r="${r}"/>`;+ const reset = s => { k = 0; return s; };++ window.UNIT_ART = [+ // Unit 3 (motion, forces, work): a road with a car-dot speeding along it, and speed = distance ÷ time.+ reset(P('M228 130H572') + Array.from({ length: 7 }, (_, i) => P(`M${250 + i * 50} 122v16`, 'a')).join('') ++ `<circle class="t hop" r="8" fill="currentColor" stroke="none" style="--k:${k++};offset-path:path('M250 116Q275 84 300 116Q325 84 350 116Q375 84 400 116')"/>` ++ Tx(250, 60, 'speed = distance ÷ time', 26) + P('M480 70h70m-14 -10l14 10l-14 10', 'a')),+ ];+})();