An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(linear-algebra): chapters 4-7, vecs.js, a playground in every chapter
yzra225ffac277c
diff --git a/site/linear-algebra/ch01/audio/en/play.mp3 b/site/linear-algebra/ch01/audio/en/play.mp3new file mode 100644index 0000000..704877eBinary files /dev/null and b/site/linear-algebra/ch01/audio/en/play.mp3 differdiff --git a/site/linear-algebra/ch01/audio/en/timings.js b/site/linear-algebra/ch01/audio/en/timings.jsindex 3f31001..e2cfd5f 100644--- a/site/linear-algebra/ch01/audio/en/timings.js+++ b/site/linear-algebra/ch01/audio/en/timings.js@@ -713,6 +713,30 @@ window.TIMINGS = {]]},+ "play": {+ "dur": 11.424,+ "marks": {+ "go": 3.958+ },+ "cues": [+ [+ 0.104,+ "Playground."+ ],+ [+ 1.094,+ "Nothing here is marked right or wrong."+ ],+ [+ 3.958,+ "Change the numbers, drag the line, draw on the board if you like, and see what moves."+ ],+ [+ 9.688,+ "Press continue when you're done."+ ]+ ]+ },"finish": {"dur": 8.424,"marks": {},diff --git a/site/linear-algebra/ch01/index.html b/site/linear-algebra/ch01/index.htmlindex dbdd65b..0f61359 100644--- a/site/linear-algebra/ch01/index.html+++ b/site/linear-algebra/ch01/index.html@@ -11,6 +11,7 @@<script src="../lib/engine.js"></script><script src="../lib/math.js"></script><script src="../lib/linsys.js"></script>+<script src="../lib/play.js"></script><script src="audio/en/timings.js"></script><script>'use strict';@@ -431,6 +432,13 @@ const BEATS = [build: (body, api) => { targets([[3, 0, 14, 56], [0, -1, 16, 34]]); return lsTask(S.sys, v => v.b0 !== 0 && 3 * v.a00 === v.b0 && -v.a01 === v.b0, 'x − 3y = 3: (3, 0) gives 3, and (0, −1) gives 3.','Both points must give the same right side. (3, 0) gives 3 times the x number; (0, −1) gives minus the y number.', () => S.sys.set({ a00: 1, a01: -3, b0: 3 }))(body, api); },}], done, 'Chapter practice · set 4 of 4') }],+ ['play', 'Playground', (m) => {+ const p = panel(0);+ text(p, 'Playground', 60, 110, .2, { size: 40, weight: 600 });+ S.sys = oneLine(p, 2, -1, 0);+ const hint = text(p, 'try: make it flat, make it pass through (0, 0), make it steep', 90, 330, m('go'), { size: 28, fill: COL.dim });+ hide(hint, m('go') + 6, .6);+ }, { ask: playAsk(() => S.sys, { tip: 'Your line. Change any number, drag the line, or draw on the board. Nothing is marked.' }) }],['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));diff --git a/site/linear-algebra/ch06/index.html b/site/linear-algebra/ch06/index.htmlindex 671dd46..3701f69 100644--- a/site/linear-algebra/ch06/index.html+++ b/site/linear-algebra/ch06/index.html@@ -26,9 +26,34 @@ const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start',const showRow = (r, t0, from = 0, to = r.parts.length, dur = .5) => r.parts.slice(from, to).forEach(e => show(e, t0, dur));const thick = (vs, id, t0, w = 5) => { tw(vs.A[id].path, { 'a_stroke-width': w + 4 }, t0, .3); tw(vs.A[id].path, { 'a_stroke-width': w }, t0 + .7, .4); };const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;+// A curved arrow from one number to another, arched over (up) or under the row: "this one goes there".+const centre = e => { const b = e.getBBox(); return [b.x + b.width / 2, b.y + b.height / 2, b.height]; };+const curve = (p, a, b, t0, { color = COL.task, up = true, dur = .7 } = {}) => {+ const [ax, ay, ah] = centre(a), [bx, by, bh] = centre(b), sy = up ? -1 : 1;+ const y0 = ay + sy * ah * .6, y1 = by + sy * bh * .6, top = (up ? Math.min(y0, y1) : Math.max(y0, y1)) + sy * 36;+ const e = path(p, `M${ax} ${y0}C${ax} ${top} ${bx} ${top} ${bx} ${y1}`, { stroke: color, 'stroke-width': 3, fill: 'none', 'stroke-linecap': 'round' }, { d: 0 });+ draw(e, t0, dur);+ return e;+};+const boxAround = (p, els, t0, color = COL.task) => {+ const bs = els.map(e => e.getBBox()), x = Math.min(...bs.map(b => b.x)) - 10, y = Math.min(...bs.map(b => b.y)) - 6;+ const w = Math.max(...bs.map(b => b.x + b.width)) + 10 - x, hh = Math.max(...bs.map(b => b.y + b.height)) + 6 - y;+ const r = path(p, `M${x + 10} ${y}H${x + w - 10}Q${x + w} ${y} ${x + w} ${y + 10}V${y + hh - 10}Q${x + w} ${y + hh} ${x + w - 10} ${y + hh}H${x + 10}Q${x} ${y + hh} ${x} ${y + hh - 10}V${y + 10}Q${x} ${y} ${x + 10} ${y}Z`, { stroke: color, 'stroke-width': 3, fill: 'none' }, { d: 0 });+ draw(r, t0, .8);+ return r;+};+// The two top numbers flow into the top of the sum, the two bottom numbers into its bottom.+const sumLinks = (p, vs, tTop, tBot, tBox) => {+ const g = G(p, {}), n = k => vs.num(k)[0];+ curve(g, n('cv0'), n('sum0'), tTop, { color: GREEN }); curve(g, n('dw0'), n('sum0'), tTop + .8, { color: VIOLET });+ curve(g, n('cv1'), n('sum1'), tBot, { color: GREEN, up: false }); curve(g, n('dw1'), n('sum1'), tBot + .8, { color: VIOLET, up: false });+ if (tBox !== undefined) boxAround(g, [n('sum0'), n('sum1')], tBox);+ return g;+};// "2v − w", "v + w", "0": the combination's name from c and d.const comboLabel = vs => v => {const term = (k, n) => k === 1 ? n : k === -1 ? '−' + n : vs.fmt(k) + n;+ if (!vs.nice(v.c) || !vs.nice(v.d)) return [];if (!v.c && !v.d) return ['0'];if (!v.d) return [term(v.c, 'v')];if (!v.c) return [term(v.d, 'w')];@@ -127,7 +152,8 @@ const BEATS = [vs.flash('cv0', m('add') + .6); vs.flash('dw0', m('add') + 1.4); vs.flash('sum0', m('add') + 2.4);vs.flash('cv1', m('addb') + .4); vs.flash('dw1', m('addb') + 1); vs.flash('sum1', m('addb') + 1.8);vs.flash('sum0', m('res') + .4); vs.flash('sum1', m('res') + .4);- vs.dim(['v', 'w'], m('pic'), .25);+ const lk = sumLinks(p, vs, m('add') + .5, m('addb') + .3, m('res') + .2); hide(lk, m('name') - .3, .4);+ vs.dim(['v', 'w'], m('pic'), .25); hide(vs.A.v.lab, m('pic'), .3); hide(vs.A.w.lab, m('pic'), .3);vs.show('cv', m('pic') + .2, .6);slideIn(vs, 'dw', LV, m('pic2') + .1, 1.6);vs.show('sum', m('end'), .6);@@ -150,6 +176,9 @@ const BEATS = [const [f0, f1] = vs.num('fn');lightUp(f0, m('t') + .2); vs.flash('sum0', m('t') + 4.2);lightUp(f1, m('b') + .2); vs.flash('sum1', m('b') + 4.4);+ const lk = G(p, {});+ curve(lk, f0, vs.num('sum0')[0], m('t') + 3.8); curve(lk, f1, vs.num('sum1')[0], m('b') + 4, { up: false });+ boxAround(lk, [vs.num('sum0')[0], vs.num('sum1')[0]], m('r') + .1); hide(lk, m('c3') - .2, .4);vs.P.dot(3, 0, COL.task, m('r'), { r: 8, into: dots });vs.to({ c: -1, d: 1 }, m('c3'), 1.4); vs.flash('c', m('c3')); vs.flash('d', m('c3') + .6);lightUp(f0, m('t3')); vs.flash('sum0', m('t3') + 1.6);@@ -213,12 +242,19 @@ const BEATS = [vs.label('sum', v => whole(v) ? lab(v) : []);line1(vs, 240, 1); line2(vs, 420, 1);const ring = ringAt(vs.P, 0, 3, m('target'), p);- vs.P.dot(0, 0, COL.task, m('start'), { r: 8 });+ pulse(ring, m('ask') + .3, 1.6); pulse(ring, m('ask') + 1.4, 1.6);+ ['c', 'd'].forEach(k => vs.flash(k, m('ask') + .8));+ const o = vs.P.dot(0, 0, COL.task, m('start'), { r: 8 }); pulse(o, m('start') + .6, 1.8);+ vs.to({ c: .5 }, m('start') + 1.6, .8); vs.to({ c: 0 }, m('start') + 2.6, .8); // a first nudge: c moves the tip along vvs.to({ c: 1 }, m('up'), 1.2); vs.flash('c', m('up'));vs.to({ d: 1 }, m('d1'), 1); vs.flash('d', m('d1'));vs.to({ d: 2 }, m('d2'), 1); vs.flash('d', m('d2'));pulse(ring, m('hit') + .2, 1.5); vs.flash('c', m('hit') + .6); vs.flash('d', m('hit') + .6);hide(ring, m('drag'), .4);+ thick(vs, 'sum', m('hit') + 1.6, 6); thick(vs, 'cv', m('hit') + 2.6); thick(vs, 'dw', m('hit') + 3.4);+ const grab = G(p, { x: vs.P.PX(0), y: vs.P.PY(3), o: 0 });+ mk('circle', { r: 16, fill: 'none', stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '4 4' }, grab);+ show(grab, m('turn') + .4, .3); pulse(grab, m('turn') + 1, 1.6); pulse(grab, m('turn') + 2.2, 1.6); hide(grab, m('drag'), .2);vs.solve(true);handPath(p, vs, [[0, 3], [3, 0]], m('drag'), 2.2);vs.flash('c', m('p30') + .2); vs.flash('d', m('p30') + .2);@@ -264,7 +300,7 @@ const BEATS = [vs.show(['cv', 'dw', 'sum'], m('roam') - .3, .4);vs.solve(true);vs.to({ c: 1, d: 1 }, .1, .01);- handPath(p, vs, [[1, 1], [3, 3], [-4, 1], [2, -5], [5, 2]], m('roam') + .2, 1.6);+ handPath(p, vs, [[1, 1], [3, 3], [-4, 1], [2, -5], [5, 2], [-2, 5], [-5, -4], [0, 0]], m('roam') + .2, 1.7);const all = path(p, `M${vs.P.PX(-6)} ${vs.P.PY(6)}H${vs.P.PX(6)}V${vs.P.PY(-6)}H${vs.P.PX(-6)}Z`, { fill: COL.task, stroke: 'none' }, { o: 0 });vs.P.g.insertBefore(all, vs.P.g.lastChild);tw(all, { o: .12 }, m('plane'), 1);@@ -276,6 +312,7 @@ const BEATS = [text(p, 'Count the steps: along v, then along w', 60, 110, .2, { size: 40, weight: 600 });const vs = lecture(p, { c: 0, d: 0, show: ['cv', 'dw', 'sum'] });vs.lattice(.3, true, .6);+ vs.label('sum', []); // the ring names the targetline1(vs, 240, 1); line2(vs, 420, 1);const go = (x, y, c, d, t0, tc, td, marks) => {const ring = ringAt(vs.P, x, y, t0, marks);@@ -287,8 +324,10 @@ const BEATS = [const r1 = go(1, 4, 2, 3, m('t'), m('sv') + .9, m('sw') + .9, m1);pulse(r1, m('there') + .2, 1.5);vs.flash('c', m('read') + .6); vs.flash('d', m('read') + 2.2);+ thick(vs, 'cv', m('read') + .6); thick(vs, 'dw', m('read') + 2.2);vs.flash('sum0', m('check') + .4); vs.flash('sum1', m('check') + 3.4);- hide(m1, m('t2') - .2, .4);+ const lk = sumLinks(p, vs, m('check') + 1, m('check') + 4, m('check') + 6.5);+ hide(m1, m('t2') - .2, .4); hide(lk, m('t2') - .2, .4);vs.to({ c: 0, d: 0 }, m('t2') - .2, .6);const m2 = G(p, {});go(-1, 5, 1, 3, m('t2'), m('s2') + .2, m('s3') + .4, m2);@@ -302,7 +341,8 @@ const BEATS = [vs.row([{ t: 'v', fill: GREEN }, '=', { col: 'v', fixed: true }, ' ', { t: 'w', fill: VIOLET }, '=', { col: 'w', fixed: true }], { x: 70, y: 240, size: 42 });vs.lattice(.3, true, .6);vs.to({ w0: 4, w1: -2 }, m('turn') + .3, m('par') - m('turn') - .3, lin);- say(p, ['w = 2v'], 70, 420, m('par'), { size: 44, fill: VIOLET });+ const w2 = say(p, ['w = 2v'], 70, 420, m('par'), { size: 44, fill: VIOLET }); hide(w2, m('rule'), .3);+ vs.to({ w0: -1, w1: 2 }, m('rule') + .3, 1.6); vs.to({ w0: 4, w1: -2 }, m('rule') + 4, 1.8);text(p, 'the grid squashes flat', 70, 480, m('squash'), { size: 28, fill: COL.dim });text(p, 'every combination: on one line', 70, 530, m('line'), { size: 30, fill: COL.task, weight: 600 });const miss = ringAt(vs.P, 0, 3, m('miss'), p, COL.bad);@@ -353,13 +393,20 @@ const BEATS = [}, { ask: done => quiz(CARD, STEER.map(([x, y], i) => ({id: `p-steer${i + 1}`, prompt: ['Change ', $m('c'), ' and ', $m('d'), ' until ', $m('c v + d w'), ' lands on ', $m(pairStr(x, y)), '.'],build: (body, api) => {- S.vs.set({ c: 1, d: 1 }); S.q6?.remove(); S.q6 = ringAt(S.vs.P, x, y, 0, S.vs.stage); fx(S.q6, { o: 1 }, 0, .3);+ S.vs.solve(false); S.vs.set({ c: 1, d: 1 }); S.q6?.remove(); S.q6 = ringAt(S.vs.P, x, y, 0, S.vs.stage); fx(S.q6, { o: 1 }, 0, .3);const s = S.vs.solveFor(x, y);return vsTask(S.vs, (v, k) => k.sum[0] === x && k.sum[1] === y, `c = ${num(s.c)}, d = ${num(s.d)}.`,(v, k) => `You are at ${pairStr(k.sum[0], k.sum[1])}. c moves the tip along v (2 right, 1 down), d along w (1 left, 2 up).`,() => S.vs.set(s), { drag: ['cv', 'dw'] })(body, api);},- })), done, 'Chapter practice · set 4 of 4') }],+ })).concat([[-2, 4, 'c = 0, d = 2: the target is just 2w.'], [0, 1, 'c = 1/3, d = 2/3: fractions, and that is fine.']].map(([x, y, why], i) => ({+ id: `p-solve${i + 1}`, prompt: ['Now drag the tip of the combination itself to ', $m(pairStr(x, y)), ', and watch ', $m('c'), ' and ', $m('d'), ' follow.'],+ build: (body, api) => {+ S.vs.solve(true); S.vs.set({ c: 1, d: 1 }); S.q6?.remove(); S.q6 = ringAt(S.vs.P, x, y, 0, S.vs.stage); fx(S.q6, { o: 1 }, 0, .3);+ return vsTask(S.vs, (v, k) => Math.abs(k.sum[0] - x) < 1e-9 && Math.abs(k.sum[1] - y) < 1e-9, why,+ (v, k) => `The tip is at ${pairStr(k.sum[0], k.sum[1])}. Drag the amber tip onto the ring.`, () => S.vs.set(S.vs.solveFor(x, y)), { drag: ['sum'] })(body, api);+ },+ }))), done, 'Chapter practice · set 4 of 4') }],['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));diff --git a/site/linear-algebra/ch07/audio/en/both.mp3 b/site/linear-algebra/ch07/audio/en/both.mp3new file mode 100644index 0000000..e0b7148Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/both.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/cols.mp3 b/site/linear-algebra/ch07/audio/en/cols.mp3new file mode 100644index 0000000..8b40fddBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/cols.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/final1.mp3 b/site/linear-algebra/ch07/audio/en/final1.mp3new file mode 100644index 0000000..fdfdeffBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/final1.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/final2.mp3 b/site/linear-algebra/ch07/audio/en/final2.mp3new file mode 100644index 0000000..7b6d5e2Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/final2.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/final3.mp3 b/site/linear-algebra/ch07/audio/en/final3.mp3new file mode 100644index 0000000..b51021cBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/final3.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/final4.mp3 b/site/linear-algebra/ch07/audio/en/final4.mp3new file mode 100644index 0000000..adb9e7bBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/final4.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/finish.mp3 b/site/linear-algebra/ch07/audio/en/finish.mp3new file mode 100644index 0000000..0433836Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/finish.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/intro.mp3 b/site/linear-algebra/ch07/audio/en/intro.mp3new file mode 100644index 0000000..55e03bfBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/intro.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/linkb.mp3 b/site/linear-algebra/ch07/audio/en/linkb.mp3new file mode 100644index 0000000..e343a64Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/linkb.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/mix.mp3 b/site/linear-algebra/ch07/audio/en/mix.mp3new file mode 100644index 0000000..671006eBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/mix.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/more.mp3 b/site/linear-algebra/ch07/audio/en/more.mp3new file mode 100644index 0000000..1a3018aBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/more.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/q1.mp3 b/site/linear-algebra/ch07/audio/en/q1.mp3new file mode 100644index 0000000..1035c20Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/q1.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/q2.mp3 b/site/linear-algebra/ch07/audio/en/q2.mp3new file mode 100644index 0000000..42c9e36Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/q2.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/q3.mp3 b/site/linear-algebra/ch07/audio/en/q3.mp3new file mode 100644index 0000000..f337fb6Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/q3.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/rows.mp3 b/site/linear-algebra/ch07/audio/en/rows.mp3new file mode 100644index 0000000..5b0d089Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/rows.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/second.mp3 b/site/linear-algebra/ch07/audio/en/second.mp3new file mode 100644index 0000000..d41d87dBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/second.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/timings.js b/site/linear-algebra/ch07/audio/en/timings.jsnew file mode 100644index 0000000..9542bd6--- /dev/null+++ b/site/linear-algebra/ch07/audio/en/timings.js@@ -0,0 +1,593 @@+window.TIMINGS = {+ "intro": {+ "dur": 8.88,+ "marks": {+ "sub": 2.695,+ "down": 6.003+ },+ "cues": [+ [+ 0.104,+ "Chapter seven."+ ],+ [+ 1.315,+ "The column picture."+ ],+ [+ 2.695,+ "The same two equations, read a new way: not across the rows, but down the columns."+ ]+ ]+ },+ "rows": {+ "dur": 21.72,+ "marks": {+ "e1": 2.331,+ "e2": 4.883,+ "row": 8.281,+ "meet": 10.352,+ "ans": 13.711,+ "name": 16.458+ },+ "cues": [+ [+ 0.13,+ "Here's our system from chapter two."+ ],+ [+ 2.331,+ "Two x minus y equals zero, and minus x plus two y equals three."+ ],+ [+ 8.281,+ "Each equation is a line."+ ],+ [+ 10.352,+ "The lines meet at one point: one, two."+ ],+ [+ 13.711,+ "So x is one, and y is two."+ ],+ [+ 16.458,+ "This way of seeing a system, one line for each row, is called the row picture."+ ]+ ]+ },+ "cols": {+ "dur": 57.0,+ "marks": {+ "xcol": 2.344,+ "xvec": 7.865,+ "ycol": 13.633,+ "yvec": 16.888,+ "bcol": 19.466,+ "eq": 24.909,+ "why": 32.188,+ "top": 33.815,+ "bot": 43.659,+ "same": 53.685+ },+ "cues": [+ [+ 0.104,+ "Now read the same numbers downward."+ ],+ [+ 2.344,+ "Look at the numbers in front of x: two in the first equation, minus one in the second."+ ],+ [+ 7.865,+ "Stand them up, and they make a column, a vector: two, minus one."+ ],+ [+ 13.633,+ "The numbers in front of y are minus one and two."+ ],+ [+ 16.888,+ "Another column: minus one, two."+ ],+ [+ 19.466,+ "And the right sides, zero and three, make a third column."+ ],+ [+ 23.867,+ "We call it b."+ ],+ [+ 24.909,+ "Now the whole system is one equation: x times the first column, plus y times the second column, equals b."+ ],+ [+ 32.188,+ "Why is that the same thing?"+ ],+ [+ 33.815,+ "Work out the top numbers: x times two, plus y times minus one."+ ],+ [+ 38.19,+ "That's two x minus y, and it must equal zero: the first equation."+ ],+ [+ 43.659,+ "Now the bottom numbers: x times minus one, plus y times two."+ ],+ [+ 47.773,+ "That's minus x plus two y, and it must equal three: the second equation."+ ],+ [+ 53.685,+ "The same two equations, packed into columns."+ ]+ ]+ },+ "mix": {+ "dur": 39.792,+ "marks": {+ "seen": 1.979,+ "ch6": 3.307,+ "found": 14.609,+ "here": 17.734,+ "mixit": 25.938,+ "plus": 30.872,+ "lands": 32.63,+ "name": 34.635+ },+ "cues": [+ [+ 0.091,+ "Look closely at that equation."+ ],+ [+ 1.979,+ "You've seen it before."+ ],+ [+ 3.307,+ "In chapter six, v was two, minus one, w was minus one, two, and we looked for c and d with c v plus d w equal to zero, three."+ ],+ [+ 14.609,+ "We found c equals one and d equals two."+ ],+ [+ 17.734,+ "Here the columns are v and w, the unknowns x and y play the parts of c and d, and b is the target."+ ],+ [+ 25.938,+ "So x equals one and y equals two: one of the first column, plus two of the second, lands exactly on b."+ ],+ [+ 34.635,+ "This is the column picture."+ ],+ [+ 36.302,+ "The solution is the mix of the columns that makes b."+ ]+ ]+ },+ "both": {+ "dur": 21.576,+ "marks": {+ "left": 2.318,+ "right": 6.706,+ "same": 12.682,+ "point": 16.198,+ "amounts": 17.956+ },+ "cues": [+ [+ 0.091,+ "Let's put the two pictures side by side."+ ],+ [+ 2.318,+ "On the left, the row picture: two lines, meeting at one, two."+ ],+ [+ 6.706,+ "On the right, the column picture: one of column one, plus two of column two, reaching b."+ ],+ [+ 12.682,+ "The same two numbers, one and two, answer both."+ ],+ [+ 16.198,+ "In the row picture they're a point."+ ],+ [+ 17.956,+ "In the column picture they're amounts: how much of each column."+ ]+ ]+ },+ "more": {+ "dur": 45.672,+ "marks": {+ "a": 2.591,+ "ax": 7.513,+ "ay": 10.365,+ "ab": 13.698,+ "acheck": 16.198,+ "acheck2": 24.883,+ "b": 28.307,+ "bx": 33.841,+ "by": 40.625,+ "bb": 43.633+ },+ "cues": [+ [+ 0.104,+ "Two more, to practise reading down."+ ],+ [+ 2.591,+ "x plus four y equals nine, and three x minus y equals one."+ ],+ [+ 7.513,+ "In front of x: one, and three."+ ],+ [+ 10.365,+ "In front of y: four, and minus one."+ ],+ [+ 13.698,+ "The right sides: nine and one."+ ],+ [+ 16.198,+ "Try x equals one and y equals two."+ ],+ [+ 19.401,+ "One of column one, plus two of column two: one plus eight is nine, and three minus two is one."+ ],+ [+ 27.331,+ "That's b."+ ],+ [+ 28.307,+ "Now: y equals two, and x minus three y equals zero."+ ],+ [+ 33.841,+ "The first equation has no x, so its x number is zero."+ ],+ [+ 38.086,+ "The x column is zero, one."+ ],+ [+ 40.625,+ "The y column is one, minus three."+ ],+ [+ 43.633,+ "And b is two, zero."+ ]+ ]+ },+ "q1": {+ "dur": 3.504,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.12,+ "Read this system down its columns."+ ]+ ]+ },+ "linkb": {+ "dur": 39.264,+ "marks": {+ "change": 1.732,+ "to30": 3.945,+ "rows": 5.951,+ "cols": 10.885,+ "agree": 16.706,+ "to11": 19.036,+ "ag2": 20.456,+ "drag": 25.417,+ "pull": 28.229,+ "ag3": 30.69+ },+ "cues": [+ [+ 0.104,+ "The two pictures are linked."+ ],+ [+ 1.732,+ "Change the right side, b."+ ],+ [+ 3.945,+ "Make b three, zero."+ ],+ [+ 5.951,+ "On the left, both lines slide, and now they meet at two, one."+ ],+ [+ 10.885,+ "On the right, b moves, and the mix becomes two of column one plus one of column two."+ ],+ [+ 16.706,+ "Two, one, in both pictures."+ ],+ [+ 19.036,+ "Make b one, one."+ ],+ [+ 20.456,+ "The lines meet at one, one, and one of each column reaches b."+ ],+ [+ 25.417,+ "Or drag b in the column picture."+ ],+ [+ 28.229,+ "Pull it to minus three, three."+ ],+ [+ 30.69,+ "The mix becomes minus one of column one, plus one of column two, and on the left the lines move to meet at minus one, one."+ ]+ ]+ },+ "q2": {+ "dur": 7.92,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Your turn."+ ],+ [+ 1.016,+ "Move b, in either picture, until the solution is x equals three, y equals two."+ ]+ ]+ },+ "second": {+ "dur": 32.784,+ "marks": {+ "e": 3.229,+ "cols": 7.513,+ "rowp": 15.56,+ "colp": 19.18,+ "two": 23.841,+ "sum": 26.979,+ "same": 30.182+ },+ "cues": [+ [+ 0.104,+ "A second system: the riddle from chapter two."+ ],+ [+ 3.229,+ "x plus y equals five, and x minus y equals one."+ ],+ [+ 7.513,+ "Down the columns: the x column is one, one."+ ],+ [+ 10.846,+ "The y column is one, minus one."+ ],+ [+ 13.607,+ "And b is five, one."+ ],+ [+ 15.56,+ "In the row picture, the lines meet at three, two."+ ],+ [+ 19.18,+ "In the column picture: three of column one is three, three."+ ],+ [+ 23.841,+ "Two of column two is two, minus two."+ ],+ [+ 26.979,+ "Add them: five, one."+ ],+ [+ 29.154,+ "That's b."+ ],+ [+ 30.182,+ "Three and two, in both pictures."+ ]+ ]+ },+ "which": {+ "dur": 27.072,+ "marks": {+ "e": 2.721,+ "cols": 8.073,+ "colp": 13.672,+ "miss": 15.677,+ "rowp": 19.74,+ "both": 24.648+ },+ "cues": [+ [+ 0.104,+ "What if the two columns point the same way?"+ ],+ [+ 2.721,+ "Take x plus two y equals three, and two x plus four y equals five."+ ],+ [+ 8.073,+ "The columns are one, two, and two, four."+ ],+ [+ 11.237,+ "The second is twice the first."+ ],+ [+ 13.672,+ "All their mixes lie on one line, and b, three, five, is off that line."+ ],+ [+ 18.372,+ "No mix reaches it."+ ],+ [+ 19.74,+ "The row picture says the same: the two lines are parallel, and never meet."+ ],+ [+ 24.648,+ "No solution, seen two ways."+ ]+ ]+ },+ "q3": {+ "dur": 2.784,+ "marks": {},+ "cues": [+ [+ 0.091,+ "Quick check."+ ],+ [+ 1.12,+ "Find the mix that makes b."+ ]+ ]+ },+ "wrap": {+ "dur": 26.256,+ "marks": {+ "w1": 0.99,+ "w2": 9.141,+ "w3": 14.688,+ "w4": 21.224,+ "end": 24.036+ },+ "cues": [+ [+ 0.104,+ "To sum up."+ ],+ [+ 0.99,+ "Reading a system down its columns gives one vector equation: x times column one, plus y times column two, equals b."+ ],+ [+ 9.141,+ "The row picture draws one line per equation; the solution is where they meet."+ ],+ [+ 14.688,+ "The column picture draws one arrow per column; the solution is the mix that reaches b."+ ],+ [+ 21.224,+ "Both pictures always give the same answer."+ ],+ [+ 24.036,+ "Now try the chapter practice."+ ]+ ]+ },+ "final1": {+ "dur": 4.104,+ "marks": {},+ "cues": [+ [+ 0.117,+ "Chapter practice."+ ],+ [+ 1.536,+ "Read each system down its columns."+ ]+ ]+ },+ "final2": {+ "dur": 1.992,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Now find the mix that makes b."+ ]+ ]+ },+ "final3": {+ "dur": 1.872,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Is this the right mix?"+ ]+ ]+ },+ "final4": {+ "dur": 4.536,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Last set."+ ],+ [+ 1.302,+ "Move b until the solution is the one asked for."+ ]+ ]+ },+ "finish": {+ "dur": 8.328,+ "marks": {},+ "cues": [+ [+ 0.104,+ "Well done."+ ],+ [+ 1.055,+ "That's the end of chapter seven, the column picture."+ ],+ [+ 4.167,+ "Next: we stand the columns side by side, and get a matrix."+ ]+ ]+ }+};diff --git a/site/linear-algebra/ch07/audio/en/which.mp3 b/site/linear-algebra/ch07/audio/en/which.mp3new file mode 100644index 0000000..f3cab51Binary files /dev/null and b/site/linear-algebra/ch07/audio/en/which.mp3 differdiff --git a/site/linear-algebra/ch07/audio/en/wrap.mp3 b/site/linear-algebra/ch07/audio/en/wrap.mp3new file mode 100644index 0000000..f878aeeBinary files /dev/null and b/site/linear-algebra/ch07/audio/en/wrap.mp3 differdiff --git a/site/linear-algebra/ch07/index.html b/site/linear-algebra/ch07/index.htmlnew file mode 100644index 0000000..9385af5--- /dev/null+++ b/site/linear-algebra/ch07/index.html@@ -0,0 +1,425 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<title>The Column Picture</title>+<link rel="stylesheet" href="../lib/engine.css">+<link rel="expect" href="#bar" blocking="render"><!-- hold the first frame until the player exists, so the page transition can run -->+</head>+<body>+<script src="../lib/engine.js"></script>+<script src="../lib/math.js"></script>+<script src="../lib/linsys.js"></script>+<script src="../lib/vecs.js"></script>+<script src="audio/en/timings.js"></script>+<script>+'use strict';+const CHAPTER = { number: 7, title: 'The Column Picture', minutes: 10, language: 'en' };++/* ---------- chapter drawing helpers ---------- */+const [GREEN, VIOLET] = VS_COL; // column 1 green, column 2 violet, b amber (style.json)+const [BLUE, CORAL] = LS_ROW; // row 1 blue, row 2 coral+const LA = [[2, -1], [-1, 2]], LB = [0, 3]; // the lecture's system+const CARD = { x: 40, y: 320, w: 720, cls: 'side' };+const TOPCARD = { x: 840, y: 120, w: 720, cls: 'side' }; // over the column equation in the side-by-side layout+const say = (p, parts, x, y, t0, { size = 40, fill = COL.chalk, anchor = 'start' } = {}) => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };+const text = (p, str, x, y, t0, { size = 30, fill = COL.chalk, anchor = 'start', weight = 500 } = {}) => { const e = T(p, str, { x, y, size, fill, anchor, weight, o: 0 }); show(e, t0); return e; };+const showRow = (r, t0, from = 0, to = r.parts.length, dur = .5) => r.parts.slice(from, to).forEach(e => show(e, t0, dur));+const thick = (vs, id, t0, w = 5) => { tw(vs.A[id].path, { 'a_stroke-width': w + 4 }, t0, .3); tw(vs.A[id].path, { 'a_stroke-width': w }, t0 + .7, .4); };+const pairStr = (x, y) => `(${num(x)}, ${num(y)})`;+const lightUp = (e, t0, base = COL.chalk) => { tw(e, { c_color: COL.task }, t0, .25); tw(e, { c_color: base }, t0 + 1.2, .6); };+const flashLs = (sys, key, t0) => sys.num(key).forEach(e => { tw(e, { c_fill: COL.task }, t0, .25); tw(e, { c_fill: COL.chalk }, t0 + 1.2, .6); });+const rbox = (p, x, y, w, h, color, t0) => { const r = path(p, `M${x + 12} ${y}H${x + w - 12}Q${x + w} ${y} ${x + w} ${y + 12}V${y + h - 12}Q${x + w} ${y + h} ${x + w - 12} ${y + h}H${x + 12}Q${x} ${y + h} ${x} ${y + h - 12}V${y + 12}Q${x} ${y} ${x + 12} ${y}Z`, { stroke: color, 'stroke-width': 3, fill: 'none' }, { d: 0 }); draw(r, t0, .8); return r; };+// The column picture of a system: its columns as v (column 1) and w (column 2), x and y as c and d, the mix 'sum' = b.+const colPic = (p, A, opts = {}) => {+ const vs = vecs(p, { vecs: { v: [A[0][0], A[1][0]], w: [A[0][1], A[1][1]] }, show: ['v', 'w', 'cv', 'dw', 'sum'], ...opts });+ vs.label('v', ['col 1']); vs.label('w', ['col 2']); vs.label('sum', ['b']); vs.label('cv', []); vs.label('dw', []);+ return vs;+};+// x [col 1] + y [col 2] = [b], and below it the amounts: 1 [col 1] + 2 [col 2] = [b]+const colEq = (vs, x, y, size = 40, o = 1) => vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x, y, size, o });+const colAmt = (vs, x, y, size = 40, o = 1) => vs.row([{ key: 'c' }, { col: 'v', fixed: true }, { key: 'd', signed: true }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x, y, size, o });+// Row picture (linsys, left) and column picture (vecs, right) of one system, linked both ways:+// change the system or b on the left and the mix follows on the right; drag b on the right and the lines follow.+const twin = (p, A, b, { t0 = .1, rows = true } = {}) => {+ const sys = linsys(p, { A, b, mat: null, eq: [110, 190], size: 46, plane: { cx: 420, cy: 625, u: 28, step: 2 }, t0 });+ const s0 = sys.solve();+ const vs = colPic(p, A, { c: s0.x ?? 0, d: s0.y ?? 0, plane: { cx: 1180, cy: 625, u: 28, step: 2 }, labelSize: 24, t0 });+ vs.solve(true);+ const r6 = n => Math.round(n * 1e6) / 1e6;+ let busy = false;+ sys.onChange((v, s) => { if (busy) return; busy = true; vs.set({ v0: v.a00, v1: v.a10, w0: v.a01, w1: v.a11, ...(s.x !== undefined ? { c: r6(s.x), d: r6(s.y) } : {}) }); busy = false; });+ vs.onChange((v, k) => { if (busy) return; busy = true; sys.set({ a00: v.v0, a10: v.v1, a01: v.w0, a11: v.w1, b0: r6(k.sum[0]), b1: r6(k.sum[1]) }); busy = false; });+ const heads = G(p, { o: 0 });+ T(heads, 'row picture', { x: 420, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });+ T(heads, 'column picture', { x: 1180, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });+ show(heads, t0 + .3);+ const r = rows ? [colEq(vs, 860, 230), colAmt(vs, 860, 370)] : [];+ return { sys, vs, rows: r, heads };+};+// A task on the twin pictures: the reader moves b (right sides on the left, or b's tip on the right).+// (Not lsTask: its hint is fixed text, and these hints say where the reader is now.)+const twinTask = (T2, test, why, hint, reveal) => (body, api) => {+ T2.vs.live(true, { drag: ['sum'] }); T2.sys.live(true, { only: ['b0', 'b1'] });+ return {+ check: () => { const s = T2.sys.solve(), ok = test(T2.sys.v, s); api.grade(ok, ok ? why : typeof hint === 'function' ? hint(T2.sys.v, s) : hint); },+ reveal: () => { reveal?.(); return why; },+ lock: () => { T2.sys.live(false); T2.vs.live(false); },+ hint: [kbd('Tab'), ' pick a number ', kbd('↑'), kbd('↓'), ' change it, or drag b or a line'],+ };+};+const solIs = (x, y) => (v, s) => s.x !== undefined && Math.abs(s.x - x) < 1e-9 && Math.abs(s.y - y) < 1e-9;+const bFor = (A, x, y) => [A[0][0] * x + A[0][1] * y, A[1][0] * x + A[1][1] * y];+// A system written out, each term placed so the x terms, the y terms and the right sides stand in columns.+const sysText = (p, rowsTxt, x, y, { size = 50, gap = 84, o = 1 } = {}) => {+ const g = G(p, { o }), parts = [];+ rowsTxt.forEach(([a, sg, bt, rr], i) => {+ const yy = y + i * gap, cs = [BLUE, CORAL][i];+ mk('rect', { x: x - 30, y: yy - size * .7, width: 8, height: size * .8, rx: 4, fill: cs }, g);+ const k = size / 50;+ parts.push([M(g, [a], { x: x + 90 * k, y: yy, size, anchor: 'end' }), M(g, [sg], { x: x + 125 * k, y: yy, size, anchor: 'middle' }), M(g, [bt], { x: x + 225 * k, y: yy, size, anchor: 'end' }),+ M(g, [rr], { x: x + 300 * k, y: yy, size, anchor: 'start' }), M(g, ['='], { x: x + 265 * k, y: yy, size, anchor: 'middle' })]);+ });+ g.parts = parts;+ // boxes around the x terms, the y terms and the right sides (for drawing round a column)+ const k = size / 50, top = y - size * .95, h = gap * (rowsTxt.length - 1) + size * 1.3;+ g.boxes = [[x + 14 * k, 92 * k], [x + 150 * k, 92 * k], [x + 288 * k, 70 * k]].map(([bx, w]) => [bx, top, w, h]);+ return g;+};+// Boxes round the x terms, the y terms and the right sides of a linsys system's equations, drawn on cue.+const sysCols = (p, sys, times, colors = [GREEN, VIOLET, COL.task]) => {+ const g = G(p, {}), R = sys.eqRows;+ const groups = [R.flatMap(r => [r.a.t, r.a.l]), R.flatMap(r => [r.bb.t, r.bb.l]), R.map(r => r.c.t)];+ groups.forEach((els, j) => {+ const bs = els.filter(e => e && e.textContent).map(e => { const b = e.getBBox(), q = st(e); return { x: b.x + q.x, y: b.y + q.y, width: b.width, height: b.height }; }); // T() places text by its state+ const x = Math.min(...bs.map(b => b.x)) - 12, y = Math.min(...bs.map(b => b.y)) - 6, w = Math.max(...bs.map(b => b.x + b.width)) + 12 - x, h = Math.max(...bs.map(b => b.y + b.height)) + 6 - y;+ rbox(g, x, y, w, h, colors[j], times[j]);+ });+ return g;+};+// Bring one equation forward (the other dims) without touching the lines, which a beat may still be hiding.+const focusEq = (sys, i, at) => sys.eqRows.forEach((r, j) => tw(r.g, { o: i === null || i === j ? 1 : .28 }, at, .5));+const boxCol = (p, st, j, color, t0) => { const [x, y, w, h] = st.boxes[j]; return rbox(p, x, y, w, h, color, t0); };++/* ---------- practice data ---------- */+const READ1 = [+ { sys: 'x + 3y = 5, 2x − y = 3', cols: [[1, 2], [3, -1], [5, 3]] },+ { sys: '4x − y = 1, x + 5y = −2', cols: [[4, 1], [-1, 5], [1, -2]] },+ { sys: 'y = 3, 2x − y = 0', cols: [[0, 2], [1, -1], [3, 0]] },+];+const READQ = READ1.flatMap(({ sys, cols }) => ['x column', 'y column', 'b'].map((name, j) => ({+ q: [name], ans: cols[j],+ why: j < 2 ? `The numbers in front of ${'xy'[j]}, top equation first: ${num(cols[j][0])} and ${num(cols[j][1])}.` : `The right sides: ${num(cols[2][0])} and ${num(cols[2][1])}.`,+ hint: j < 2 ? `Take the number in front of ${'xy'[j]} in each equation, first equation on top. A missing letter means 0; a letter alone means 1 (or −1).` : 'The right sides, first equation on top.',+})));+const MIXQ = [[[1, 2], [3, 1], 2, 1], [[1, 0], [0, 1], 4, -3], [[2, 1], [-1, 1], 2, 3], [[1, 1], [1, -1], 4, 2], [[3, 1], [1, 2], 1, 2], [[2, -1], [-1, 2], 2, 1]].map(([a, b, x, y]) => ({ a, b, x, y, B: [a[0] * x + b[0] * y, a[1] * x + b[1] * y] }));+const RIGHTQ = [[[1, 2], [3, 1], [5, 5], 2, 1], [[2, 1], [1, 3], [4, 7], 1, 2], [[1, 1], [2, -1], [4, 1], 1, 2], [[3, 0], [1, 2], [5, 4], 1, 2], [[1, -1], [1, 1], [0, 2], 2, 1]].map(([a, b, B, x, y]) => {+ const got = [a[0] * x + b[0] * y, a[1] * x + b[1] * y], ok = got[0] === B[0] && got[1] === B[1];+ return { parts: [$m('x'), hcol(...a, GREEN), ' + ', $m('y'), hcol(...b, VIOLET), ' = ', hcol(...B, COL.task), ` x = ${num(x)}, y = ${num(y)}`], ans: [ok ? 'y' : 'n'],+ why: `${num(x)}·[${num(a[0])}, ${num(a[1])}] + ${num(y)}·[${num(b[0])}, ${num(b[1])}] = [${num(got[0])}, ${num(got[1])}]${ok ? ': that is b.' : `, not [${num(B[0])}, ${num(B[1])}].`}` };+});+const MOVEQ = [[-1, 2], [2, 0], [0, -1], [1, 1]];++/* ---------- beats: [id, title, run(m, D), { ask }?] ---------- */+const BEATS = [+ ['intro', 'The column picture', (m, D) => {+ const g = G(scene, { o: 0, y: 24 });+ T(g, 'Unit 1, Chapter 7', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });+ T(g, 'The Column Picture', { x: 800, y: 410, size: 88, weight: 600, anchor: 'middle' });+ tw(g, { o: 1, y: 0 }, .2, 1.1, out);+ const r = text(scene, 'the same system, read down its columns', 800, 510, m('sub'), { size: 36, fill: COL.dim, anchor: 'middle' });+ const pic = G(scene, { o: 0 });+ const st = sysText(pic, [['2x', '−', 'y', '0'], ['−x', '+', '2y', '3']], 640, 640, { size: 40, gap: 64 });+ show(pic, m('sub') + .8, .5);+ boxCol(pic, st, 0, GREEN, m('down')); boxCol(pic, st, 1, VIOLET, m('down') + .5); boxCol(pic, st, 2, COL.task, m('down') + 1);+ tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8); hide(pic, D - .9, .8);+ }],++ ['rows', 'The row picture', (m) => {+ const p = panel(0);+ text(p, 'The row picture: one line per equation', 60, 110, .2, { size: 40, weight: 600 });+ const sys = linsys(p, { A: LA, b: LB, mat: null, eq: [90, 220], t0: .1 });+ put(sys.meetBox, { o: 0 }); put(sys.readout, { o: 0 });+ sys.lines.forEach(l => put(l.g, { o: 0 }));+ sys.focus(0, m('e1')); show(sys.lines[0].g, m('e1') + .4, .8);+ sys.focus(1, m('e2')); show(sys.lines[1].g, m('e2') + .4, .8);+ sys.focus(null, m('row'));+ show(sys.meetBox, m('meet'), .5); pulse(sys.meet, m('meet') + .5, 1.6);+ show(sys.readout, m('ans'), .5);+ const n = G(p, { o: 0 });+ T(n, 'row picture: the solution is where the lines meet', { x: 90, y: 560, size: 30, weight: 600, fill: COL.task });+ show(n, m('name'));+ sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 9 }, m('name') + .4 + i * .5, .3); tw(l.l, { 'a_stroke-width': 5 }, m('name') + 1.1 + i * .5, .4); });+ }],++ ['cols', 'Down the columns', (m) => {+ const p = panel(0);+ text(p, 'Read the numbers down the columns', 60, 110, .2, { size: 40, weight: 600 });+ const st = sysText(p, [['2x', '−', 'y', '0'], ['−x', '+', '2y', '3']], 120, 230, { size: 50 });+ const xs = st.parts.map(r => r[0]), ys = st.parts.map(r => r[2]), bs = st.parts.map(r => r[3]);+ boxCol(p, st, 0, GREEN, m('xcol')); xs.forEach((e, i) => tw(e, { s: 1.15 }, m('xcol') + .3 + i * .8, .3));+ xs.forEach((e, i) => tw(e, { s: 1 }, m('xcol') + .7 + i * .8, .3));+ boxCol(p, st, 1, VIOLET, m('ycol'));+ boxCol(p, st, 2, COL.task, m('bcol'));+ // the three columns, stood up on the right+ const vs = colPic(p, LA, { c: 1, d: 2, hidePlane: true, show: [] });+ const cx = [900, 1100, 1300];+ const cA = vs.row([{ col: 'v', fixed: true }], { x: cx[0], y: 270, size: 50, o: 0 }), cB = vs.row([{ col: 'w', fixed: true }], { x: cx[1], y: 270, size: 50, o: 0 }), cC = vs.row([{ col: 'sum', fixed: true }], { x: cx[2], y: 270, size: 50, o: 0 });+ showRow(cA, m('xvec')); showRow(cB, m('yvec')); showRow(cC, m('bcol') + .4);+ text(p, 'column 1', cx[0] + 47, 370, m('xvec') + .3, { size: 26, fill: GREEN, anchor: 'middle', weight: 600 });+ text(p, 'column 2', cx[1] + 47, 370, m('yvec') + .3, { size: 26, fill: VIOLET, anchor: 'middle', weight: 600 });+ text(p, 'b', cx[2] + 47, 370, m('bcol') + .7, { size: 30, fill: COL.task, anchor: 'middle', weight: 600 });+ // the whole system as one vector equation+ const eq = vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 120, y: 540, size: 54, o: 0 });+ showRow(eq, m('eq'), 0, 2); showRow(eq, m('eq') + 2.4, 2, 5); showRow(eq, m('eq') + 4.6, 5, 7);+ const top = [vs.num('v0').pop(), vs.num('w0').pop(), vs.num('sum0').pop()], bot = [vs.num('v1').pop(), vs.num('w1').pop(), vs.num('sum1').pop()];+ const hl = (els, t0, dur) => els.forEach(e => { tw(e, { c_color: COL.task }, t0, .3); tw(e, { c_color: e.getAttribute('color') }, t0 + dur, .5); });+ hl(top, m('top') + .4, m('bot') - m('top') - .8);+ say(p, ['x·2 + y·(−1) = 0'], 120, 720, m('top') + .6, { size: 40 });+ say(p, ['→ 2x − y = 0'], 520, 720, m('top') + 4.2, { size: 40, fill: BLUE });+ hl(bot, m('bot') + .4, m('same') - m('bot') - .6);+ say(p, ['x·(−1) + y·2 = 3'], 120, 790, m('bot') + .6, { size: 40 });+ say(p, ['→ −x + 2y = 3'], 520, 790, m('bot') + 4.4, { size: 40, fill: CORAL });+ rbox(p, 100, 670, 820, 150, COL.good, m('same') + .3);+ }],++ ['mix', 'A combination again', (m) => {+ const p = panel(0);+ text(p, 'The solution is a mix of the columns', 60, 110, .2, { size: 40, weight: 600 });+ const vs = colPic(p, LA, { c: 1, d: 2, show: [] });+ colEq(vs, 70, 240, 42);+ const amt = colAmt(vs, 70, 420, 42, 0);+ const c6 = G(p, { o: 0 });+ T(c6, 'chapter 6: c v + d w = [0, 3] with c = 1, d = 2', { x: 70, y: 600, size: 28, fill: COL.dim, weight: 600 });+ show(c6, m('ch6'));+ tw(c6.firstChild, { c_fill: COL.task }, m('found'), .3);+ const here = G(p, { o: 0 });+ T(here, 'columns = v and w, x and y = c and d, b = the target', { x: 70, y: 650, size: 28, fill: COL.chalk, weight: 600 });+ show(here, m('here'));+ vs.show(['v', 'w'], m('seen'), .6);+ thick(vs, 'v', m('ch6') + 1.6); thick(vs, 'w', m('ch6') + 3.4);+ const tgt = G(vs.P.g, { x: vs.P.PX(0), y: vs.P.PY(3), o: 0 });+ mk('circle', { r: 15, fill: 'none', stroke: COL.task, 'stroke-width': 4 }, tgt);+ show(tgt, m('ch6') + 6.4, .3); pulse(tgt, m('ch6') + 7, 1.5); pulse(tgt, m('found') + .4, 1.5);+ ['v0', 'v1'].forEach(k => vs.flash(k, m('here') + .6)); thick(vs, 'v', m('here') + .6);+ ['w0', 'w1'].forEach(k => vs.flash(k, m('here') + 1.6)); thick(vs, 'w', m('here') + 1.6);+ pulse(tgt, m('here') + 5.6, 1.5); ['sum0', 'sum1'].forEach(k => vs.flash(k, m('here') + 5.6));+ hide(tgt, m('lands'), .3);+ showRow(amt, m('mixit'));+ vs.flash('c', m('mixit') + .4); vs.flash('d', m('mixit') + .9);+ vs.show('cv', m('mixit') + .4, .6); tw(vs.A.v.g, { o: .45 }, m('mixit') + .4, .4);+ const u = vs.P.u;+ put(vs.A.dw.g, { x: -LA[0][0] * u, y: LA[1][0] * u, o: 0 });+ tw(vs.A.dw.g, { o: 1 }, m('plus'), .3); tw(vs.A.dw.g, { x: 0, y: 0 }, m('plus') + .4, 1.4);+ vs.show('sum', m('lands'), .6); thick(vs, 'sum', m('lands') + .6, 6);+ const nm = G(p, { o: 0 });+ T(nm, 'column picture: the solution is the mix that makes b', { x: 70, y: 720, size: 30, weight: 600, fill: COL.task });+ show(nm, m('name'));+ }],++ ['both', 'Side by side', (m) => {+ const p = panel(0);+ text(p, 'Two pictures, one answer', 60, 110, .2, { size: 40, weight: 600 });+ const T2 = S.T2 = twin(p, LA, LB);+ const { sys, vs } = T2;+ tw(sys.stage, { o: .35 }, .1, .01); tw(vs.stage, { o: .35 }, .1, .01);+ show(sys.stage, m('left'), .5); sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 9 }, m('left') + .4 + i * .4, .3); tw(l.l, { 'a_stroke-width': 5 }, m('left') + 1 + i * .4, .4); });+ pulse(sys.meet, m('left') + 2, 1.6);+ show(vs.stage, m('right'), .5); thick(vs, 'cv', m('right') + .6); thick(vs, 'dw', m('right') + 1.6); thick(vs, 'sum', m('right') + 2.6, 6);+ flashLs(sys, 'b0', m('same')); vs.flash('c', m('same') + .5); vs.flash('d', m('same') + .9);+ pulse(sys.meet, m('point') + .3, 1.8);+ const box = vs.num('c').concat(vs.num('d'));+ box.forEach((e, i) => lightUp(e, m('amounts') + .3 + i * .5));+ void T2.sys.readout;+ }],++ ['more', 'Two more systems', (m) => {+ const p = panel(0);+ text(p, 'Two more: read down the columns', 60, 110, .2, { size: 40, weight: 600 });+ const sa = sysText(p, [['x', '+', '4y', '9'], ['3x', '−', 'y', '1']], 120, 230, { size: 46, gap: 70, o: 0 });+ show(sa, m('a'));+ boxCol(p, sa, 0, GREEN, m('ax')); boxCol(p, sa, 1, VIOLET, m('ay')); boxCol(p, sa, 2, COL.task, m('ab'));+ const va = colPic(p, [[1, 4], [3, -1]], { c: 1, d: 2, hidePlane: true, show: [] });+ const ea = va.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 640, y: 250, size: 42, o: 0 });+ showRow(ea, m('ax') + 1, 0, 2); showRow(ea, m('ay') + 1, 2, 5); showRow(ea, m('ab') + .8, 5, 7);+ const ca = va.row([{ key: 'c' }, { col: 'v', fixed: true }, { key: 'd', signed: true }, { col: 'w', fixed: true }, '=', { fn: () => ['1 + 8', '3 − 2'], w: 150 }, '=', { col: 'sum', fixed: true }], { x: 640, y: 400, size: 42, o: 0 });+ showRow(ca, m('acheck'), 0, 4); showRow(ca, m('acheck') + 3, 4, 6);+ const [ft, fb] = va.num('fn'); put(fb, { o: 0 }); show(fb, m('acheck2'));+ showRow(ca, m('acheck2') + 1.6, 6, 8); [ft, fb].forEach(e => lightUp(e, m('acheck2') + 1.8));+ const sb = sysText(p, [['', '', 'y', '2'], ['x', '−', '3y', '0']], 120, 600, { size: 46, gap: 70, o: 0 });+ show(sb, m('b'));+ say(p, ['0x'], 120 + 90 * .92, 600, m('bx') + .6, { size: 46, fill: COL.task, anchor: 'end' });+ boxCol(p, sb, 0, GREEN, m('bx') + 1.2); boxCol(p, sb, 1, VIOLET, m('by')); boxCol(p, sb, 2, COL.task, m('bb'));+ const vb = colPic(p, [[0, 1], [1, -3]], { c: 6, d: 2, hidePlane: true, show: [] });+ const eb = vb.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 640, y: 640, size: 42, o: 0 });+ showRow(eb, m('bx') + 3, 0, 2); showRow(eb, m('by') + .6, 2, 5); showRow(eb, m('bb') + .6, 5, 7);+ vb.flash('v0', m('bx') + 3.4);+ }],++ ['q1', 'Quick check', () => {+ const p = panel(0);+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });+ sysText(p, [['3x', '+', 'y', '4'], ['x', '−', '2y', '6']], 120, 210, { size: 46, gap: 70 });+ }, { ask: done => quiz(CARD, [{+ id: 'c-read', prompt: ['Read the system down its columns.'],+ build: vcolBlanks([+ { q: ['x column'], ans: [3, 1], why: 'In front of x: 3, then 1.', hint: 'The numbers in front of x, first equation on top. x alone means 1.' },+ { q: ['y column'], ans: [1, -2], why: 'In front of y: 1, then −2.', hint: 'The numbers in front of y: + y means 1, − 2y means −2.' },+ { q: ['b'], ans: [4, 6], why: 'The right sides: 4 and 6.', hint: 'The right sides, first equation on top.' },+ ], { cols: 2 }),+ }], done) }],++ ['linkb', 'Linked', (m) => {+ const p = panel(0);+ text(p, 'Change b: both pictures follow', 60, 110, .2, { size: 40, weight: 600 });+ const { sys, vs } = twin(p, LA, LB);+ flashLs(sys, 'b0', m('change')); flashLs(sys, 'b1', m('change')); vs.flash('sum0', m('change')); vs.flash('sum1', m('change'));+ sys.to({ b0: 3, b1: 0 }, m('to30') + .2, 1.8);+ pulse(sys.meet, m('rows') + 1.6, 1.6);+ thick(vs, 'sum', m('cols') + .4, 6); vs.flash('c', m('cols') + 1.6); vs.flash('d', m('cols') + 2.8);+ vs.flash('c', m('agree') + .2); vs.flash('d', m('agree') + .2); pulse(sys.meet, m('agree') + .2, 1.6);+ sys.to({ b0: 1, b1: 1 }, m('to11') + .2, 1.6);+ pulse(sys.meet, m('ag2') + .4, 1.6); vs.flash('c', m('ag2') + 1.6); vs.flash('d', m('ag2') + 1.6);+ // a hand drags b in the column picture; the tip snaps to grid points, x and y are found at each+ const { PX, PY } = vs.P, hand = G(p, { o: 0 });+ mk('circle', { r: 18, fill: COL.task, 'fill-opacity': .25, stroke: COL.task, 'stroke-width': 3 }, hand);+ put(hand, { x: PX(1), y: PY(1) });+ show(hand, m('drag') + .4, .3);+ prog(q => {+ const x = 1 - 4 * q, y = 1 + 2 * q;+ put(hand, { x: PX(x), y: PY(y) });+ vs.set(vs.solveFor(Math.round(x), Math.round(y)));+ }, m('pull'), 2.2, io);+ hide(hand, m('ag3') + .6, .3);+ pulse(sys.meet, m('ag2') + 2.8, 1.6);+ const grab = G(p, { x: PX(1), y: PY(1), o: 0 });+ mk('circle', { r: 16, fill: 'none', stroke: COL.task, 'stroke-width': 3, 'stroke-dasharray': '4 4' }, grab);+ show(grab, m('drag') + .2, .3); pulse(grab, m('drag') + .8, 1.6); pulse(grab, m('drag') + 2, 1.6); hide(grab, m('pull'), .2);+ thick(vs, 'cv', m('ag3') + .8); thick(vs, 'dw', m('ag3') + 2);+ sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 8 }, m('ag3') + 4.4 + i * .5, .3); tw(l.l, { 'a_stroke-width': 5 }, m('ag3') + 5.1 + i * .5, .4); });+ vs.flash('c', m('ag3') + .4); vs.flash('d', m('ag3') + 1.6); pulse(sys.meet, m('ag3') + 3.4, 1.6);+ }],++ ['q2', 'Your turn', () => {+ const p = panel(0);+ text(p, 'Your turn', 60, 110, .2, { size: 40, weight: 600 });+ S.T2 = twin(p, LA, LB, { rows: false });+ }, { ask: done => quiz(TOPCARD, [{+ id: 'c-move', prompt: ['Move ', $m('b'), ' (its numbers on the left, or its tip on the right) until the solution is ', $m('x = 3, y = 2'), '.'],+ build: twinTask(S.T2, solIs(3, 2), ['b = ', hcol(4, 1, COL.task), ': 3 of column 1 plus 2 of column 2. On the left, the lines meet at (3, 2).'],+ (v, s) => s.x === undefined ? 'Move b so the lines cross.' : `Now x = ${S.T2.vs.fmt(s.x)}, y = ${S.T2.vs.fmt(s.y)}. b must be 3·[2, −1] + 2·[−1, 2].`,+ () => S.T2.sys.set({ b0: 4, b1: 1 })),+ }], done) }],++ ['second', 'A second system', (m) => {+ const p = panel(0);+ text(p, 'Another system, both pictures', 60, 110, .2, { size: 40, weight: 600 });+ const A2 = [[1, 1], [1, -1]];+ const { sys, vs, rows } = twin(p, A2, [5, 1]);+ put(sys.readout, { o: 0 }); rows[1].parts.forEach(e => put(e, { o: 0 })); // no answer before it is found+ show(sys.readout, m('rowp') + 1.4, .5); showRow(rows[1], m('colp'));+ sys.lines.forEach(l => put(l.g, { o: 0 })); put(sys.meetBox, { o: 0 });+ ['cv', 'dw', 'sum'].forEach(id => { put(vs.A[id].g, { o: 0 }); put(vs.A[id].lab, { o: 0 }); });+ focusEq(sys, 0, m('e') + .2); focusEq(sys, 1, m('e') + 2.2); focusEq(sys, null, m('cols') - .2);+ thick(vs, 'v', m('cols') + .3); thick(vs, 'w', m('cols') + 1.9);+ const cb = sysCols(p, sys, [m('cols') + 1.6, m('cols') + 3.6, m('cols') + 5.8]); hide(cb, m('rowp') + .4, .5);+ flashLs(sys, 'a00', m('cols')); flashLs(sys, 'a10', m('cols')); flashLs(sys, 'a01', m('cols') + 1.6); flashLs(sys, 'a11', m('cols') + 1.6); flashLs(sys, 'b0', m('cols') + 3.6); flashLs(sys, 'b1', m('cols') + 3.6);+ vs.flash('v0', m('cols') + .3); vs.flash('v1', m('cols') + .3); vs.flash('w0', m('cols') + 1.9); vs.flash('w1', m('cols') + 1.9); vs.flash('sum0', m('cols') + 3.9); vs.flash('sum1', m('cols') + 3.9);+ sys.lines.forEach((l, i) => show(l.g, m('rowp') + i * .4, .6)); show(sys.meetBox, m('rowp') + 1, .4); pulse(sys.meet, m('rowp') + 1.4, 1.6);+ vs.show('cv', m('colp') + .3, .6); tw(vs.A.v.g, { o: .45 }, m('colp') + .3, .4);+ const u = vs.P.u;+ put(vs.A.dw.g, { x: -3 * u, y: 3 * u, o: 0 });+ tw(vs.A.dw.g, { o: 1 }, m('two'), .3); tw(vs.A.dw.g, { x: 0, y: 0 }, m('two') + .4, 1.2); show(vs.A.dw.lab, m('two') + 1.6, .4);+ vs.show('sum', m('sum'), .6); vs.flash('sum0', m('sum') + .6); vs.flash('sum1', m('sum') + .6);+ vs.flash('c', m('same') + .2); vs.flash('d', m('same') + .2); pulse(sys.meet, m('same') + .2, 1.6);+ }],++ ['which', 'When the columns line up', (m) => {+ const p = panel(0);+ text(p, 'Columns on one line: no mix reaches b', 60, 110, .2, { size: 40, weight: 600 });+ const A3 = [[1, 2], [2, 4]];+ const sys = linsys(p, { A: A3, b: [3, 5], mat: null, eq: [110, 190], size: 46, plane: { cx: 420, cy: 625, u: 28, step: 2 } });+ put(sys.stage, { o: 0 }); show(sys.stage, m('rowp') - .2, .5);+ put(sys.readout, { o: 0 }); show(sys.readout, m('rowp') + 2, .5);+ const vs = colPic(p, A3, { c: 1, d: 0, plane: { cx: 1180, cy: 625, u: 28, step: 2 }, labelSize: 24, show: ['v', 'w'] });+ vs.label('w', ['col 2'], 'tip', [30, 16]);+ vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { fn: () => ['3', '5'], w: 76, fill: COL.task }], { x: 860, y: 230, size: 40 });+ const heads = G(p, {});+ T(heads, 'row picture', { x: 420, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });+ T(heads, 'column picture', { x: 1180, y: 855, size: 26, fill: COL.dim, anchor: 'middle', weight: 600 });+ thick(vs, 'v', m('cols') + .3); thick(vs, 'w', m('cols') + 1.3);+ focusEq(sys, 0, m('e') + .2); focusEq(sys, 1, m('e') + 2.6); focusEq(sys, null, m('cols') - .2);+ vs.lattice(m('colp'), true, .8); // parallel columns: the lattice is one amber line+ const bArr = G(vs.P.g, {});+ vs.P.arrow(0, 0, 3, 5, COL.task, m('miss'), { label: 'b', into: bArr });+ const ring = G(vs.P.g, { x: vs.P.PX(3), y: vs.P.PY(5), o: 0 });+ mk('circle', { r: 14, fill: 'none', stroke: COL.bad, 'stroke-width': 3 }, ring);+ show(ring, m('miss') + 1, .3); pulse(ring, m('miss') + 1.4, 1.6);+ text(p, 'no mix of the columns reaches b', 860, 400, m('miss') + 1.6, { size: 26, fill: COL.bad, weight: 600 });+ sys.lines.forEach((l, i) => { tw(l.l, { 'a_stroke-width': 9 }, m('rowp') + .8 + i * .5, .3); tw(l.l, { 'a_stroke-width': 5 }, m('rowp') + 1.5 + i * .5, .4); });+ text(p, 'no solution, seen two ways', 800, 820, m('both'), { size: 30, fill: COL.task, weight: 600, anchor: 'middle' });+ }],++ ['q3', 'Quick check', () => {+ const p = panel(0);+ text(p, 'Quick check', 60, 110, .2, { size: 40, weight: 600 });+ S.vs = colPic(p, [[2, 1], [1, 3]], { c: 2, d: 1, show: ['v', 'w'] });+ S.vs.P.arrow(0, 0, 5, 5, COL.task, .4, { label: 'b' });+ S.vs.row([{ t: 'x' }, { col: 'v', fixed: true }, '+', { t: 'y' }, { col: 'w', fixed: true }, '=', { col: 'sum', fixed: true }], { x: 90, y: 230, size: 42 });+ }, { ask: done => quiz(CARD, [{+ id: 'c-mix', prompt: ['How much of each column makes ', $m('b'), '?'],+ build: blanks([{ parts: ['x = ', { box: '2' }, ' y = ', { box: '1' }], why: '2·[2, 1] + 1·[1, 3] = [4 + 1, 2 + 3] = [5, 5].',+ hint: 'Top: 2x + y must be 5. Bottom: x + 3y must be 5. Try small whole numbers.',+ fx: () => ['cv', 'dw'].forEach((id, i) => fx(S.vs.A[id].g, { o: 1 }, i * .5, .5)) }]),+ }], done) }],++ ['wrap', 'Summary', (m) => {+ const p = panel(0);+ [['Read down the columns: x·(column 1) + y·(column 2) = b.', 'w1'], ['Row picture: one line per equation; they meet at the solution.', 'w2'],+ ['Column picture: the solution is the mix of columns that makes b.', 'w3'], ['Both pictures always give the same answer.', 'w4']].forEach(([str, mark], i) => {+ const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });+ const dg = G(g, { x: 150, y: -12 });+ mk('circle', { r: 26, fill: COL.task }, dg);+ T(dg, String(i + 1), { x: 0, y: 11, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });+ const tl = T(g, str, { x: 210, size: 34, weight: 600 });+ tw(g, { o: 1, x: 0 }, m(mark), .6);+ pulse(dg, m('end') + i * .3, 1.25);+ const next = ['w2', 'w3', 'w4', 'end'][i], ul = path(g, `M210 16H${210 + tl.getComputedTextLength()}`, { stroke: COL.task, 'stroke-width': 3, 'stroke-opacity': .6 }, { d: 0 });+ draw(ul, m(mark) + .5, Math.max(1, m(next) - m(mark) - 1), lin);+ });+ }],+ ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, READ1.map((r, i) => ({+ id: `p-read${i + 1}`, prompt: ['Read the system down its columns: ', $m(r.sys)], build: vcolBlanks(READQ.slice(3 * i, 3 * i + 3), { cols: 3 }),+ })), done, 'Chapter practice · set 1 of 4') }],+ ['final2', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, MIXQ.map((q, i) => ({+ id: `p-mix${i + 1}`, prompt: ['Find the mix: ', $m('x'), hcol(...q.a, GREEN), ' + ', $m('y'), hcol(...q.b, VIOLET), ' = ', hcol(...q.B, COL.task)],+ build: blanks([{ parts: ['x = ', { box: String(q.x) }, ' y = ', { box: String(q.y) }],+ why: `${num(q.x)}·[${num(q.a[0])}, ${num(q.a[1])}] + ${num(q.y)}·[${num(q.b[0])}, ${num(q.b[1])}] = [${num(q.B[0])}, ${num(q.B[1])}].`,+ hint: `Top: ${num(q.a[0])}x + ${num(q.b[0])}y = ${num(q.B[0])}. Bottom: ${num(q.a[1])}x + ${num(q.b[1])}y = ${num(q.B[1])}. Try small whole numbers in both.` }]),+ })), done, 'Chapter practice · set 2 of 4') }],+ ['final3', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{+ id: 'p-right', prompt: ['Is the given x and y the right mix? Work out x·(column 1) + y·(column 2) and compare with b.'],+ build: grid(RIGHTQ, [['y', 'Yes', null, 'Y'], ['n', 'No', null, 'N']], { multi: false, text: true }),+ }], done, 'Chapter practice · set 3 of 4') }],+ ['final4', 'Chapter practice', () => {+ const p = panel(0);+ text(p, 'Move b', 60, 110, .2, { size: 40, weight: 600 });+ S.T2 = twin(p, LA, LB, { rows: false });+ }, { ask: done => quiz(TOPCARD, MOVEQ.map(([x, y], i) => ({+ id: `p-move${i + 1}`, prompt: ['Move ', $m('b'), ' until the solution is ', $m(`x = ${num(x)}, y = ${num(y)}`), '.'],+ build: (body, api) => {+ S.T2.sys.set({ b0: 0, b1: 3 });+ const B = bFor(LA, x, y);+ return twinTask(S.T2, solIs(x, y), ['b = ', hcol(...B, COL.task), `: ${num(x)} of column 1 plus ${num(y)} of column 2.`],+ (v, s) => s.x === undefined ? 'Move b so the lines cross.' : `Now x = ${S.T2.vs.fmt(s.x)}, y = ${S.T2.vs.fmt(s.y)}. b must be ${num(x)}·[2, −1] + ${num(y)}·[−1, 2].`,+ () => S.T2.sys.set({ b0: B[0], b1: B[1] }))(body, api);+ },+ })), done, 'Chapter practice · set 4 of 4') }],+ ['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],+].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));++boot();+</script>+</body>+</html>diff --git a/site/linear-algebra/lib/linsys.js b/site/linear-algebra/lib/linsys.jsindex 9ab633c..9ddf227 100644--- a/site/linear-algebra/lib/linsys.js+++ b/site/linear-algebra/lib/linsys.js@@ -279,11 +279,12 @@ function linsys(p, { A = [[2, -1], [-1, 2]], b = [0, 3], eq = [90, 250], mat = [return tr;},// Bring row i (0 or 1) forward: its equation and its line; the other row dims. focus(null, at) shows both again.- focus(i, at, dur = .5) {+ // { lines: false } leaves the lines as they are (a beat that keeps them hidden until later).+ focus(i, at, dur = .5, { lines: withLines = true } = {}) {RI.forEach(j => {const on = i === null || i === j;tw(eqRows[j].g, { o: on ? 1 : .28 }, at, dur);- tw(lines[j].g, { o: on ? 1 : .28 }, at, dur);+ if (withLines) tw(lines[j].g, { o: on ? 1 : .28 }, at, dur);tw(lines[j].l, { 'a_stroke-width': i === j ? 8 : 5 }, at, dur);});},@@ -324,7 +325,7 @@ const lsTask = (sys, test, why, hint, reveal, { only, trail = false } = {}) => (sys.live(true, { only });if (trail) sys.trail?.(true);return {- check: () => { const ok = test(sys.v, sys.solve()); api.grade(ok, ok ? why : hint); },+ check: () => { const v = sys.v, s = sys.solve(), ok = test(v, s); api.grade(ok, ok ? why : typeof hint === 'function' ? hint(v, s) : hint); }, // a hint may say where the reader is nowreveal: () => { reveal?.(); return why; },lock: () => sys.live(false),hint: [kbd('Tab'), ' pick a number ', kbd('↑'), kbd('↓'), ' change it, or drag in the picture'],diff --git a/site/linear-algebra/lib/play.js b/site/linear-algebra/lib/play.jsnew file mode 100644index 0000000..4896efd--- /dev/null+++ b/site/linear-algebra/lib/play.js@@ -0,0 +1,67 @@+// A playground beat: no question, no score. The chapter's linked picture is handed over whole (every number, line,+// plane and arrow the component lets the reader move), with a pen to draw on the board, a reset and a way on.+// Use it as a beat's ask: ['play', 'Playground', m => { … build S.sys … }, { ask: playAsk(() => S.sys, { tip }) }]+// Works with any component that has .live(on), .v and .set(values) (linsys, lin3, vecs, grid2).+const PLAY_INK = [COL.chalk, COL.task, COL.whole, COL.nat];++function playAsk(getSys, { pos = { x: 40, y: 430, w: 720, cls: 'side' }, tip = 'Change anything you like and watch what moves with it.' } = {}) {+ return done => {+ const gen = P.gen, sys = getSys(), start = { ...sys.v };+ sys.live(true);+ // the ink sits over the picture; in draw mode a sheet over the whole stage takes the pointer+ const L = qlayer(), ink = G(L, {}), sheet = mk('rect', { width: SW, height: SH, fill: 'transparent' }, L);+ Object.assign(sheet.style, { display: 'none', cursor: 'crosshair', touchAction: 'none' });+ const svg = $('stage'), at = e => { const q = svg.createSVGPoint(); q.x = e.clientX; q.y = e.clientY; return q.matrixTransform(svg.getScreenCTM().inverse()); };+ let drawing = false, colour = 0, line = null, d = '';+ sheet.addEventListener('pointerdown', e => {+ if (P.gen !== gen) return;+ e.preventDefault();+ const p = at(e);+ d = `M${p.x.toFixed(1)} ${p.y.toFixed(1)}`;+ line = mk('path', { d, fill: 'none', stroke: PLAY_INK[colour], 'stroke-width': 5, 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }, ink);+ sheet.setPointerCapture(e.pointerId);+ });+ sheet.addEventListener('pointermove', e => {+ if (!line) return;+ const p = at(e);+ d += `L${p.x.toFixed(1)} ${p.y.toFixed(1)}`;+ line.setAttribute('d', d);+ });+ const lift = () => { line = null; };+ sheet.addEventListener('pointerup', lift);+ sheet.addEventListener('lostpointercapture', lift);++ const c = card(pos, 'quiz play');+ const bDraw = h('button', 'btn quiet', ['Draw', kbd('D')]), bInk = h('button', 'btn quiet', ['Colour', kbd('K')]);+ const bClear = h('button', 'btn quiet', ['Clear drawing', kbd('X')]), bReset = h('button', 'btn quiet', ['Reset numbers', kbd('R')]);+ const bOn = h('button', 'btn go', [translate('continue'), kbd('Enter')]);+ const swatch = h('span', 'swatch');+ Object.assign(swatch.style, { display: 'inline-block', width: '14px', height: '14px', borderRadius: '50%', marginLeft: '8px', verticalAlign: '-1px' });+ bInk.append(swatch);+ const paint = () => {+ swatch.style.background = PLAY_INK[colour];+ bDraw.firstChild.textContent = drawing ? 'Stop drawing' : 'Draw';+ bDraw.className = 'btn ' + (drawing ? 'go' : 'quiet');+ sheet.style.display = drawing ? '' : 'none';+ };+ bDraw.onclick = () => { drawing = !drawing; paint(); };+ bInk.onclick = () => { colour = (colour + 1) % PLAY_INK.length; paint(); };+ bClear.onclick = () => ink.replaceChildren();+ bReset.onclick = () => sys.set(start);+ bOn.onclick = () => { if (P.gen !== gen) return; drawing = false; paint(); sys.live(false); done(); };+ const acts = h('div', 'acts', [bDraw, bInk, bClear, bReset, bOn]);+ acts.style.flexWrap = 'wrap';+ c.replaceChildren(h('div', 'head', [h('p', 'kicker', 'Playground · no score'), h('p', 'prompt', [rich([tip], 24)]),+ h('p', 'keys', ['Drag numbers sideways or use ', kbd('Tab'), kbd('↑'), kbd('↓'), '; drag lines and arrows; ', kbd('D'), ' to draw on the board.'])]), acts);+ paint();+ P.keys = e => {+ if (P.gen !== gen) return false;+ if (e.key === 'Enter') { bOn.click(); return true; }+ if (isShortcut(e, 'd')) { bDraw.click(); return true; }+ if (isShortcut(e, 'k')) { bInk.click(); return true; }+ if (isShortcut(e, 'x')) { bClear.click(); return true; }+ if (isShortcut(e, 'r')) { bReset.click(); return true; }+ return false;+ };+ };+}diff --git a/site/linear-algebra/lib/vecs.js b/site/linear-algebra/lib/vecs.jsindex ecab351..9d5b0e6 100644--- a/site/linear-algebra/lib/vecs.js+++ b/site/linear-algebra/lib/vecs.js@@ -5,9 +5,17 @@// dragging the tip of 'sum' (or scrubbing its numbers) finds c and d.// The beat moves it with vs.to(); a question turns the reader's hands on with vs.live(true).// Loads after engine.js and math.js (it uses plane() and mathW()); linsys.js is not needed.+//+// const vs = vecs(p, { vecs: { v: [2, −1], w: [−1, 2] }, c: 1, d: 2, show: ['cv', 'dw', 'sum'], plane: { cx, cy, u, step },+// snap: 1 | .5, steps: { c: .5 }, range: { c: [−5, 5] }, labelSize, hidePlane })+// state vs.v = { v0, v1, w0, w1, c, d }; arrows vs.A[id] (id: each name, 'cv', 'dw', 'dw0', 'cv1', 'sum') with .g .path .lab+// vs.row(items, { x, y, size, o }) the algebra, live (see row below); vs.to(next, t0, dur); vs.set(next); vs.onChange(f)+// vs.show / hide / dim(ids, t0); vs.legs(ids, t0, on); vs.label(id, parts | v => parts, 'tip' | 'mid', [dx, dy]); vs.lattice(t0)+// vs.solve(on); vs.solveFor(x, y) → { c, d }; vs.flash(key, t0); vs.num(key); vs.fmt(n), vs.parts(n), vs.paren(n), vs.nice(n)+// vs.live(on, { drag: ids, move }); questions: vsTask(vs, test, why, hint, reveal, opts), vcolBlanks(rows, { cols }), hcol(top, bottom, colour)const VS_COL = [COL.irr, COL.real, COL.rat]; // first, second, third vector: green, violet, pink (the columns of A later)-function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, snap = 1, steps = {}, range = {}, show: shown, size = 46, t0 = .1, hidePlane = false } = {}) {+function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, snap = 1, steps = {}, range = {}, show: shown, size = 46, labelSize = 32, t0 = .1, hidePlane = false } = {}) {const names = Object.keys(list), [n1, n2 = n1] = names;const v = { c, d };names.forEach(n => { v[n + '0'] = list[n][0]; v[n + '1'] = list[n][1]; });@@ -169,9 +177,11 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, snaif (id in colorOf && names.includes(id)) return [[0, 0], vec(id)];return { cv: [[0, 0], k.cv], dw: [k.cv, k.sum], dw0: [[0, 0], k.dw], cv1: [k.dw, k.sum], sum: [[0, 0], k.sum] }[id];};+ // A value passing between whole numbers (a decimal) gets no label: "1.3v" flickering by is noise.+ const nice = n => !fmt(n).includes(DECIMAL_SIGN);const defaultLabel = {- cv: () => v.c === 1 ? [n1] : v.c === -1 ? ['−' + n1] : [...parts(v.c), n1],- dw: () => v.d === 1 ? [n2] : v.d === -1 ? ['−' + n2] : [...parts(v.d), n2],+ cv: () => !nice(v.c) ? [] : v.c === 1 ? [n1] : v.c === -1 ? ['−' + n1] : [...parts(v.c), n1],+ dw: () => !nice(v.d) ? [] : v.d === 1 ? [n2] : v.d === -1 ? ['−' + n2] : [...parts(v.d), n2],sum: () => [],};defaultLabel.cv1 = defaultLabel.cv; defaultLabel.dw0 = defaultLabel.dw;@@ -248,8 +258,8 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, snaput(a.zero, { x: PX(xa) - PX(0), y: PY(ya) - PY(0) });put(a.h, { x: PX(xb), y: PY(yb) });// label: beside the tip (pushed out along the arrow) or beside the middle (on the side away from the origin)- const pp = a.label(v), key = JSON.stringify(pp);- if (key !== a.labKey) { a.labKey = key; a.labInk.replaceChildren(); if (pp.length) M(a.labInk, pp, { size: 32, fill: colorOf[id], anchor: 'middle' }); }+ const pp = L < .3 && id !== 'sum' ? [] : a.label(v), key = JSON.stringify(pp); // no label on an arrow too short to see+ if (key !== a.labKey) { a.labKey = key; a.labInk.replaceChildren(); if (pp.length) M(a.labInk, pp, { size: labelSize, fill: colorOf[id], anchor: 'middle' }); }const ux = L > 1e-9 ? (xb - xa) / L : .7, uy = L > 1e-9 ? (yb - ya) / L : .7;let lx, ly;if (a.at === 'tip') {@@ -320,6 +330,7 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, snaconst vs = {v, P: P2, stage: holder, A, names, calc, solveFor, parts, fmt, row, lattice: latG,paren: n => n < 0 ? `(${fmt(n)})` : fmt(n), // a number inside a sum: 1 + (−4)+ nice: n => !fmt(n).includes(DECIMAL_SIGN), // whole, or a simple fraction (not a value in passing)// Move the numbers to new values over dur seconds, on the beat clock (deterministic, so seeking replays it).to(next, at, dur = 1.2, ease = io) {const from = { ...plan };@@ -330,7 +341,7 @@ function vecs(p, { vecs: list = { v: [3, 2] }, c = 1, d = 1, plane: po = {}, sna// Show or hide arrows (with their labels) on the beat clock: vs.show(['cv', 'dw'], t0).show(list, at, dur = .5) { [].concat(list).forEach(id => { show(A[id].g, at, dur); show(A[id].lab, at, dur); }); },hide(list, at, dur = .5) { [].concat(list).forEach(id => { hide(A[id].g, at, dur); hide(A[id].lab, at, dur); }); },- dim(list, at, o = .3, dur = .5) { [].concat(list).forEach(id => { tw(A[id].g, { o }, at, dur); tw(A[id].lab, { o }, at, dur); }); },+ dim(list, at, o = .3, dur = .5) { [].concat(list).forEach(id => { tw(A[id].g, { o }, at, dur); tw(A[id].lab, { o: 0 }, at, dur); }); }, // a ghost keeps no label// The dashed walk across then up, with its numbers.legs(list, at, on = true, dur = .5) { [].concat(list).forEach(id => tw(A[id].leg, { o: on ? 1 : 0 }, at, dur)); },// A label is a function of the state returning math parts; where = 'tip' or 'mid'; nudge = [dx, dy] in stage px.@@ -391,13 +402,15 @@ document.head.append(Object.assign(document.createElement('style'), { textConten// Questions whose answer is a column: each row shows q (rich text, columns by hcol) = [box over box].// rows: { q, ans: [top, bottom], why, hint, fx }. Graded by blanks (any equal value, fractions too).-const vcolBlanks = rowsIn => (body, api) => {+// { cols: n } lays the rows out n to a line (one system's three columns side by side).+const vcolBlanks = (rowsIn, { cols } = {}) => (body, api) => {const ctl = blanks(rowsIn.map(r => ({ ...r, parts: [{ box: String(r.ans[0]) }, { box: String(r.ans[1]) }] })))(body, api);body.querySelectorAll('.bline').forEach((line, i) => {const bs = line.querySelectorAll('input.box');line.prepend(...(rowsIn[i].q ? [rich(rowsIn[i].q, 30), h('span', 'veq', ' = ')] : []), h('span', 'vcol vin', [bs[0], bs[1]]));});- if (rowsIn.length > 3) body.classList.add('vgrid'); // many rows: two columns, so a full-screen set fits+ if (cols) { body.classList.add('vgrid'); body.style.gridTemplateColumns = `repeat(${cols}, auto)`; }+ else if (rowsIn.length > 3) body.classList.add('vgrid'); // many rows: two columns, so a full-screen set fitsreturn ctl;};document.head.append(Object.assign(document.createElement('style'), { textContent: