Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

11.6 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Introduction to Equations — 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: 24, title: 'Introduction to equations', minutes: 6, next: '../ch25/' };
const LS = COL.whole, RS = COL.nat, IN = COL.int, OUTC = COL.irr;

/* ---------- 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 function machine: input slot on the left, rule inside, output on the right.
function machine(p, rule, x = 800, y = 360) {
  const g = G(p, { o: 0 });
  mk('rect', { x: x - 170, y: y - 110, width: 340, height: 220, rx: 24, fill: mix(COL.board, COL.real, .25), stroke: COL.real, 'stroke-width': 3 }, g);
  M(g, rule, { x, y: y + 16, size: 44 });
  path(g, `M${x - 360} ${y}H${x - 190}M${x - 212} ${y - 14}L${x - 190} ${y}L${x - 212} ${y + 14}`, { stroke: IN, 'stroke-width': 4 });
  path(g, `M${x + 190} ${y}H${x + 360}M${x + 338} ${y - 14}L${x + 360} ${y}L${x + 338} ${y + 14}`, { stroke: OUTC, 'stroke-width': 4 });
  return {
    g,
    run(xv, yv, t0, tag, run = tw) {
      const a = M(p, [xv], { x: x - 400, y: y + 16, size: 48, fill: IN, o: 0 }), b = M(p, [yv], { x: x + 190, y: y + 16, size: 48, fill: OUTC, o: 0 });
      run(a, { o: 1 }, t0, .3); run(a, { x: x - 180, o: 0 }, t0 + .4, .7);
      run(b, { o: 1, x: x + 420 }, t0 + 1.2, .7);
      if (tag) { const t = T(p, tag, { x: x + 420, y: y + 80, size: 24, fill: COL.dim, anchor: 'middle', o: 0 }); run(t, { o: 1 }, t0 + 1.6, .3); run(t, { o: 0 }, t0 + 4, .3); }
      run(b, { o: 0 }, t0 + 4, .3);
    },
  };
}

/* ---------- beats ---------- */
const BEATS = [
  ['intro', 'Introduction to equations', (m, D) => {
    const g = G(scene, { o: 0, y: 24 });
    T(g, 'Unit 5, Chapter 24', { x: 800, y: 320, size: 28, fill: COL.dim, anchor: 'middle' });
    T(g, 'Introduction to equations', { x: 800, y: 420, size: 88, weight: 600, anchor: 'middle' });
    tw(g, { o: 1, y: 0 }, .2, 1.1, out);
    const r = mline(scene, ['x + 2 = 6'], 800, 590, m('q'), COL.dim, 60);
    tw(g, { o: 0, y: -24 }, D - .9, .8); hide(r, D - .9, .8);
  }],
  ['define', 'Equations', (m) => {
    const p = panel(0);
    mline(p, ['x + 2'], 400, 160, .2, COL.dim, 50);
    show(T(p, 'expression', { x: 400, y: 220, size: 24, fill: COL.dim, anchor: 'middle', o: 0 }), .4);
    const eq = tokens(p, [{ t: 'x + 2', fill: LS }, ' = ', { t: '6', fill: RS }], { x: 1100, y: 160, size: 56, anchor: 'middle', o: 0 });
    eq.forEach(e => show(e, m('eq')));
    show(T(p, 'equation', { x: 1100, y: 220, size: 24, fill: COL.task, anchor: 'middle', o: 0 }), m('eq', .5));
    const B = balance(p, { y: 360 });
    show(B.g, m('scale'));
    B.load(-1, ['x + 2'], LS, m('left')); B.load(1, ['6'], RS, m('right'));
    B.tilt(12, m('scale', .3)); B.tilt(0, m('level'));
    mline(p, ['x = 4'], 800, 800, m('sol'), COL.good, 56);
    show(T(p, 'solution', { x: 960, y: 792, size: 28, fill: COL.good, weight: 600, o: 0 }), m('sol', .5));
  }],
  ['check', 'Checking a solution', (m) => {
    const p = panel(0);
    const q1 = mline(p, ['4x = −12,   x = −3 ?'], 800, 140, m('q'), COL.chalk, 50);
    const B = balance(p, { y: 290, L: 280 });
    show(B.g, m('q', 1));
    const l1 = B.load(-1, ['4(−3)'], LS, m('sub')), r1 = B.load(1, ['−12'], RS, m('sub'));
    const l1b = B.load(-1, ['−12'], LS, m('sub', 2));
    tw(l1, { o: 0 }, m('sub', 2), .3);
    show(T(p, '✓ solution', { x: 800, y: 260, size: 32, fill: COL.good, weight: 600, anchor: 'middle', o: 0 }), m('yes'));
    [l1b, r1].forEach(e => hide(e, m('q2', -.3), .3)); hide(p.lastChild, m('q2', -.3), .3);
    hide(q1, m('q2', -.3), .3);
    mline(p, ['6y = 4x + 15,   x = −2,  y = 5 ?'], 800, 140, m('q2'), COL.chalk, 46);
    B.load(-1, ['6(5) = 30'], LS, m('sub2'), 38); B.load(1, ['4(−2) + 15 = 7'], RS, m('sub2', 2), 34);
    B.tilt(14, m('no'));
    show(T(p, '✗ 30 ≠ 7: not a solution', { x: 800, y: 780, size: 32, fill: COL.bad, weight: 600, anchor: 'middle', o: 0 }), m('no', .5));
  }],
  ['q1', 'Quick check', () => {
    const p = panel(0);
    S.B = balance(p, { y: 280, L: 280 });
    show(S.B.g, .1);
    mline(p, ['3x + 5 = 20'], 800, 150, .2, COL.chalk, 52);
    S.B.load(-1, ['3x + 5'], LS, .3); S.B.load(1, ['20'], RS, .3);
    S.B.tilt(8, .3);
    show(T(p, 'Which x makes it level?', { x: 800, y: 700, size: 26, fill: COL.dim, anchor: 'middle', o: 0 }), .5);
  }, { ask: done => quiz(BAND, [{
    id: 'c-sol', prompt: ['Which value of x is a solution of ', $m('3x + 5 = 20'), '?'],
    build: choice([['x = 3'], ['x = 5'], ['x = 25']], 1, '3(5) + 5 = 20. Both sides match.',
      ['3(3) + 5 = 14, not 20.', null, '3(25) + 5 = 80, not 20.'], () => S.B.tilt(0, 0, fxp)),
  }], done) }],
  ['machine', 'Input and output', (m) => {
    const p = panel(0);
    mline(p, ['y = 4x + 10'], 800, 150, m('q'), COL.chalk, 56);
    const Mc = machine(p, ['× 4, then + 10']);
    show(Mc.g, m('q', .5));
    show(T(p, 'input x: independent', { x: 460, y: 540, size: 30, fill: IN, weight: 600, anchor: 'middle', o: 0 }), m('in'));
    show(T(p, 'output y: dependent', { x: 1140, y: 540, size: 30, fill: OUTC, weight: 600, anchor: 'middle', o: 0 }), m('out'));
    Mc.run('−1', '6', m('ex'), '4(−1) + 10 = 6');
    Mc.run('2', '18', m('ex2'), '4(2) + 10 = 18');
  }],
  ['linear', 'Linear equations', (m) => {
    const p = panel(0);
    caption(p, 'linear: no variable has an exponent above 1', .2, 140, COL.chalk);
    mline(p, ['4a + 6 = 9a'], 520, 270, m('yes'), COL.chalk, 48); mline(p, ['y = 3x + 7'], 1080, 270, m('yes', 1.5), COL.chalk, 48);
    show(T(p, '✓ linear', { x: 800, y: 340, size: 30, fill: COL.good, weight: 600, anchor: 'middle', o: 0 }), m('yes', 3));
    mline(p, ['3m', E(2), ' + 7m − 6 = 0'], 520, 470, m('no'), COL.chalk, 48);
    show(T(p, '✗ m is squared', { x: 520, y: 540, size: 28, fill: COL.bad, weight: 600, anchor: 'middle', o: 0 }), m('no', 1.5));
    mline(p, ['9c + 7d − 4'], 1080, 470, m('noeq'), COL.chalk, 48);
    show(T(p, '✗ no equals sign', { x: 1080, y: 540, size: 28, fill: COL.bad, weight: 600, anchor: 'middle', o: 0 }), m('noeq', 1.5));
    caption(p, 'Their graphs are straight lines.', m('why'), 700, COL.dim);
  }],
  ['q2', 'Quick check', () => {
    const p = panel(0);
    S.Mc = machine(p, ['× 3, then − 2'], 800, 300);
    show(S.Mc.g, .1);
    mline(p, ['y = 3x − 2'], 800, 130, .2, COL.chalk, 52);
  }, { ask: done => quiz(BAND, [{
    id: 'c-machine', prompt: ['What comes out when x = −4?'],
    build: blanks([{ parts: ['y = 3(−4) − 2 = ', { box: '-14' }], why: '−12 − 2 = −14.', hint: 'Multiply first: 3 × (−4) = −12.', fx: () => S.Mc.run('−4', '−14', 0, null, fx) }]),
  }], done) }],
  ['write', 'Writing an equation', (m) => {
    const p = panel(0);
    caption(p, '$20 fee, plus $5 for each hour', m('q'), 140, COL.chalk, 34);
    show(T(p, 'x = hours,   y = total cost', { x: 800, y: 220, size: 30, fill: COL.dim, anchor: 'middle', o: 0 }), m('vars'));
    const e = tokens(p, ['y = ', { t: '5x', fill: IN }, ' + ', { t: '20', fill: OUTC }], { x: 800, y: 380, size: 80, anchor: 'middle', o: 0 });
    show(e[0], m('eq')); show(e[1], m('parts')); show(e[2], m('parts', 2)); show(e[3], m('parts', 2));
    show(T(p, '$5 per hour', { x: e[1]._px, y: 460, size: 26, fill: IN, anchor: 'middle', o: 0 }), m('parts', .5));
    show(T(p, 'fee', { x: e[3]._px, y: 460, size: 26, fill: OUTC, anchor: 'middle', o: 0 }), m('parts', 2.5));
    mline(p, ['x = 3:   y = 5(3) + 20 = 35'], 800, 620, m('use'), COL.good, 48);
  }],
  ['q3', 'Quick check', () => { panel(0); }, { ask: done => quiz(BAND, [{
    id: 'c-write', prompt: ['Betty is 12 years older than twice John’s age. b = Betty’s age, j = John’s age.'],
    build: choice([[$m('b = 2j + 12')], [$m('b = 2(j + 12)')], [$m('j = 2b + 12')]], 0, 'Twice John’s age is 2j, and 12 more is 2j + 12.',
      ['That adds 12 before doubling.', null, 'That makes John the older one.']),
  }], done) }],
  ['wrap', 'Summary', (m) => {
    const p = panel(0);
    [['An equation: two equal expressions, like a level balance.', 'w1'], ['A solution makes both sides equal. Substitute to check.', 'w1'],
     ['Input (independent) goes in; output (dependent) comes out.', 'w2'], ['Linear: no variable has an exponent above 1.', 'w3']].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, i === 1 ? 2 : 0), .6);
    });
  }],
  ['final1', 'Chapter practice', () => { panel(0); }, { ask: done => quiz(SCREEN, [{
    id: 'p-out', prompt: ['Find each output.'], build: blanks(OUTQ),
  }], done, 'Chapter practice   1 of 3') }],
  ['final2', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-sol', prompt: ['Is the value a solution?'], build: grid(SOLQ, [['y', 'Solution', COL.good], ['n', 'Not a solution', COL.bad]], { multi: false }),
  }], done, 'Chapter practice   2 of 3') }],
  ['final3', 'Chapter practice', () => {}, { ask: done => quiz(SCREEN, [{
    id: 'p-write', prompt: ['Which equation fits?'], build: grid(WRITEQ, [['a', 'A'], ['b', 'B'], ['c', 'C']], { multi: false, text: true }),
  }], done, 'Chapter practice   3 of 3') }],
  ['finish', 'Finished', () => {}, { ask: finishCard }],
].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));

