An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
refactor(skill): shorts.js names apart from film.js, so both can load
yzr03d7c8dcc83f
diff --git a/.claude/skills/papermorph/assets/templates/shorts/chapter.html b/.claude/skills/papermorph/assets/templates/shorts/chapter.htmlindex 90d9e48..736f15f 100644--- a/.claude/skills/papermorph/assets/templates/shorts/chapter.html+++ b/.claude/skills/papermorph/assets/templates/shorts/chapter.html@@ -31,7 +31,7 @@ const BEATS = [const p = panel(0);const s = shot(p, 0, undefined);photo(s, 'hook-picture', 0, D, { s0: 1.0, s1: 1.15, dim: .2 });- word(s, 'Big word', CX, 640, m('big'), { size: 140, fill: '#fff', stroke: INK });+ word(s, 'Big word', CX, 640, m('big'), { size: 140, fill: '#fff', stroke: DARK });label(s, 'Series · part 1', CX, 1200, .3, { size: 44, fill: RED });}, { pre: OPEN_PRE }],].map(shortsBeat);diff --git a/.claude/skills/papermorph/assets/templates/shorts/lib/shorts.js b/.claude/skills/papermorph/assets/templates/shorts/lib/shorts.jsindex d7a5353..bb28df3 100644--- a/.claude/skills/papermorph/assets/templates/shorts/lib/shorts.js+++ b/.claude/skills/papermorph/assets/templates/shorts/lib/shorts.js@@ -9,15 +9,15 @@Full bleed, one idea per shot, 1–3 s a shot.Platforms draw over the top 120 and the bottom 300 of the 900 x 1600 stage, and their buttons over the right 90between y 700 and 1300: words stay in x 50..810, y 130..1290. Pictures may run under all of it. */-const KEY = '"Oswald", "Arial Narrow", sans-serif', SER = '"EB Garamond", Georgia, serif';-const INK = '#1f1b16', RED = '#c8281e', TEAL = '#2f6f73', PAPER = '#ece4d3', SOFT = '#8a7d68', MARK = '#ffd23f', SEA = '#123c44';+const SANS = '"Oswald", "Arial Narrow", sans-serif', SERIF = '"EB Garamond", Georgia, serif';+const DARK = '#1f1b16', RED = '#c8281e', TEAL = '#2f6f73', LIGHT = '#ece4d3', MUTED = '#8a7d68', MARK = '#ffd23f', SEA = '#123c44';const CX = 450, W = 900, H = 1600;-const CTX = document.createElement('canvas').getContext('2d');-const wid = (str, size, font = KEY, weight = 600) => { CTX.font = `${weight} ${size}px ${font}`; return CTX.measureText(str).width; };+const TEXT_CTX = document.createElement('canvas').getContext('2d');+const inkW = (str, size, font = SANS, weight = 600) => { TEXT_CTX.font = `${weight} ${size}px ${font}`; return TEXT_CTX.measureText(str).width; };const rect = (p, x, y, w, h, attrs = {}) => mk('rect', { x, y, width: w, height: h, ...attrs }, p);-const span01 = (t, a, b) => Math.min(1, Math.max(0, (t - a) / (b - a)));+const ramp01 = (t, a, b) => Math.min(1, Math.max(0, (t - a) / (b - a)));const smooth = q => q * q * (3 - 2 * q);-function rng(seed) { return () => (seed = (seed * 16807) % 2147483647) / 2147483647; }+function seeded(seed) { return () => (seed = (seed * 16807) % 2147483647) / 2147483647; }// the cut-out figures' widths at 1000 tall, by file name: the book fills it, Object.assign(MEME, { 'meme-cook': 672 })const MEME = {};// one meme crossing the frame left to right, then a fast swarm of the same (smaller and higher is farther away):@@ -26,7 +26,7 @@ function swarm(g, name, t0, { h = 560, y = 1500, cross = 1.6, n = 16, after = 1.const w = MEME[name] * h / 1000;const e = meme(g, name, -w / 2 - 40, y, h, t0, { rise: 0, dur: .01 });tw(e, { x: W + w / 2 + 40 }, t0, cross, lin); sfx(BEAT_ID, t0 + .1, 'whoosh', .6);- const R = rng(seed);+ const R = seeded(seed);for (let i = 0; i < n; i++) {const t1 = t0 + after + i * .12 + R() * .08, far = R(), hh = hmin + (1 - far) * (h - hmin), ww = MEME[name] * hh / 1000;const f = meme(g, name, -ww / 2 - 20, ymin + (1 - far) * (y - ymin), hh, t1, { rise: 0, dur: .01 });@@ -66,40 +66,40 @@ function photo(g, name, t0, t1, { s0 = 1.02, s1 = 1.1, dx = 0, dy = 0, dim = 0,mk('image', { href: `../img/${name}.webp`, x: -W / 2, y: -H / 2, width: W, height: H, preserveAspectRatio: 'xMidYMid slice' }, im);tw(im, { s: s1, x: CX + dx, y: H / 2 + dy }, t0, t1 - t0, lin);if (dim) rect(g, 0, 0, W, H, { fill: '#000', opacity: dim });- if (ai) tag(g, 'AI illustration', 50, 150, t0);+ if (ai) srcTag(g, 'AI illustration', 50, 150, t0);return im;}// a small grey label top left: a source or "AI illustration"; shown with ?tags (export.py --query tags), so a cut// being worked on stays clean while the calls stay in placeconst TAGS = new URLSearchParams(location.search).has('tags');-function tag(g, str, x, y, t0) {+function srcTag(g, str, x, y, t0) {if (!TAGS) return G(g, { o: 0 });- const e = G(g, { x, y, o: 0 }), w = wid(str.toUpperCase(), 20, KEY, 500) + 20;+ const e = G(g, { x, y, o: 0 }), w = inkW(str.toUpperCase(), 20, SANS, 500) + 20;rect(e, 0, -22, w, 30, { fill: 'rgba(20,18,15,.55)', rx: 3 });- T(e, str.toUpperCase(), { x: 10, y: 0, size: 20, fill: '#f0ebe0', font: KEY, weight: 500 }).setAttribute('letter-spacing', '.06em');+ T(e, str.toUpperCase(), { x: 10, y: 0, size: 20, fill: '#f0ebe0', font: SANS, weight: 500 }).setAttribute('letter-spacing', '.06em');show(e, t0, .2, lin);return e;}// big condensed capitals popping in (a word or two); stroke: a dark edge to read over pictures-function word(g, str, x, y, t0, { size = 120, fill = INK, anchor = 'middle', stroke, dur = .22, from = .82 } = {}) {+function word(g, str, x, y, t0, { size = 120, fill = DARK, anchor = 'middle', stroke, dur = .22, from = .82 } = {}) {const e = G(g, { x, y, s: from, o: 0 });- const t = T(e, str.toUpperCase(), { x: 0, y: 0, size, fill, font: KEY, weight: 600, anchor });+ const t = T(e, str.toUpperCase(), { x: 0, y: 0, size, fill, font: SANS, weight: 600, anchor });if (stroke) { t.setAttribute('stroke', stroke); t.setAttribute('stroke-width', size / 14); t.setAttribute('paint-order', 'stroke'); t.setAttribute('stroke-linejoin', 'round'); }if (t0 <= .01) put(e, { s: 1, o: 1 }); else tw(e, { s: 1, o: 1 }, t0, dur, out); // there on a beat's first frame- e._w = wid(str.toUpperCase(), size);+ e._w = inkW(str.toUpperCase(), size);return e;}// a label: caps on a solid block (Vox's MARY / JESUS chips); not `chip`, which is the engine's own-function label(g, str, x, y, t0, { size = 40, fill = INK, colour = PAPER, anchor = 'middle', pad = 18 } = {}) {- const w = wid(str.toUpperCase(), size, KEY, 600) + pad * 2, x0 = anchor === 'middle' ? -w / 2 : anchor === 'end' ? -w : 0;+function label(g, str, x, y, t0, { size = 40, fill = DARK, colour = LIGHT, anchor = 'middle', pad = 18 } = {}) {+ const w = inkW(str.toUpperCase(), size, SANS, 600) + pad * 2, x0 = anchor === 'middle' ? -w / 2 : anchor === 'end' ? -w : 0;const e = G(g, { x, y, s: .85, o: 0 });rect(e, x0, -size * .95, w, size * 1.3, { fill, rx: 4 });- T(e, str.toUpperCase(), { x: x0 + pad, y: 0, size, fill: colour, font: KEY, weight: 600 });+ T(e, str.toUpperCase(), { x: x0 + pad, y: 0, size, fill: colour, font: SANS, weight: 600 });tw(e, { s: 1, o: 1 }, t0, .18, out);return e;}// lines of a sentence as stacked chips, each popping in turn-function band(g, lines, y, t0, { size = 64, fill = INK, colour = PAPER, step = .25, lh = 1.3 } = {}) {+function band(g, lines, y, t0, { size = 64, fill = DARK, colour = LIGHT, step = .25, lh = 1.3 } = {}) {lines.forEach((l, i) => label(g, l, CX, y + i * size * lh, t0 + i * step, { size, fill, colour }));}// a yellow marker swept behind [x, y, w, h]@@ -127,16 +127,16 @@ function meme(g, name, x, y, h, t0, { flip = false, rise = 260, dur = .35 } = {}}// a rubber stamp slammed onfunction stamp(g, str, x, y, t0, { size = 110, colour = RED, r = -9 } = {}) {- const w = wid(str, size) + 60, e = G(g, { x, y, r, s: 1.7, o: 0 });+ const w = inkW(str, size) + 60, e = G(g, { x, y, r, s: 1.7, o: 0 });rect(e, -w / 2, -size * .85, w, size * 1.2, { fill: 'none', stroke: colour, 'stroke-width': size / 11, rx: 10 });- T(e, str, { y: size * .3, size, fill: colour, font: KEY, weight: 600, anchor: 'middle' });+ T(e, str, { y: size * .3, size, fill: colour, font: SANS, weight: 600, anchor: 'middle' });tw(e, { s: 1, o: 1 }, t0, .16, out);sfx(BEAT_ID, t0, 'bang', 1.4);return e;}// a number counting up to n over dur-function counter(g, n, x, y, t0, { size = 90, fill = INK, anchor = 'middle', dur = 1.1, pre = '', ticks = true } = {}) {- const t = T(g, pre + '0', { x, y, size, fill, font: KEY, weight: 600, anchor, o: 0 });+function counter(g, n, x, y, t0, { size = 90, fill = DARK, anchor = 'middle', dur = 1.1, pre = '', ticks = true } = {}) {+ const t = T(g, pre + '0', { x, y, size, fill, font: SANS, weight: 600, anchor, o: 0 });show(t, t0, .1, lin);prog(q => { t.textContent = pre + Math.round(n * q).toLocaleString('en-US'); }, t0, dur, out);if (ticks) for (let k = 0; k < 6; k++) sfx(BEAT_ID, t0 + k * dur / 6, 'tick', .45);@@ -145,7 +145,7 @@ function counter(g, n, x, y, t0, { size = 90, fill = INK, anchor = 'middle', dur// a phone-shaped card holding a picture (rounded, black rim)function phoneCard(g, x, y, w, h, img) {const e = G(g, { x, y }), id = 'pc' + (++fxN);- rect(e, -w / 2 - 10, -h / 2 - 10, w + 20, h + 20, { rx: 34, fill: INK });+ rect(e, -w / 2 - 10, -h / 2 - 10, w + 20, h + 20, { rx: 34, fill: DARK });mk('rect', { x: -w / 2, y: -h / 2, width: w, height: h, rx: 26 }, mk('clipPath', { id }, mk('defs', {}, e)));const im = mk('image', { href: `../img/${img}.webp`, x: -w / 2, y: -h / 2, width: w, height: h, preserveAspectRatio: 'xMidYMid slice' }, e);im.setAttribute('clip-path', `url(#${id})`);@@ -180,11 +180,11 @@ function clipImg(g, name, x, y, w, h, rx = 0) {mk('image', { href: `../img/${name}.webp`, x, y, width: w, height: h, preserveAspectRatio: 'xMidYMid slice' }, g).setAttribute('clip-path', `url(#${id})`);}/* an ink price tag */-function priceTag(p, x, y, str, t0, colour = INK) {- const g = G(p, { x, y, o: 0, r: -4, s: 1.2 }), w = wid(str, 80, SER, 500) + 90;+function priceTag(p, x, y, str, t0, colour = DARK) {+ const g = G(p, { x, y, o: 0, r: -4, s: 1.2 }), w = inkW(str, 80, SERIF, 500) + 90;path(g, `M0 0L40 -56H${w}V56H40Z`, { fill: '#f6f1e6', stroke: colour, 'stroke-width': 5 });mk('circle', { cx: 36, cy: 0, r: 11, fill: 'none', stroke: colour, 'stroke-width': 5 }, g);- T(g, str, { x: 66, y: 26, size: 80, fill: colour, font: SER, weight: 500 });+ T(g, str, { x: 66, y: 26, size: 80, fill: colour, font: SERIF, weight: 500 });tw(g, { o: 1, s: 1 }, t0, .2, out);return g;}diff --git a/.claude/skills/papermorph/references/shorts.md b/.claude/skills/papermorph/references/shorts.mdindex 2f1e11a..f2ac6af 100644--- a/.claude/skills/papermorph/references/shorts.md+++ b/.claude/skills/papermorph/references/shorts.md@@ -43,8 +43,9 @@ When the user wants a film that already exists recut as shorts (*Madness and Civ`shorts.js` holds the grammar, every helper a pure function of the beat clock:- `shot()` a full-frame shot with a hard cut, `whip` (a sideways slide with motion blur) or `swipe` (the next clip rising as in a feed); `photo()` a full-bleed picture with a slow push, centred (a landscape picture whose subject is off-centre needs a camera that pans across it without showing an edge: the worked example's `wide()` in `site/madness-shorts/lib/madness.js`);-- `word()` big condensed capitals, `label()` and `band()` caps on solid blocks, `marker()` a highlighter sweep, `vlog()` white outlined overlay text, `tag()` a source or "AI illustration";+- `word()` big condensed capitals, `label()` and `band()` caps on solid blocks, `marker()` a highlighter sweep, `vlog()` white outlined overlay text, `srcTag()` a source or "AI illustration";- `meme()` a cut-out figure rising in, `swarm()` one crossing then a crowd of them, `stamp()` a rubber stamp slammed on, `counter()` a number counting up, `priceTag()`, `phoneCard()`, `ico()` and `icons()` (Phosphor, MIT), `bar()`, `clipImg()`;+- its palette (`DARK`, `RED`, `LIGHT`, `MUTED`, …), fonts (`SANS`, `SERIF`) and small tools (`inkW()` text width, `ramp01()`, `seeded()`) are named apart from the documentary kit's `film.js`, so a short can load `film.js` too when it wants a documentary helper (`pic()`, `say()`, `traced()`): load it before `shorts.js`;- `shortsBeat` turns a beat tuple into the engine's beat with every cue `LEAD` (0.22 s) early: a cut that lands on the word itself reads as late.What made the first shorts work:diff --git a/site/madness-shorts/ch01/index.html b/site/madness-shorts/ch01/index.htmlindex 3d38211..68420b5 100644--- a/site/madness-shorts/ch01/index.html+++ b/site/madness-shorts/ch01/index.html@@ -29,13 +29,13 @@ const BEATS = [const s = shot(p, 0, undefined), bt = m('boats');wide(s, 'bosch', [[0, .76, .56, 2.4], [bt - .3, .75, .57, 2.75], [bt + .35, .5, .62, 1.0], [D + .8, .5, .66, 1.07]]);rect(s, 0, 0, W, H, { fill: '#000', opacity: .12 });- tag(s, 'Bosch, The Ship of Fools, c. 1500', 50, 150, 0);- word(s, '500 years ago', CX, 250, 0, { size: 96, fill: '#fff', stroke: INK });- const lk = word(s, 'Locked up', CX, 1180, m('mad') - .9, { size: 150, fill: '#fff', stroke: INK });+ srcTag(s, 'Bosch, The Ship of Fools, c. 1500', 50, 150, 0);+ word(s, '500 years ago', CX, 250, 0, { size: 96, fill: '#fff', stroke: DARK });+ const lk = word(s, 'Locked up', CX, 1180, m('mad') - .9, { size: 150, fill: '#fff', stroke: DARK });const st = strike(s, lk, CX, 1180, m('mad') - .2, 150);hide(lk, bt - .1, .1, lin); hide(st, bt - .1, .1, lin);sfx('hook', m('mad') - .2, 'whoosh', .4);- word(s, 'On boats', CX, 1180, bt, { size: 200, fill: RED, stroke: INK });+ word(s, 'On boats', CX, 1180, bt, { size: 200, fill: RED, stroke: DARK });sfx('hook', bt, 'thud', 1.4); sfx('hook', bt - .1, 'whoosh', .5);}, { pre: OPEN_PRE }],@@ -45,8 +45,8 @@ const BEATS = [const one = m('one');let s = shot(p, 0, one, { bg: BURG });traced(s, 'mf-front', { x: CX, y: 720, h: 860, at: 0, draw: 1.0 });- label(s, 'Michel Foucault', CX, 1230, 0, { size: 60, fill: PAPER, colour: INK });- quote(s, ['Madness and Civilization, 1961'], 1330, m('mc'), { size: 52, fill: SOFT });+ label(s, 'Michel Foucault', CX, 1230, 0, { size: 60, fill: LIGHT, colour: DARK });+ quote(s, ['Madness and Civilization, 1961'], 1330, m('mc'), { size: 52, fill: MUTED });s = shot(p, one, undefined, { bg: BURG, swipe: true });seriesCard(s, one, 1, m('ship'));}],@@ -58,28 +58,28 @@ const BEATS = [const t2 = cue(1), fd = cue(2), id = cue(4); // "In the Middle Ages", "Then leprosy faded", "And so did the idea"let s = shot(p, 0, t2);photo(s, 'e1-ward', 0, t2, { s0: 1.0, s1: 1.08, dim: .25 });- word(s, 'An empty room', CX, 1150, .2, { size: 120, fill: '#fff', stroke: INK });+ word(s, 'An empty room', CX, 1150, .2, { size: 120, fill: '#fff', stroke: DARK });// Europe lights up with leper houses; the number lands on the words = shot(p, t2, id, { bg: BURG, whip: true });- word(s, 'Leper houses', CX, 250, t2 + .1, { size: 100, fill: PAPER });+ word(s, 'Leper houses', CX, 250, t2 + .1, { size: 100, fill: LIGHT });const eu = europeMap(s, 40, 360, 820, t2 + .05);eu.el.forEach((e, i) => show(e, t2 + .2 + (i / eu.el.length) * (hs - t2), .15, lin));const n = counter(s, 19000, CX, 1180, t2 + .1, { size: 180, fill: RED, dur: hs - t2 + .1 });- tag(s, 'Matthew Paris, 13th c., quoted by Foucault', 50, 150, t2);+ srcTag(s, 'Matthew Paris, 13th c., quoted by Foucault', 50, 150, t2);// leprosy fades: the dots go out; the buildings stay: an empty ring where each stood- const R = rng(11);+ const R = seeded(11);eu.el.forEach(e => hide(e, fd + R() * 1.2, .2));hide(n, fd, .2);- const lf = word(s, 'Leprosy fades', CX, 1180, fd + .1, { size: 110, fill: SOFT });+ const lf = word(s, 'Leprosy fades', CX, 1180, fd + .1, { size: 110, fill: MUTED });hide(lf, bl - .1, .15);const rings = G(eu.g, { o: 0 });- EUROPE.dots.forEach(([cx, cy], i) => { if (i % 3 === 0) mk('circle', { cx, cy, r: 6, fill: 'none', stroke: PAPER, 'stroke-width': 1.6 }, rings); });+ EUROPE.dots.forEach(([cx, cy], i) => { if (i % 3 === 0) mk('circle', { cx, cy, r: 6, fill: 'none', stroke: LIGHT, 'stroke-width': 1.6 }, rings); });show(rings, bl, .4);- word(s, 'The buildings stayed', CX, 1180, bl + .05, { size: 110, fill: PAPER });+ word(s, 'The buildings stayed', CX, 1180, bl + .05, { size: 110, fill: LIGHT });// and so did the idea: push someone outs = shot(p, id, undefined, { whip: true });photo(s, 'e1-gate', id, D + .6, { s0: 1.04, s1: 1.16, dx: 30 });- word(s, 'And the idea', CX, 280, id + .1, { size: 110, fill: '#fff', stroke: INK });+ word(s, 'And the idea', CX, 280, id + .1, { size: 110, fill: '#fff', stroke: DARK });band(s, ['Keep the town clean:', 'push someone out'], 1120, pu + .1, { size: 66, step: 1.1 });}],@@ -89,9 +89,9 @@ const BEATS = [const g = m('greedy'), v = m('vain'), d = m('drunk'), i = m('idle'), nw = m('nowhere');let s = shot(p, 0, g);wide(s, 'narragonien', [[0, .5, .4, 1.55], [g, .5, .42, 1.85]]); // into the woodcut's boat- tag(s, 'Sebastian Brant, Das Narrenschiff, Basel 1494', 50, 150, 0);+ srcTag(s, 'Sebastian Brant, Das Narrenschiff, Basel 1494', 50, 150, 0);label(s, '1494', CX, 250, 0, { size: 90 });- label(s, 'A bestseller', CX, 1200, m('brant') + .3, { size: 76, fill: RED, colour: INK });+ label(s, 'A bestseller', CX, 1200, m('brant') + .3, { size: 76, fill: RED, colour: DARK });sfx('brant', m('brant'), 'page', .6);// one fool per word, a quick move between thems = shot(p, g, nw, { swipe: true });@@ -99,7 +99,7 @@ const BEATS = [const keys = [];F.forEach(([t, fx, fy], k) => { if (k) keys.push([t - .05, F[k - 1][1], F[k - 1][2], 1.3]); keys.push([t + .25, fx, fy, 1.3]); });wide(s, 'nar-1549', [[g, .13, .42, 1.3], ...keys.slice(1)]);- tag(s, 'Das Narrenschiff, 1549 edition', 50, 150, g);+ srcTag(s, 'Das Narrenschiff, 1549 edition', 50, 150, g);['The greedy', 'The vain', 'The drunk', 'The idle'].forEach((str, k) => {const e = label(s, str, CX, 1180, F[k][0] + .05, { size: 80 });if (k < 3) hide(e, F[k + 1][0] - .05, .05, lin);@@ -108,7 +108,7 @@ const BEATS = [// the whole boat, going nowhere; the fools' giggle closes the sections = shot(p, nw, undefined, { bg: BURG });wide(s, 'nar-1549', [[nw, .2, .5, 1.0], [D + 1.3, .8, .5, 1.0]]);- word(s, 'Sailing nowhere', CX, 1180, nw, { size: 120, fill: '#fff', stroke: INK });+ word(s, 'Sailing nowhere', CX, 1180, nw, { size: 120, fill: '#fff', stroke: DARK });sfx('brant', D - .2, 'laugh-jester', .9);prog(() => {}, D, 1.3, lin);}],@@ -125,9 +125,9 @@ const BEATS = [const map = wide(s, 'rhine-full', [[ff, .452, .563, 1.0], [pd + .3, .452, .563, 1.6]]);const [iw, ih] = ART['rhine-full'], Ws = iw * H / ih;const pin = G(map, { x: (.452 - .5) * Ws, y: (.563 - .5) * H, o: 0, s: 0 });- mk('circle', { r: 16, fill: RED, stroke: INK, 'stroke-width': 5 }, pin);+ mk('circle', { r: 16, fill: RED, stroke: DARK, 'stroke-width': 5 }, pin);pop(pin, ff + .2);- tag(s, 'Visscher, map of the Rhine, c. 1690', 50, 150, ff);+ srcTag(s, 'Visscher, map of the Rhine, c. 1690', 50, 150, ff);label(s, 'Frankfurt', CX, 1200, ff + .2, { size: 80 });stamp(s, '1399', CX, 360, ff + .8, { size: 170, colour: '#b3201a' });// the city pays@@ -138,7 +138,7 @@ const BEATS = [// away; handed to a boatman; left downrivers = shot(p, aw, hd, { whip: true });photo(s, 'e1-river', aw, hd + .3, { s0: 1.0, s1: 1.08, dy: 60 });- word(s, 'Away', CX, 300, aw + .05, { size: 160, fill: '#fff', stroke: INK });+ word(s, 'Away', CX, 300, aw + .05, { size: 160, fill: '#fff', stroke: DARK });s = shot(p, hd, dn, { swipe: true });photo(s, 'e1-handover', hd, dn + .3, { s0: 1.0, s1: 1.08 });label(s, 'Handed to boatmen', CX, 1200, hd + .1, { size: 72 });@@ -153,19 +153,19 @@ const BEATS = [const bt = m('between'), ld = m('land'), pr = m('pris');let s = shot(p, 0, bt, { bg: BURG });plate(s, 'bars', CX, 650, { h: 560 });- const lk = word(s, 'Locked up', CX, 1150, 0, { size: 150, fill: PAPER });+ const lk = word(s, 'Locked up', CX, 1150, 0, { size: 150, fill: LIGHT });strike(s, lk, CX, 1150, .6, 150);s = shot(p, bt, undefined, { swipe: true });photo(s, 'e1-between', bt, D + .6, { s0: 1.0, s1: 1.14, dy: -30 });- const sb = word(s, 'Sent between', CX, 640, bt + .05, { size: 120, fill: '#fff', stroke: INK });+ const sb = word(s, 'Sent between', CX, 640, bt + .05, { size: 120, fill: '#fff', stroke: DARK });hide(sb, ld - .3, .2);const L = [['Land', 270, 0], ['Water', 640, .35], ['Land', 1260, .7]].map(([str, y, dt]) => label(s, str, CX, y, ld + dt, { size: 70 }));// Foucault's phrase over the whole picture- const dim = G(s, { o: 0 }); rect(dim, 0, 0, W, H, { fill: INK, opacity: .62 });+ const dim = G(s, { o: 0 }); rect(dim, 0, 0, W, H, { fill: DARK, opacity: .62 });show(dim, pr - .4, .4);L.forEach(e => hide(e, pr - .4, .2));quote(s, ['“the prisoner', 'of the passage”'], 720, pr, { size: 104 });- T(s, '— FOUCAULT', { x: CX, y: 1010, size: 56, fill: SOFT, font: KEY, weight: 500, anchor: 'middle', o: 0 });+ T(s, '— FOUCAULT', { x: CX, y: 1010, size: 56, fill: MUTED, font: SANS, weight: 500, anchor: 'middle', o: 0 });show(s.lastChild, pr + .6, .3);}],@@ -175,20 +175,20 @@ const BEATS = [const tk = m('talked'), lr = m('lear'), fo = m('folly'), ws = m('wise');let s = shot(p, 0, lr);photo(s, 'e1-calling', 0, lr + .3, { s0: 1.0, s1: 1.1, dx: -30 });- word(s, 'Out there', CX, 280, .1, { size: 120, fill: '#fff', stroke: INK });- word(s, 'Madness talked', CX, 1200, tk, { size: 130, fill: RED, stroke: INK });+ word(s, 'Out there', CX, 280, .1, { size: 120, fill: '#fff', stroke: DARK });+ word(s, 'Madness talked', CX, 1200, tk, { size: 130, fill: RED, stroke: DARK });// the Fool looks up at the king and tells him: close on the fool, then up to Lears = shot(p, lr, fo, { whip: true });wide(s, 'lear', [[lr, .5, .72, 1.6], [lr + .8, .5, .71, 1.66], [lr + 1.7, .67, .43, 1.3], [fo, .66, .43, 1.36]]);- tag(s, 'William Dyce, King Lear and the Fool in the Storm, 1851', 50, 150, lr);+ srcTag(s, 'William Dyce, King Lear and the Fool in the Storm, 1851', 50, 150, lr);label(s, 'Shakespeare · King Lear', CX, 200, lr + .1, { size: 52 });band(s, ['The fool', 'tells the king', 'the truth'], 330, lr + .2, { size: 70, step: 1.4 });// Folly takes the pulpit; then the listenerss = shot(p, fo, undefined, { whip: true });wide(s, 'holbein-full', [[fo, .82, .6, 1.5], [ws - .1, .84, .6, 1.6], [ws + .3, .55, .67, 1.7], [D + .8, .55, .67, 1.76]]);- tag(s, 'Holbein, margin drawing in The Praise of Folly, 1515', 50, 150, fo);+ srcTag(s, 'Holbein, margin drawing in The Praise of Folly, 1515', 50, 150, fo);label(s, 'Erasmus · The Praise of Folly', CX, 200, fo + .1, { size: 52 });- const fs = word(s, 'Folly speaks', CX, 1180, fo + .5, { size: 140, fill: RED, stroke: INK });+ const fs = word(s, 'Folly speaks', CX, 1180, fo + .5, { size: 140, fill: RED, stroke: DARK });hide(fs, ws + .1, .15);band(s, ['The wise', 'look ridiculous'], 1120, ws + .3, { size: 72, step: .5 });}],@@ -200,10 +200,10 @@ const BEATS = [let s = shot(p, 0, y6, { bg: BURG });const b = plate(s, 'fool-boat', CX, 880, { w: 760 });clockRun(t => { const q = smooth(Math.min(1, t / y6)); put(b, { x: CX + 170 * q, y: 880 - 140 * q + 10 * Math.sin(t * 1.7), r: 2 * Math.sin(t * 1.1), s: 1 - .5 * q }); }, D);- word(s, 'He drifted', CX, 330, .1, { size: 120, fill: PAPER });+ word(s, 'He drifted', CX, 330, .1, { size: 120, fill: LIGHT });word(s, 'Still talking', CX, 1250, m('talking'), { size: 130, fill: RED });- s = shot(p, y6, as, { bg: INK, whip: true });- word(s, '1656', CX, 860, y6 + .05, { size: 330, fill: PAPER });+ s = shot(p, y6, as, { bg: DARK, whip: true });+ word(s, '1656', CX, 860, y6 + .05, { size: 330, fill: LIGHT });s = shot(p, as, wt);photo(s, 'e1-ashore', as, wt, { s0: 1.06, s1: 1.12 });sfx('end', as + .05, 'thud', 1.6);@@ -217,10 +217,10 @@ const BEATS = [s = shot(p, nx, D, { bg: BURG, swipe: true });seriesCard(s, nx, 2, nx + .9);// and the next episode, full frame- s = shot(p, D, undefined, { bg: INK });- label(s, 'Next', CX, 660, D, { size: 70, fill: RED, colour: INK });- word(s, 'Locked up', CX, 880, D + .05, { size: 220, fill: PAPER });- T(s, 'PART 2 OF 4', { x: CX, y: 990, size: 52, fill: SOFT, font: KEY, weight: 500, anchor: 'middle', o: 0 }); show(s.lastChild, D + .2, .2);+ s = shot(p, D, undefined, { bg: DARK });+ label(s, 'Next', CX, 660, D, { size: 70, fill: RED, colour: DARK });+ word(s, 'Locked up', CX, 880, D + .05, { size: 220, fill: LIGHT });+ T(s, 'PART 2 OF 4', { x: CX, y: 990, size: 52, fill: MUTED, font: SANS, weight: 500, anchor: 'middle', o: 0 }); show(s.lastChild, D + .2, .2);prog(() => {}, D, 1.8, lin);}],].map(shortsBeat);diff --git a/site/madness-shorts/lib/madness.js b/site/madness-shorts/lib/madness.jsindex 033041e..219e383 100644--- a/site/madness-shorts/lib/madness.js+++ b/site/madness-shorts/lib/madness.js@@ -27,7 +27,7 @@ function wide(g, name, keys) {}// a Foucault line drawing (LINES from the documentary's trace.py), drawn on stroke by stroke over `draw` s-function traced(p, name, { x = CX, y = 800, h = 600, at = 0, draw: dd = 1.5, colour = PAPER } = {}) {+function traced(p, name, { x = CX, y = 800, h = 600, at = 0, draw: dd = 1.5, colour = LIGHT } = {}) {const L = LINES[name], [x0, y0, x1, y1] = L.box, k = h / (y1 - y0);const g = G(p, { x, y });const inner = mk('g', { transform: `scale(${k}) translate(${-(x0 + x1) / 2},${-(y0 + y1) / 2})` }, g);@@ -45,7 +45,7 @@ function europeMap(g, x, y, w, t0) {const [bx, by, bw, bh] = EUROPE.box, k = w / bw, m = G(g, { x: x - bx * k, y: y - by * k, s: k, o: 0 });const id = 'eu' + (++fxN), cp = mk('clipPath', { id }, mk('defs', {}, m));mk('rect', { x: bx, y: by, width: bw, height: bh }, cp);- mk('path', { d: EUROPE.d, fill: 'none', stroke: PAPER, 'stroke-width': 1.6 / k, 'stroke-opacity': .7, 'clip-path': `url(#${id})` }, m);+ mk('path', { d: EUROPE.d, fill: 'none', stroke: LIGHT, 'stroke-width': 1.6 / k, 'stroke-opacity': .7, 'clip-path': `url(#${id})` }, m);const el = EUROPE.dots.map(([cx, cy]) => put(mk('circle', { cx, cy, r: 5 / k, fill: RED }, m), { o: 0 }));if (t0 <= .01) put(m, { o: 1 }); else show(m, t0, .4);return { g: m, el };@@ -54,18 +54,18 @@ function europeMap(g, x, y, w, t0) {// the series card: four episodes, `n` (1-based) lit at tLit; the rest dimconst EPISODES = [['The ship', 'fool-boat'], ['Locked up', 'bars'], ['Liberation', 'chain'], ['The last voices', 'fool-vangogh']];function seriesCard(s, t0, n, tLit) {- word(s, 'Madness &', CX, 250, t0, { size: 96, fill: PAPER });- word(s, 'Civilization', CX, 360, t0 + .15, { size: 96, fill: PAPER });- T(s, 'AFTER MICHEL FOUCAULT, 1961', { x: CX, y: 430, size: 42, fill: SOFT, font: KEY, weight: 500, anchor: 'middle' });+ word(s, 'Madness &', CX, 250, t0, { size: 96, fill: LIGHT });+ word(s, 'Civilization', CX, 360, t0 + .15, { size: 96, fill: LIGHT });+ T(s, 'AFTER MICHEL FOUCAULT, 1961', { x: CX, y: 430, size: 42, fill: MUTED, font: SANS, weight: 500, anchor: 'middle' });sfx(BEAT_ID, t0, 'thud', 1);const pos = [[250, 640], [650, 640], [250, 1040], [650, 1040]], sz = 340;const tiles = EPISODES.map(([title, img], i) => {const [x, y] = pos[i], c = G(s, { x, y, o: 0 });- rect(c, -sz / 2, -sz / 2, sz, sz, { rx: 18, fill: INK });+ rect(c, -sz / 2, -sz / 2, sz, sz, { rx: 18, fill: DARK });const [iw, ih] = ART[img], k = Math.min((sz - 70) / iw, (sz - 110) / ih);mk('image', { href: `../img/${img}.webp`, x: -iw * k / 2, y: -ih * k / 2 - 18, width: iw * k, height: ih * k }, c);- T(c, String(i + 1), { x: -sz / 2 + 22, y: -sz / 2 + 62, size: 56, fill: PAPER, font: KEY, weight: 600 });- T(c, title.toUpperCase(), { x: 0, y: sz / 2 - 22, size: 42, fill: PAPER, font: KEY, weight: 600, anchor: 'middle' });+ T(c, String(i + 1), { x: -sz / 2 + 22, y: -sz / 2 + 62, size: 56, fill: LIGHT, font: SANS, weight: 600 });+ T(c, title.toUpperCase(), { x: 0, y: sz / 2 - 22, size: 42, fill: LIGHT, font: SANS, weight: 600, anchor: 'middle' });tw(c, { o: 1 }, t0 + .3 + i * .12, .25);return c;});@@ -84,9 +84,9 @@ function strike(g, e, x, y, t0, size, colour = RED) {}// a quote in the serif, centred lines, shown whole at t0-function quote(g, lines, y, t0, { size = 74, fill = PAPER, lh = 1.2 } = {}) {+function quote(g, lines, y, t0, { size = 74, fill = LIGHT, lh = 1.2 } = {}) {const e = G(g, { o: 0, y: 20 });- lines.forEach((l, i) => T(e, l, { x: CX, y: y + i * size * lh, size, fill, font: SER, weight: 400, anchor: 'middle' }).setAttribute('font-style', 'italic'));+ lines.forEach((l, i) => T(e, l, { x: CX, y: y + i * size * lh, size, fill, font: SERIF, weight: 400, anchor: 'middle' }).setAttribute('font-style', 'italic'));tw(e, { o: 1, y: 0 }, t0, .3, out);return e;}diff --git a/site/madness-shorts/lib/shorts.js b/site/madness-shorts/lib/shorts.jsindex 02d8868..0c486cd 100644--- a/site/madness-shorts/lib/shorts.js+++ b/site/madness-shorts/lib/shorts.js@@ -9,16 +9,16 @@Full bleed, one idea per shot, 1–3 s a shot.Platforms draw over the top 120 and the bottom 300 of the 900 x 1600 stage, and their buttons over the right 90between y 700 and 1300: words stay in x 50..810, y 130..1290. Pictures may run under all of it. */-const KEY = '"Oswald", "Arial Narrow", sans-serif', SER = '"EB Garamond", Georgia, serif';+const SANS = '"Oswald", "Arial Narrow", sans-serif', SERIF = '"EB Garamond", Georgia, serif';// Madness and Civilization: the documentary's burgundy ground and cream ink; RED is its hot accent-const INK = '#2a060a', RED = '#f08a4b', TEAL = '#2f6f73', PAPER = '#f3ede0', SOFT = '#d9b9b0', MARK = '#ffd23f', SEA = '#123c44', BURG = '#5a0e16';+const DARK = '#2a060a', RED = '#f08a4b', TEAL = '#2f6f73', LIGHT = '#f3ede0', MUTED = '#d9b9b0', MARK = '#ffd23f', SEA = '#123c44', BURG = '#5a0e16';const CX = 450, W = 900, H = 1600;-const CTX = document.createElement('canvas').getContext('2d');-const wid = (str, size, font = KEY, weight = 600) => { CTX.font = `${weight} ${size}px ${font}`; return CTX.measureText(str).width; };+const TEXT_CTX = document.createElement('canvas').getContext('2d');+const inkW = (str, size, font = SANS, weight = 600) => { TEXT_CTX.font = `${weight} ${size}px ${font}`; return TEXT_CTX.measureText(str).width; };const rect = (p, x, y, w, h, attrs = {}) => mk('rect', { x, y, width: w, height: h, ...attrs }, p);-const span01 = (t, a, b) => Math.min(1, Math.max(0, (t - a) / (b - a)));+const ramp01 = (t, a, b) => Math.min(1, Math.max(0, (t - a) / (b - a)));const smooth = q => q * q * (3 - 2 * q);-function rng(seed) { return () => (seed = (seed * 16807) % 2147483647) / 2147483647; }+function seeded(seed) { return () => (seed = (seed * 16807) % 2147483647) / 2147483647; }// the cut-out figures' widths at 1000 tall, by file name: the book fills it, Object.assign(MEME, { 'meme-cook': 672 })const MEME = {};// one meme crossing the frame left to right, then a fast swarm of the same (smaller and higher is farther away):@@ -27,7 +27,7 @@ function swarm(g, name, t0, { h = 560, y = 1500, cross = 1.6, n = 16, after = 1.const w = MEME[name] * h / 1000;const e = meme(g, name, -w / 2 - 40, y, h, t0, { rise: 0, dur: .01 });tw(e, { x: W + w / 2 + 40 }, t0, cross, lin); sfx(BEAT_ID, t0 + .1, 'whoosh', .6);- const R = rng(seed);+ const R = seeded(seed);for (let i = 0; i < n; i++) {const t1 = t0 + after + i * .12 + R() * .08, far = R(), hh = hmin + (1 - far) * (h - hmin), ww = MEME[name] * hh / 1000;const f = meme(g, name, -ww / 2 - 20, ymin + (1 - far) * (y - ymin), hh, t1, { rise: 0, dur: .01 });@@ -67,42 +67,42 @@ function photo(g, name, t0, t1, { s0 = 1.02, s1 = 1.1, dx = 0, dy = 0, dim = 0,mk('image', { href: `../img/${name}.webp`, x: -W / 2, y: -H / 2, width: W, height: H, preserveAspectRatio: 'xMidYMid slice' }, im);tw(im, { s: s1, x: CX + dx, y: H / 2 + dy }, t0, t1 - t0, lin);if (dim) rect(g, 0, 0, W, H, { fill: '#000', opacity: dim });- if (ai) tag(g, 'AI illustration', 50, 150, t0);+ if (ai) srcTag(g, 'AI illustration', 50, 150, t0);return im;}// a small grey label top left: a source or "AI illustration"; shown with ?tags (export.py --query tags), so a cut// being worked on stays clean while the calls stay in placeconst TAGS = new URLSearchParams(location.search).has('tags');-function tag(g, str, x, y, t0) {+function srcTag(g, str, x, y, t0) {if (!TAGS) return G(g, { o: 0 });- const e = G(g, { x, y, o: 0 }), w = wid(str.toUpperCase(), 20, KEY, 500) + 20;+ const e = G(g, { x, y, o: 0 }), w = inkW(str.toUpperCase(), 20, SANS, 500) + 20;rect(e, 0, -22, w, 30, { fill: 'rgba(20,18,15,.55)', rx: 3 });- T(e, str.toUpperCase(), { x: 10, y: 0, size: 20, fill: '#f0ebe0', font: KEY, weight: 500 }).setAttribute('letter-spacing', '.06em');+ T(e, str.toUpperCase(), { x: 10, y: 0, size: 20, fill: '#f0ebe0', font: SANS, weight: 500 }).setAttribute('letter-spacing', '.06em');show(e, t0, .2, lin);return e;}// big condensed capitals popping in (a word or two); stroke: a dark edge to read over pictures// (narrowed to maxW, so a centred word stays inside the platform's safe x 90..810)-function word(g, str, x, y, t0, { size = 120, fill = INK, anchor = 'middle', stroke, dur = .22, from = .82, maxW = 720 } = {}) {- size = Math.min(size, size * maxW / wid(str.toUpperCase(), size));+function word(g, str, x, y, t0, { size = 120, fill = DARK, anchor = 'middle', stroke, dur = .22, from = .82, maxW = 720 } = {}) {+ size = Math.min(size, size * maxW / inkW(str.toUpperCase(), size));const e = G(g, { x, y, s: from, o: 0 });- const t = T(e, str.toUpperCase(), { x: 0, y: 0, size, fill, font: KEY, weight: 600, anchor });+ const t = T(e, str.toUpperCase(), { x: 0, y: 0, size, fill, font: SANS, weight: 600, anchor });if (stroke) { t.setAttribute('stroke', stroke); t.setAttribute('stroke-width', size / 14); t.setAttribute('paint-order', 'stroke'); t.setAttribute('stroke-linejoin', 'round'); }if (t0 <= .01) put(e, { s: 1, o: 1 }); else tw(e, { s: 1, o: 1 }, t0, dur, out); // there on a beat's first frame- e._w = wid(str.toUpperCase(), size);+ e._w = inkW(str.toUpperCase(), size);return e;}// a label: caps on a solid block (Vox's MARY / JESUS chips); not `chip`, which is the engine's own-function label(g, str, x, y, t0, { size = 40, fill = INK, colour = PAPER, anchor = 'middle', pad = 18 } = {}) {- const w = wid(str.toUpperCase(), size, KEY, 600) + pad * 2, x0 = anchor === 'middle' ? -w / 2 : anchor === 'end' ? -w : 0;+function label(g, str, x, y, t0, { size = 40, fill = DARK, colour = LIGHT, anchor = 'middle', pad = 18 } = {}) {+ const w = inkW(str.toUpperCase(), size, SANS, 600) + pad * 2, x0 = anchor === 'middle' ? -w / 2 : anchor === 'end' ? -w : 0;const e = G(g, { x, y, s: .85, o: 0 });rect(e, x0, -size * .95, w, size * 1.3, { fill, rx: 4 });- T(e, str.toUpperCase(), { x: x0 + pad, y: 0, size, fill: colour, font: KEY, weight: 600 });+ T(e, str.toUpperCase(), { x: x0 + pad, y: 0, size, fill: colour, font: SANS, weight: 600 });tw(e, { s: 1, o: 1 }, t0, .18, out);return e;}// lines of a sentence as stacked chips, each popping in turn-function band(g, lines, y, t0, { size = 64, fill = INK, colour = PAPER, step = .25, lh = 1.3 } = {}) {+function band(g, lines, y, t0, { size = 64, fill = DARK, colour = LIGHT, step = .25, lh = 1.3 } = {}) {lines.forEach((l, i) => label(g, l, CX, y + i * size * lh, t0 + i * step, { size, fill, colour }));}// a yellow marker swept behind [x, y, w, h]@@ -130,16 +130,16 @@ function meme(g, name, x, y, h, t0, { flip = false, rise = 260, dur = .35 } = {}}// a rubber stamp slammed onfunction stamp(g, str, x, y, t0, { size = 110, colour = RED, r = -9 } = {}) {- const w = wid(str, size) + 60, e = G(g, { x, y, r, s: 1.7, o: 0 });+ const w = inkW(str, size) + 60, e = G(g, { x, y, r, s: 1.7, o: 0 });rect(e, -w / 2, -size * .85, w, size * 1.2, { fill: 'none', stroke: colour, 'stroke-width': size / 11, rx: 10 });- T(e, str, { y: size * .3, size, fill: colour, font: KEY, weight: 600, anchor: 'middle' });+ T(e, str, { y: size * .3, size, fill: colour, font: SANS, weight: 600, anchor: 'middle' });tw(e, { s: 1, o: 1 }, t0, .16, out);sfx(BEAT_ID, t0, 'bang', 1.4);return e;}// a number counting up to n over dur-function counter(g, n, x, y, t0, { size = 90, fill = INK, anchor = 'middle', dur = 1.1, pre = '', ticks = true } = {}) {- const t = T(g, pre + '0', { x, y, size, fill, font: KEY, weight: 600, anchor, o: 0 });+function counter(g, n, x, y, t0, { size = 90, fill = DARK, anchor = 'middle', dur = 1.1, pre = '', ticks = true } = {}) {+ const t = T(g, pre + '0', { x, y, size, fill, font: SANS, weight: 600, anchor, o: 0 });show(t, t0, .1, lin);prog(q => { t.textContent = pre + Math.round(n * q).toLocaleString('en-US'); }, t0, dur, out);if (ticks) for (let k = 0; k < 6; k++) sfx(BEAT_ID, t0 + k * dur / 6, 'tick', .45);@@ -148,7 +148,7 @@ function counter(g, n, x, y, t0, { size = 90, fill = INK, anchor = 'middle', dur// a phone-shaped card holding a picture (rounded, black rim)function phoneCard(g, x, y, w, h, img) {const e = G(g, { x, y }), id = 'pc' + (++fxN);- rect(e, -w / 2 - 10, -h / 2 - 10, w + 20, h + 20, { rx: 34, fill: INK });+ rect(e, -w / 2 - 10, -h / 2 - 10, w + 20, h + 20, { rx: 34, fill: DARK });mk('rect', { x: -w / 2, y: -h / 2, width: w, height: h, rx: 26 }, mk('clipPath', { id }, mk('defs', {}, e)));const im = mk('image', { href: `../img/${img}.webp`, x: -w / 2, y: -h / 2, width: w, height: h, preserveAspectRatio: 'xMidYMid slice' }, e);im.setAttribute('clip-path', `url(#${id})`);@@ -183,11 +183,11 @@ function clipImg(g, name, x, y, w, h, rx = 0) {mk('image', { href: `../img/${name}.webp`, x, y, width: w, height: h, preserveAspectRatio: 'xMidYMid slice' }, g).setAttribute('clip-path', `url(#${id})`);}/* an ink price tag */-function priceTag(p, x, y, str, t0, colour = INK) {- const g = G(p, { x, y, o: 0, r: -4, s: 1.2 }), w = wid(str, 80, SER, 500) + 90;+function priceTag(p, x, y, str, t0, colour = DARK) {+ const g = G(p, { x, y, o: 0, r: -4, s: 1.2 }), w = inkW(str, 80, SERIF, 500) + 90;path(g, `M0 0L40 -56H${w}V56H40Z`, { fill: '#f6f1e6', stroke: colour, 'stroke-width': 5 });mk('circle', { cx: 36, cy: 0, r: 11, fill: 'none', stroke: colour, 'stroke-width': 5 }, g);- T(g, str, { x: 66, y: 26, size: 80, fill: colour, font: SER, weight: 500 });+ T(g, str, { x: 66, y: 26, size: 80, fill: colour, font: SERIF, weight: 500 });tw(g, { o: 1, s: 1 }, t0, .2, out);return g;}