Skip to content

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

feat(pandemic): smooth map, real photos, one look per scene

DozenTwelve14c9b6f3d58d
diff --git a/README.md b/README.md
index 37e2cdf..5824a24 100644
--- a/README.md
+++ b/README.md
@@ -131,4 +131,4 @@ Then open [localhost:8765](http://localhost:8765/). (The full history is large;
## License
-[MIT](LICENSE). The bundled MathJax (`engine/vendor/mathjax`) is under the Apache License 2.0.
+[MIT](LICENSE). The bundled MathJax (`engine/vendor/mathjax`) is under the Apache License 2.0. The MIT licence covers the code. Pictures, recordings and data under `site/` keep their own licences, listed beside them (for example `site/pandemic/img/SOURCES.md`); toned copies of CC BY-SA pictures stay CC BY-SA.
diff --git a/site/pandemic/ch01/audio/bgm/theme.mp3 b/site/pandemic/ch01/audio/bgm/theme.mp3
index 04e4da5..d11ccc6 100644
Binary files a/site/pandemic/ch01/audio/bgm/theme.mp3 and b/site/pandemic/ch01/audio/bgm/theme.mp3 differ
diff --git a/site/pandemic/ch01/audio/sfx/chalk.mp3 b/site/pandemic/ch01/audio/sfx/chalk.mp3
deleted file mode 100644
index 91269ed..0000000
Binary files a/site/pandemic/ch01/audio/sfx/chalk.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/audio/sfx/clack.mp3 b/site/pandemic/ch01/audio/sfx/clack.mp3
deleted file mode 100644
index d3efe21..0000000
Binary files a/site/pandemic/ch01/audio/sfx/clack.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/audio/sfx/clang.mp3 b/site/pandemic/ch01/audio/sfx/clang.mp3
deleted file mode 100644
index e8fe1bd..0000000
Binary files a/site/pandemic/ch01/audio/sfx/clang.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/audio/sfx/pop.mp3 b/site/pandemic/ch01/audio/sfx/pop.mp3
deleted file mode 100644
index 152bf00..0000000
Binary files a/site/pandemic/ch01/audio/sfx/pop.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/audio/sfx/shutter.mp3 b/site/pandemic/ch01/audio/sfx/shutter.mp3
deleted file mode 100644
index b1c5b37..0000000
Binary files a/site/pandemic/ch01/audio/sfx/shutter.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/audio/sfx/tick.mp3 b/site/pandemic/ch01/audio/sfx/tick.mp3
deleted file mode 100644
index 2e1e687..0000000
Binary files a/site/pandemic/ch01/audio/sfx/tick.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/audio/sfx/whoosh.mp3 b/site/pandemic/ch01/audio/sfx/whoosh.mp3
deleted file mode 100644
index 6c63e5e..0000000
Binary files a/site/pandemic/ch01/audio/sfx/whoosh.mp3 and /dev/null differ
diff --git a/site/pandemic/ch01/index.html b/site/pandemic/ch01/index.html
index e9dba8f..515bd82 100644
--- a/site/pandemic/ch01/index.html
+++ b/site/pandemic/ch01/index.html
@@ -22,15 +22,14 @@ const CHAPTER = { number: 1, title: 'The Forgotten Crisis', minutes: 2, language
const CN = ['Beijing', 'Shanghai', 'Guangzhou', 'Chongqing', 'Chengdu', 'Xian', 'Zhengzhou', 'Changsha', 'Nanjing', 'Hangzhou', 'Shenzhen', 'Harbin', 'Kunming'];
const C = n => GEO.cities[n];
-// Li Wenliang's chip: a red disc with a paper silhouette (no likeness is claimed: there is no free photograph)
-function liChip(p, x, y, r, t0, { o = 1 } = {}) {
- const g = G(p, { x, y, s: 0, o: 0 });
+// a doctor's chip: a toned portrait in a red ring. li-wenliang is his own selfie (fair use); doctor-1..7 are AI
+// illustrations standing in for the other seven, who are not identified here
+const LI_CLIP = mk('clipPath', { id: 'liclip', clipPathUnits: 'objectBoundingBox' }, DEFS);
+mk('circle', { cx: .5, cy: .5, r: .5 }, LI_CLIP);
+function liChip(p, x, y, r, t0, { o = 1, img = 'li-wenliang' } = {}) {
+ const g = G(p, { x, y, s: 0, o: 0 }), k = r * .9;
mk('circle', { r, fill: RED }, g);
- const s = G(g, { s: r / 150 });
- mk('path', { d: 'M-118 150C-112 70-70 40-28 30L-22 6C-46-8-56-36-56-66C-56-112-30-142 0-142C30-142 56-112 56-66C56-36 46-8 22 6L28 30C70 40 112 70 118 150Z', fill: CHAR }, s);
- mk('rect', { x: -46, y: -82, width: 32, height: 22, rx: 6, fill: 'none', stroke: '#9aa0a8', 'stroke-width': 4 }, s);
- mk('rect', { x: 14, y: -82, width: 32, height: 22, rx: 6, fill: 'none', stroke: '#9aa0a8', 'stroke-width': 4 }, s);
- mk('path', { d: 'M-14-72h28', stroke: '#9aa0a8', 'stroke-width': 4 }, s);
+ mk('image', { href: `../img/${img}.webp`, x: -k, y: -k, width: 2 * k, height: 2 * k, 'clip-path': 'url(#liclip)' }, g);
tw(g, { s: 1, o }, t0, .5, back);
return g;
}
@@ -43,13 +42,24 @@ function caseDots(g, on = () => 1) {
// the city framing where Li's story plays: Wuhan on screen at (BX, BY)
const BX = 420, BY = 440, ZL = 9, VIEW_LI = { x: (800 - BX) / ZL, y: (450 - BY) / ZL, z: ZL };
-// the people who left before the gates closed: a destination, a phase, a speed; positions are fractions of the way
-const EXO = (() => { const R = rng(8); return [...Array(260)].map(() => [CN[Math.floor(R() * CN.length)], R(), .18 + R() * .2]); })();
+// the people who left before the gates closed: 30 trains of about 10,000 (the 300,000), each a destination, a phase and
+// a speed; positions are fractions of the way. People are ink: red is kept for the virus, which lights a city on arrival
+const EXO = (() => { const R = rng(8); return [...Array(30)].map((_, i) => [CN[i % CN.length], i / 30 + R() * .03, .18 + R() * .2]); })();
const exoLaunch = (tS, ph) => tS + ph * 2.6;
+// a train: three cars heading away from Wuhan, and a faint wake back to it (data-sw: the paper map keeps its width)
+function trainMk(g) {
+ const tr = mk('path', { d: '', fill: 'none', stroke: MAPINK, 'data-sw': 1.6, opacity: 0 }, g), car = G(g, { o: 0 });
+ for (let k = 0; k < 3; k++) mk('rect', { x: -33 + k * 11.5, y: -3.6, width: 10, height: 7.2, rx: k === 2 ? 3.6 : 1.2, fill: MAPINK, stroke: '#f6f1e4', 'stroke-width': 1.2 }, car);
+ return { tr, car };
+}
+function trainAt({ tr, car }, x, y, z, car_, wake) {
+ put(car, { x, y, r: Math.atan2(y, x) * 180 / Math.PI, s: 1 / z, o: car_ ? 1 : 0 });
+ tr.setAttribute('d', `M0 0L${x.toFixed(1)} ${y.toFixed(1)}`); tr.setAttribute('opacity', wake ? .35 : 0);
+}
/* ---------- beats ---------- */
const BEATS = [
- // 0. Cold open: the flicker, the list, the shutter, the two numbers, the words that crumble, a breath, the globe dives
+ // 0. Cold open: the flicker, the list, the wall going dark, the two numbers, the words that crumble, a breath, the globe dives
['open', 'The only story on Earth', (m, D) => {
const p = panel(0);
ground(p, NIGHT);
@@ -64,7 +74,7 @@ const BEATS = [
return { lon, lat, H, gain };
});
clockRun(t => gb(Math.sin(Math.PI * span01(t, tA, tB)) ** 3 * 46), D, { tail: true });
- tw(glob, { o: .55 }, m('count') - 1, 1.2, lin);
+ tw(glob, { o: .55 }, m('shut') + .75, .9, lin);
tw(glob, { o: 1 }, tA - .3, .6, lin);
// the flicker under 2020: the world's pictures at seven a second, then one picture per word
@@ -80,25 +90,45 @@ const BEATS = [
const y20 = key(mon, '2020', 800, 560, m('y2020'), { size: 300, from: 0 });
put(y20, { s: 1.25 }); tw(y20, { s: 1 }, m('y2020'), .18, out); tw(y20, { s: 1.06 }, m('y2020') + .2, 1.6, lin); hide(y20, tN, .01);
sfx('open', m('y2020'), 'thud', 1.2);
+ // "shut": the last picture pulls back into a wall of the year's pictures, and they go dark one by one, like windows
+ // 4 x 4 tiles of the stage's shape; tile 5 (the street) starts exactly where the street still is: the same picture
+ // scale (the still's push at tS) and the same picture row (focus .55) at the centre of the screen
+ const tS = m('shut') - .35, sT = 1.04 + .1 * (tS - m('whole')) / (m('shut') + 1.2 - m('whole'));
+ const [aw, ah] = ART['street-hwy407'], kS = sT * Math.max(SW / aw, SH / ah), kT = 394 / aw; // screen px per picture px
+ const rowT = ah - 219 / kT / 2; // the tile shows the picture's bottom (YMax): the row at its centre
+ const W4 = kS / kT, wall = G(mon, { x: SW / 2 - W4 * 600, y: SH / 2 - W4 * (337.5 - (rowT - .55 * ah) * kT), s: W4, o: 0 });
+ mk('rect', { x: 0, y: 0, width: SW, height: SH, fill: '#000' }, wall);
+ const offs = ['virus-sem-red', 'airport-pek-empty', 'street-glenview-24', 'school-empty-classroom', 'closed-sign-temporary', 'street-hwy407',
+ 'ppe-nurses-faceshields', 'mask-cbp-officer', 'mask-hawaii-guard', 'school-closed-banner', 'airport-pek-empty', 'virus-sem-red',
+ 'street-glenview-24', 'school-empty-classroom', 'mask-hawaii-guard', 'closed-sign-temporary'].map((n, i) => {
+ const x = (i % 4) * 400 + 3, y = Math.floor(i / 4) * 225 + 3;
+ // the picture itself fades to the black behind it: a black cover the same size leaves a hairline at its edges
+ return put(mk('image', { href: `../img/${n}.webp`, x, y, width: 394, height: 219, preserveAspectRatio: i === 5 ? 'xMidYMax slice' : 'xMidYMid slice' }, wall), { o: .7 });
+ });
+ tw(wall, { o: 1 }, tS, .01, lin); tw(wall, { x: 0, y: 0, s: 1 }, tS, .5, out);
+ [3, 9, 14, 0, 12, 6, 11, 2, 15, 8, 4, 13, 10, 1, 7, 5].forEach((k, i) => tw(offs[k], { o: 0 }, m('shut') + i * .045, .06, lin)); // the street goes last
const labs = [['Schools', 'schools', 'borders'], ['Borders', 'borders', 'whole'], ['Whole countries', 'whole', 'shut']]
.map(([l, a, b]) => { const c = chipLabel(mon, l, 110, 810, m(a), { size: 66 }); hide(c, m(b), .01); return c; });
- shutter(mon, m('shut') - .42, .42);
- stamp(mon, 'SHUT', 800, 500, m('shut') + .05, { size: 190 });
- hide(mon, m('count') - .9, .5);
- sfx('open', m('shut') - .05, 'shutter', 1.6);
- [tN, m('y2020') + 3.1, m('schools'), m('borders'), m('whole')].forEach(t => sfx('open', t, 'tick', .7));
+ hide(mon, m('shut') + .75, .4); // the wall is dark: the globe comes up at once, no dead black before the count
// the two numbers, and the gap between them
const n1 = counter(p, 800, 470, 0, 7115706, m('count'), 1.7, { size: 150 });
const t1 = tag(p, 'confirmed COVID-19 deaths', 800, 535, m('count') + 1, { anchor: 'middle', size: 30, fill: CREAM });
tw(n1, { y: 330, s: .62 }, m('real') - .2, .6, io); tw(t1, { y: 385 }, m('real') - .2, .6, io);
const n2 = counter(p, 800, 600, 0, 27000000, m('twentyseven') - .3, 1.4, { size: 190, fill: RED, weight: 600 });
- sfx('open', m('twentyseven') + 1.05, 'thud', 1.4);
- const t2 = tag(p, 'estimated from excess deaths (The Economist, 2024)', 800, 665, m('twentyseven') + .9, { anchor: 'middle', size: 28, fill: CREAM });
- const arr = path(p, 'M1080 330C1200 340 1240 420 1190 520', { stroke: RED, 'stroke-width': 4, 'marker-end': 'url(#arrowR)' }, { d: 0 });
- draw(arr, m('twentyseven') + .1, .5);
- const x4 = key(p, '× 4', 1300, 450, m('twentyseven') + .35, { size: 90, fill: RED });
- [n1, t1, n2, t2, x4, arr].forEach(e => hide(e, m('biggest') - .2, .25));
+ const t2 = tag(p, 'estimated from excess deaths (The Economist, 2024)', 800, 665, m('twentyseven') + .2, { anchor: 'middle', size: 28, fill: CREAM });
+ // the gap as lengths: a cream bar for the confirmed deaths, then red lengths of the same size push out to the estimate
+ const bars = G(p, {}), U = 340, K = 27000000 / 7115706, bx = 800 - U * K / 2;
+ const conf = mk('rect', { x: bx, y: 720, width: 0, height: 26, fill: CREAM }, bars);
+ prog(q => conf.setAttribute('width', U * q), m('real') - .1, .5, out);
+ for (let j = 1; j < Math.ceil(K); j++) {
+ const seg = mk('rect', { x: bx + U * j, y: 720, width: 0, height: 26, fill: RED }, bars), w = U * Math.min(1, K - j) - 4;
+ prog(q => seg.setAttribute('width', w * q), m('twentyseven') - .2 + (j - 1) * .2, .22, out);
+ }
+ st(conf).c_fill = CREAM; tw(conf, { c_fill: RED }, m('twentyseven') + 1.05, .3); // one red length
+ tag(bars, 'nearly 4×', bx + U * K, 790, m('twentyseven') + .6, { anchor: 'end', size: 30, fill: RED });
+ [n1, t1, n2, t2].forEach(e => hide(e, m('biggest') - .2, .25));
+ hide(bars, m('forget'), 1); // the bars stay under the words, so "nearly 4×" can be read
// the words that crumble, and the lights going out with them; then nothing is said for two seconds
crumble(p, 'THE BIGGEST CRISIS', 800, 400, m('forget') + .1, 1.7, { size: 120, appear: m('biggest') - .1 });
@@ -115,7 +145,6 @@ const BEATS = [
const mp = G(p, { o: 0 }), M = paperMap(mp, D + HOLD, { x: 0, y: 0, z: z1 }), cam = M.cam;
paperTop(mp, .4);
tw(mp, { o: 1 }, tH - .12, .14, lin); hide(glob, tH + .05, .01); // the style change hides in the fastest moment
- sfx('wuhan', tH - .25, 'whoosh', .8);
cam.to({ z: z1 * 1.8 }, tH, 1.2, out);
cam.to({ z: .62 }, m('eleven') + 1.3, 1.4, soft); // "right in the middle of China"
cam.to({ z: .56 }, m('eleven') + 2.7, m('dec') - m('eleven') - 3.3, lin); // a creep while it sinks in
@@ -138,6 +167,14 @@ const BEATS = [
dateTag(p, 'December 2019', m('dec') - .1, { fill: MAPINK });
const unk = chipLabel(p, 'Pneumonia of unknown cause', 1000, 300, m('explain') - .6, { tx: 830, ty: 430, fill: MAPINK });
hide(unk, m('more') - .2, .3);
+ // under the label, a lung CT on dark film: the hazy patches circled
+ const ct = G(p, { x: 1040, y: 350, o: 0 });
+ mk('rect', { x: -10, y: -10, width: 440, height: 342, rx: 6, fill: '#0b0f12' }, ct);
+ mk('image', { href: '../img/ct-pneumonia.webp', x: 0, y: 0, width: 420, height: 322 }, ct);
+ [[93, 256], [322, 256]].forEach(([x, y], i) => draw(mk('ellipse', { cx: x, cy: y, rx: 62, ry: 44, fill: 'none', stroke: RED, 'stroke-width': 3 }, ct), m('explain') + .5 + i * .25, .5));
+ tag(ct, 'CT scan, COVID-19 pneumonia · Hellerhoff, CC BY-SA 3.0, toned', 0, 352, m('explain') + .2, { size: 15, fill: MAPINK });
+ tw(ct, { o: 1, y: 330 }, m('explain') - .3, .4, out);
+ hide(ct, m('more') - .2, .3);
// the cases: one, a cluster, another cluster
const ds = caseDots(M.marks);
ds.forEach((d, i) => {
@@ -145,13 +182,11 @@ const BEATS = [
put(d, { o: 0 }); tw(d, { o: 1 }, t0, .12, lin);
const ring = mk('circle', { cx: CASES[i][0], cy: CASES[i][1], r: .9, fill: 'none', stroke: RED, 'data-sw': 2, opacity: 0 }, M.marks);
prog(q => { ring.setAttribute('r', .9 + q * 4); ring.setAttribute('opacity', 1 - q); }, t0, .8, out);
- sfx('wuhan', t0, 'pop', .5);
});
// push through the first case into red
cam.to({ x: CASES[0][0], y: CASES[0][1], z: 1600 }, D, HOLD, ease3);
const red = mk('rect', { x: 0, y: 0, width: SW, height: SH, fill: RED, opacity: 0 }, p);
clockRun(t => red.setAttribute('opacity', span01(t, D + HOLD - .16, D + HOLD)), D, { tail: true });
- sfx('wuhan', D - .1, 'whoosh', 1);
}],
// 2. The doctor: his badge on the Wuhan map, his message and the letter as cards beside it, then eight badges
@@ -176,20 +211,19 @@ const BEATS = [
const nm = G(pin, { o: 1 });
key(nm, 'Li Wenliang', 0, 175, m('li') - .1, { size: 52 });
tag(nm, 'eye doctor, Wuhan Central Hospital', 0, 212, m('li') + .5, { anchor: 'middle', size: 26, fill: CREAM });
+ tag(nm, 'photo: his own selfie, Weibo', 0, 240, m('li') + .5, { anchor: 'middle', size: 16 });
// the message: a dark card beside the badge
const card = G(p, { x: 1700 });
mk('rect', { x: 0, y: 0, width: 740, height: 420, rx: 22, fill: '#1b1e24', stroke: '#3a3f48', 'stroke-width': 2 }, card);
T(card, 'MEDICAL SCHOOL CLASSMATES', { x: 40, y: 56, size: 22, fill: '#aeb4bd', font: KEY, weight: 500 }).setAttribute('letter-spacing', '.14em');
mk('path', { d: 'M40 78H700', stroke: '#3a3f48', 'stroke-width': 2 }, card);
tw(card, { x: 720, y: 210 }, m('classmates') - .45, .5, out); put(card, { y: 210 });
- sfx('message', m('classmates') - .45, 'whoosh', .6);
const bub = G(card, { o: 0, x: 40, y: 110 });
mk('rect', { x: 0, y: 0, width: 600, height: 190, rx: 18, fill: '#f2f0ea' }, bub);
['7 confirmed cases of SARS were', 'reported … from Huanan', 'Seafood Market.'].forEach((l, i) =>
stream(T(bub, '', { x: 28, y: 56 + i * 46, size: 34, fill: '#16181c', font: UI, weight: 500 }), l, m('msg') + .05 + i * .6, .65));
T(bub, '17:43', { x: 580, y: 178, size: 18, fill: '#7a7f88', font: UI, anchor: 'end' });
tw(bub, { o: 1 }, m('msg') - .1, .15);
- sfx('message', m('msg') - .1, 'pop', .6);
tag(card, 'his message, translated', 40, 395, m('msg') + 1.4, { size: 24 });
// "tell your families": the message is forwarded, copy after copy sliding out of frame
for (let i = 0; i < 5; i++) {
@@ -217,19 +251,19 @@ const BEATS = [
hide(card, four + .2, .01);
sfx('message', four - .25, 'page', .9);
tw(doc_, { s: .62 }, four + .2, m('eight') - four - .6, lin);
- draw(sig, m('sign'), .9, lin); sfx('message', m('sign'), 'chalk', .5);
+ draw(sig, m('sign'), .9, lin);
prog(q => hl.setAttribute('width', 600 * q), m('untrue') - .3, .6, io);
// one of eight: the letter goes, seven more badges ring Wuhan
tw(doc_, { x: 1500, y: 1300, r: 12 }, m('eight') - .45, .45, p => p * p);
hide(nm, m('eight') - .4, .2);
for (let i = 0; i < 7; i++) {
const a = (-90 + i * (360 / 7)) * Math.PI / 180;
- liChip(pin, Math.cos(a) * 215, Math.sin(a) * 215, 50, m('eight') + .15 + i * .07);
- sfx('message', m('eight') + .15 + i * .07, 'clack', .35);
+ liChip(pin, Math.cos(a) * 215, Math.sin(a) * 215, 50, m('eight') + .15 + i * .07, { img: `doctor-${i + 1}` });
}
tw(chip, { s: .7 }, m('eight') - .2, .4, io);
key(p, '8 doctors', 1110, 430, m('eight') + .4, { size: 110 });
tag(p, 'punished for “spreading rumours”', 1110, 490, m('eight') + .9, { anchor: 'middle', size: 32, fill: CREAM });
+ tag(p, 'the other seven: AI illustrations', 1110, 525, m('eight') + .9, { anchor: 'middle', size: 18 });
}],
// 3. Meanwhile, on the same map, the cases double
@@ -245,21 +279,21 @@ const BEATS = [
mk('rect', { x: 0, y: 0, width: SW, height: SH, fill: '#0b0d11', opacity: .55 }, left);
const pin = G(left, {}), [bx, by] = cam.screen(0, 0, 0); put(pin, { x: bx, y: by });
put(liChip(pin, 0, 0, 110, -1), { s: .7 });
- for (let i = 0; i < 7; i++) { const a = (-90 + i * (360 / 7)) * Math.PI / 180; liChip(pin, Math.cos(a) * 215, Math.sin(a) * 215, 50, -1); }
+ for (let i = 0; i < 7; i++) { const a = (-90 + i * (360 / 7)) * Math.PI / 180; liChip(pin, Math.cos(a) * 215, Math.sin(a) * 215, 50, -1, { img: `doctor-${i + 1}` }); }
T(left, '8 DOCTORS', { x: 1110, y: 430, size: 110, fill: CREAM, font: KEY, weight: 600, anchor: 'middle' });
+ T(left, 'the other seven: AI illustrations', { x: 1110, y: 525, size: 18, fill: SOFT, font: SER, anchor: 'middle' });
tw(left, { o: 0 }, .05, .4, lin);
cam.to({ x: 2, y: 0, z: 3 }, .2, D + .2, soft);
- // generations: each doubles the dots, spreading over the city (screen-size dots: non-scaling round strokes)
+ // generations: a red stain whose area doubles at each one (the first cases' dots under it); every size it leaves
+ // stays as a thin ring, like a tree's
const times = [m('d1'), m('d2'), m('d2') + .55, m('d2') + 1.05, m('week') - .15, m('week') + .35, m('week') + .8, D - .35];
- let n = CASES.length;
+ const rOf = g => 7 * 2 ** ((g + 1) / 2);
+ const stain = put(mk('circle', { cx: 1, cy: 0, r: rOf(-1), fill: RED, 'fill-opacity': .28, stroke: RED, 'data-sw': 2.5 }, M.marks), { o: 0 });
+ tw(stain, { o: 1 }, times[0] - .15, .15, lin);
times.forEach((t, g) => {
- const R = rng(30 + g), rg = 7 * 2 ** ((g + 1) / 2);
- let d = '';
- for (let i = 0; i < n; i++) { const r = rg * Math.sqrt(R()), a = R() * Math.PI * 2; d += `M${(1 + r * Math.cos(a)).toFixed(2)} ${(r * Math.sin(a) * .8).toFixed(2)}h0`; }
- const e = path(M.marks, d, { stroke: RED, 'data-sw': 7 }, { o: 0 });
- tw(e, { o: .9 }, t, .12, lin);
- sfx('double', t, 'pop', g < 3 ? .7 : .35);
- n *= 2;
+ const r0 = rOf(g - 1), r1 = rOf(g);
+ prog(q => stain.setAttribute('r', r0 + (r1 - r0) * q), t, .3, back);
+ tw(put(mk('circle', { cx: 1, cy: 0, r: r0, fill: 'none', stroke: RED, 'data-sw': 1.2 }, M.marks), { o: 0 }), { o: .6 }, t, .05, lin);
});
// the count and the date, from the later studies
const box = G(p, { x: 1180, y: 120, o: 0 });
@@ -275,7 +309,6 @@ const BEATS = [
const band = mk('rect', { x: 0, y: 790, width: SW, height: 100, fill: '#0b0d11', opacity: 0 }, p); tw(band, { o: .85 }, m('week') - .2, .3);
key(p, 'Cases double every 7½ days', 800, 860, m('week') - .05, { size: 60, fill: CREAM });
whipOut(p, D, 1, 'y');
- sfx('double', D + HOLD - .3, 'whoosh', 1);
}],
// 4. The migration, the order, the rewind: they left before the gates closed
@@ -337,22 +370,19 @@ const BEATS = [
prog(q => setClock(2 + 8 * q), a0, a1 - a0, lin);
prog(q => { setClock(10 - 8 * soft(q)); hb(Math.sin(Math.PI * q) * 14); }, r0, r1 - r0, lin);
prog(q => setClock(2 + 8 * q), r1, b1 - r1, lin);
- for (let i = 0; i < 9; i++) sfx('migration', a0 + i * (a1 - a0) / 8, 'tick', .45);
- for (let i = 0; i < 8; i++) sfx('migration', r0 + i * .06, 'tick', .3);
chipLabel(all, '10:00 · everything stops', 1530, 400, m('ten'), { fill: RED, size: 30, anchor: 'end' });
const rw = chipLabel(all, '◀◀ before 10:00', 1530, 440, r0, { fill: MAPINK, size: 26, anchor: 'end' });
// the trains leave during the second pass and freeze where they are when the ring closes
- const fd = EXO.map(() => mk('circle', { r: 1, fill: RED, opacity: 0 }, M.marks));
+ const fd = EXO.map(() => trainMk(M.marks));
clockRun(t => {
const z = cam.at(t).z, tt = Math.min(t, b1);
EXO.forEach(([n, ph, v], i) => {
- const L = exoLaunch(r1, ph), q = Math.max(0, (tt - L) * v), [x, y] = C(n);
- fd[i].setAttribute('opacity', tt > L && q < 1 ? 1 : 0);
- fd[i].setAttribute('cx', x * Math.min(1, q)); fd[i].setAttribute('cy', y * Math.min(1, q)); fd[i].setAttribute('r', 3.4 / z);
+ const L = exoLaunch(r1, ph), q = Math.min(1, Math.max(0, (tt - L) * v)), [x, y] = C(n);
+ trainAt(fd[i], x * q, y * q, z, tt > L && q < 1, tt > L);
});
}, D, { tail: true });
cam.to({ x: -60, y: -10, z: 1.05 }, r1 + .2, b1 - r1 - .2, soft);
- counter(all, 800, 820, 0, 300000, m('k300') - .2, 1.6, { size: 96, fill: RED, font: KEY, weight: 600 });
+ counter(all, 800, 820, 0, 300000, m('k300') - .2, 1.6, { size: 96, fill: MAPINK, font: KEY, weight: 600 });
tag(all, 'left Wuhan by train before 10 a.m.', 800, 860, m('k300') + .5, { anchor: 'middle', size: 28, fill: MAPINK });
}],
@@ -384,23 +414,27 @@ const BEATS = [
const Tm = TIMINGS.migration, mb1 = Tm.dur - .15, mr1 = Tm.marks.before - .25 + .5; // the last beat's freeze, in its own clock
const fd = EXO.map(([n, ph, v], i) => {
const L = exoLaunch(mr1, ph), q0 = Math.max(0, Math.min(1, (mb1 - L) * v)), ta = but + .05 + ph * .9;
- return { n, q0, ta, launched: mb1 > L, e: mk('circle', { r: 1, fill: RED, opacity: 0 }, M.marks) };
+ return { n, q0, ta, launched: mb1 > L, e: trainMk(M.marks) };
});
clockRun(t => {
const z = cam.at(t).z;
fd.forEach(f => {
- if (!f.launched || f.q0 >= 1) return;
+ if (!f.launched) return;
const q = f.q0 + (1 - f.q0) * span01(t, 0, f.ta), [x, y] = C(f.n);
- f.e.setAttribute('opacity', q < 1 ? 1 : 0); f.e.setAttribute('cx', x * q); f.e.setAttribute('cy', y * q); f.e.setAttribute('r', 3.4 / z);
+ trainAt(f.e, x * q, y * q, z, q < 1, true);
});
}, D, { tail: true });
cam.to({ z: .95 }, 0, m('locks'), lin);
// "Wuhan locks down": the slam on the word
prog(q => lockFill.setAttribute('fill-opacity', q), m('locks'), .2, lin);
cam.shake(7, m('locks'), .45);
- sfx('gone', m('locks'), 'clang', 1.4);
- const st_ = stamp(mp, 'LOCKED DOWN', 870, 340, m('locks') + .05, { size: 90 });
- hide(st_, but - .3, .3);
+ // a news print drops beside the ring: the Yangtze bridge, empty, six days in
+ const ph = G(mp, { x: 1230, y: 380, r: -3, s: 1.05, o: 0 });
+ mk('rect', { x: -296, y: -228, width: 592, height: 476, fill: '#f6f1e4' }, ph);
+ mk('image', { href: '../img/wuhan-bridge-empty.webp', x: -280, y: -212, width: 560, height: 420 }, ph);
+ T(ph, 'Wuhan, 29 January 2020 · photo 汮汐, CC BY-SA 4.0, toned', { x: -280, y: 234, size: 18, fill: MAPINK, font: SER });
+ tw(ph, { s: .85, o: 1 }, m('locks') + .05, .16, out);
+ hide(ph, but - .3, .3);
tag(mp, 'Wuhan, then all of Hubei: about 57 million people', 800, 860, m('locks') + .6, { anchor: 'middle', size: 28, fill: MAPINK });
// "But the virus has already left": each city lights as the first train reaches it
cam.to({ x: 0, y: 0, z: .62 }, but - .1, 1.2, soft);
@@ -409,11 +443,9 @@ const BEATS = [
const d = mk('circle', { cx: x, cy: y, r: 0, fill: RED }, M.marks), r = mk('circle', { cx: x, cy: y, r: 0, fill: 'none', stroke: RED, 'data-sw': 2 }, M.marks);
prog(q => d.setAttribute('r', 12 * q), t, .2, back);
prog(q => { r.setAttribute('r', 12 + 50 * q); r.setAttribute('opacity', 1 - q); }, t, .7, out);
- sfx('gone', t, 'pop', .3);
});
// the paper map gives way to the night globe in the fastest moment of the pull-out
tw(glob, { o: 1 }, t0g - .05, .01); hide(mp, t0g, .18, lin);
- sfx('gone', t0g - .2, 'whoosh', .8);
const dl = dateTag(p, '23 January 2020', t0g + .2), txt = dl.lastChild;
const fmtD = w => new Date(Date.parse(w)).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' }).toUpperCase();
weeks.forEach((w, i) => prog(() => { txt.textContent = fmtD(w); }, tD0 + i * wk, 0, lin));
@@ -421,15 +453,15 @@ const BEATS = [
tw(cnt, { o: 1 }, tD0, .2);
weeks.forEach((w, i) => prog(() => { cnt.textContent = String(list.filter(s => wOf(s) <= i).length); }, tD0 + i * wk, 0, lin));
const cntTag = tag(p, 'countries with cases', 1530, 136, tD0 + .3, { anchor: 'end', size: 24, fill: CREAM });
+ const owid = tag(p, 'data: Our World in Data, CC BY 4.0', 1530, 162, tD0 + .3, { anchor: 'end', size: 16 });
const ant = chipLabel(p, 'Antarctica: not until December 2020', 800, 830, tilt1 - .15, { size: 30, anchor: 'middle' });
// the old-TV switch-off: the world squashes to a line, the line to a point, then black
- const tv = G(p, {}); p.insertBefore(tv, glob); tv.appendChild(glob); [cnt, cntTag, dl, ant].forEach(e => tv.appendChild(e));
+ const tv = G(p, {}); p.insertBefore(tv, glob); tv.appendChild(glob); [cnt, cntTag, owid, dl, ant].forEach(e => tv.appendChild(e));
const tOff = m('lw') - .45;
prog(q => tv.setAttribute('transform', `translate(800 450) scale(${1 - .98 * q * q},${Math.max(.004, 1 - q)}) translate(-800 -450)`), tOff, .14, lin);
prog(q => tv.setAttribute('transform', `translate(800 450) scale(${.02 * (1 - q) + .001},.004) translate(-800 -450)`), tOff + .14, .1, lin);
const flash = mk('rect', { x: 0, y: 447, width: SW, height: 6, fill: '#fff', opacity: 0 }, p);
prog(q => flash.setAttribute('opacity', Math.sin(Math.PI * q)), tOff + .08, .22, lin);
- sfx('gone', tOff, 'whoosh', .4);
// Li Wenliang, over black
const L = G(p, { o: 0 });
ground(L, '#000');
@@ -454,7 +486,7 @@ const BEATS = [
window.MUSIC_UP_IN_PRE = ['open'];
// One track for the whole film, never stopped; ?bgm= sets its level by ear (gain under the ducking to 30 %)
-music('audio/bgm/theme.mp3', BEATS.map(b => b.id), +(new URLSearchParams(location.search).get('bgm') || .3), 0);
+music('audio/bgm/theme.mp3', BEATS.map(b => b.id), +(new URLSearchParams(location.search).get('bgm') || .6), 0);
Promise.all([...['600 40px Oswald', '500 40px Oswald', '700 40px Oswald', 'italic 400 40px "EB Garamond"', '400 40px "EB Garamond"', '500 40px "EB Garamond"']
.map(f => document.fonts.load(f)), import('../lib/globe.js'), new Promise(r => { (function w() { window.GLOBE_READY ? r() : setTimeout(w, 30); })(); })])
diff --git a/site/pandemic/img/SOURCES.md b/site/pandemic/img/SOURCES.md
new file mode 100644
index 0000000..749926a
--- /dev/null
+++ b/site/pandemic/img/SOURCES.md
@@ -0,0 +1,24 @@
+# Pictures and data in this film
+
+The code in this repository is MIT. The pictures and data here keep their own licences.
+
+| File | Source | Author | Licence |
+|---|---|---|---|
+| `virus-sem-red.webp` | [Novel Coronavirus SARS-CoV-2](https://commons.wikimedia.org/wiki/File:Novel_Coronavirus_SARS-CoV-2_(49597020718).jpg), NIH Image Gallery | NIAID | Public domain |
+| `airport-pek-empty.webp` | Wikimedia Commons | Mx. Granger | CC0 |
+| `street-glenview-24.webp` | [Glenview March 2020 24](https://commons.wikimedia.org/wiki/File:Glenview_March_2020_24.jpg) | C. E. Miller | Public domain |
+| `street-hwy407.webp` | [EmptyHwy407](https://commons.wikimedia.org/wiki/File:EmptyHwy407.jpg) | Raysonho @ Open Grid Scheduler | CC0 |
+| `school-closed-banner.webp` | Wikimedia Commons | Cyan&Orange | CC0 |
+| `school-empty-classroom.webp` | U.S. Army, ID 200318-A-AW719-1022 | Pfc. Kaden Pitt | Public domain |
+| `mask-cbp-officer.webp` | U.S. Customs and Border Protection, 200313-H-NI589-249 | CBP | Public domain |
+| `mask-hawaii-guard.webp` | [DVIDS 6178786](https://www.dvidshub.net/image/6178786/) | Sgt. John Schoebel | Public domain |
+| `ppe-nurses-faceshields.webp` | U.S. Navy | PO3 Jacob L. Greenberg | Public domain |
+| `closed-sign-temporary.webp` | [Flickr 49703752138](https://www.flickr.com/photos/184594136@N08/49703752138/) | Alabama Extension | CC0 |
+| `night.webp` | [Black Marble 2016](https://earthobservatory.nasa.gov/features/NightLights/page3.php) | NASA Earth Observatory | Public domain |
+| `ct-pneumonia.webp` | [COVID-19 Pneumonie - 74m CTax - 002](https://commons.wikimedia.org/wiki/File:COVID-19_Pneumonie_-_74m_CTax_-_002.jpg), cropped and toned | Hellerhoff | [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) (this toned copy too) |
+| `wuhan-bridge-empty.webp` | [Roadblock in Wuhan on January 29th, 2020 - 2](https://commons.wikimedia.org/wiki/File:Roadblock_in_Wuhan_on_January_29th,_2020_-_2.jpg), toned | 汮汐 | [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/) (this toned copy too) |
+| `li-wenliang.webp` | Li Wenliang's own selfie, posted on Weibo, cropped and toned | Li Wenliang | Not licensed: used as fair use, for commentary on the events it shows |
+| `doctor-1.webp` … `doctor-7.webp` | Generated with an image model (gpt-image via OpenRouter), toned | AI illustration | Stand-ins for the seven other doctors, who are not identified; tagged on screen |
+| `paper.webp` | Paper texture | not yet recorded | to be confirmed |
+| `geo.js` | [Natural Earth](https://www.naturalearthdata.com/), projected | Natural Earth | Public domain |
+| `spread.js` | First case per country, [Our World in Data](https://ourworldindata.org/coronavirus) | Our World in Data | [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) |
diff --git a/site/pandemic/img/ct-pneumonia.webp b/site/pandemic/img/ct-pneumonia.webp
new file mode 100644
index 0000000..4f9db03
Binary files /dev/null and b/site/pandemic/img/ct-pneumonia.webp differ
diff --git a/site/pandemic/img/doctor-1.webp b/site/pandemic/img/doctor-1.webp
new file mode 100644
index 0000000..15ceec5
Binary files /dev/null and b/site/pandemic/img/doctor-1.webp differ
diff --git a/site/pandemic/img/doctor-2.webp b/site/pandemic/img/doctor-2.webp
new file mode 100644
index 0000000..c5824c4
Binary files /dev/null and b/site/pandemic/img/doctor-2.webp differ
diff --git a/site/pandemic/img/doctor-3.webp b/site/pandemic/img/doctor-3.webp
new file mode 100644
index 0000000..7a67bf9
Binary files /dev/null and b/site/pandemic/img/doctor-3.webp differ
diff --git a/site/pandemic/img/doctor-4.webp b/site/pandemic/img/doctor-4.webp
new file mode 100644
index 0000000..fde37a9
Binary files /dev/null and b/site/pandemic/img/doctor-4.webp differ
diff --git a/site/pandemic/img/doctor-5.webp b/site/pandemic/img/doctor-5.webp
new file mode 100644
index 0000000..78735ae
Binary files /dev/null and b/site/pandemic/img/doctor-5.webp differ
diff --git a/site/pandemic/img/doctor-6.webp b/site/pandemic/img/doctor-6.webp
new file mode 100644
index 0000000..03a9961
Binary files /dev/null and b/site/pandemic/img/doctor-6.webp differ
diff --git a/site/pandemic/img/doctor-7.webp b/site/pandemic/img/doctor-7.webp
new file mode 100644
index 0000000..abe8b45
Binary files /dev/null and b/site/pandemic/img/doctor-7.webp differ
diff --git a/site/pandemic/img/li-wenliang.webp b/site/pandemic/img/li-wenliang.webp
new file mode 100644
index 0000000..79012ec
Binary files /dev/null and b/site/pandemic/img/li-wenliang.webp differ
diff --git a/site/pandemic/img/wuhan-bridge-empty.webp b/site/pandemic/img/wuhan-bridge-empty.webp
new file mode 100644
index 0000000..fa7c593
Binary files /dev/null and b/site/pandemic/img/wuhan-bridge-empty.webp differ
diff --git a/site/pandemic/lib/doc.js b/site/pandemic/lib/doc.js
index d8e7c93..ad21b26 100644
--- a/site/pandemic/lib/doc.js
+++ b/site/pandemic/lib/doc.js
@@ -48,12 +48,16 @@ function blurOn(el, axis = 'x') {
dir: 1 = the camera swings right (the picture moves left). */
const WHIP = .32;
function whipOut(g, D, dir = 1, axis = 'x', dist = 1300) {
- const b = blurOn(g, axis), E = D + HOLD;
- clockRun(t => {
- const q = ease3(span01(t, E - WHIP, E)), o = -dir * dist * q;
+ const b = blurOn(g, axis);
+ // clockRun inline: a tail's dur is stretched to the beat's real end, which can pass D + HOLD (a clock run to D + HOLD
+ // adds another HOLD), so the throw lands on that end and the frame never freezes thrown
+ const w = { t0: 0, dur: D, ease: lin, tail: true };
+ w.pf = q => {
+ const t = q * w.dur, E = w.dur, k = ease3(span01(t, E - WHIP, E)), o = -dir * dist * k;
put(g, axis === 'x' ? { x: o } : { y: o });
- axis === 'x' ? b(q * 90, o) : b(q * 90, 0, o);
- }, D, { tail: true });
+ axis === 'x' ? b(k * 90, o) : b(k * 90, 0, o);
+ };
+ TW.push(w);
}
function whipIn(g, dir = 1, axis = 'x', dist = 1300, dur = WHIP + .1) {
const b = blurOn(g, axis);
@@ -71,28 +75,6 @@ function still(p, name, at, until, { s0 = 1.04, s1 = 1.14, focus = [.5, .5], o =
tw(g, { s: s1 }, at, until - at, lin);
return g;
}
-// a stamped word (CLOSED) slamming onto a still
-function stamp(p, str, x, y, t0, { size = 150, fill = RED, r = -6 } = {}) {
- const g = G(p, { x, y, s: 1.6, o: 0, r });
- const w = wid(str, size, KEY, '', 700) + 60;
- mk('rect', { x: -w / 2, y: -size * .78, width: w, height: size * 1.02, fill: 'none', stroke: fill, 'stroke-width': 9, rx: 8 }, g);
- T(g, str, { x: 0, y: size * .02, size, fill, font: KEY, weight: 700, anchor: 'middle' });
- tw(g, { s: 1, o: 1 }, t0, .16, out);
- return g;
-}
-// a roller shutter coming down over the frame, landing at t0 + dur
-function shutter(p, t0, dur = .45) {
- const g = G(p, { y: -SH - 20 });
- mk('rect', { x: -20, y: 0, width: SW + 40, height: SH + 20, fill: '#3a3d42' }, g);
- for (let y = 10; y < SH + 20; y += 26) {
- mk('rect', { x: -20, y, width: SW + 40, height: 3, fill: '#24262a' }, g);
- mk('rect', { x: -20, y: y + 3, width: SW + 40, height: 2, fill: '#55595f' }, g);
- }
- mk('rect', { x: -20, y: SH - 14, width: SW + 40, height: 34, fill: '#1c1d20' }, g);
- tw(g, { y: 0 }, t0, dur, p2 => p2 * p2);
- tw(g, { y: -14 }, t0 + dur, .08, out); tw(g, { y: 0 }, t0 + dur + .08, .1, io); // a small bounce
- return g;
-}
// a number that rolls from a to b; fmt turns a value into text
function counter(p, x, y, a, b, t0, dur, { size = 150, fill = CREAM, font = SER, anchor = 'middle', weight = 500, fmt = v => Math.round(v).toLocaleString('en-US'), ease = out } = {}) {
const e = T(p, fmt(a), { x, y, size, fill, font, weight, anchor, o: 0 });
@@ -137,24 +119,124 @@ function dateTag(p, str, t0, { fill = CREAM, x = 70, y = 86 } = {}) {
return g;
}
+/* ---------- level of detail for the map's paths ----------
+ The map holds ~2.8 M characters of path, far finer than a screen pixel at most zooms, and the browser repaints every
+ point on every frame the camera moves: one core flat out, 7–16 fps (thinning the points 4× gives ~55–60). So each
+ source path is parsed once into rings; the view picks a tolerance and a clip box (lodKey), and a path's d
+ is rebuilt only when either changes: clipped to the box, then simplified (Douglas–Peucker). Pure in t, like the rest. */
+const LOD_SRC = new Map(); // source d -> { rings: [{ p: Float64Array, closed, bb }], cache: Map(key -> d) }
+function lodSource(d) {
+ let s = LOD_SRC.get(d);
+ if (s) return s;
+ const rings = d.split('M').filter(Boolean).map(sub => {
+ const p = Float64Array.from(sub.match(/-?\d+(?:\.\d+)?(?:e-?\d+)?/g), Number), bb = [Infinity, Infinity, -Infinity, -Infinity];
+ for (let i = 0; i < p.length; i += 2) { bb[0] = Math.min(bb[0], p[i]); bb[1] = Math.min(bb[1], p[i + 1]); bb[2] = Math.max(bb[2], p[i]); bb[3] = Math.max(bb[3], p[i + 1]); }
+ return { p, closed: sub.includes('Z'), bb };
+ });
+ LOD_SRC.set(d, s = { rings, cache: new Map() });
+ return s;
+}
+// a closed ring clipped to a box (Sutherland–Hodgman); the cut edges run along the box, off screen
+function clipRing(p, [x0, y0, x1, y1]) {
+ let pts = p;
+ for (const [k, v, keep] of [[0, x0, 1], [0, x1, -1], [1, y0, 1], [1, y1, -1]]) {
+ const out = [], n = pts.length;
+ if (!n) break;
+ for (let i = 0; i < n; i += 2) {
+ const j = (i + 2) % n, a = (pts[i + k] - v) * keep, b = (pts[j + k] - v) * keep;
+ if (a >= 0) out.push(pts[i], pts[i + 1]);
+ if ((a >= 0) !== (b >= 0)) { const q = a / (a - b); out.push(pts[i] + (pts[j] - pts[i]) * q, pts[i + 1] + (pts[j + 1] - pts[i + 1]) * q); }
+ }
+ pts = out;
+ }
+ return pts;
+}
+// an open line cut to the box: runs of points inside, each with its outside neighbours so it reaches the edge
+function clipLine(p, [x0, y0, x1, y1]) {
+ const ins = i => p[i] >= x0 && p[i] <= x1 && p[i + 1] >= y0 && p[i + 1] <= y1, runs = [];
+ let run = null;
+ for (let i = 0; i < p.length; i += 2) {
+ if (ins(i) || (i > 0 && ins(i - 2)) || (i + 2 < p.length && ins(i + 2))) (run || (runs.push(run = []), run)).push(p[i], p[i + 1]);
+ else run = null;
+ }
+ return runs;
+}
+function simplify(p, tol) { // Douglas–Peucker on a flat [x, y, ...] list
+ const n = p.length / 2;
+ if (n < 3 || tol <= 0) return p;
+ const keep = new Uint8Array(n), st = [0, n - 1], t2 = tol * tol;
+ keep[0] = keep[n - 1] = 1;
+ while (st.length) {
+ const b = st.pop(), a = st.pop(), ax = p[2 * a], ay = p[2 * a + 1], dx = p[2 * b] - ax, dy = p[2 * b + 1] - ay, L = dx * dx + dy * dy;
+ let m = -1, md = t2;
+ for (let i = a + 1; i < b; i++) {
+ let u = L ? ((p[2 * i] - ax) * dx + (p[2 * i + 1] - ay) * dy) / L : 0; u = u < 0 ? 0 : u > 1 ? 1 : u;
+ const ex = p[2 * i] - ax - u * dx, ey = p[2 * i + 1] - ay - u * dy, e = ex * ex + ey * ey;
+ if (e > md) { md = e; m = i; }
+ }
+ if (m > 0) { keep[m] = 1; st.push(a, m, m, b); }
+ }
+ const out = [];
+ for (let i = 0; i < n; i++) if (keep[i]) out.push(p[2 * i], p[2 * i + 1]);
+ return out;
+}
+const lodPts = (p, closed) => p.length < 4 ? '' : 'M' + Array.from({ length: p.length / 2 }, (_, i) => `${+p[2 * i].toFixed(2)},${+p[2 * i + 1].toFixed(2)}`).join('L') + (closed ? 'Z' : '');
+function lodBuild(src, tol, box) {
+ const key = tol + '|' + box;
+ let d = src.cache.get(key);
+ if (d !== undefined) return d;
+ if (src.cache.size >= 6) src.cache.delete(src.cache.keys().next().value); // the oldest: a beat revisits few keys
+ const parts = [];
+ for (const r of src.rings) {
+ const bb = r.bb;
+ if (box && (bb[2] < box[0] || bb[0] > box[2] || bb[3] < box[1] || bb[1] > box[3])) continue;
+ const inside = !box || (bb[0] >= box[0] && bb[2] <= box[2] && bb[1] >= box[1] && bb[3] <= box[3]);
+ if (r.closed) { const c = inside ? r.p : clipRing(r.p, box); if (c.length >= 6) parts.push(lodPts(simplify(c, tol), true)); }
+ else for (const c of inside ? [r.p] : clipLine(r.p, box)) parts.push(lodPts(simplify(c, tol), false));
+ }
+ src.cache.set(key, d = parts.join(''));
+ return d;
+}
+// the tolerance and box for a view {x, y, z}: a tolerance of half to one screen px (stepping by 2), and a box of 5 x 5
+// cells of at least one view each, so the screen keeps 1.5 views of margin (a whip throws the panel 1300 px, 1.44
+// views tall; a shake a few px). At wide zooms it covers everything (null: no clip). Measured on the RTX, headed
+// Chromium: 12–21 ms a frame on every map beat (half a px with 7 x 7 cells: 16–29 ms)
+function lodKey(s) {
+ const tol = 2 ** Math.floor(Math.log2(1 / s.z)), k = 1 / tol; // k: the bucket's widest zoom, <= s.z
+ const cw = SW / k, ch = SH / k;
+ if (5 * cw > 6000) return [tol, null];
+ const gx = Math.floor(s.x / cw), gy = Math.floor(s.y / ch);
+ return [tol, [(gx - 2) * cw, (gy - 2) * ch, (gx + 3) * cw, (gy + 3) * ch]];
+}
+
/* ---------- the paper map of China on a camera ---------- */
function paperMap(p, D, view, { rails = false } = {}) {
const cam = camera(p, D, view);
- const w = cam.world, nz = sw => ({ 'stroke-width': sw, 'data-sw': sw });
- // strokes keep their screen width: data-sw px at any zoom (vector-effect: non-scaling-stroke drops WebKit to ~12 fps)
- clockRun(t => { const z = cam.at(t).z; w.querySelectorAll('[data-sw]').forEach(e => e.setAttribute('stroke-width', e.dataset.sw / z));
- w.querySelectorAll('[data-dash]').forEach(e => e.setAttribute('stroke-dasharray', e.dataset.dash.split(' ').map(v => v / z).join(' '))); }, D, { tail: true });
+ const w = cam.world, nz = sw => ({ 'stroke-width': sw, 'data-sw': sw }), lods = [];
+ const lp = (d, attrs, g = w) => { const e = mk('path', { ...attrs, d: '' }, g); e._lod = lodSource(d); lods.push(e); return e; };
mk('rect', { x: -6000, y: -6000, width: 12000, height: 12000, fill: MAPSEA }, w);
- mk('path', { d: GEO.land, fill: MAPLAND, stroke: MAPLINE, ...nz(1.1) }, w);
- mk('path', { d: GEO.china, fill: MAPCN, stroke: MAPINK, ...nz(1.6) }, w);
+ lp(GEO.land, { fill: MAPLAND, stroke: MAPLINE, ...nz(1.1) });
+ lp(GEO.china, { fill: MAPCN, stroke: MAPINK, ...nz(1.6) });
const provs = G(w, {});
- for (const n in GEO.provinces) mk('path', { d: GEO.provinces[n], fill: 'none', stroke: MAPLINE, 'data-dash': '4 3', ...nz(.9) }, provs);
- const hubei = mk('path', { d: GEO.provinces.Hubei, fill: RED, 'fill-opacity': 0, stroke: 'none' }, w);
- mk('path', { d: GEO.urban, fill: '#cdb995', stroke: 'none' }, w);
- mk('path', { d: GEO.lakes, fill: MAPSEA, stroke: '#8fa9ad', ...nz(.8) }, w);
- mk('path', { d: GEO.rivers10, fill: 'none', stroke: '#8fa9ad', ...nz(1.6) }, w);
- const rail = rails ? GEO.rails.map(d => mk('path', { d, fill: 'none', stroke: MAPINK, opacity: 0, ...nz(1.3) }, w)) : [];
+ for (const n in GEO.provinces) lp(GEO.provinces[n], { fill: 'none', stroke: MAPLINE, 'data-dash': '4 3', ...nz(.9) }, provs);
+ const hubei = lp(GEO.provinces.Hubei, { fill: RED, 'fill-opacity': 0, stroke: 'none' });
+ lp(GEO.urban, { fill: '#cdb995', stroke: 'none' });
+ lp(GEO.lakes, { fill: MAPSEA, stroke: '#8fa9ad', ...nz(.8) });
+ lp(GEO.rivers10, { fill: 'none', stroke: '#8fa9ad', ...nz(1.6) });
+ const rail = rails ? GEO.rails.map(d => lp(d, { fill: 'none', stroke: MAPINK, opacity: 0, ...nz(1.3) })) : [];
const marks = G(w, {}); // dots, rings, routes: drawn by the beat
+ // strokes keep their screen width: data-sw px at any zoom (vector-effect: non-scaling-stroke drops WebKit to ~12 fps);
+ // the paths take the detail the view needs
+ let lastKey = '';
+ clockRun(t => {
+ const s = cam.at(t), z = s.z, [tol, box] = lodKey(s), key = tol + '|' + box;
+ if (key !== lastKey) {
+ lastKey = key;
+ for (const e of lods) { const d = lodBuild(e._lod, tol, box); if (d !== e._d) e.setAttribute('d', e._d = d); }
+ }
+ w.querySelectorAll('[data-sw]').forEach(e => e.setAttribute('stroke-width', e.dataset.sw / z));
+ w.querySelectorAll('[data-dash]').forEach(e => e.setAttribute('stroke-dasharray', e.dataset.dash.split(' ').map(v => v / z).join(' ')));
+ }, D, { tail: true });
return { cam, w, hubei, rail, marks };
}
// a city dot that keeps its screen size whatever the zoom: r px at zoom z