An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Solving Systems by Substitution — Elementary Algebra</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="audio/en/timings.js"></script>
<script>
'use strict';
const CHAPTER = { number: 29, title: 'Solving systems by substitution', minutes: 7, next: '../ch30/' };
const E1 = COL.whole, E2 = COL.nat, SUB = COL.task, SOL = COL.good;
/* ---------- chapter drawing helpers ---------- */
const caption = (p, str, t0, y = 140, fill = COL.dim, size = 30, x = 800) => show(T(p, str, { x, y, size, fill, weight: 600, anchor: 'middle', o: 0 }), t0);
const mline = (p, parts, x, y, t0, fill = COL.chalk, size = 48, anchor = 'middle') => { const e = M(p, [].concat(parts), { x, y, size, fill, anchor, o: 0 }); show(e, t0); return e; };
// A system: a curly brace with two equations, numbered ① ②. Returns the two lines.
function system(p, a, b, x, y, t0, { size = 48, gap = 80 } = {}) {
const g = G(p, { o: 0 });
const h = gap + size * .9, top = y - size * .8;
path(g, `M${x - 18} ${top}Q${x - 36} ${top} ${x - 36} ${top + h * .2}V${top + h * .4}Q${x - 36} ${top + h / 2} ${x - 52} ${top + h / 2}Q${x - 36} ${top + h / 2} ${x - 36} ${top + h * .6}V${top + h * .8}Q${x - 36} ${top + h} ${x - 18} ${top + h}`, { stroke: COL.dim, 'stroke-width': 3 });
const l1 = M(g, [].concat(a), { x, y, size, fill: E1, anchor: 'start' }), l2 = M(g, [].concat(b), { x, y: y + gap, size, fill: E2, anchor: 'start' });
T(g, '①', { x: x - 90, y: y - 4, size: 30, fill: E1, anchor: 'middle' }); T(g, '②', { x: x - 90, y: y + gap - 4, size: 30, fill: E2, anchor: 'middle' });
show(g, t0);
return g;
}
const step = (p, n, str, y, t0, x = 180) => show(T(p, `${n}. ${str}`, { x, y, size: 26, fill: SUB, weight: 600, o: 0 }), t0);
/* ---------- beats ---------- */
const BEATS = [
['intro', 'Systems by substitution', (m, D) => {
const g = G(scene, { o: 0, y: 24 });
T(g, 'Unit 5, Chapter 29', { x: 800, y: 300, size: 28, fill: COL.dim, anchor: 'middle' });
T(g, 'Solving systems by substitution', { x: 800, y: 400, size: 76, weight: 600, anchor: 'middle' });
tw(g, { o: 1, y: 0 }, .2, 1.1, out);
const r = mline(scene, ['10 tickets, $50: adults $8, children $3'], 800, 580, 1.5, COL.dim, 42);
tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
}],
['system', 'A system of equations', (m) => {
const p = panel(0);
system(p, ['x + y = 5'], ['5x − 4y = −2'], 560, 220, m('ex'));
caption(p, 'A solution makes both equations true.', m('sol'), 400, COL.chalk);
mline(p, ['test (2, 3)'], 800, 480, m('test'), SUB, 44);
mline(p, ['① 2 + 3 = 5 ✓'], 800, 580, m('e1'), E1, 42);
mline(p, ['② 5(2) − 4(3) = 10 − 12 = −2 ✓'], 800, 670, m('e2'), E2, 42);
caption(p, '(2, 3) is a solution of the system', m('ans'), 760, SOL, 30);
}],
['tickets', 'Tickets', (m) => {
const p = panel(0);
show(T(p, 'a = adults, c = children', { x: 450, y: 150, size: 30, fill: COL.dim, anchor: 'middle', o: 0 }), m('vars'));
system(p, ['a + c = 10'], ['8a + 3c = 50'], 300, 260, m('e1'));
const tb = G(p, { o: 0 }), x0 = 900, rh = 50;
[['a', 'c', 'cost'], ...Array.from({ length: 7 }, (_, i) => [i + 1, 9 - i, 8 * (i + 1) + 3 * (9 - i)])].forEach((r, i) => {
r.forEach((v, j) => T(tb, String(v), { x: x0 + j * 150, y: 170 + i * rh, size: 28, fill: i ? COL.chalk : COL.dim, font: i ? MATH : UI, anchor: 'middle', weight: i ? 400 : 600 }));
});
show(tb, m('guess'), .6);
const hl = rect(p, x0 - 70, 170 + 4 * rh - 36, 440, 48, SOL); hl.setAttribute('fill-opacity', .2);
show(hl, m('hit'), .4);
show(T(p, '$50 ✓', { x: x0 + 390, y: 170 + 4 * rh, size: 28, fill: SOL, weight: 600, o: 0 }), m('hit', .3));
}],
['method', 'Four steps', (m) => {
const p = panel(0);
[['Solve one equation for one variable.', 's1'], ['Substitute into the other equation.', 's2'], ['Solve the new one-variable equation.', 's3'], ['Substitute back to find the other variable.', 's4']].forEach(([str, mark], i) => {
const g = G(p, { x: -16, y: 230 + i * 120, o: 0 });
mk('circle', { cx: 200, cy: -12, r: 26, fill: SUB }, g);
T(g, String(i + 1), { x: 200, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
T(g, str, { x: 260, size: 36, weight: 600 });
tw(g, { o: 1, x: 0 }, m(mark), .6);
});
}],
['ex1', 'An example', (m) => {
const p = panel(0);
system(p, ['5x + y = 11'], ['2x − 3y = 1'], 220, 140, m('q'), { size: 40, gap: 60 });
step(p, 1, 'solve ① for y', 290, m('s1'));
eqLine(p, ['y'], ['11 − 5x'], 290, m('s1', .5), { xEq: 840, size: 42 });
step(p, 2, 'substitute into ②', 400, m('s2'));
const r = tokens(p, ['2x − 3', { t: 'y', fill: E2 }, ' = 1'], { x: 720, y: 400, size: 42, o: 0 });
r.forEach(e => show(e, m('s2', .3)));
const fly = M(p, ['(11 − 5x)'], { x: 900, y: 290, size: 42, fill: SUB, o: 0 });
show(fly, m('s2', 1.5), .2); tw(fly, { x: r[1]._px + 80, y: 400 }, m('s2', 1.6), 1);
hide(fly, m('s2', 2.6), .2);
collapse(r, 1, 1, ['(11 − 5x)'], m('s2', 2.4), { color: SUB, fill: SUB });
step(p, 3, 'solve', 510, m('s3'));
mline(p, ['2x − 33 + 15x = 1 → 17x = 34 → x = 2'], 740, 510, m('s3', .5), COL.chalk, 38, 'start');
step(p, 4, 'substitute back', 620, m('s4'));
mline(p, ['y = 11 − 5(2) = 1'], 740, 620, m('s4', .5), COL.chalk, 40, 'start');
mline(p, ['(x, y) = (2, 1)'], 800, 730, m('ans'), SOL, 50);
show(T(p, 'check ②: 2(2) − 3(1) = 1 ✓', { x: 800, y: 790, size: 26, fill: COL.dim, anchor: 'middle', o: 0 }), m('check'));
}],
['q1', 'Quick check', () => {
const p = panel(0);
system(p, ['x + 2y = 5'], ['4x + 5y = 8'], 620, 200, .2, { size: 50 });
mline(p, ['① → x = 5 − 2y'], 800, 420, .4, SUB, 44);
}, { ask: done => quiz(BAND, [{
id: 'c-sub', prompt: ['Substitute into ② and solve.'],
build: blanks([{ parts: ['y = ', { box: '4' }, ', x = ', { box: '-3' }], why: '4(5 − 2y) + 5y = 8 → 20 − 3y = 8 → y = 4. Then x = 5 − 8 = −3.', hint: 'Replace x in 4x + 5y = 8 with (5 − 2y), then solve for y.' }]),
}], done) }],
['back', 'Solving the ticket problem', (m) => {
const p = panel(0);
system(p, ['a + c = 10'], ['8a + 3c = 50'], 220, 140, .2, { size: 40, gap: 60 });
step(p, 1, 'solve ① for a', 290, m('s1'));
mline(p, ['a = 10 − c'], 760, 290, m('s1', .5), SUB, 42, 'start');
step(p, 2, 'substitute into ②', 400, m('s2'));
mline(p, ['8(10 − c) + 3c = 50'], 760, 400, m('s2', 1), COL.chalk, 42, 'start');
step(p, 3, 'solve', 510, m('s3'));
mline(p, ['80 − 5c = 50 → c = 6'], 760, 510, m('s3', 1), COL.chalk, 42, 'start');
step(p, 4, 'substitute back', 620, m('s4'));
mline(p, ['a = 10 − 6 = 4'], 760, 620, m('s4', .5), COL.chalk, 42, 'start');
caption(p, '4 adults and 6 children', m('ans'), 740, SOL, 34);
}],
['choose', 'Which variable first?', (m) => {
const p = panel(0);
caption(p, 'Look for a coefficient of 1 or −1: no fractions.', m('tip'), 160, SUB, 32);
const r = tokens(p, ['3x ', { t: '− y', fill: SUB }, ' = −4'], { x: 800, y: 330, size: 64, anchor: 'middle', o: 0 });
r.forEach(e => show(e, m('ex')));
const ring = put(mk('ellipse', { fill: 'none', stroke: SUB, 'stroke-width': 3 }, p), { o: 0, a_cx: r[1]._px, a_cy: 310, a_rx: r[1]._w / 2 + 12, a_ry: 48 });
show(ring, m('ex', 2));
mline(p, ['y = 3x + 4'], 800, 500, m('res'), SOL, 60);
}],
['q2', 'Quick check', () => { panel(0); }, { ask: done => quiz(BAND, [{
id: 'c-word', prompt: ['8 notebooks and 9 binders cost $60. 6 notebooks and 5 binders cost $38. Find each price.'],
build: blanks([{ parts: ['notebook $', { box: '3' }, ', binder $', { box: '4' }], why: '8n + 9b = 60 and 6n + 5b = 38 give n = 3, b = 4. Check: 24 + 36 = 60, 18 + 20 = 38.', hint: 'Write two equations, solve one for n, and substitute.' }]),
}], done) }],
['wrap', 'Summary', (m) => {
const p = panel(0);
[['Solve one equation for one variable.', 'w1'], ['Substitute into the other equation.', 'w2'], ['Solve, then substitute back.', 'w3'], ['Check the pair in both equations.', 'w4']].forEach(([str, mark], i) => {
const g = G(p, { x: -16, y: 230 + i * 120, o: 0 });
mk('circle', { cx: 200, cy: -12, r: 26, fill: COL.task }, g);
T(g, String(i + 1), { x: 200, y: -1, size: 30, fill: COL.board, weight: 700, anchor: 'middle' });
T(g, str, { x: 260, size: 34, weight: 600 });
tw(g, { o: 1, x: 0 }, m(mark), .6);
});
}],
['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
id: 'p-solve', prompt: ['Solve each system.'], build: blanks(SOLVE),
}], done, 'Chapter practice 1 of 3') }],
['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
id: 'p-check', prompt: ['Is the pair a solution of the system?'], build: grid(CHECKQ, [['y', 'Solution', SOL], ['n', 'Not a solution', COL.bad]], { multi: false }),
}], done, 'Chapter practice 2 of 3') }],
['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
id: 'p-word', prompt: ['A class of 30 students has 6 more girls than boys. How many of each?'], build: blanks(WORD),
}], done, 'Chapter practice 3 of 3') }],
['finish', 'Finished', () => {}, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
/* ---------- chapter practice data ---------- */
const SOLVE = [
{ parts: ['3x + y = 5, 2x + 3y = 8: x = ', { box: '1' }, ', y = ', { box: '2' }], why: 'y = 5 − 3x; 2x + 15 − 9x = 8, so x = 1, y = 2.' },
{ parts: ['3x − y = −4, 5x + 9y = −28: x = ', { box: '-2' }, ', y = ', { box: '-2' }], why: 'y = 3x + 4; 5x + 27x + 36 = −28, so x = −2, y = −2.' },
{ parts: ['8x − 3y = −5, −2x + 5y = 14: x = ', { box: '1/2' }, ', y = ', { box: '3' }], why: 'From ②, x = (5y − 14)/2; then 20y − 56 − 3y = −5, y = 3, x = 1/2.' },
{ parts: ['y = 2x, x + y = 12: x = ', { box: '4' }, ', y = ', { box: '8' }], why: 'x + 2x = 12, x = 4.' },
];
const CHECKQ = [
{ parts: ['x + y = 7, x − y = 1; (4, 3)'], ans: ['y'], why: '4 + 3 = 7 and 4 − 3 = 1.' },
{ parts: ['2x + y = 5, x + y = 4; (2, 1)'], ans: ['n'], why: '2(2) + 1 = 5 ✓, but 2 + 1 = 3, not 4.' },
{ parts: ['y = 3x − 1, 2x + y = 9; (2, 5)'], ans: ['y'], why: '3(2) − 1 = 5 and 4 + 5 = 9.' },
{ parts: ['x − 2y = 0, x + y = 6; (2, 4)'], ans: ['n'], why: '2 − 8 = −6, not 0. (4, 2) works.' },
];
const WORD = [
{ parts: ['b + g = 30, g = b + 6: boys ', { box: '12' }, ', girls ', { box: '18' }], why: 'b + (b + 6) = 30, so b = 12, g = 18.' },
];
boot();
</script>
</body>
</html>