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 Quadratic Equations by Completing the Square — 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: 64, title: 'Solving Quadratic Equations by Completing the Square', minutes: 10, next: '../ch65/' };
const HALF = COL.whole, SQR = COL.int, HIT = COL.good;
/* ---------- chapter drawing helpers ---------- */
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; };
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 steps = (p, lines, X, y0, gap, size = 48) => lines.forEach(([parts, t0, note, fill]) => {
mline(p, parts, X, y0, t0, fill || COL.chalk, size, 'start');
if (note) text(p, note, 1100, y0 - 8, t0, { size: 26, fill: COL.task, weight: 600 });
y0 += gap;
});
const pmRow = (lead, h, k, n, why, hint) => ({ parts: [...[].concat(lead), ': x = ', { box: String(h) }, ' ± ', { box: String(k) }, ' √', { box: String(n) }], why, hint });
const two = (a, b) => ([p, q]) => Math.abs(p - a) + Math.abs(q - b) < 1e-9 || Math.abs(p - b) + Math.abs(q - a) < 1e-9;
/* ---------- beats ---------- */
const BEATS = [
['intro', 'Completing the square', (m, D) => {
const g = G(scene, { o: 0, y: 24 });
T(g, 'Unit 12, Chapter 64', { x: 800, y: 280, size: 28, fill: COL.dim, anchor: 'middle' });
T(g, 'Solving Quadratic Equations', { x: 800, y: 380, size: 72, weight: 600, anchor: 'middle' });
T(g, 'by Completing the Square', { x: 800, y: 470, size: 72, weight: 600, anchor: 'middle' });
tw(g, { o: 1, y: 0 }, .2, 1.1, out);
const r = mline(scene, ['x', E(2), ' + 6x + 9 = (x + 3)', E(2)], 800, 620, m('sub'), COL.dim, 54);
tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
}],
['tiles', 'A square with a missing corner', (m) => {
const p = panel(0), g = G(p, { x: 170, y: 170, s: 2 }); // tile units: x = 120, 1 = 30
mline(p, ['x', E(2), ' + 6x'], 1150, 170, .2, COL.chalk, 60);
const sq = atile(g, 'x2', 60, 60);
popIn([sq], m('sq'));
const xs = Array.from({ length: 6 }, (_, i) => atile(g, 'x', 170 + i * 36, 60));
popIn(xs, m('strips'), .1);
xs.slice(0, 3).forEach((t, i) => tw(t, { x: 135 + i * 30, y: 60 }, m('split', i * .2), .8));
xs.slice(3).forEach((t, j) => tw(t, { x: 60, y: 135 + j * 30, r: 90 }, m('split2', j * .2), .8));
const gap = put(mk('rect', { x: 120, y: 120, width: 90, height: 90, fill: 'none', stroke: COL.task, 'stroke-width': 2, 'stroke-dasharray': '6 5' }, g), { o: 0 });
show(gap, m('gap'));
text(p, '3', 170 + 165 * 2, 170 + 225 * 2 + 30, m('size'), { size: 34, fill: COL.task, anchor: 'middle', weight: 700 });
text(p, '3', 170 + 225 * 2 + 16, 170 + 165 * 2 + 12, m('size'), { size: 34, fill: COL.task, weight: 700 });
const ones = Array.from({ length: 9 }, (_, i) => atile(g, 'one', 135 + (i % 3) * 30, 135 + Math.floor(i / 3) * 30));
popIn(ones, m('fill'), .08);
draw(path(p, `M170 ${170 - 26}H${170 + 210 * 2}`, { stroke: HALF, 'stroke-width': 4 }, { d: 0 }), m('done'), .5);
mline(p, 'x + 3', 170 + 105 * 2, 170 - 40, m('done', .3), HALF, 44);
draw(path(p, `M${170 - 26} 170V${170 + 210 * 2}`, { stroke: HALF, 'stroke-width': 4 }, { d: 0 }), m('done', .5), .5);
mline(p, 'x + 3', 170 - 40, 170 + 105 * 2 + 14, m('done', .8), HALF, 44, 'end');
mline(p, ['+ 9'], 1150, 260, m('fill'), SQR, 56);
mline(p, ['x', E(2), ' + 6x + 9 = (x + 3)', E(2)], 1150, 420, m('ans'), HIT, 54);
}],
['rule', 'Half of b, squared', (m) => {
const p = panel(0);
const t = tokens(p, [['x', E(2), ' + '], { t: 'b', fill: HALF }, 'x + ', { t: ['(', F('b', 2), ')', E(2)], fill: SQR }, ' = ', { t: ['(x + ', F('b', 2), ')', E(2)], fill: HIT }], { x: 800, y: 200, size: 64, anchor: 'middle', o: 0 });
show(t[0], .2); show(t[1], .2); show(t[2], .2);
mline(p, ['6 ÷ 2 = 3'], 500, 360, m('half'), HALF, 48);
mline(p, ['3', E(2), ' = 9'], 1100, 360, m('sq'), SQR, 48);
show(t[3], m('add')); show(t[4], m('add', 1)); show(t[5], m('add', 1.5));
mline(p, ['x', E(2), ' + 8x + 16 = (x + 4)', E(2)], 800, 520, m('ex'), COL.chalk, 50);
text(p, '8 ÷ 2 = 4, 4² = 16', 800, 580, m('ex', 1), { size: 28, fill: COL.dim, anchor: 'middle' });
mline(p, ['x', E(2), ' − 10x + 25 = (x − 5)', E(2)], 800, 700, m('neg'), COL.chalk, 50);
text(p, '−10 ÷ 2 = −5, (−5)² = 25', 800, 760, m('neg', 1), { size: 28, fill: COL.dim, anchor: 'middle' });
}],
['q1', 'Quick check', () => { panel(0); }, { ask: done => quiz({ x: 260, y: 240, w: 1080, cls: 'side' }, [{
id: 'c-add', prompt: ['What number completes the square?'],
build: blanks([
{ parts: ['x', E(2), ' + 22x + ', { box: '121' }], why: '22 ÷ 2 = 11, and 11² = 121.', hint: 'Half of 22, then square it.' },
{ parts: ['x', E(2), ' + 7x + ', { box: '49/4' }], why: '7 ÷ 2 = 7/2, and (7/2)² = 49/4.', hint: 'Half of 7 is 7/2. The answer can be a fraction.' },
]),
}], done) }],
['solve', 'Solving an equation', (m) => {
const p = panel(0);
text(p, 'half of −14 is −7; (−7)² = 49', 1100, 120, m('half'), { size: 26, fill: SQR, weight: 600 });
steps(p, [
[['x', E(2), ' − 14x = −11'], m('ex')],
[['x', E(2), ' − 14x + 49 = −11 + 49'], m('both'), 'add 49 to both sides'],
[['(x − 7)', E(2), ' = 38'], m('fac'), 'factor'],
[['x − 7 = ±', R(38)], m('root'), 'square roots'],
[['x = 7 ± ', R(38)], m('ans'), '', HIT],
], 260, 160, 115);
const b = put(mk('rect', { x: 236, y: 220, width: 740, height: 80, rx: 14, fill: 'none', stroke: SQR, 'stroke-width': 3 }, p), { o: 0 });
show(b, m('both', .5));
}],
['q2', 'Quick check', () => { panel(0); }, { ask: done => quiz({ x: 260, y: 240, w: 1080, cls: 'side' }, [{
id: 'c-solve', prompt: ['Solve ', $m('x', E(2), ' + 10x = 4'), ' by completing the square.'],
build: blanks([{ parts: ['x = ', { box: '-5' }, ' ± ', { box: '1' }, ' √', { box: '29' }], why: '(x + 5)² = 4 + 25 = 29.', hint: 'Add (10 ÷ 2)² = 25 to both sides.' }]),
}], done) }],
['lead', 'Make the coefficient 1', (m) => {
const p = panel(0);
steps(p, [
[['2x', E(2), ' + 12x = 10'], m('ex')],
[['x', E(2), ' + 6x = 5'], m('div'), '÷2 every term'],
[['(x + 3)', E(2), ' = 14'], m('add'), '+9 both sides'],
[['x = −3 ± ', R(14)], m('ans'), '', HIT],
], 260, 200, 130);
}],
['frac', 'Fractions are fine', (m) => {
const p = panel(0);
steps(p, [
[['−3x', E(2), ' − x + 10 = 0'], m('ex')],
[['x', E(2), ' + ', F(1, 3), 'x = ', F(10, 3)], m('div'), '−10, then ÷(−3)'],
[['(', F(1, 3), ' ÷ 2)', E(2), ' = (', F(1, 6), ')', E(2), ' = ', F(1, 36)], m('half'), 'half of b, squared'],
[['(x + ', F(1, 6), ')', E(2), ' = ', F(121, 36)], m('add'), '10/3 + 1/36 = 121/36'],
[['x + ', F(1, 6), ' = ±', F(11, 6)], m('root'), 'square roots'],
[['x = ', F(5, 3), ' or x = −2'], m('ans'), '', HIT],
], 260, 130, 115, 46);
}],
['wrap', 'Summary', (m) => {
const p = panel(0);
[['Write it as x² + bx = c (divide so x² has coefficient 1).', 'w1', COL.task], ['Add (b/2)² to both sides.', 'w2', SQR],
['Factor: (x + b/2)².', 'w3', HALF], ['Take square roots and solve.', 'w4', HIT]].forEach(([str, mark, c], i) => {
const g = G(p, { x: -16, y: 230 + i * 130, o: 0 });
mk('circle', { cx: 200, cy: -12, r: 26, fill: c }, 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-add', prompt: ['What number completes the square?'], build: blanks([
{ parts: ['x', E(2), ' − 2x + ', { box: '1' }], why: '(−1)² = 1.', hint: 'Half of −2 is −1.' },
{ parts: ['x', E(2), ' + 12x + ', { box: '36' }], why: '6² = 36.' },
{ parts: ['x', E(2), ' − 9x + ', { box: '81/4' }], why: '(−9/2)² = 81/4.', hint: 'Half of −9 is −9/2.' },
{ parts: ['x', E(2), ' + ', F(2, 3), 'x + ', { box: '1/9' }], why: '(1/3)² = 1/9.', hint: 'Half of 2/3 is 1/3.' },
]),
}], done, 'Chapter practice 1 of 3') }],
['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
id: 'p-solve', prompt: ['Solve by completing the square. Write x = h ± k√n.'], build: blanks([
pmRow(['x', E(2), ' − 18x = −57'], 9, 2, 6, '(x − 9)² = 24 = 4 · 6.', 'Add 81 to both sides.'),
pmRow(['3x', E(2), ' + 12x = 21'], -2, 1, 11, 'x² + 4x = 7, so (x + 2)² = 11.', 'Divide by 3 first.'),
pmRow(['4x', E(2), ' = 8 − 40x'], -5, 3, 3, 'x² + 10x = 2, so (x + 5)² = 27 = 9 · 3.', 'Move −40x over and divide by 4.'),
]),
}], done, 'Chapter practice 2 of 3') }],
['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
id: 'p-two', prompt: ['Solve. The two solutions can go in either order.'], build: blanks([
{ parts: ['−2x', E(2), ' + 7x + 4 = 0: x = ', { box: '4' }, ' or x = ', { box: '-1/2' }], test: two(4, -.5), why: 'x² − 7/2 x = 2, so (x − 7/4)² = 81/16 and x = 7/4 ± 9/4.', hint: 'Divide by −2, then add (7/4)² = 49/16.' },
{ parts: ['x', E(2), ' + 18x = 0: x = ', { box: '0' }, ' or x = ', { box: '-18' }], test: two(0, -18), why: '(x + 9)² = 81, so x + 9 = ±9.', hint: 'Add 81 to both sides.' },
]),
}], done, 'Chapter practice 3 of 3') }],
['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));
boot();
</script>
</body>
</html>