vizmatic 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PROMPT.md +75 -531
- package/README.md +85 -1052
- package/ROADMAP.md +49 -67
- package/SCIENCE.md +250 -0
- package/assets/THIRD_PARTY_LICENSES.md +44 -1
- package/assets/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/assets/fonts/InstrumentSerif-Regular.ttf +0 -0
- package/assets/fonts/SourceSerif4-24pt-Italic.ttf +0 -0
- package/assets/fonts/SourceSerif4-24pt-Regular.ttf +0 -0
- package/assets/licenses/raster-codecs-MIT.txt +74 -0
- package/dist/chunk-3F2VQ7NW.js +1 -0
- package/dist/{chunk-FEIPTPBZ.js → chunk-4XE64I2U.js} +53 -463
- package/dist/chunk-5ZAFH2JC.js +4231 -0
- package/dist/chunk-JHHPLALU.js +79 -0
- package/dist/chunk-LTX44BAE.js +112 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-PSBF4TEK.js +1 -0
- package/dist/chunk-RPAHMKAR.js +605 -0
- package/dist/chunk-RWF4VBUL.js +3617 -0
- package/dist/cli.js +369 -12
- package/dist/index.cjs +7413 -1810
- package/dist/index.d.cts +900 -599
- package/dist/index.d.ts +900 -599
- package/dist/index.js +5019 -3278
- package/dist/math-LXB4FH4E.js +7 -0
- package/dist/math-QVCETQDQ.js +1 -0
- package/dist/scene-browser-assets.d.ts +38 -0
- package/dist/scene-browser-assets.js +53 -0
- package/dist/scene-browser-chunks/chunk-5MVLYGXM.js +70 -0
- package/dist/scene-browser-chunks/chunk-ASXKN3NU.js +1 -0
- package/dist/scene-browser-chunks/chunk-CM5Y5LZP.js +1 -0
- package/dist/scene-browser-chunks/chunk-DP7NB4EW.js +6 -0
- package/dist/scene-browser-chunks/emscripten-module.browser-M5AEKJGE.js +1 -0
- package/dist/scene-browser-chunks/ffi-FL6ORJU3.js +1 -0
- package/dist/scene-browser-chunks/module-ES6BEMUI-JD5S5VKR.js +1 -0
- package/dist/scene-browser-chunks/module-asyncify-2EFITU5U-HWPFJFJC.js +1 -0
- package/dist/scene-browser-chunks/scene-browser-layout-M3XSXMV4.js +27 -0
- package/dist/scene-browser.d.ts +117 -0
- package/dist/scene-browser.js +220 -0
- package/dist/scene-cli.js +1 -1
- package/dist/scene-runtime.cjs +168 -103
- package/dist/scene-runtime.d.cts +3 -2
- package/dist/scene-runtime.d.ts +3 -2
- package/dist/scene-runtime.js +3 -1
- package/dist/server-2FYHZ4UO.js +331 -0
- package/dist/stage-browser/browser.d.ts +2483 -0
- package/dist/stage-browser/chunk-SQE76S5B.js +1 -0
- package/dist/stage-browser/chunk-VZNL6JY2.js +59 -0
- package/dist/stage-browser/dagre.esm-N2NIVIAZ.js +6 -0
- package/dist/stage-browser/math-4WFNHVV2.js +18 -0
- package/dist/stage-browser/stage.js +19 -0
- package/dist/stage-export.cjs +4980 -0
- package/dist/stage-export.d.cts +112 -0
- package/dist/stage-export.d.ts +112 -0
- package/dist/stage-export.js +544 -0
- package/dist/stage.cjs +9789 -0
- package/dist/stage.d.cts +1679 -0
- package/dist/stage.d.ts +1679 -0
- package/dist/stage.js +5418 -0
- package/dist/svg-import-Djj2q7Pc.d.cts +742 -0
- package/dist/svg-import-Djj2q7Pc.d.ts +742 -0
- package/dist/video-CcHW1qhV.d.cts +532 -0
- package/dist/video-CcHW1qhV.d.ts +532 -0
- package/examples/README.md +18 -0
- package/examples/agent-pipeline.tsx +4 -4
- package/examples/animated-pipeline.tsx +1 -5
- package/examples/attention-head.tsx +12 -12
- package/examples/aurora-incident.tsx +4 -3
- package/examples/building-blocks.tsx +8 -9
- package/examples/catalog-charts.tsx +4 -4
- package/examples/catalog-content.tsx +7 -9
- package/examples/catalog-convolution-kernel.tsx +116 -0
- package/examples/catalog-data.tsx +2 -8
- package/examples/catalog-dataflow.tsx +5 -9
- package/examples/catalog-dense.tsx +80 -0
- package/examples/catalog-deployment.tsx +5 -11
- package/examples/catalog-diagrams.tsx +13 -16
- package/examples/catalog-drawing.tsx +7 -7
- package/examples/catalog-flows.tsx +4 -4
- package/examples/catalog-foundations.tsx +11 -11
- package/examples/catalog-gaussian-blur.tsx +146 -0
- package/examples/catalog-image-tensors.tsx +115 -0
- package/examples/catalog-ml.tsx +36 -31
- package/examples/catalog-numeric-matrices.tsx +93 -0
- package/examples/catalog-photo-blur.tsx +209 -0
- package/examples/catalog-science-ai.tsx +130 -0
- package/examples/catalog-science-chemistry.tsx +103 -0
- package/examples/catalog-science-math.tsx +93 -0
- package/examples/catalog-science-physics.tsx +84 -0
- package/examples/catalog-sequence.tsx +59 -38
- package/examples/data-pipeline-lineage-presentation.tsx +5 -0
- package/examples/data-pipeline-lineage.tsx +85 -0
- package/examples/daybreak-launch.tsx +1 -0
- package/examples/desired-quadrant.tsx +7 -8
- package/examples/engineering-dashboard-presentation.tsx +13 -0
- package/examples/engineering-dashboard.tsx +160 -0
- package/examples/engineering-flow.tsx +2 -4
- package/examples/eval-dashboard.tsx +6 -6
- package/examples/films/attention.ts +278 -0
- package/examples/films/cache-miss.ts +431 -0
- package/examples/films/catalog.json +132 -0
- package/examples/films/central-limit.ts +269 -0
- package/examples/films/complex-maps.ts +273 -0
- package/examples/films/deck-example.ts +224 -0
- package/examples/films/euler-circle.ts +179 -0
- package/examples/films/fourier-epicycles.ts +265 -0
- package/examples/films/gradient-descent.ts +345 -0
- package/examples/films/linear-maps.ts +175 -0
- package/examples/films/lorenz.ts +207 -0
- package/examples/films/pythagoras.ts +185 -0
- package/examples/films/taylor-series.ts +159 -0
- package/examples/films/vizmatic-title.ts +117 -0
- package/examples/llm-serving-stack-presentation.tsx +5 -0
- package/examples/llm-serving-stack.tsx +94 -0
- package/examples/model-garden.tsx +1 -0
- package/examples/model-router.tsx +6 -6
- package/examples/nccl-all-gather.tsx +3 -3
- package/examples/nccl-all-reduce.tsx +3 -3
- package/examples/nccl-all-to-all.tsx +1 -1
- package/examples/nccl-broadcast.tsx +1 -1
- package/examples/nccl-reduce-scatter.tsx +5 -5
- package/examples/orthogonal-routing.tsx +4 -4
- package/examples/pareto-frontier.tsx +9 -10
- package/examples/presentation-frame.tsx +6 -6
- package/examples/production-system-map-presentation.tsx +5 -0
- package/examples/production-system-map.tsx +130 -0
- package/examples/rag-graph.tsx +7 -7
- package/examples/release-card.tsx +5 -5
- package/examples/spec-anatomy.tsx +5 -5
- package/examples/system-architecture.tsx +19 -32
- package/examples/theme-system.tsx +1 -1
- package/examples/token-matrix.tsx +4 -2
- package/examples/transparent-badge.tsx +1 -2
- package/examples/videos/README.md +36 -2
- package/examples/videos/calculus-tangent.tsx +101 -0
- package/examples/videos/catalyst-pathway.tsx +56 -0
- package/examples/videos/causal-attention.tsx +91 -0
- package/examples/videos/convolution-kernel.tsx +34 -0
- package/examples/videos/gaussian-blur.tsx +32 -0
- package/examples/videos/image-to-matrix.tsx +22 -0
- package/examples/videos/matrix-multiplication.tsx +128 -0
- package/examples/videos/photo-gaussian-blur.tsx +39 -0
- package/examples/videos/wave-interference.tsx +80 -0
- package/examples/vizmatic-bare.d.ts +1 -0
- package/examples/vizmatic-hero.tsx +9 -18
- package/examples/website-workflow.tsx +7 -7
- package/examples/weekend-field-notes.tsx +3 -2
- package/package.json +65 -11
- package/dist/chunk-TH3F4SDB.js +0 -79
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A short presentation, played one chapter at a time with
|
|
3
|
+
* <vz-film src="..." stepped>. The arrow keys move between slides, and each slide
|
|
4
|
+
* builds with its own motion. The speed figures were measured on this repository:
|
|
5
|
+
* a 234-frame 720p film took 64.84 s on the old path, about 3.6 frames per second,
|
|
6
|
+
* and a 955-frame 1080p film on this engine rendered at 72.4 frames per second.
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
Node, arrow, dot, dynamic, draw, fadeIn, fadeOut, film, line, linear, lagged, rect, seq, smoother, text, tex, write,
|
|
10
|
+
type ColorInput,
|
|
11
|
+
} from 'vizmatic/stage'
|
|
12
|
+
|
|
13
|
+
const LEFT = -820
|
|
14
|
+
const OLD_FPS = 3.6
|
|
15
|
+
const NEW_FPS = 72.4
|
|
16
|
+
const OLD_PIXELS = 1280 * 720
|
|
17
|
+
const NEW_PIXELS = 1920 * 1080
|
|
18
|
+
|
|
19
|
+
function place<T extends Node>(node: T, x: number, y: number): T {
|
|
20
|
+
node.at(x + node.bounds().width / 2, y)
|
|
21
|
+
return node
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default film({
|
|
25
|
+
title: 'Why we rebuilt the renderer',
|
|
26
|
+
description: 'A six-step talk that plays one chapter at a time, with a timeline you can see and a measured result.',
|
|
27
|
+
fps: 60,
|
|
28
|
+
look: 'paper',
|
|
29
|
+
}, (s) => {
|
|
30
|
+
const heading = (content: string) => place(text(content, { font: 'serif', size: 72 }), LEFT, -370)
|
|
31
|
+
const kicker = (content: string) => place(text(content, { size: 20, color: 'dim', uppercase: true, tracking: 0.1, weight: 600 }), LEFT, -446)
|
|
32
|
+
const pageNumber = s.value(2)
|
|
33
|
+
const pageMark = dynamic(() => {
|
|
34
|
+
const label = text(`${Math.round(pageNumber.value)} / 6`, { font: 'mono', size: 20, color: 'dim' })
|
|
35
|
+
return label.at(820 - label.bounds().width / 2, 480)
|
|
36
|
+
})
|
|
37
|
+
const footerRule = line([LEFT, 446], [820, 446], { stroke: 'grid', width: 1.3 })
|
|
38
|
+
const footerName = place(text('Why we rebuilt the renderer', { size: 20, color: 'dim' }), LEFT, 480)
|
|
39
|
+
|
|
40
|
+
// ── 1. Title ────────────────────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
s.chapter('Title')
|
|
43
|
+
const lead = place(text('Engineering review', { size: 24, color: 'dim', uppercase: true, tracking: 0.1, weight: 600 }), LEFT, -220)
|
|
44
|
+
const big = text('Drawing a frame should not mean laying out a page.', { font: 'serif', size: 116, maxWidth: 1400, leading: 1.02 })
|
|
45
|
+
big.alignTo([LEFT, 0], 'left').alignTo([0, -170], 'top')
|
|
46
|
+
const underline = line([LEFT, 220], [LEFT + 340, 220], { stroke: 'teal', width: 5 })
|
|
47
|
+
s.play(fadeIn(lead, { shift: [0, 10] }), write(big), { duration: 2.2 })
|
|
48
|
+
s.play(draw(underline), { duration: 0.7 })
|
|
49
|
+
s.wait(0.3)
|
|
50
|
+
|
|
51
|
+
// ── 2. The problem ──────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
s.chapter('The problem')
|
|
54
|
+
s.play(fadeOut([lead, big, underline], { shift: [0, -30] }), { duration: 0.6 })
|
|
55
|
+
const k2 = kicker('The problem'), h2 = heading('Every frame repeated all of the work.')
|
|
56
|
+
s.add(footerRule, footerName)
|
|
57
|
+
s.play(fadeIn([k2, footerName, footerRule, pageMark]), write(h2), { duration: 1.2 })
|
|
58
|
+
const stages = ['TSX', 'React tree', 'Flex layout', 'SVG text', 'Rasterize', 'Encode']
|
|
59
|
+
const stageWidth = 216, stageGap = 58, top = -200
|
|
60
|
+
const nodes = stages.map((name, i) => {
|
|
61
|
+
const x = LEFT + i * (stageWidth + stageGap)
|
|
62
|
+
const chip = rect(stageWidth, 96, { fill: 'surface', stroke: i < 5 ? 'gridStrong' : 'grid', width: 1.6, radius: 8 }).at(x + stageWidth / 2, top + 48)
|
|
63
|
+
const label = text(name, { size: 27, weight: 600 }).moveTo([x + stageWidth / 2, top + 48])
|
|
64
|
+
return new Node().add(chip, label)
|
|
65
|
+
})
|
|
66
|
+
const links = stages.slice(1).map((_, i) => {
|
|
67
|
+
const x = LEFT + i * (stageWidth + stageGap) + stageWidth
|
|
68
|
+
return arrow([x + 6, top + 48], [x + stageGap - 6, top + 48], { stroke: 'dim', width: 2.2, tip: 12 })
|
|
69
|
+
})
|
|
70
|
+
const cycle = new Node().add(
|
|
71
|
+
line([LEFT + 2, top + 118], [LEFT + 2, top + 150], { stroke: 'red', width: 3 }),
|
|
72
|
+
line([LEFT + 2, top + 150], [LEFT + 4 * (stageWidth + stageGap) + stageWidth, top + 150], { stroke: 'red', width: 3 }),
|
|
73
|
+
line([LEFT + 4 * (stageWidth + stageGap) + stageWidth, top + 150], [LEFT + 4 * (stageWidth + stageGap) + stageWidth, top + 118], { stroke: 'red', width: 3 }),
|
|
74
|
+
)
|
|
75
|
+
const cycleLabel = place(text('Repeated for every frame', { size: 26, color: 'red' }), LEFT + 14, top + 184)
|
|
76
|
+
s.play(lagged(nodes.map((node) => fadeIn(node, { shift: [0, 14] })), { lag: 0.22 }), lagged(links.map((link) => fadeIn(link)), { lag: 0.22 }), { duration: 1.5 })
|
|
77
|
+
s.play(draw(cycle, { lag: 0.2 }), fadeIn(cycleLabel), { duration: 0.9 })
|
|
78
|
+
const costBig = text('277 ms', { font: 'mono', size: 150, color: 'red' })
|
|
79
|
+
place(costBig, LEFT, 210)
|
|
80
|
+
const costNote = place(text('per frame at 720p, or 3.6 frames per second.', { size: 34, color: 'dim' }), LEFT + costBig.bounds().width + 44, 228)
|
|
81
|
+
s.play(fadeIn(costBig, { shift: [0, 16] }), fadeIn(costNote, { shift: [0, 16] }), { duration: 0.9 })
|
|
82
|
+
s.wait(0.3)
|
|
83
|
+
|
|
84
|
+
// ── 3. The idea ─────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
s.chapter('The idea')
|
|
87
|
+
s.play(fadeOut([k2, h2, ...nodes, ...links, cycle, cycleLabel, costBig, costNote], { shift: [0, -24] }), { duration: 0.6 })
|
|
88
|
+
const k3 = kicker('The idea'), h3 = heading('Compile once. Sample anywhere.')
|
|
89
|
+
pageNumber.set(3)
|
|
90
|
+
s.play(fadeIn(k3), write(h3), { duration: 1.2 })
|
|
91
|
+
// A real timeline: three tracks of keys, a playhead, and the picture they produce.
|
|
92
|
+
const TRACK_X = LEFT, TRACK_W = 900, TRACK_TOP = -210, TRACK_H = 92
|
|
93
|
+
const tracks: { name: string; color: ColorInput; keys: readonly [number, number][] }[] = [
|
|
94
|
+
{ name: 'x position', color: 'blue', keys: [[0.05, 0.3], [0.55, 0.9]] },
|
|
95
|
+
{ name: 'scale', color: 'teal', keys: [[0.25, 0.55], [0.7, 0.95]] },
|
|
96
|
+
{ name: 'color', color: 'pink', keys: [[0.1, 0.4], [0.6, 0.8]] },
|
|
97
|
+
]
|
|
98
|
+
const trackNodes = new Node()
|
|
99
|
+
tracks.forEach((track, i) => {
|
|
100
|
+
const y = TRACK_TOP + i * TRACK_H
|
|
101
|
+
trackNodes.add(place(text(track.name, { font: 'mono', size: 21, color: 'dim' }), TRACK_X, y - 28))
|
|
102
|
+
trackNodes.add(line([TRACK_X, y], [TRACK_X + TRACK_W, y], { stroke: 'grid', width: 1.6 }))
|
|
103
|
+
for (const [from, to2] of track.keys) {
|
|
104
|
+
trackNodes.add(rect((to2 - from) * TRACK_W, 22, { fill: track.color, stroke: null, radius: 4 }).at(TRACK_X + ((from + to2) / 2) * TRACK_W, y).opacity(0.85))
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
const playhead = s.value(0)
|
|
108
|
+
const eased = (u: number) => u * u * (3 - 2 * u)
|
|
109
|
+
const sampleTrack = (index: number, t: number): number => {
|
|
110
|
+
let value = 0
|
|
111
|
+
for (const [from, end] of tracks[index]!.keys) {
|
|
112
|
+
const clipped = Math.max(0, Math.min(1, (t - from) / (end - from)))
|
|
113
|
+
value += eased(clipped) * 0.5
|
|
114
|
+
}
|
|
115
|
+
return value
|
|
116
|
+
}
|
|
117
|
+
const head = dynamic(() => {
|
|
118
|
+
const x = TRACK_X + playhead.value * TRACK_W
|
|
119
|
+
const stamp = text(`t = ${(playhead.value * 4).toFixed(2)} s`, { font: 'mono', size: 20, color: 'ink' })
|
|
120
|
+
stamp.at(x, TRACK_TOP + 3 * TRACK_H - 22)
|
|
121
|
+
return [line([x, TRACK_TOP - 44], [x, TRACK_TOP + 2.5 * TRACK_H], { stroke: 'ink', width: 2.4 }), stamp]
|
|
122
|
+
})
|
|
123
|
+
const PIC_X = 250, PIC_W = 570
|
|
124
|
+
const picture = dynamic(() => {
|
|
125
|
+
const t = playhead.value
|
|
126
|
+
const px = sampleTrack(0, t), scale = sampleTrack(1, t), tint = sampleTrack(2, t)
|
|
127
|
+
const color: ColorInput = tint < 0.25 ? 'blue' : tint < 0.75 ? 'teal' : 'pink'
|
|
128
|
+
return [
|
|
129
|
+
rect(PIC_W, 300, { fill: 'surface', stroke: 'grid', width: 1.6, radius: 8 }).at(PIC_X + PIC_W / 2, TRACK_TOP + 110),
|
|
130
|
+
dot(26 + 54 * scale, color).at(PIC_X + 60 + px * (PIC_W - 120), TRACK_TOP + 110),
|
|
131
|
+
]
|
|
132
|
+
})
|
|
133
|
+
const idea = place(text('A frame is a pure function of time, so playback can seek in any direction with no replay.', { size: 30, color: 'dim' }), LEFT, 210)
|
|
134
|
+
s.play(fadeIn(trackNodes, { lag: 0.02 }), fadeIn(head), fadeIn(picture), { duration: 1 })
|
|
135
|
+
s.play(seq(playhead.to(1, { ease: linear, duration: 2.6 }), playhead.to(0.34, { ease: smoother, duration: 1.2 }), playhead.to(0.76, { ease: smoother, duration: 1 })), { duration: 4.8 })
|
|
136
|
+
s.play(fadeIn(idea, { shift: [0, 12] }), { duration: 0.7 })
|
|
137
|
+
s.wait(0.3)
|
|
138
|
+
|
|
139
|
+
// ── 4. The result ───────────────────────────────────────────────────────
|
|
140
|
+
|
|
141
|
+
s.chapter('The result')
|
|
142
|
+
s.play(fadeOut([k3, h3, trackNodes, head, picture, idea], { shift: [0, -24] }), { duration: 0.6 })
|
|
143
|
+
const k4 = kicker('The result'), h4 = heading('Twenty times the speed, at higher resolution.')
|
|
144
|
+
pageNumber.set(4)
|
|
145
|
+
s.play(fadeIn(k4), write(h4), { duration: 1.2 })
|
|
146
|
+
const BAR_X = LEFT + 370, BAR_W = 960, BAR_TOP = -200, SCALE = BAR_W / NEW_FPS
|
|
147
|
+
const rows: { name: string; note: string; value: number; color: ColorInput; y: number }[] = [
|
|
148
|
+
{ name: 'Before', note: '720p, flex layout per frame', value: OLD_FPS, color: 'red', y: BAR_TOP },
|
|
149
|
+
{ name: 'After', note: '1080p, sampled vector frames', value: NEW_FPS, color: 'teal', y: BAR_TOP + 130 },
|
|
150
|
+
]
|
|
151
|
+
const grow = s.value(0)
|
|
152
|
+
const bars = dynamic(() => rows.flatMap((row) => {
|
|
153
|
+
const width = Math.max(2, row.value * SCALE * grow.value)
|
|
154
|
+
return [
|
|
155
|
+
rect(width, 62, { fill: row.color, stroke: null, radius: 3 }).at(BAR_X + width / 2, row.y),
|
|
156
|
+
place(text(`${(row.value * grow.value).toFixed(1)} fps`, { font: 'mono', size: 36, color: row.color === 'red' ? 'red' : 'ink' }), BAR_X + width + 20, row.y),
|
|
157
|
+
]
|
|
158
|
+
}))
|
|
159
|
+
const barLabels = new Node().add(...rows.flatMap((row) => [
|
|
160
|
+
place(text(row.name, { size: 36, weight: 600 }), LEFT, row.y - 16),
|
|
161
|
+
place(text(row.note, { size: 22, color: 'dim' }), LEFT, row.y + 22),
|
|
162
|
+
]))
|
|
163
|
+
const speed = NEW_FPS / OLD_FPS
|
|
164
|
+
const pixels = NEW_PIXELS / OLD_PIXELS
|
|
165
|
+
const facts: [string, string][] = [
|
|
166
|
+
[`${speed.toFixed(0)} times`, 'more frames each second'],
|
|
167
|
+
[`${pixels.toFixed(2)} times`, 'the pixels in each frame'],
|
|
168
|
+
[`${(speed * pixels).toFixed(0)} times`, 'the pixels per second, measured end to end'],
|
|
169
|
+
]
|
|
170
|
+
const factNodes = facts.map(([value, note], i) => {
|
|
171
|
+
const x = LEFT + i * 560
|
|
172
|
+
return new Node().add(
|
|
173
|
+
place(text(value, { font: 'serif', size: 86, color: 'ink' }), x, 150),
|
|
174
|
+
place(text(note, { size: 26, color: 'dim' }), x, 226),
|
|
175
|
+
)
|
|
176
|
+
})
|
|
177
|
+
const measured = place(text('Measured on two demo films on one 18-core laptop, in the same week.', { size: 20, color: 'faint' }), LEFT, 330)
|
|
178
|
+
s.add(bars)
|
|
179
|
+
s.play(fadeIn([barLabels, measured]), grow.to(1, { ease: smoother }), { duration: 2 })
|
|
180
|
+
s.play(lagged(factNodes.map((node) => fadeIn(node, { shift: [0, 14] })), { lag: 0.3 }), { duration: 1.4 })
|
|
181
|
+
s.wait(0.3)
|
|
182
|
+
|
|
183
|
+
// ── 5. What it costs ────────────────────────────────────────────────────
|
|
184
|
+
|
|
185
|
+
s.chapter('The tradeoff')
|
|
186
|
+
s.play(fadeOut([k4, h4, bars, barLabels, measured, ...factNodes], { shift: [0, -24] }), { duration: 0.6 })
|
|
187
|
+
const k5 = kicker('The tradeoff'), h5 = heading('Pixels stay. Layout moves to authoring.')
|
|
188
|
+
pageNumber.set(5)
|
|
189
|
+
s.play(fadeIn(k5), write(h5), { duration: 1.2 })
|
|
190
|
+
const eq = tex('\\text{frame}(t) = \\text{paint}\\big(\\text{sample}(\\text{timeline}, t)\\big)', { size: 56 })
|
|
191
|
+
eq.alignTo([LEFT, 0], 'left').alignTo([0, -220], 'top')
|
|
192
|
+
const columns: [string, ColorInput, string][] = [
|
|
193
|
+
['Keep', 'teal', 'Diagrams and dashboards still lay out from TSX, and keep every check they had.'],
|
|
194
|
+
['Gain', 'blue', 'Live seeking in the browser, and the same pixels from Node for video.'],
|
|
195
|
+
['Pay', 'orange', 'Motion is authored as a timeline, so a frame cannot depend on the one before it.'],
|
|
196
|
+
]
|
|
197
|
+
const cards = columns.map(([name, color, body], i) => {
|
|
198
|
+
const x = LEFT + i * 560
|
|
199
|
+
return new Node().add(
|
|
200
|
+
line([x, -68], [x + 510, -68], { stroke: color, width: 4 }),
|
|
201
|
+
place(text(name, { font: 'serif', size: 62 }), x, -16),
|
|
202
|
+
(() => {
|
|
203
|
+
const paragraph = text(body, { size: 30, color: 'dim', maxWidth: 500, leading: 1.4 })
|
|
204
|
+
paragraph.alignTo([x, 0], 'left').alignTo([0, 44], 'top')
|
|
205
|
+
return paragraph
|
|
206
|
+
})(),
|
|
207
|
+
)
|
|
208
|
+
})
|
|
209
|
+
s.play(write(eq), { duration: 1.3 })
|
|
210
|
+
s.play(lagged(cards.map((node) => fadeIn(node, { shift: [0, 16] })), { lag: 0.3 }), { duration: 1.5 })
|
|
211
|
+
s.wait(0.3)
|
|
212
|
+
|
|
213
|
+
// ── 6. The end ──────────────────────────────────────────────────────────
|
|
214
|
+
|
|
215
|
+
s.chapter('Next')
|
|
216
|
+
s.play(fadeOut([k5, h5, eq, ...cards], { shift: [0, -24] }), { duration: 0.6 })
|
|
217
|
+
const closing = text('Ship the film, not a screenshot.', { font: 'serif', size: 124, maxWidth: 1660, leading: 1.02 })
|
|
218
|
+
closing.alignTo([LEFT, 0], 'left').alignTo([0, -190], 'top')
|
|
219
|
+
const contact = place(text('This deck is one TypeScript file. Press the right arrow to step through it.', { size: 32, color: 'dim' }), LEFT, 210)
|
|
220
|
+
pageNumber.set(6)
|
|
221
|
+
s.play(write(closing), { duration: 2 })
|
|
222
|
+
s.play(fadeIn(contact, { shift: [0, 10] }), { duration: 0.8 })
|
|
223
|
+
s.wait(2)
|
|
224
|
+
})
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A point on the unit circle, read two ways. Its height traces sine and its
|
|
3
|
+
* horizontal position traces cosine, against the angle. Stop at theta = pi and the
|
|
4
|
+
* general formula collapses to Euler's identity, one substitution at a time.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
Node, arc, arrow, circle, curveThrough, draw, dot, dynamic, fadeIn, fadeOut, film, flash, line, linear, morphMatching, rect, smoother, text, tex, to, write,
|
|
8
|
+
type Vec,
|
|
9
|
+
} from 'vizmatic/stage'
|
|
10
|
+
|
|
11
|
+
const TAU = Math.PI * 2
|
|
12
|
+
const R = 185
|
|
13
|
+
const CX = -650, CY = -208
|
|
14
|
+
const PLOT_X = -366, PLOT_W = 1210
|
|
15
|
+
const SIN_Y = CY, COS_Y = 176
|
|
16
|
+
|
|
17
|
+
export default film({
|
|
18
|
+
title: "Euler's identity from a circle",
|
|
19
|
+
description: 'A point sweeps the unit circle, sine and cosine trace themselves, and the formula collapses at theta equals pi.',
|
|
20
|
+
fps: 60,
|
|
21
|
+
}, (s) => {
|
|
22
|
+
const theta = s.value(0)
|
|
23
|
+
const P = (): Vec => [CX + Math.cos(theta.value) * R, CY - Math.sin(theta.value) * R]
|
|
24
|
+
const plotX = (t: number) => PLOT_X + (t / TAU) * PLOT_W
|
|
25
|
+
|
|
26
|
+
// ── The circle ──────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
const axisH = line([CX - R - 34, CY], [CX + R + 34, CY], { stroke: 'faint', width: 1.6 })
|
|
29
|
+
const axisV = line([CX, CY - R - 34], [CX, CY + R + 34], { stroke: 'faint', width: 1.6 })
|
|
30
|
+
const ring = circle(R, { stroke: 'dim', width: 2.4 }).at(CX, CY)
|
|
31
|
+
const unit = tex('1', { size: 24, color: 'dim', display: false }).moveTo([CX + R + 16, CY + 24])
|
|
32
|
+
|
|
33
|
+
const hand = dynamic(() => {
|
|
34
|
+
const [px, py] = P()
|
|
35
|
+
const t = theta.value
|
|
36
|
+
const c = Math.cos(t), sn = Math.sin(t)
|
|
37
|
+
const items: Node[] = []
|
|
38
|
+
if (t > 0.02) {
|
|
39
|
+
items.push(arc(46, 0, -t, { stroke: 'yellow', width: 3 }).at(CX, CY))
|
|
40
|
+
}
|
|
41
|
+
items.push(
|
|
42
|
+
line([CX, CY], [CX + c * R, CY], { stroke: 'blue', width: 7 }),
|
|
43
|
+
line([CX + c * R, CY], [CX + c * R, CY - sn * R], { stroke: 'pink', width: 7 }),
|
|
44
|
+
arrow([CX, CY], [px, py], { stroke: 'ink', width: 3.2, tip: 16 }),
|
|
45
|
+
dot(9.5, 'yellow').at(px, py).glow(14),
|
|
46
|
+
)
|
|
47
|
+
if (t > 0.3) {
|
|
48
|
+
// Drawn last, on a backing, so the sweeping radius passes behind the label.
|
|
49
|
+
const mid = t / 2
|
|
50
|
+
const label = tex('\\theta', { size: 28, color: 'yellow', display: false }).moveTo([CX + Math.cos(mid) * 74, CY - Math.sin(mid) * 74])
|
|
51
|
+
const b = label.bounds()
|
|
52
|
+
items.push(rect(b.width + 8, b.height + 6, { fill: 'bg', stroke: null, radius: 4 }).at(b.x + b.width / 2, b.y + b.height / 2), label)
|
|
53
|
+
}
|
|
54
|
+
return items
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// ── The two traces ──────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
const frame = (y: number, label: string, color: string): Node => {
|
|
60
|
+
const parts: Node[] = [
|
|
61
|
+
line([PLOT_X, y], [PLOT_X + PLOT_W + 10, y], { stroke: 'faint', width: 1.6 }),
|
|
62
|
+
line([PLOT_X, y - R - 14], [PLOT_X, y + R + 14], { stroke: 'faint', width: 1.6 }),
|
|
63
|
+
line([PLOT_X - 6, y - R], [PLOT_X + 6, y - R], { stroke: 'faint', width: 1.6 }),
|
|
64
|
+
line([PLOT_X - 6, y + R], [PLOT_X + 6, y + R], { stroke: 'faint', width: 1.6 }),
|
|
65
|
+
// Top middle stays clear: at theta = pi, sine is at 0 and cosine is at its lowest.
|
|
66
|
+
tex(label, { size: 36, color, display: false }).moveTo([PLOT_X + PLOT_W * 0.5, y - R + 6]),
|
|
67
|
+
]
|
|
68
|
+
for (const [mark, at] of [['\\frac{\\pi}{2}', 0.25], ['\\pi', 0.5], ['\\frac{3\\pi}{2}', 0.75], ['2\\pi', 1]] as const) {
|
|
69
|
+
const x = PLOT_X + at * PLOT_W
|
|
70
|
+
parts.push(line([x, y - 6], [x, y + 6], { stroke: 'faint', width: 1.6 }))
|
|
71
|
+
parts.push(tex(mark, { size: 21, color: 'dim', display: false }).moveTo([x + (at === 1 ? -4 : 0), y + 30]))
|
|
72
|
+
}
|
|
73
|
+
return new Node().add(...parts)
|
|
74
|
+
}
|
|
75
|
+
const sinFrame = frame(SIN_Y, '\\sin\\theta', 'pink')
|
|
76
|
+
const cosFrame = frame(COS_Y, '\\cos\\theta', 'blue')
|
|
77
|
+
|
|
78
|
+
const traces = dynamic(() => {
|
|
79
|
+
const end = theta.value
|
|
80
|
+
const steps = Math.max(2, Math.ceil(end * 44))
|
|
81
|
+
const sinPoints: Vec[] = [], cosPoints: Vec[] = []
|
|
82
|
+
for (let i = 0; i <= steps; i++) {
|
|
83
|
+
const t = (end * i) / steps
|
|
84
|
+
sinPoints.push([plotX(t), SIN_Y - Math.sin(t) * R])
|
|
85
|
+
cosPoints.push([plotX(t), COS_Y - Math.cos(t) * R])
|
|
86
|
+
}
|
|
87
|
+
const x = plotX(end)
|
|
88
|
+
const sy = SIN_Y - Math.sin(end) * R, cy = COS_Y - Math.cos(end) * R
|
|
89
|
+
return [
|
|
90
|
+
// Same height on both sides: the point's height is the graph's value.
|
|
91
|
+
line(P(), [x, sy], { stroke: 'pink', width: 1.5, dash: [3, 8], opacity: 0.7 }),
|
|
92
|
+
new Node(curveThrough(sinPoints)).stroke('pink', 4).glow(6),
|
|
93
|
+
new Node(curveThrough(cosPoints)).stroke('blue', 4).glow(6),
|
|
94
|
+
dot(8, 'pink').at(x, sy),
|
|
95
|
+
dot(8, 'blue').at(x, cy),
|
|
96
|
+
]
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// ── Readouts, under the circle ──────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
const LEFT = -864
|
|
102
|
+
const readLabel = (content: string, y: number, color: string) => text(content, { font: 'mono', size: 28, color }).alignTo([LEFT, 0], 'left').alignTo([0, y], 'top')
|
|
103
|
+
const reads = dynamic(() => {
|
|
104
|
+
const t = theta.value
|
|
105
|
+
const clean = (v: number) => (Math.abs(v) < 0.005 ? 0 : v).toFixed(3).padStart(6, ' ')
|
|
106
|
+
return [
|
|
107
|
+
readLabel(`theta ${clean(t)}`, 40, 'yellow'),
|
|
108
|
+
readLabel(`cos ${clean(Math.cos(t))}`, 84, 'blue'),
|
|
109
|
+
readLabel(`sin ${clean(Math.sin(t))}`, 128, 'pink'),
|
|
110
|
+
]
|
|
111
|
+
})
|
|
112
|
+
const note = text('A complex number with length one is a point on this circle. Its angle is the exponent.', {
|
|
113
|
+
size: 23, color: 'dim', maxWidth: 400, leading: 1.42,
|
|
114
|
+
}).alignTo([LEFT, 0], 'left').alignTo([0, 206], 'top')
|
|
115
|
+
|
|
116
|
+
// ── Words and equations ─────────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
const title = text('One point, two shadows.', { font: 'serif', size: 66 })
|
|
119
|
+
title.alignTo([LEFT, 0], 'left').alignTo([0, -504], 'top')
|
|
120
|
+
|
|
121
|
+
const EQ_Y = 452
|
|
122
|
+
const at = (source: string, size = 62) => tex(source, { size }).moveTo([0, EQ_Y])
|
|
123
|
+
const paint = (eq: ReturnType<typeof tex>, fragment: string, color: string) => {
|
|
124
|
+
for (const glyph of eq.part(fragment)) glyph.fill(color)
|
|
125
|
+
}
|
|
126
|
+
const general = at('e^{i\\theta} = \\cos\\theta + i\\sin\\theta')
|
|
127
|
+
paint(general, '\\cos\\theta', 'blue')
|
|
128
|
+
paint(general, '\\sin\\theta', 'pink')
|
|
129
|
+
paint(general, 'e^{i\\theta}', 'yellow')
|
|
130
|
+
const atPi = at('e^{i\\pi} = \\cos\\pi + i\\sin\\pi')
|
|
131
|
+
paint(atPi, '\\cos\\pi', 'blue')
|
|
132
|
+
paint(atPi, '\\sin\\pi', 'pink')
|
|
133
|
+
paint(atPi, 'e^{i\\pi}', 'yellow')
|
|
134
|
+
const values = at('e^{i\\pi} = -1 + i \\cdot 0')
|
|
135
|
+
paint(values, '-1', 'blue')
|
|
136
|
+
paint(values, '0', 'pink')
|
|
137
|
+
paint(values, 'e^{i\\pi}', 'yellow')
|
|
138
|
+
const reduced = at('e^{i\\pi} = -1')
|
|
139
|
+
paint(reduced, 'e^{i\\pi}', 'yellow')
|
|
140
|
+
const identity = tex('e^{i\\pi} + 1 = 0', { size: 170 }).moveTo([0, 10])
|
|
141
|
+
paint(identity, 'e^{i\\pi}', 'yellow')
|
|
142
|
+
const caption = text('Half a turn, and you land on minus one.', { font: 'serif', italic: true, size: 50, color: 'dim' }).moveTo([0, 210])
|
|
143
|
+
|
|
144
|
+
// ── Timeline ────────────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
s.chapter('The point')
|
|
147
|
+
s.play(write(title), draw(axisH), draw(axisV), draw(ring), { duration: 1.8 })
|
|
148
|
+
s.play(fadeIn(unit), fadeIn(hand), { duration: 0.8 })
|
|
149
|
+
s.play(write(general), fadeIn(note, { shift: [0, 8] }), { duration: 1.8 })
|
|
150
|
+
s.play(theta.to(0.85), fadeIn(reads), { duration: 1.8 })
|
|
151
|
+
s.wait(0.6)
|
|
152
|
+
|
|
153
|
+
s.chapter('Two shadows')
|
|
154
|
+
s.play(draw(sinFrame, { lag: 0.03 }), draw(cosFrame, { lag: 0.03 }), { duration: 1.6 })
|
|
155
|
+
s.add(traces)
|
|
156
|
+
s.play(fadeIn(traces), { duration: 0.4 })
|
|
157
|
+
s.play(theta.to(TAU, { ease: linear }), { duration: 8 })
|
|
158
|
+
s.wait(0.8)
|
|
159
|
+
|
|
160
|
+
s.chapter('Stop at pi')
|
|
161
|
+
s.play(theta.to(Math.PI, { ease: smoother }), { duration: 3.2 })
|
|
162
|
+
s.play(flash(P(), { color: 'yellow', radius: 56 }), { duration: 0.7 })
|
|
163
|
+
s.wait(0.5)
|
|
164
|
+
s.play(morphMatching(general, atPi), { duration: 1.4 })
|
|
165
|
+
s.wait(0.9)
|
|
166
|
+
s.play(morphMatching(atPi, values), { duration: 1.4 })
|
|
167
|
+
s.wait(0.9)
|
|
168
|
+
s.play(morphMatching(values, reduced), { duration: 1.2 })
|
|
169
|
+
s.wait(0.7)
|
|
170
|
+
|
|
171
|
+
s.chapter('The identity')
|
|
172
|
+
s.play(
|
|
173
|
+
morphMatching(reduced, identity),
|
|
174
|
+
fadeOut([title, note, reads, unit, hand, traces, sinFrame, cosFrame, axisH, axisV], { duration: 1.3 }),
|
|
175
|
+
to(ring, (r) => r.moveTo([0, 10]).scale(2.3).opacity(0.14)), { duration: 1.9 },
|
|
176
|
+
)
|
|
177
|
+
s.play(fadeIn(caption, { shift: [0, 14] }), { duration: 1.2 })
|
|
178
|
+
s.wait(3.2)
|
|
179
|
+
})
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A closed curve is a sum of rotating arrows. The coefficients are a real
|
|
3
|
+
* discrete Fourier transform of an ampersand's outline, and every readout comes
|
|
4
|
+
* from them, including the energy and error figures via Parseval's identity.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
Node, dot, dynamic, draw, fade, fadeIn, film, flash, fontFor, linear, linearGradient, line, parseColor, pathBounds,
|
|
8
|
+
pointAt, polyPath, circlePath, rect, smoother, signedArea, text, tex, transformPath, write, ramp,
|
|
9
|
+
type Path, type Rgba, type Ring, type Vec,
|
|
10
|
+
} from 'vizmatic/stage'
|
|
11
|
+
|
|
12
|
+
const TAU = Math.PI * 2
|
|
13
|
+
const SAMPLES = 2048
|
|
14
|
+
const MAX_FREQ = 320
|
|
15
|
+
const TRACE = 900
|
|
16
|
+
const MAX_TERMS = 240
|
|
17
|
+
|
|
18
|
+
interface Term { n: number; re: number; im: number; size: number }
|
|
19
|
+
|
|
20
|
+
/** Discrete Fourier transform, for the frequencies a drawing actually needs. */
|
|
21
|
+
function transform(points: readonly Vec[]): Term[] {
|
|
22
|
+
const terms: Term[] = []
|
|
23
|
+
const m = points.length
|
|
24
|
+
for (let n = -MAX_FREQ; n <= MAX_FREQ; n++) {
|
|
25
|
+
let re = 0, im = 0
|
|
26
|
+
for (let j = 0; j < m; j++) {
|
|
27
|
+
const angle = -TAU * n * j / m
|
|
28
|
+
const c = Math.cos(angle), s = Math.sin(angle)
|
|
29
|
+
re += points[j]![0] * c - points[j]![1] * s
|
|
30
|
+
im += points[j]![0] * s + points[j]![1] * c
|
|
31
|
+
}
|
|
32
|
+
re /= m
|
|
33
|
+
im /= m
|
|
34
|
+
terms.push({ n, re, im, size: Math.hypot(re, im) })
|
|
35
|
+
}
|
|
36
|
+
return terms
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default film({
|
|
40
|
+
title: 'Fourier epicycles',
|
|
41
|
+
description: 'An ampersand redrawn by a chain of rotating arrows as the term count grows.',
|
|
42
|
+
fps: 60,
|
|
43
|
+
}, (s) => {
|
|
44
|
+
fontFor('serif', 400, true)
|
|
45
|
+
const glyph = text('&', { font: 'serif', italic: true, size: 900 }).at(-300, 40)
|
|
46
|
+
const leaf = glyph.chars[0]!
|
|
47
|
+
const world = transformPath(leaf.get('path')!, leaf.worldMatrix())
|
|
48
|
+
const outline: Ring = [...world].sort((a, b) => Math.abs(signedArea(b)) - Math.abs(signedArea(a)))[0]!
|
|
49
|
+
const single: Path = [outline]
|
|
50
|
+
const points: Vec[] = Array.from({ length: SAMPLES }, (_, i) => pointAt(single, i / SAMPLES))
|
|
51
|
+
|
|
52
|
+
const all = transform(points)
|
|
53
|
+
const center = all.find((term) => term.n === 0)!
|
|
54
|
+
const ranked = all.filter((term) => term.n !== 0).sort((a, b) => b.size - a.size)
|
|
55
|
+
const terms = ranked.slice(0, MAX_TERMS)
|
|
56
|
+
const totalPower = ranked.reduce((sum, term) => sum + term.size * term.size, 0)
|
|
57
|
+
const cumulative: number[] = [0]
|
|
58
|
+
for (const term of ranked) cumulative.push(cumulative[cumulative.length - 1]! + term.size * term.size)
|
|
59
|
+
const shapeBounds = pathBounds(single)!
|
|
60
|
+
|
|
61
|
+
// Rotation tables, so the whole curve costs additions per frame instead of sines.
|
|
62
|
+
const cosTable = new Float32Array(terms.length * (TRACE + 1))
|
|
63
|
+
const sinTable = new Float32Array(terms.length * (TRACE + 1))
|
|
64
|
+
terms.forEach((term, k) => {
|
|
65
|
+
for (let i = 0; i <= TRACE; i++) {
|
|
66
|
+
const angle = TAU * term.n * i / TRACE
|
|
67
|
+
cosTable[k * (TRACE + 1) + i] = Math.cos(angle)
|
|
68
|
+
sinTable[k * (TRACE + 1) + i] = Math.sin(angle)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
const weightOf = (k: number, count: number) => Math.max(0, Math.min(1, count - k))
|
|
72
|
+
const curvePoint = (index: number, count: number): Vec => {
|
|
73
|
+
let x = center.re, y = center.im
|
|
74
|
+
const limit = Math.min(terms.length, Math.ceil(count))
|
|
75
|
+
for (let k = 0; k < limit; k++) {
|
|
76
|
+
const term = terms[k]!, w = weightOf(k, count)
|
|
77
|
+
const c = cosTable[k * (TRACE + 1) + index]!, sn = sinTable[k * (TRACE + 1) + index]!
|
|
78
|
+
x += w * (term.re * c - term.im * sn)
|
|
79
|
+
y += w * (term.re * sn + term.im * c)
|
|
80
|
+
}
|
|
81
|
+
return [x, y]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const phase = s.value(0)
|
|
85
|
+
const count = s.value(1)
|
|
86
|
+
const reveal = s.value(0)
|
|
87
|
+
const tip = (): Vec => {
|
|
88
|
+
const u = phase.value % 1
|
|
89
|
+
return curvePoint(Math.round(u * TRACE), count.value)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const stroke = linearGradient(
|
|
93
|
+
[shapeBounds.x, shapeBounds.y + shapeBounds.height], [shapeBounds.x + shapeBounds.width, shapeBounds.y],
|
|
94
|
+
['teal', 'blue', 'purple', 'pink', 'yellow'],
|
|
95
|
+
)
|
|
96
|
+
const faintInk: Rgba = parseColor('dim')
|
|
97
|
+
|
|
98
|
+
// Faint ghost of the target, so the viewer can judge how close the sum has come.
|
|
99
|
+
const target = new Node(single).stroke('faint', 1.6).dash([3, 9])
|
|
100
|
+
|
|
101
|
+
// The camera zooms in later. Marks divide by the zoom so lines stay fine at any scale.
|
|
102
|
+
const follow = s.value(0)
|
|
103
|
+
const zoom = s.value(1)
|
|
104
|
+
|
|
105
|
+
const curve = dynamic(() => {
|
|
106
|
+
const n = count.value
|
|
107
|
+
const frac = reveal.value
|
|
108
|
+
if (frac <= 0) return null
|
|
109
|
+
const end = Math.floor(TRACE * Math.min(1, frac))
|
|
110
|
+
const out: Vec[] = []
|
|
111
|
+
for (let i = 0; i <= end; i++) out.push(curvePoint(i, n))
|
|
112
|
+
const z = zoom.value
|
|
113
|
+
return new Node(polyPath(out, frac >= 1)).stroke(stroke, 3.2 / Math.pow(z, 0.8)).glow(7 / Math.pow(z, 0.8), 'blue')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const chain = dynamic(() => {
|
|
117
|
+
const n = count.value
|
|
118
|
+
const u = phase.value % 1
|
|
119
|
+
const z = zoom.value
|
|
120
|
+
const limit = Math.min(terms.length, Math.ceil(n))
|
|
121
|
+
let x = center.re, y = center.im
|
|
122
|
+
const rings: Ring[][] = [[], [], []]
|
|
123
|
+
const shafts: Ring[][] = [[], [], []]
|
|
124
|
+
const heads: Ring[][] = [[], [], []]
|
|
125
|
+
for (let k = 0; k < limit; k++) {
|
|
126
|
+
const term = terms[k]!, w = weightOf(k, n)
|
|
127
|
+
const angle = TAU * term.n * u
|
|
128
|
+
const c = Math.cos(angle), sn = Math.sin(angle)
|
|
129
|
+
const vx = w * (term.re * c - term.im * sn), vy = w * (term.re * sn + term.im * c)
|
|
130
|
+
const bucket = k < 8 ? 0 : k < 40 ? 1 : 2
|
|
131
|
+
const radius = term.size * w
|
|
132
|
+
if (radius > 0.25 / z) rings[bucket]!.push(...circlePath(x, y, radius))
|
|
133
|
+
const nx = x + vx, ny = y + vy
|
|
134
|
+
const length = Math.hypot(vx, vy)
|
|
135
|
+
if (length > 0.5 / z) {
|
|
136
|
+
const tipLength = Math.min(length * 0.34, 16 / z)
|
|
137
|
+
const ux = vx / length, uy = vy / length
|
|
138
|
+
const bx = nx - ux * tipLength, by = ny - uy * tipLength
|
|
139
|
+
shafts[bucket]!.push(...polyPath([[x, y], [bx, by]]))
|
|
140
|
+
const half = tipLength * 0.36
|
|
141
|
+
heads[bucket]!.push(...polyPath([[nx, ny], [bx - uy * half, by + ux * half], [bx + uy * half, by - ux * half]], true))
|
|
142
|
+
}
|
|
143
|
+
x = nx
|
|
144
|
+
y = ny
|
|
145
|
+
}
|
|
146
|
+
const out: Node[] = []
|
|
147
|
+
const circleAlpha = [0.42, 0.26, 0.14], shaftAlpha = [1, 0.8, 0.5], widths = [2.4, 1.6, 1]
|
|
148
|
+
for (let b = 0; b < 3; b++) {
|
|
149
|
+
if (rings[b]!.length) out.push(new Node(rings[b]!).stroke('blue', 1.2 / z, circleAlpha[b]))
|
|
150
|
+
if (shafts[b]!.length) out.push(new Node(shafts[b]!).stroke('ink', widths[b]! / z, shaftAlpha[b]))
|
|
151
|
+
if (heads[b]!.length) out.push(new Node(heads[b]!).fill('ink', shaftAlpha[b]))
|
|
152
|
+
}
|
|
153
|
+
out.push(dot(6.5 / z, 'yellow').at(x, y).glow(10 / z))
|
|
154
|
+
return out
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
// ── Right column ────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
const COLUMN = 470
|
|
160
|
+
// An opaque column keeps the readouts clean while the camera works underneath it.
|
|
161
|
+
const backing = rect(960 - COLUMN + 60, 1080, { fill: 'bg', stroke: null }).at((COLUMN - 60 + 960) / 2 , 0).pin()
|
|
162
|
+
const rule = line([COLUMN - 60, -540], [COLUMN - 60, 540], { stroke: 'grid', width: 1.2 }).pin()
|
|
163
|
+
const title = text('A drawing is a sum of circles.', { font: 'serif', size: 66 }).pin()
|
|
164
|
+
title.alignTo([-864, 0], 'left').alignTo([0, -484], 'top')
|
|
165
|
+
const eqTerm = tex('z(t) = \\sum_{k=1}^{N} c_k \\, e^{2\\pi i n_k t}', { size: 44 }).pin()
|
|
166
|
+
eqTerm.alignTo([COLUMN, 0], 'left').alignTo([0, -466], 'top')
|
|
167
|
+
const eqNote = text('Each term is one arrow: a length, a start angle, and a whole number of turns per trip.', {
|
|
168
|
+
size: 22, color: 'dim', maxWidth: 400, leading: 1.4,
|
|
169
|
+
}).pin()
|
|
170
|
+
eqNote.alignTo([COLUMN, 0], 'left').alignTo([0, -300], 'top')
|
|
171
|
+
|
|
172
|
+
const labelStyle = { size: 19, color: 'dim' as const, uppercase: true, tracking: 0.08, weight: 600 as const }
|
|
173
|
+
const termLabel = text('Arrows in the chain', labelStyle).pin().alignTo([COLUMN, 0], 'left').alignTo([0, -196], 'top')
|
|
174
|
+
const termRead = dynamic(() => text(String(Math.round(count.value)), { font: 'mono', size: 86, color: 'yellow' })
|
|
175
|
+
.alignTo([COLUMN, 0], 'left').alignTo([0, -166], 'top')).pin()
|
|
176
|
+
const energyLabel = text('Energy captured', labelStyle).pin().alignTo([COLUMN, 0], 'left').alignTo([0, -32], 'top')
|
|
177
|
+
const energyRead = dynamic(() => {
|
|
178
|
+
const n = Math.round(count.value)
|
|
179
|
+
const share = (100 * cumulative[Math.min(n, cumulative.length - 1)]!) / totalPower
|
|
180
|
+
return text(`${share.toFixed(2)}%`, { font: 'mono', size: 40, color: 'ink' })
|
|
181
|
+
.alignTo([COLUMN, 0], 'left').alignTo([0, -2], 'top')
|
|
182
|
+
}).pin()
|
|
183
|
+
const errorLabel = text('RMS distance to outline', labelStyle).pin().alignTo([COLUMN, 0], 'left').alignTo([0, 82], 'top')
|
|
184
|
+
const errorRead = dynamic(() => {
|
|
185
|
+
const n = Math.round(count.value)
|
|
186
|
+
const rest = Math.sqrt(Math.max(0, totalPower - cumulative[Math.min(n, cumulative.length - 1)]!))
|
|
187
|
+
return text(`${rest.toFixed(1)} px`, { font: 'mono', size: 40, color: 'ink' })
|
|
188
|
+
.alignTo([COLUMN, 0], 'left').alignTo([0, 112], 'top')
|
|
189
|
+
}).pin()
|
|
190
|
+
|
|
191
|
+
// The spectrum: every frequency in play, lit as its arrow joins the chain.
|
|
192
|
+
const BAR_X = COLUMN, BAR_WIDTH = 394, BAR_BASE = 446, BAR_HEIGHT = 190, RANGE = 48
|
|
193
|
+
const logTop = Math.log10(terms[0]!.size + 1)
|
|
194
|
+
const spectrumPaint = ramp(2, 'faint', 'yellow')
|
|
195
|
+
const spectrumLabel = text('Spectrum, by frequency', labelStyle).pin().alignTo([COLUMN, 0], 'left').alignTo([0, 208], 'top')
|
|
196
|
+
const rankByFrequency = new Map(terms.map((term, k) => [term.n, k]))
|
|
197
|
+
const spectrum = dynamic(() => {
|
|
198
|
+
const n = count.value
|
|
199
|
+
const lit: Ring[] = [], dark: Ring[] = []
|
|
200
|
+
for (let f = -RANGE; f <= RANGE; f++) {
|
|
201
|
+
if (f === 0) continue
|
|
202
|
+
const term = all.find((entry) => entry.n === f)!
|
|
203
|
+
const x = BAR_X + ((f + RANGE) / (2 * RANGE)) * BAR_WIDTH
|
|
204
|
+
const height = (Math.log10(term.size + 1) / logTop) * BAR_HEIGHT
|
|
205
|
+
const rank = rankByFrequency.get(f)
|
|
206
|
+
;(rank !== undefined && rank < n ? lit : dark).push(...polyPath([[x, BAR_BASE], [x, BAR_BASE - Math.max(1, height)]]))
|
|
207
|
+
}
|
|
208
|
+
return [
|
|
209
|
+
new Node(dark).stroke(spectrumPaint[0]!, 2.4),
|
|
210
|
+
new Node(lit).stroke(spectrumPaint[1]!, 2.4),
|
|
211
|
+
line([BAR_X, BAR_BASE + 3], [BAR_X + BAR_WIDTH, BAR_BASE + 3], { stroke: faintInk, width: 1.2 }),
|
|
212
|
+
]
|
|
213
|
+
}).pin()
|
|
214
|
+
const lowLabel = tex(`-${RANGE}`, { size: 20, color: 'dim', display: false }).pin()
|
|
215
|
+
lowLabel.alignTo([BAR_X, 0], 'left').alignTo([0, BAR_BASE + 12], 'top')
|
|
216
|
+
const highLabel = tex(`+${RANGE}`, { size: 20, color: 'dim', display: false }).pin()
|
|
217
|
+
highLabel.alignTo([BAR_X + BAR_WIDTH, 0], 'right').alignTo([0, BAR_BASE + 12], 'top')
|
|
218
|
+
const nLabel = tex('n', { size: 22, color: 'dim', display: false }).pin()
|
|
219
|
+
nLabel.moveTo([BAR_X + BAR_WIDTH / 2, BAR_BASE + 24])
|
|
220
|
+
|
|
221
|
+
// ── Timeline ────────────────────────────────────────────────────────────
|
|
222
|
+
|
|
223
|
+
s.chapter('The target')
|
|
224
|
+
s.add(backing, rule)
|
|
225
|
+
s.play(write(title), draw(target), { duration: 2.2 })
|
|
226
|
+
s.play(write(eqTerm), fadeIn(eqNote, { shift: [0, 10] }), { duration: 1.8 })
|
|
227
|
+
s.wait(0.6)
|
|
228
|
+
s.play(fadeIn([termLabel, termRead, energyLabel, energyRead, errorLabel, errorRead, spectrumLabel, spectrum, lowLabel, highLabel, nLabel]), { duration: 1 })
|
|
229
|
+
|
|
230
|
+
s.chapter('One arrow')
|
|
231
|
+
s.add(curve)
|
|
232
|
+
s.play(fadeIn(chain), { duration: 0.7 })
|
|
233
|
+
backing.zIndex(2)
|
|
234
|
+
rule.zIndex(2)
|
|
235
|
+
for (const pinned of [eqTerm, eqNote, termLabel, termRead, energyLabel, energyRead, errorLabel, errorRead, spectrumLabel, spectrum, lowLabel, highLabel, nLabel]) pinned.zIndex(3)
|
|
236
|
+
title.zIndex(3)
|
|
237
|
+
s.play(reveal.to(1, { ease: linear }), phase.to(1, { ease: linear }), { duration: 4 })
|
|
238
|
+
s.wait(0.4)
|
|
239
|
+
|
|
240
|
+
s.chapter('Add arrows')
|
|
241
|
+
for (const [next, seconds] of [[3, 3.2], [8, 3.2], [24, 3.6]] as const) {
|
|
242
|
+
s.play(count.to(next, { ease: smoother }), phase.to(phase.value + 1, { ease: linear }), { duration: seconds })
|
|
243
|
+
s.wait(0.25)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
s.chapter('Two hundred')
|
|
247
|
+
s.play(count.to(200, { ease: smoother }), phase.to(phase.value + 2, { ease: linear }), { duration: 8 })
|
|
248
|
+
s.play(flash(tip(), { color: 'yellow', radius: 50 }))
|
|
249
|
+
|
|
250
|
+
s.chapter('Up close')
|
|
251
|
+
s.update(s.camera, (camera) => {
|
|
252
|
+
const [tx, ty] = tip()
|
|
253
|
+
const a = follow.value, z = zoom.value
|
|
254
|
+
// Keep the tip left of center, in the open part of the frame.
|
|
255
|
+
camera.at((tx + 240 / z) * a, (ty) * a)
|
|
256
|
+
camera.set('sx', z)
|
|
257
|
+
})
|
|
258
|
+
s.play(fade(title, 0), fade(target, 0), follow.to(1, { ease: smoother }), zoom.to(9, { ease: smoother }), phase.to(phase.value + 0.06, { ease: linear }), { duration: 3 })
|
|
259
|
+
s.play(phase.to(phase.value + 0.14, { ease: linear }), { duration: 6 })
|
|
260
|
+
s.play(fade(title, 1), follow.to(0, { ease: smoother }), zoom.to(1, { ease: smoother }), phase.to(phase.value + 0.08, { ease: linear }), { duration: 3 })
|
|
261
|
+
|
|
262
|
+
s.chapter('The whole curve')
|
|
263
|
+
s.play(phase.to(phase.value + 1, { ease: linear }), { duration: 4.6 })
|
|
264
|
+
s.wait(1.4)
|
|
265
|
+
})
|