vizmatic 0.3.2 → 0.5.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 -525
- package/README.md +87 -578
- package/ROADMAP.md +49 -67
- package/SCIENCE.md +250 -0
- package/assets/THIRD_PARTY_LICENSES.md +40 -1
- package/assets/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/assets/fonts/InstrumentSerif-Regular.ttf +0 -0
- package/assets/licenses/raster-codecs-MIT.txt +74 -0
- package/dist/chunk-3F2VQ7NW.js +1 -0
- package/dist/chunk-4XE64I2U.js +755 -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/chunk-WHT6HRMX.js +4201 -0
- package/dist/cli.js +371 -10
- package/dist/index.cjs +11129 -2922
- package/dist/index.d.cts +1225 -369
- package/dist/index.d.ts +1225 -369
- package/dist/index.js +6220 -3015
- 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.d.ts +1 -0
- package/dist/scene-cli.js +4 -0
- package/dist/scene-runtime.cjs +995 -0
- package/dist/scene-runtime.d.cts +81 -0
- package/dist/scene-runtime.d.ts +81 -0
- package/dist/scene-runtime.js +22 -0
- package/dist/server-2FYHZ4UO.js +331 -0
- package/dist/stage-browser/browser.d.ts +2482 -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 +4950 -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 +9745 -0
- package/dist/stage.d.cts +1678 -0
- package/dist/stage.d.ts +1678 -0
- package/dist/stage.js +5404 -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/pressure-mechanism.scene.json +14 -0
- 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 +62 -0
- 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/request-lifecycle.tsx +99 -0
- package/examples/videos/signal-to-story.tsx +126 -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 +77 -12
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Lorenz system with sigma = 10, rho = 28, beta = 8/3, integrated by fourth
|
|
3
|
+
* order Runge-Kutta at a fixed step. The separation readout and the time when two
|
|
4
|
+
* nearby runs part are measured from the same integration that gets drawn.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
Node, dot, dynamic, fadeIn, fadeOut, film, line, linear, polyPath, ramp, rect, smoother, text, tex, write,
|
|
8
|
+
type Rgba, type Vec,
|
|
9
|
+
} from 'vizmatic/stage'
|
|
10
|
+
|
|
11
|
+
const SIGMA = 10, RHO = 28, BETA = 8 / 3
|
|
12
|
+
const DT = 0.004
|
|
13
|
+
const COLUMN = 480
|
|
14
|
+
const CENTER: Vec = [-232, 8]
|
|
15
|
+
|
|
16
|
+
type State = readonly [number, number, number]
|
|
17
|
+
|
|
18
|
+
function derivative([x, y, z]: State): State {
|
|
19
|
+
return [SIGMA * (y - x), x * (RHO - z) - y, x * y - BETA * z]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function step(state: State, dt: number): State {
|
|
23
|
+
const add = (a: State, b: State, k: number): State => [a[0] + b[0] * k, a[1] + b[1] * k, a[2] + b[2] * k]
|
|
24
|
+
const k1 = derivative(state)
|
|
25
|
+
const k2 = derivative(add(state, k1, dt / 2))
|
|
26
|
+
const k3 = derivative(add(state, k2, dt / 2))
|
|
27
|
+
const k4 = derivative(add(state, k3, dt))
|
|
28
|
+
return [
|
|
29
|
+
state[0] + (dt / 6) * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0]),
|
|
30
|
+
state[1] + (dt / 6) * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1]),
|
|
31
|
+
state[2] + (dt / 6) * (k1[2] + 2 * k2[2] + 2 * k3[2] + k4[2]),
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function integrate(start: State, count: number): Float32Array {
|
|
36
|
+
const out = new Float32Array(count * 3)
|
|
37
|
+
let state = start
|
|
38
|
+
for (let i = 0; i < count; i++) {
|
|
39
|
+
out[i * 3] = state[0]
|
|
40
|
+
out[i * 3 + 1] = state[1]
|
|
41
|
+
out[i * 3 + 2] = state[2]
|
|
42
|
+
state = step(state, DT)
|
|
43
|
+
}
|
|
44
|
+
return out
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default film({
|
|
48
|
+
title: 'The Lorenz attractor',
|
|
49
|
+
description: 'Many deterministic trajectories fill a butterfly, and two nearby starts part ways.',
|
|
50
|
+
fps: 60,
|
|
51
|
+
bloom: 0.2,
|
|
52
|
+
}, (s) => {
|
|
53
|
+
const SPAN = 15000
|
|
54
|
+
// Settle onto the attractor first, so every drawn run starts on it.
|
|
55
|
+
let settled: State = [1, 1, 1]
|
|
56
|
+
for (let i = 0; i < 6000; i++) settled = step(settled, DT)
|
|
57
|
+
|
|
58
|
+
const OFFSET = 1e-5
|
|
59
|
+
const runA = integrate(settled, SPAN)
|
|
60
|
+
const runB = integrate([settled[0] + OFFSET, settled[1], settled[2]], SPAN)
|
|
61
|
+
const separation = new Float32Array(SPAN)
|
|
62
|
+
let partedAt = -1
|
|
63
|
+
for (let i = 0; i < SPAN; i++) {
|
|
64
|
+
separation[i] = Math.hypot(runA[i * 3]! - runB[i * 3]!, runA[i * 3 + 1]! - runB[i * 3 + 1]!, runA[i * 3 + 2]! - runB[i * 3 + 2]!)
|
|
65
|
+
if (partedAt < 0 && separation[i]! > 10) partedAt = i * DT
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const CLOUD = 72
|
|
69
|
+
const cloudColors: readonly Rgba[] = ramp(CLOUD, 'blue', 'teal', 'green', 'yellow', 'orange', 'pink', 'purple')
|
|
70
|
+
const cloud = Array.from({ length: CLOUD }, (_, i) => integrate([settled[0] + (i - CLOUD / 2) * 0.012, settled[1], settled[2]], SPAN))
|
|
71
|
+
|
|
72
|
+
const clock = s.value(0)
|
|
73
|
+
const showSingle = s.value(1)
|
|
74
|
+
const showPair = s.value(0)
|
|
75
|
+
const showCloud = s.value(0)
|
|
76
|
+
const azimuth = s.value(-1.25)
|
|
77
|
+
const tilt = s.value(0.28)
|
|
78
|
+
const zoom = s.value(1)
|
|
79
|
+
|
|
80
|
+
const project = (x: number, y: number, z: number): Vec => {
|
|
81
|
+
const az = azimuth.value, el = tilt.value
|
|
82
|
+
const ca = Math.cos(az), sa = Math.sin(az), ce = Math.cos(el), se = Math.sin(el)
|
|
83
|
+
const X = x * ca - y * sa, Y = x * sa + y * ca
|
|
84
|
+
const Z = z - 25
|
|
85
|
+
const distance = 150
|
|
86
|
+
const depth = Y * ce - Z * se + distance
|
|
87
|
+
const scale = (19 * zoom.value * distance) / depth
|
|
88
|
+
return [CENTER[0] + X * scale, CENTER[1] - (Y * se + Z * ce) * scale]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const tail = (data: Float32Array, from: number, to: number, stride: number): Vec[] => {
|
|
92
|
+
const out: Vec[] = []
|
|
93
|
+
for (let i = Math.max(0, from); i <= to; i += stride) out.push(project(data[i * 3]!, data[i * 3 + 1]!, data[i * 3 + 2]!))
|
|
94
|
+
return out
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A line that fades into its own past, in four stretches. */
|
|
98
|
+
const comet = (data: Float32Array, head: number, length: number, color: string | Rgba, width: number, stride: number, alpha: number): Node[] => {
|
|
99
|
+
const out: Node[] = []
|
|
100
|
+
const stops = [[1, 0.6, 0.1], [0.6, 0.32, 0.26], [0.32, 0.12, 0.55], [0.12, 0, 1]] as const
|
|
101
|
+
for (const [far, near, opacity] of stops) {
|
|
102
|
+
const from = Math.floor(head - length * far), to = Math.floor(head - length * near)
|
|
103
|
+
if (to <= 0 || to <= from) continue
|
|
104
|
+
const points = tail(data, Math.max(0, from), Math.min(head, to), stride)
|
|
105
|
+
if (points.length > 1) out.push(new Node(polyPath(points)).stroke(color, width, opacity * alpha))
|
|
106
|
+
}
|
|
107
|
+
return out
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const scene = dynamic(() => {
|
|
111
|
+
const t = clock.value
|
|
112
|
+
const head = Math.min(SPAN - 1, Math.floor(t / DT))
|
|
113
|
+
const out: Node[] = []
|
|
114
|
+
if (showSingle.value > 0) {
|
|
115
|
+
// The long trail keeps the shape of the butterfly while one point runs through it.
|
|
116
|
+
const points = tail(runA, 0, head, 2)
|
|
117
|
+
if (points.length > 1) out.push(new Node(polyPath(points)).stroke('blue', 1.6, 0.8 * showSingle.value).glow(3, 'blue'))
|
|
118
|
+
out.push(dot(8, 'yellow').at(project(runA[head * 3]!, runA[head * 3 + 1]!, runA[head * 3 + 2]!)).glow(12).opacity(showSingle.value))
|
|
119
|
+
}
|
|
120
|
+
if (showPair.value > 0) {
|
|
121
|
+
const a = showPair.value
|
|
122
|
+
out.push(...comet(runA, head, 1400, 'yellow', 3, 2, a), ...comet(runB, head, 1400, 'pink', 3, 2, a))
|
|
123
|
+
out.push(dot(8, 'yellow').at(project(runA[head * 3]!, runA[head * 3 + 1]!, runA[head * 3 + 2]!)).glow(10).opacity(a))
|
|
124
|
+
out.push(dot(8, 'pink').at(project(runB[head * 3]!, runB[head * 3 + 1]!, runB[head * 3 + 2]!)).glow(10).opacity(a))
|
|
125
|
+
}
|
|
126
|
+
if (showCloud.value > 0) {
|
|
127
|
+
const a = showCloud.value
|
|
128
|
+
cloud.forEach((data, i) => {
|
|
129
|
+
out.push(...comet(data, head, 420, cloudColors[i]!, 2, 4, a))
|
|
130
|
+
out.push(dot(4.5, cloudColors[i]!).at(project(data[head * 3]!, data[head * 3 + 1]!, data[head * 3 + 2]!)).opacity(a))
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
return out
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// ── Column ──────────────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
const rule = line([COLUMN - 70, -540], [COLUMN - 70, 540], { stroke: 'grid', width: 1.2 }).zIndex(6)
|
|
139
|
+
const place = <T extends Node>(node: T, top: number): T => {
|
|
140
|
+
node.alignTo([COLUMN, 0], 'left').alignTo([0, top], 'top')
|
|
141
|
+
node.zIndex(6)
|
|
142
|
+
return node
|
|
143
|
+
}
|
|
144
|
+
const label = (content: string, top: number) => place(text(content, { size: 19, color: 'dim', uppercase: true, tracking: 0.08, weight: 600 }), top)
|
|
145
|
+
const column = rect(960 - COLUMN + 70, 1080, { fill: 'bg', stroke: null }).at((COLUMN - 70 + 960) / 2, 0).zIndex(5)
|
|
146
|
+
|
|
147
|
+
const title = place(text('The rules are exact. The future is not.', { font: 'serif', size: 58, maxWidth: 410, leading: 1.08 }), -490)
|
|
148
|
+
const equations = place(tex('\\begin{aligned} \\dot{x} &= \\sigma (y - x) \\\\ \\dot{y} &= x (\\rho - z) - y \\\\ \\dot{z} &= x y - \\beta z \\end{aligned}', { size: 36 }), -348)
|
|
149
|
+
const constants = place(tex('\\sigma = 10, \\quad \\rho = 28, \\quad \\beta = 8/3', { size: 26, color: 'dim' }), -196)
|
|
150
|
+
const timeLabel = label('Model time', -128)
|
|
151
|
+
const timeRead = dynamic(() => place(text(`${clock.value.toFixed(2).padStart(5, ' ')} s`, { font: 'mono', size: 44, color: 'ink' }), -102)).zIndex(6)
|
|
152
|
+
|
|
153
|
+
const gapLabel = label('Distance between the two runs', -20)
|
|
154
|
+
const gapRead = dynamic(() => {
|
|
155
|
+
const head = Math.min(SPAN - 1, Math.floor(clock.value / DT))
|
|
156
|
+
const value = separation[head]!
|
|
157
|
+
const body = value < 0.01 ? value.toExponential(2).replace('e-', ' e-') : value.toFixed(2)
|
|
158
|
+
return place(text(body, { font: 'mono', size: 44, color: 'pink' }), 6)
|
|
159
|
+
}).zIndex(6)
|
|
160
|
+
// Log-scale separation over time. The straight rise is exponential growth.
|
|
161
|
+
const CX = COLUMN + 56, CW = 330, CT = 86, CH = 210
|
|
162
|
+
const logMin = -6, logMax = 2
|
|
163
|
+
const chartY = (value: number) => CT + CH - ((Math.log10(Math.max(1e-6, value)) - logMin) / (logMax - logMin)) * CH
|
|
164
|
+
const chartAxes = new Node().add(
|
|
165
|
+
line([CX, CT], [CX, CT + CH], { stroke: 'faint', width: 1.3 }),
|
|
166
|
+
line([CX, CT + CH], [CX + CW, CT + CH], { stroke: 'faint', width: 1.3 }),
|
|
167
|
+
...[-5, -3, -1, 1].map((power) => line([CX - 5, chartY(10 ** power)], [CX + 5, chartY(10 ** power)], { stroke: 'faint', width: 1.3 })),
|
|
168
|
+
).zIndex(6)
|
|
169
|
+
const chartTicks = new Node().add(...[-5, -3, -1, 1].map((power) => {
|
|
170
|
+
const tag = tex(`10^{${power}}`, { size: 20, color: 'dim', display: false })
|
|
171
|
+
tag.alignTo([CX - 12, 0], 'right')
|
|
172
|
+
const b = tag.bounds()
|
|
173
|
+
tag.shift(0, chartY(10 ** power) - (b.y + b.height / 2))
|
|
174
|
+
return tag
|
|
175
|
+
})).zIndex(6)
|
|
176
|
+
const chart = dynamic(() => {
|
|
177
|
+
const head = Math.min(SPAN - 1, Math.floor(clock.value / DT))
|
|
178
|
+
const points: Vec[] = []
|
|
179
|
+
const span = 32
|
|
180
|
+
for (let i = 0; i <= head; i += 12) points.push([CX + ((i * DT) / span) * CW, chartY(separation[i]!)])
|
|
181
|
+
return points.length > 1 ? new Node(polyPath(points)).stroke('pink', 2.6) : null
|
|
182
|
+
}).zIndex(6)
|
|
183
|
+
const axisNote = place(text('Distance, log scale, against model time', { size: 19, color: 'dim' }), CT + CH + 10)
|
|
184
|
+
const partedNote = place(text(`Starting ${OFFSET} apart, they are 10 units apart by ${partedAt.toFixed(1)} s.`, { size: 24, color: 'ink', maxWidth: 400, leading: 1.38 }), 340)
|
|
185
|
+
const cloudNote = place(text(`${CLOUD} starts packed into a line ${(0.012 * (CLOUD - 1)).toFixed(2)} long. Soon they cover the whole shape.`, { size: 24, color: 'ink', maxWidth: 400, leading: 1.38 }), 340)
|
|
186
|
+
|
|
187
|
+
// ── Timeline ────────────────────────────────────────────────────────────
|
|
188
|
+
|
|
189
|
+
s.add(scene)
|
|
190
|
+
s.add(column, rule)
|
|
191
|
+
s.chapter('One path')
|
|
192
|
+
s.play(write(title), write(equations), fadeIn(constants), fadeIn([timeLabel, timeRead]), clock.to(3.2, { ease: linear }), azimuth.to(-1.05, { ease: linear }), { duration: 4 })
|
|
193
|
+
s.play(clock.to(11, { ease: linear }), azimuth.to(-0.6, { ease: linear }), { duration: 7 })
|
|
194
|
+
s.wait(0.2)
|
|
195
|
+
|
|
196
|
+
s.chapter('Two paths')
|
|
197
|
+
s.play(showSingle.to(0.22), showPair.to(1), fadeIn([gapLabel, gapRead, chartAxes, chartTicks, chart, axisNote]), azimuth.to(-0.58, { ease: linear }), clock.to(0, { ease: smoother }), { duration: 2.2 })
|
|
198
|
+
s.play(clock.to(Math.min(partedAt + 3.5, SPAN * DT - 1), { ease: linear }), azimuth.to(-1.05, { ease: linear }), { duration: 11 })
|
|
199
|
+
s.play(fadeIn(partedNote, { shift: [0, 8] }), { duration: 0.9 })
|
|
200
|
+
s.wait(0.6)
|
|
201
|
+
|
|
202
|
+
s.chapter('A crowd')
|
|
203
|
+
s.play(showPair.to(0), showSingle.to(0.08), showCloud.to(1), clock.to(0, { ease: smoother }), fadeOut(partedNote), azimuth.to(-1.1, { ease: linear }), { duration: 1.8 })
|
|
204
|
+
s.play(fadeIn(cloudNote, { shift: [0, 8] }), { duration: 0.8 })
|
|
205
|
+
s.play(clock.to(32, { ease: linear }), azimuth.to(-0.35, { ease: linear }), { duration: 14 })
|
|
206
|
+
s.wait(1.5)
|
|
207
|
+
})
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A proof by rearrangement. The same four triangles sit inside the same square
|
|
3
|
+
* twice, and only slide between the two pictures. Whatever they leave uncovered
|
|
4
|
+
* must have the same area both times, so c^2 = a^2 + b^2. Legs are 3 and 4 units.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
Node, draw, fade, fadeIn, fadeOut, film, morph, polygon, polyPath, rect, shape, smoother, text, tex, to, write,
|
|
8
|
+
type Vec,
|
|
9
|
+
} from 'vizmatic/stage'
|
|
10
|
+
|
|
11
|
+
const A = 3, B = 4
|
|
12
|
+
const SIDE = A + B
|
|
13
|
+
const UNIT = 74
|
|
14
|
+
const HALF = (SIDE * UNIT) / 2
|
|
15
|
+
const LEFT_X = -470, RIGHT_X = 470, CY = 40
|
|
16
|
+
|
|
17
|
+
/** Grid coordinates inside a square, to stage coordinates. */
|
|
18
|
+
const at = (cx: number, x: number, y: number): Vec => [cx - HALF + x * UNIT, CY - HALF + y * UNIT]
|
|
19
|
+
|
|
20
|
+
export default film({
|
|
21
|
+
title: 'Pythagoras by rearrangement',
|
|
22
|
+
description: 'Four triangles slide inside a square, and the leftover area shows why a squared plus b squared equals c squared.',
|
|
23
|
+
fps: 60,
|
|
24
|
+
}, (s) => {
|
|
25
|
+
// A single right triangle, introduced at the center.
|
|
26
|
+
const triangle: Vec[] = [[0, 0], [A, 0], [0, B]]
|
|
27
|
+
const fills = ['blue', 'teal', 'purple', 'pink']
|
|
28
|
+
|
|
29
|
+
const makeTriangle = (color: string, opacity: number) => {
|
|
30
|
+
const shapeNode = polygon(triangle.map(([x, y]) => [x * UNIT, y * UNIT] as Vec), { fill: color, stroke: color, width: 2.5 })
|
|
31
|
+
shapeNode.set('fillOpacity', opacity)
|
|
32
|
+
return shapeNode
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const hero = makeTriangle('blue', 0.5)
|
|
36
|
+
hero.moveTo([0, 40])
|
|
37
|
+
const heroBounds = hero.bounds()
|
|
38
|
+
const heroAt = (x: number, y: number): Vec => [heroBounds.x + x * UNIT, heroBounds.y + y * UNIT]
|
|
39
|
+
const labelA = tex('a', { size: 44, color: 'yellow', display: false }).moveTo([heroAt(A / 2, 0)[0], heroAt(0, 0)[1] - 30])
|
|
40
|
+
const labelB = tex('b', { size: 44, color: 'teal', display: false }).moveTo([heroAt(0, 0)[0] - 30, heroAt(0, B / 2)[1]])
|
|
41
|
+
const labelC = tex('c', { size: 44, color: 'pink', display: false }).moveTo([heroAt(A / 2, B / 2)[0] + 28, heroAt(A / 2, B / 2)[1] + 22])
|
|
42
|
+
const corner = shape(polyPath([heroAt(0.3, 0), heroAt(0.3, 0.3), heroAt(0, 0.3)]), { stroke: 'ink', width: 2 })
|
|
43
|
+
|
|
44
|
+
const title = text('Move the pieces. Keep the square.', { font: 'serif', size: 66 })
|
|
45
|
+
title.moveTo([0, -462])
|
|
46
|
+
|
|
47
|
+
// Each triangle is rigid: placed by its own origin and rotation, moved only by translation.
|
|
48
|
+
// Corners below are the four positions inside the first big square.
|
|
49
|
+
const placements: { right: Vec; rotation: number; slide: Vec; color: string }[] = [
|
|
50
|
+
{ right: [0, 0], rotation: 0, slide: [B, 0], color: fills[0]! },
|
|
51
|
+
{ right: [SIDE, 0], rotation: Math.PI / 2, slide: [-A, B], color: fills[1]! },
|
|
52
|
+
{ right: [SIDE, SIDE], rotation: Math.PI, slide: [0, -A], color: fills[2]! },
|
|
53
|
+
{ right: [0, SIDE], rotation: (3 * Math.PI) / 2, slide: [0, 0], color: fills[3]! },
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
const triangleAt = (cx: number, placement: (typeof placements)[number]) => {
|
|
57
|
+
const node = makeTriangle(placement.color, 0.5)
|
|
58
|
+
node.set('rotation', placement.rotation)
|
|
59
|
+
node.set('px', 0)
|
|
60
|
+
node.set('py', 0)
|
|
61
|
+
node.at(at(cx, placement.right[0], placement.right[1]))
|
|
62
|
+
return node
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The second picture starts as a copy of the first.
|
|
66
|
+
const frameRight = rect(SIDE * UNIT, SIDE * UNIT, { stroke: 'ink', width: 3 }).at(RIGHT_X, CY)
|
|
67
|
+
const rightTriangles = placements.map((placement) => triangleAt(RIGHT_X, placement))
|
|
68
|
+
|
|
69
|
+
const sideMark = (cx: number, from: Vec, to: Vec, label: string, color: string, offset: Vec): Node => {
|
|
70
|
+
const a = at(cx, from[0], from[1]), b = at(cx, to[0], to[1])
|
|
71
|
+
const mid: Vec = [(a[0] + b[0]) / 2 + offset[0], (a[1] + b[1]) / 2 + offset[1]]
|
|
72
|
+
return tex(label, { size: 34, color, display: false }).moveTo(mid)
|
|
73
|
+
}
|
|
74
|
+
const edgeLabels = new Node().add(
|
|
75
|
+
sideMark(LEFT_X, [0, 0], [A, 0], 'a', 'yellow', [0, -30]),
|
|
76
|
+
sideMark(LEFT_X, [A, 0], [SIDE, 0], 'b', 'teal', [0, -30]),
|
|
77
|
+
sideMark(LEFT_X, [0, 0], [0, B], 'b', 'teal', [-28, 0]),
|
|
78
|
+
sideMark(LEFT_X, [0, B], [0, SIDE], 'a', 'yellow', [-28, 0]),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
// Squares the moved triangles reveal.
|
|
82
|
+
const squareB = polygon([at(RIGHT_X, 0, 0), at(RIGHT_X, B, 0), at(RIGHT_X, B, B), at(RIGHT_X, 0, B)], { fill: 'teal', stroke: 'teal', width: 2.5 })
|
|
83
|
+
squareB.set('fillOpacity', 0.3)
|
|
84
|
+
const squareA = polygon([at(RIGHT_X, B, B), at(RIGHT_X, SIDE, B), at(RIGHT_X, SIDE, SIDE), at(RIGHT_X, B, SIDE)], { fill: 'orange', stroke: 'orange', width: 2.5 })
|
|
85
|
+
squareA.set('fillOpacity', 0.3)
|
|
86
|
+
const bSquared = tex('b^2', { size: 64, color: 'teal' }).moveTo(at(RIGHT_X, B / 2, B / 2))
|
|
87
|
+
const aSquared = tex('a^2', { size: 52, color: 'orange' }).moveTo(at(RIGHT_X, B + A / 2, B + A / 2))
|
|
88
|
+
|
|
89
|
+
const sameLeft = text('Same square', { font: 'serif', italic: true, size: 38, color: 'dim' }).moveTo([0, CY - 28])
|
|
90
|
+
const sameRight = text('Same four triangles', { font: 'serif', italic: true, size: 38, color: 'dim' }).moveTo([0, CY + 28])
|
|
91
|
+
|
|
92
|
+
const equation = tex('c^2 = a^2 + b^2', { size: 96 }).moveTo([0, 448])
|
|
93
|
+
for (const glyph of equation.part('c^2')) glyph.fill('yellow')
|
|
94
|
+
for (const glyph of equation.part('a^2')) glyph.fill('orange')
|
|
95
|
+
for (const glyph of equation.part('b^2')) glyph.fill('teal')
|
|
96
|
+
|
|
97
|
+
// A unit-grid check for the 3-4-5 case.
|
|
98
|
+
const check = tex('25 = 9 + 16', { size: 64, color: 'dim' })
|
|
99
|
+
const tilesA = new Node(), tilesB = new Node()
|
|
100
|
+
for (let x = 0; x < A; x++) for (let y = 0; y < A; y++) tilesA.add(rect(UNIT - 5, UNIT - 5, { stroke: 'orange', width: 1.5 }).at(at(RIGHT_X, B + x + 0.5, B + y + 0.5)))
|
|
101
|
+
for (let x = 0; x < B; x++) for (let y = 0; y < B; y++) tilesB.add(rect(UNIT - 5, UNIT - 5, { stroke: 'teal', width: 1.5 }).at(at(RIGHT_X, x + 0.5, y + 0.5)))
|
|
102
|
+
|
|
103
|
+
// ── Timeline ────────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
s.chapter('A right triangle')
|
|
106
|
+
s.play(write(title), draw(hero), { duration: 1.8 })
|
|
107
|
+
s.play(draw(corner), write(labelA), write(labelB), write(labelC), { duration: 1.2 })
|
|
108
|
+
s.wait(0.8)
|
|
109
|
+
|
|
110
|
+
s.chapter('Four copies')
|
|
111
|
+
s.play(fadeOut([labelA, labelB, labelC, corner]), to(hero, (node) => {
|
|
112
|
+
node.set('px', 0)
|
|
113
|
+
node.set('py', 0)
|
|
114
|
+
node.at(at(0, 0, 0))
|
|
115
|
+
}), { duration: 0.9 })
|
|
116
|
+
const center = placements.map((placement) => triangleAt(0, placement))
|
|
117
|
+
const frameCenter = rect(SIDE * UNIT, SIDE * UNIT, { stroke: 'ink', width: 3 }).at(0, CY)
|
|
118
|
+
s.add(center[0]!)
|
|
119
|
+
s.remove(hero)
|
|
120
|
+
for (let i = 1; i < 4; i++) {
|
|
121
|
+
const placement = placements[i]!
|
|
122
|
+
const copy = center[i]!
|
|
123
|
+
const finalRotation = placement.rotation
|
|
124
|
+
copy.set('rotation', finalRotation - Math.PI / 2)
|
|
125
|
+
copy.at(at(0, placement.right[0] * 0.5 - 0.2, placement.right[1] * 0.5 - 0.2))
|
|
126
|
+
s.add(copy)
|
|
127
|
+
copy.opacity(0)
|
|
128
|
+
s.play(to(copy, (node) => {
|
|
129
|
+
node.opacity(1)
|
|
130
|
+
node.set('rotation', finalRotation)
|
|
131
|
+
node.at(at(0, placement.right[0], placement.right[1]))
|
|
132
|
+
}, { ease: smoother }), { duration: 0.9 })
|
|
133
|
+
}
|
|
134
|
+
s.play(draw(frameCenter), { duration: 0.8 })
|
|
135
|
+
s.wait(0.5)
|
|
136
|
+
|
|
137
|
+
s.chapter('The tilted square')
|
|
138
|
+
const centerTilt = polygon([at(0, A, 0), at(0, SIDE, A), at(0, B, SIDE), at(0, 0, B)], { fill: 'yellow', stroke: 'yellow', width: 2.5 })
|
|
139
|
+
centerTilt.set('fillOpacity', 0.34)
|
|
140
|
+
const centerCSquared = tex('c^2', { size: 72, color: 'yellow' }).moveTo([0, CY])
|
|
141
|
+
s.play(fadeIn(centerTilt), write(centerCSquared), { duration: 1.2 })
|
|
142
|
+
s.wait(0.6)
|
|
143
|
+
|
|
144
|
+
s.chapter('Two pictures')
|
|
145
|
+
// Split into a left copy that stays and a right copy that will move.
|
|
146
|
+
const everything = [frameCenter, centerTilt, centerCSquared, ...center]
|
|
147
|
+
s.play(
|
|
148
|
+
...everything.map((node) => to(node, (n) => n.shift(LEFT_X, 0))),
|
|
149
|
+
fadeIn([frameRight, ...rightTriangles], { shift: [-200, 0] }),
|
|
150
|
+
{ duration: 1.5, ease: smoother },
|
|
151
|
+
)
|
|
152
|
+
s.add(edgeLabels)
|
|
153
|
+
s.play(fadeIn(edgeLabels), fadeIn([sameLeft, sameRight]), { duration: 0.8 })
|
|
154
|
+
s.wait(0.8)
|
|
155
|
+
|
|
156
|
+
s.chapter('Slide')
|
|
157
|
+
for (let i = 0; i < 3; i++) {
|
|
158
|
+
const placement = placements[i]!
|
|
159
|
+
const node = rightTriangles[i]!
|
|
160
|
+
s.play(to(node, (n) => n.shift(placement.slide[0] * UNIT, placement.slide[1] * UNIT), { ease: smoother }), { duration: 1.25 })
|
|
161
|
+
s.wait(0.2)
|
|
162
|
+
}
|
|
163
|
+
s.add(squareB, squareA)
|
|
164
|
+
squareB.zIndex(-1)
|
|
165
|
+
squareA.zIndex(-1)
|
|
166
|
+
s.play(fadeIn([squareB, squareA]), write(bSquared), write(aSquared), { duration: 1.1 })
|
|
167
|
+
s.wait(0.8)
|
|
168
|
+
|
|
169
|
+
s.chapter('The theorem')
|
|
170
|
+
// Copies of each square's label fly into the equation, so its terms come from the pictures.
|
|
171
|
+
s.add(equation)
|
|
172
|
+
for (const glyph of equation.glyphs) glyph.hide()
|
|
173
|
+
s.play(
|
|
174
|
+
morph(centerCSquared.clone(), equation.part('c^2')),
|
|
175
|
+
morph(aSquared.clone(), equation.part('a^2')),
|
|
176
|
+
morph(bSquared.clone(), equation.part('b^2')),
|
|
177
|
+
fade(sameLeft, 0), fade(sameRight, 0),
|
|
178
|
+
{ duration: 1.6, ease: smoother },
|
|
179
|
+
)
|
|
180
|
+
s.play(fadeIn([...equation.part('='), ...equation.part('+')]), { duration: 0.6 })
|
|
181
|
+
s.wait(1)
|
|
182
|
+
check.moveTo([430, 448])
|
|
183
|
+
s.play(to(equation, (eq) => eq.shift(-300, 0)), fadeIn([tilesA, tilesB], { lag: 0.02 }), fadeIn(check, { shift: [-30, 0] }), fade(aSquared, 0), fade(bSquared, 0), { duration: 1.4 })
|
|
184
|
+
s.wait(3)
|
|
185
|
+
})
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polynomials that know only the derivatives of sine at zero. Each new term bends
|
|
3
|
+
* the curve to agree further out. The trust interval is measured numerically: the
|
|
4
|
+
* widest |x| where the partial sum stays within 0.01 of sin x.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
Node, axes, curveThrough, draw, dynamic, fadeIn, film, line, morphMatching, parametricPath, rect, smoother, text, tex, write,
|
|
8
|
+
type Vec,
|
|
9
|
+
} from 'vizmatic/stage'
|
|
10
|
+
|
|
11
|
+
const LIMIT = 15
|
|
12
|
+
const WIDTH = 1880, HEIGHT = 1080
|
|
13
|
+
const X_RANGE: Vec = [-12, 12]
|
|
14
|
+
const Y_RANGE: Vec = [-HEIGHT / 2 / 150, HEIGHT / 2 / 150]
|
|
15
|
+
|
|
16
|
+
function partial(x: number, order: number): number {
|
|
17
|
+
let term = x, sum = x
|
|
18
|
+
for (let n = 3; n <= order; n += 2) {
|
|
19
|
+
term *= -(x * x) / (n * (n - 1))
|
|
20
|
+
sum += term
|
|
21
|
+
}
|
|
22
|
+
return sum
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Widest |x| where the order-n partial sum stays within 0.01 of sin x. */
|
|
26
|
+
function trustRadius(order: number): number {
|
|
27
|
+
let x = 0
|
|
28
|
+
while (x < 12 && Math.abs(partial(x, order) - Math.sin(x)) < 0.01) x += 0.002
|
|
29
|
+
return x
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default film({
|
|
33
|
+
title: 'Taylor series of sine',
|
|
34
|
+
description: 'Partial sums hug the sine curve further and further out as each term morphs into the formula.',
|
|
35
|
+
fps: 60,
|
|
36
|
+
bleed: true,
|
|
37
|
+
}, (s) => {
|
|
38
|
+
const plot = axes({ x: X_RANGE, y: Y_RANGE, width: WIDTH, height: HEIGHT, xStep: 2, yStep: 1, labels: false, tips: false, color: 'faint' }).at(0, 96)
|
|
39
|
+
const view = plot.world.bind(plot)
|
|
40
|
+
|
|
41
|
+
const sine = new Node(parametricPath((t) => plot.p(t, Math.sin(t)), X_RANGE[0], X_RANGE[1], 500)).stroke('blue', 5).glow(9, 'blue')
|
|
42
|
+
// Terms grow in smoothly, so every in-between curve is itself a polynomial.
|
|
43
|
+
const orders = [1, 3, 5, 7, 9, 11, 13, LIMIT]
|
|
44
|
+
const level = s.value(0)
|
|
45
|
+
const evaluate = (x: number): number => {
|
|
46
|
+
const k = level.value
|
|
47
|
+
let term = x, sum = x
|
|
48
|
+
for (let i = 1; i < orders.length; i++) {
|
|
49
|
+
const n = orders[i]!
|
|
50
|
+
term *= -(x * x) / (n * (n - 1))
|
|
51
|
+
const weight = Math.max(0, Math.min(1, k - i + 1))
|
|
52
|
+
if (weight <= 0) break
|
|
53
|
+
sum += weight * term
|
|
54
|
+
}
|
|
55
|
+
return sum
|
|
56
|
+
}
|
|
57
|
+
const approx = dynamic(() => {
|
|
58
|
+
const points: Vec[] = []
|
|
59
|
+
for (let i = 0; i <= 720; i++) {
|
|
60
|
+
const x = X_RANGE[0] + ((X_RANGE[1] - X_RANGE[0]) * i) / 720
|
|
61
|
+
const y = evaluate(x)
|
|
62
|
+
points.push(Math.abs(y) < 5.5 ? plot.p(x, y) : [NaN, NaN])
|
|
63
|
+
}
|
|
64
|
+
return new Node(curveThrough(points)).stroke('yellow', 4).glow(7, 'yellow')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const xTicks = new Node(), yTicks = new Node()
|
|
68
|
+
// Curves sweep across the whole plot, so each number sits on its own opaque chip above them.
|
|
69
|
+
const tick = (value: number, at: Vec): Node => {
|
|
70
|
+
const label = tex(String(value), { size: 21, color: 'dim', display: false }).moveTo(at)
|
|
71
|
+
const b = label.bounds()
|
|
72
|
+
const back = rect(b.width + 10, b.height + 8, { fill: 'bg', stroke: null, radius: 3 }).at(b.x + b.width / 2, b.y + b.height / 2)
|
|
73
|
+
return new Node().add(back, label)
|
|
74
|
+
}
|
|
75
|
+
for (const x of [-10, -8, -6, -4, -2, 2, 4, 6, 8, 10]) xTicks.add(tick(x, [view(x, 0)[0], view(x, 0)[1] + 26]))
|
|
76
|
+
for (const y of [-2, 2]) yTicks.add(tick(y, [view(0, y)[0] - 24, view(0, y)[1]]))
|
|
77
|
+
xTicks.zIndex(3)
|
|
78
|
+
yTicks.zIndex(3)
|
|
79
|
+
|
|
80
|
+
// The range where the sum can be trusted, marked on the x axis.
|
|
81
|
+
const trust = s.value(trustRadius(1))
|
|
82
|
+
const band = dynamic(() => {
|
|
83
|
+
const r = trust.value
|
|
84
|
+
const [x0, y0] = view(-r, 0), [x1] = view(r, 0)
|
|
85
|
+
return [
|
|
86
|
+
line([x0, y0], [x1, y0], { stroke: 'yellow', width: 7 }),
|
|
87
|
+
line([x0, y0 - 11], [x0, y0 + 11], { stroke: 'yellow', width: 3 }),
|
|
88
|
+
line([x1, y0 - 11], [x1, y0 + 11], { stroke: 'yellow', width: 3 }),
|
|
89
|
+
]
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const source = (order: number): string => {
|
|
93
|
+
const parts = ['x']
|
|
94
|
+
for (let n = 3; n <= order; n += 2) parts.push(`${(n - 1) % 4 === 2 ? '-' : '+'} \\frac{x^{${n}}}{${n}!}`)
|
|
95
|
+
return parts.join(' ')
|
|
96
|
+
}
|
|
97
|
+
const BAND_Y = -402
|
|
98
|
+
const plate = rect(1920, 208, { fill: 'bg', stroke: null }).at(0, -436).zIndex(4)
|
|
99
|
+
const plateEdge = line([-960, -332], [960, -332], { stroke: 'grid', width: 1.2 }).zIndex(4)
|
|
100
|
+
const title = text('Sine, from what it does at zero.', { font: 'serif', size: 60 }).zIndex(5)
|
|
101
|
+
title.alignTo([-888, 0], 'left').alignTo([0, -522], 'top')
|
|
102
|
+
const eqAt = (order: number) => {
|
|
103
|
+
const eq = tex(source(order), { size: 42 })
|
|
104
|
+
eq.alignTo([-888, 0], 'left')
|
|
105
|
+
const b = eq.bounds()
|
|
106
|
+
eq.shift(0, BAND_Y - (b.y + b.height / 2))
|
|
107
|
+
eq.zIndex(5)
|
|
108
|
+
return eq
|
|
109
|
+
}
|
|
110
|
+
const lhs = new Map(orders.map((order) => [order, eqAt(order)]))
|
|
111
|
+
|
|
112
|
+
const readLabel = text('Within 0.01 of sine for', { size: 19, color: 'dim', uppercase: true, tracking: 0.08, weight: 600 }).zIndex(5)
|
|
113
|
+
readLabel.alignTo([880, 0], 'right').alignTo([0, -504], 'top')
|
|
114
|
+
const readValue = dynamic(() => {
|
|
115
|
+
const node = text(`|x| < ${trust.value.toFixed(2)}`, { font: 'mono', size: 46, color: 'yellow' })
|
|
116
|
+
node.alignTo([880, 0], 'right').alignTo([0, -474], 'top')
|
|
117
|
+
return node
|
|
118
|
+
}).zIndex(5)
|
|
119
|
+
const orderValue = dynamic(() => {
|
|
120
|
+
const node = text(`degree ${orders[Math.round(level.value)]}`, { font: 'mono', size: 26, color: 'dim' })
|
|
121
|
+
node.alignTo([880, 0], 'right').alignTo([0, -416], 'top')
|
|
122
|
+
return node
|
|
123
|
+
}).zIndex(5)
|
|
124
|
+
|
|
125
|
+
const closing = text('The polynomial only ever looked at one point. It learned the whole wave.', { font: 'serif', italic: true, size: 44, color: 'ink' }).zIndex(5)
|
|
126
|
+
closing.moveTo([0, 470])
|
|
127
|
+
const closingPlate = rect(1340, 84, { fill: 'bg', stroke: null, radius: 6 }).at(0, 470).zIndex(4)
|
|
128
|
+
|
|
129
|
+
s.add(plot)
|
|
130
|
+
plot.grid.hide()
|
|
131
|
+
s.add(plate, plateEdge)
|
|
132
|
+
s.chapter('The target')
|
|
133
|
+
s.play(write(title), draw(plot.lines), fadeIn(xTicks), fadeIn(yTicks), { duration: 1.6 })
|
|
134
|
+
plot.add(sine)
|
|
135
|
+
s.play(draw(sine), { duration: 1.8 })
|
|
136
|
+
s.wait(0.4)
|
|
137
|
+
|
|
138
|
+
s.chapter('Degree one')
|
|
139
|
+
plot.add(approx)
|
|
140
|
+
s.play(fadeIn(approx), write(lhs.get(1)!), fadeIn(band), fadeIn([readLabel, readValue, orderValue]), { duration: 1.5 })
|
|
141
|
+
s.wait(0.9)
|
|
142
|
+
|
|
143
|
+
s.chapter('Add terms')
|
|
144
|
+
for (let i = 1; i < orders.length; i++) {
|
|
145
|
+
const order = orders[i]!
|
|
146
|
+
const seconds = i < 4 ? 1.7 : 1.3
|
|
147
|
+
s.play(
|
|
148
|
+
morphMatching(lhs.get(orders[i - 1]!)!, lhs.get(order)!),
|
|
149
|
+
level.to(i, { ease: smoother }),
|
|
150
|
+
trust.to(trustRadius(order), { ease: smoother }),
|
|
151
|
+
{ duration: seconds },
|
|
152
|
+
)
|
|
153
|
+
s.wait(i < 4 ? 0.7 : 0.35)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
s.chapter('The whole wave')
|
|
157
|
+
s.play(fadeIn(closingPlate), fadeIn(closing, { shift: [0, 12] }), { duration: 1.2 })
|
|
158
|
+
s.wait(3.2)
|
|
159
|
+
})
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The website hero: a seamless ten-second loop. Lit curves flow across the
|
|
3
|
+
* frame, gather into the wordmark, part around it, and let go again. Every
|
|
4
|
+
* phase runs a whole number of cycles per loop, so the last frame meets the first.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
Node, dynamic, film, linearGradient, parseColor, pointAt, polyPath, smooth, smoothPath, text, transformPath,
|
|
8
|
+
type Path, type Vec,
|
|
9
|
+
} from 'vizmatic/stage'
|
|
10
|
+
|
|
11
|
+
const LOOP = 10
|
|
12
|
+
const TAU = Math.PI * 2
|
|
13
|
+
const SAMPLES = 180
|
|
14
|
+
const EDGE = 1120
|
|
15
|
+
|
|
16
|
+
const clamp01 = (x: number) => Math.max(0, Math.min(1, x))
|
|
17
|
+
|
|
18
|
+
/** The shared gesture: one travelling swell, with a slower swell inside it. */
|
|
19
|
+
function wave(x: number, seed: number, t: number, amount: number): number {
|
|
20
|
+
const a = Math.sin(x * 0.0042 + seed * 1.7 + (TAU * t) / LOOP)
|
|
21
|
+
const b = Math.sin(x * 0.0091 - seed * 0.9 - (TAU * 2 * t) / LOOP)
|
|
22
|
+
const c = Math.sin(x * 0.0023 + seed * 0.4 + (TAU * t) / LOOP)
|
|
23
|
+
return amount * (a * 62 + b * 26 + c * 88)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 1 while the word stands, 0 while the curves run free. Staggered across the word. */
|
|
27
|
+
function gathered(t: number, stagger: number): number {
|
|
28
|
+
const shift = stagger * 0.55
|
|
29
|
+
const release = clamp01((t - 2.1 - shift) / 2.1)
|
|
30
|
+
const gather = clamp01((t - 5.9 - shift) / 2.6)
|
|
31
|
+
return 1 - smooth(release) + smooth(gather)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default film({
|
|
35
|
+
title: 'Vizmatic',
|
|
36
|
+
description: 'Curves gather into a wordmark and let go again, as a seamless loop.',
|
|
37
|
+
fps: 60,
|
|
38
|
+
bloom: 0.24,
|
|
39
|
+
}, (s) => {
|
|
40
|
+
const mark = text('vizmatic', { font: 'serif', size: 360 }).at(0, -6)
|
|
41
|
+
const bounds = mark.bounds()
|
|
42
|
+
const glyphs = mark.chars.map((leaf) => transformPath(leaf.get('path')!, leaf.worldMatrix()))
|
|
43
|
+
const left = bounds.x, width = bounds.width
|
|
44
|
+
const pigment = linearGradient([-EDGE, 0], [EDGE, 0], ['blue', 'teal', 'yellow', 'orange', 'pink'])
|
|
45
|
+
const ink = parseColor('ink'), highlight = parseColor('yellow')
|
|
46
|
+
|
|
47
|
+
interface Strand { outline: Vec[]; seed: number; stagger: number; lane: number }
|
|
48
|
+
const strands: Strand[][] = glyphs.map((path, g) => path.map((ring, r) => {
|
|
49
|
+
const outline: Vec[] = []
|
|
50
|
+
const single: Path = [ring]
|
|
51
|
+
for (let i = 0; i < SAMPLES; i++) outline.push(pointAt(single, i / SAMPLES))
|
|
52
|
+
const lane = ((g + r * 0.5) / Math.max(1, glyphs.length - 1) - 0.5) * 300
|
|
53
|
+
return { outline, seed: g * 1.3 + r * 2.1, stagger: g / Math.max(1, glyphs.length - 1), lane }
|
|
54
|
+
}))
|
|
55
|
+
|
|
56
|
+
const FIELD = 64
|
|
57
|
+
const field = Array.from({ length: FIELD }, (_, i) => {
|
|
58
|
+
const k = i - (FIELD - 1) / 2
|
|
59
|
+
return { base: k * 19, seed: i * 0.37, weight: 1 - Math.abs(k) / FIELD }
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
s.add(dynamic((t) => {
|
|
63
|
+
const out: Node[] = []
|
|
64
|
+
const calm = 1 - 0.68 * gathered(t, 0.5)
|
|
65
|
+
const part = gathered(t, 0.5)
|
|
66
|
+
for (const line of field) {
|
|
67
|
+
const points: Vec[] = []
|
|
68
|
+
for (let i = 0; i <= 70; i++) {
|
|
69
|
+
const x = -EDGE + (2 * EDGE * i) / 70
|
|
70
|
+
const bulge = Math.exp(-((x / 760) ** 4))
|
|
71
|
+
// The field parts like streamlines around an obstacle.
|
|
72
|
+
const side = line.base >= 0 ? 1 : -1
|
|
73
|
+
const push = side * 262 * Math.exp(-(line.base * line.base) / (2 * 190 * 190)) * bulge * part
|
|
74
|
+
points.push([x, line.base * (1 + 0.32 * part) + push + wave(x, line.seed, t, calm)])
|
|
75
|
+
}
|
|
76
|
+
out.push(new Node(smoothPath(points)).stroke(pigment, 1.35, 0.16 + 0.32 * line.weight * line.weight))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// A soft highlight crosses the word once per loop.
|
|
80
|
+
const cycle = ((t + 1.6) % LOOP) / LOOP
|
|
81
|
+
const at = -0.2 + cycle * 3.1
|
|
82
|
+
const shine = linearGradient([left, 0], [left + width, 0], [
|
|
83
|
+
[0, ink], [clamp01(at - 0.11), ink], [clamp01(at), highlight], [clamp01(at + 0.11), ink], [1, ink],
|
|
84
|
+
])
|
|
85
|
+
|
|
86
|
+
strands.forEach((group) => {
|
|
87
|
+
const rings: Path[] = []
|
|
88
|
+
let settled = 1
|
|
89
|
+
for (const strand of group) {
|
|
90
|
+
const alpha = gathered(t, strand.stagger)
|
|
91
|
+
settled = Math.min(settled, alpha)
|
|
92
|
+
if (alpha >= 0.999) {
|
|
93
|
+
rings.push(polyPath(strand.outline, true))
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
const points: Vec[] = strand.outline.map(([gx, gy], i) => {
|
|
97
|
+
const u = i / SAMPLES
|
|
98
|
+
const run = u < 0.5 ? u * 2 : (1 - u) * 2
|
|
99
|
+
const x = -EDGE + 2 * EDGE * run
|
|
100
|
+
const y = strand.lane + wave(x, strand.seed, t, 1) + (u < 0.5 ? 0.8 : -0.8)
|
|
101
|
+
// Points near the word's center of gravity land first, which feels drawn in.
|
|
102
|
+
const local = smooth(clamp01((alpha * 1.34 - 0.34 * Math.abs(run - 0.5) * 2)))
|
|
103
|
+
return [x + (gx - x) * local, y + (gy - y) * local]
|
|
104
|
+
})
|
|
105
|
+
rings.push(polyPath(points, true))
|
|
106
|
+
}
|
|
107
|
+
const shape = new Node(rings.flat())
|
|
108
|
+
// Letters land as a lit outline, then flood with ink at the very end.
|
|
109
|
+
const fill = smooth(clamp01((settled - 0.9) / 0.1))
|
|
110
|
+
if (fill > 0) shape.fill(shine, fill)
|
|
111
|
+
if (fill < 1) shape.stroke(pigment, 2.6, 1 - fill * fill)
|
|
112
|
+
out.push(shape)
|
|
113
|
+
})
|
|
114
|
+
return out
|
|
115
|
+
}))
|
|
116
|
+
s.wait(LOOP)
|
|
117
|
+
})
|