/* ---------- chapter practice data ---------- */
const OUTQ = [
  { parts: ['y = 3 + x,  x = −5:   y = ', { box: '-2' }], why: '3 + (−5) = −2.' },
  { parts: ['y = 4x − ', F(1, 2), ',  x = 3:   y = ', { box: '23/2' }], why: '12 − 1/2 = 23/2 = 11 1/2.' },
  { parts: ['a = ', F('b − 3', 5), ' + 7b,  b = −2:   a = ', { box: '-15' }], why: '−5/5 + (−14) = −1 − 14 = −15.' },
  { parts: ['w = (9 + z)', E(3), ',  z = −11:   w = ', { box: '-8' }], why: '(−2)³ = −8.' },
  { parts: ['m = 3n', E(2), ' − n − 7,  n = −1:   m = ', { box: '-3' }], why: '3 + 1 − 7 = −3.' },
];
const SOLQ = [
  { parts: ['2x + 1 = 9,   x = 4'], ans: ['y'], why: '2(4) + 1 = 9.' },
  { parts: ['5 − x = 8,   x = 3'], ans: ['n'], why: '5 − 3 = 2, not 8. (x = −3 works.)' },
  { parts: ['x', E(2), ' = 16,   x = −4'], ans: ['y'], why: '(−4)² = 16.' },
  { parts: ['y = 2x − 1,   x = 3, y = 4'], ans: ['n'], why: '2(3) − 1 = 5, not 4.' },
];
const WRITEQ = [
  { parts: ['Pineapples p are 8 fewer than mangoes m.   A: ', $m('p = m − 8'), '   B: ', $m('m = p − 8'), '   C: ', $m('p = 8m')], ans: ['a'], why: 'Take 8 away from the mangoes.' },
  { parts: ['The sum of two numbers x and y is 25.   A: ', $m('xy = 25'), '   B: ', $m('x + y = 25'), '   C: ', $m('x = y + 25')], ans: ['b'], why: 'Sum means add.' },
  { parts: ['3-pound boxes b and 8-pound boxes p weigh t in all.   A: ', $m('t = 8b + 3p'), '   B: ', $m('t = 11(b + p)'), '   C: ', $m('t = 3b + 8p')], ans: ['c'], why: '3 pounds for each b, 8 pounds for each p.' },
];
boot();
</script>
</body>
</html>