vizmatic 0.8.3 → 0.9.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 +32 -0
- package/README.md +8 -3
- package/ROADMAP.md +4 -2
- package/SCIENCE.md +69 -3
- package/dist/chunk-6JI55YX4.js +604 -0
- package/dist/{chunk-LTX44BAE.js → chunk-BYKXNUX7.js} +25 -4
- package/dist/{chunk-4MXGLMBG.js → chunk-EPZLNABN.js} +107 -37
- package/dist/chunk-EWCO6ZT6.js +696 -0
- package/dist/{chunk-JZPMGVBP.js → chunk-G7HRSKHV.js} +1 -1
- package/dist/{chunk-RPAHMKAR.js → chunk-JTWC2OPN.js} +7 -5
- package/dist/chunk-LJZO36IR.js +124 -0
- package/dist/chunk-REL2BZ2B.js +88 -0
- package/dist/chunk-RLPEOWST.js +1 -0
- package/dist/chunk-VMHOWCDL.js +296 -0
- package/dist/chunk-YDD63HHD.js +1 -0
- package/dist/{chunk-I745F4QK.js → chunk-YNGDEARY.js} +1134 -643
- package/dist/cli.js +80 -543
- package/dist/gpu-selection-CDWCZH27.js +1 -0
- package/dist/gpu-selection-MX6NHMNA.js +635 -0
- package/dist/index.cjs +473 -155
- package/dist/index.d.cts +30 -239
- package/dist/index.d.ts +30 -239
- package/dist/index.js +410 -457
- package/dist/math-E7W5LFWO.js +1 -0
- package/dist/{math-LXB4FH4E.js → math-NEFQUPRV.js} +3 -1
- package/dist/scene-browser.js +17 -17
- package/dist/scene-cli.js +1 -1
- package/dist/scene-runtime.cjs +4 -2
- package/dist/scene-runtime.js +2 -2
- package/dist/stage-browser/browser.d.ts +1206 -854
- package/dist/stage-browser/gpu-renderer.js +138 -0
- package/dist/stage-browser/{math-4WFNHVV2.js → math-KYHUOK7A.js} +46 -10
- package/dist/stage-browser/stage.js +107 -19
- package/dist/stage-export.cjs +8221 -6784
- package/dist/stage-export.d.cts +13 -5
- package/dist/stage-export.d.ts +13 -5
- package/dist/stage-export.js +111 -601
- package/dist/stage.cjs +6243 -3474
- package/dist/stage.d.cts +1064 -765
- package/dist/stage.d.ts +1064 -765
- package/dist/stage.js +3571 -2405
- package/dist/{svg-import-B5BGbC1t.d.cts → svg-import-CSCFWYaB.d.cts} +21 -12
- package/dist/{svg-import-B5BGbC1t.d.ts → svg-import-CSCFWYaB.d.ts} +21 -12
- package/dist/teaching-math-DTKc0XsB.d.cts +243 -0
- package/dist/teaching-math-ydDBhJ2M.d.ts +243 -0
- package/dist/{video-CiN1MDCS.d.cts → theme-DhVdDQKO.d.cts} +4 -237
- package/dist/{video-CiN1MDCS.d.ts → theme-DhVdDQKO.d.ts} +4 -237
- package/dist/video-BYCeOz8F.d.ts +259 -0
- package/dist/video-CGLxJXqu.d.cts +259 -0
- package/examples/catalog-science-physics.tsx +6 -6
- package/examples/films/_boltzmann-entropy/model.ts +63 -0
- package/examples/films/_catalysis/model.ts +49 -0
- package/examples/films/_gravitational-waves/model.ts +32 -0
- package/examples/films/_heat-equation/model.ts +54 -0
- package/examples/films/_hydrogen-orbitals/model.ts +31 -0
- package/examples/films/_maxwell/model.ts +84 -0
- package/examples/films/_planetary-orbits/appearance.ts +71 -0
- package/examples/films/_planetary-orbits/model.ts +152 -0
- package/examples/films/_planetary-orbits/saturn.ts +142 -0
- package/examples/films/_quantum-tunneling/model.ts +58 -0
- package/examples/films/_reaction-diffusion/model.ts +61 -0
- package/examples/films/_stationary-action/model.ts +38 -0
- package/examples/films/attention.ts +309 -253
- package/examples/films/beam-search.ts +321 -49
- package/examples/films/boltzmann-entropy.ts +104 -0
- package/examples/films/cache-miss.ts +387 -394
- package/examples/films/catalog.json +238 -77
- package/examples/films/catalysis.ts +128 -0
- package/examples/films/central-limit.ts +27 -22
- package/examples/films/complex-maps.ts +70 -56
- package/examples/films/deck-example.ts +261 -200
- package/examples/films/euler-circle.ts +72 -28
- package/examples/films/flash-attention.ts +549 -0
- package/examples/films/forecast.ts +2 -2
- package/examples/films/fourier-epicycles.ts +21 -20
- package/examples/films/gradient-descent.ts +23 -49
- package/examples/films/gravitational-waves.ts +179 -0
- package/examples/films/heat-equation.ts +124 -0
- package/examples/films/hydrogen-orbitals.ts +135 -0
- package/examples/films/io-uring.ts +635 -0
- package/examples/films/linear-maps.ts +42 -31
- package/examples/films/lorenz.ts +42 -79
- package/examples/films/maxwell.ts +197 -0
- package/examples/films/pathlines.ts +85 -0
- package/examples/films/planetary-orbits.ts +146 -0
- package/examples/films/pythagoras.ts +18 -10
- package/examples/films/quantum-tunneling.ts +116 -0
- package/examples/films/rag-citations.ts +423 -0
- package/examples/films/reaction-diffusion.ts +70 -0
- package/examples/films/ring-allreduce.ts +531 -0
- package/examples/films/stationary-action.ts +170 -0
- package/examples/films/svd-3d.ts +605 -0
- package/examples/films/taylor-series.ts +9 -9
- package/examples/films/vizmatic-title.ts +1 -0
- package/examples/vizmatic-hero.tsx +102 -32
- package/package.json +3 -1
- package/dist/chunk-3F2VQ7NW.js +0 -1
- package/dist/chunk-GGFDBJ25.js +0 -88
- package/dist/math-QVCETQDQ.js +0 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* general formula collapses to Euler's identity, one substitution at a time.
|
|
5
5
|
*/
|
|
6
6
|
import {
|
|
7
|
-
Node, arc, arrow, circle, curveThrough, draw, dot, dynamic, fadeIn, fadeOut, film, flash, line, linear, morphMatching, rect, smoother, text, tex, to, write,
|
|
7
|
+
Node, arc, arrow, circle, curveThrough, draw, dot, dynamic, fadeIn, fadeOut, film, flash, indicate, line, linear, morphMatching, rect, smoother, surroundingBox, text, tex, to, write,
|
|
8
8
|
type Vec,
|
|
9
9
|
} from 'vizmatic/stage'
|
|
10
10
|
|
|
@@ -18,8 +18,11 @@ export default film({
|
|
|
18
18
|
title: "Euler's identity from a circle",
|
|
19
19
|
description: 'A point sweeps the unit circle, sine and cosine trace themselves, and the formula collapses at theta equals pi.',
|
|
20
20
|
fps: 60,
|
|
21
|
+
bleed: true,
|
|
21
22
|
}, (s) => {
|
|
22
23
|
const theta = s.value(0)
|
|
24
|
+
const handAlpha = s.value(0)
|
|
25
|
+
const unitAlpha = s.value(0)
|
|
23
26
|
const P = (): Vec => [CX + Math.cos(theta.value) * R, CY - Math.sin(theta.value) * R]
|
|
24
27
|
const plotX = (t: number) => PLOT_X + (t / TAU) * PLOT_W
|
|
25
28
|
|
|
@@ -28,34 +31,52 @@ export default film({
|
|
|
28
31
|
const axisH = line([CX - R - 34, CY], [CX + R + 34, CY], { stroke: 'faint', width: 1.6 })
|
|
29
32
|
const axisV = line([CX, CY - R - 34], [CX, CY + R + 34], { stroke: 'faint', width: 1.6 })
|
|
30
33
|
const ring = circle(R, { stroke: 'dim', width: 2.4 }).at(CX, CY)
|
|
31
|
-
const unit =
|
|
34
|
+
const unit = dynamic(() => {
|
|
35
|
+
const a = unitAlpha.value
|
|
36
|
+
if (a <= 0.001) return null
|
|
37
|
+
const tag = tex('1', { size: 28, color: 'dim', display: false }).moveTo([CX + R + 28, CY + 34]).opacity(a)
|
|
38
|
+
const ub = tag.bounds()
|
|
39
|
+
return [
|
|
40
|
+
rect(ub.width + 24, ub.height + 22, { fill: 'bg', stroke: null, radius: 5 }).at(ub.x + ub.width / 2, ub.y + ub.height / 2),
|
|
41
|
+
tag,
|
|
42
|
+
]
|
|
43
|
+
}).zIndex(3)
|
|
32
44
|
|
|
33
45
|
const hand = dynamic(() => {
|
|
46
|
+
const a = handAlpha.value
|
|
47
|
+
if (a <= 0.001) return null
|
|
34
48
|
const [px, py] = P()
|
|
35
49
|
const t = theta.value
|
|
36
50
|
const c = Math.cos(t), sn = Math.sin(t)
|
|
37
51
|
const items: Node[] = []
|
|
38
52
|
if (t > 0.02) {
|
|
39
|
-
items.push(arc(46, 0, -t, { stroke: 'yellow', width: 3 }).at(CX, CY))
|
|
53
|
+
items.push(arc(46, 0, -t, { stroke: 'yellow', width: 3 }).at(CX, CY).opacity(a))
|
|
40
54
|
}
|
|
41
55
|
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),
|
|
56
|
+
line([CX, CY], [CX + c * R, CY], { stroke: 'blue', width: 7 }).opacity(a),
|
|
57
|
+
line([CX + c * R, CY], [CX + c * R, CY - sn * R], { stroke: 'pink', width: 7 }).opacity(a),
|
|
58
|
+
arrow([CX, CY], [px, py], { stroke: 'ink', width: 3.2, tip: 16 }).opacity(a),
|
|
59
|
+
dot(9.5, 'yellow').at(px, py).glow(14).opacity(a),
|
|
46
60
|
)
|
|
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
61
|
return items
|
|
55
|
-
})
|
|
62
|
+
}).zIndex(2)
|
|
63
|
+
|
|
64
|
+
const thetaTag = dynamic(() => {
|
|
65
|
+
const a = handAlpha.value
|
|
66
|
+
const t = theta.value
|
|
67
|
+
if (a <= 0.001 || t <= 0.45) return null
|
|
68
|
+
const mid = t / 2
|
|
69
|
+
const label = tex('\\theta', { size: 30, color: 'yellow', display: false }).moveTo([CX + Math.cos(mid) * 86, CY - Math.sin(mid) * 86]).opacity(a)
|
|
70
|
+
const b = label.bounds()
|
|
71
|
+
return [
|
|
72
|
+
rect(b.width + 24, b.height + 22, { fill: 'bg', stroke: null, radius: 6 }).at(b.x + b.width / 2, b.y + b.height / 2),
|
|
73
|
+
label,
|
|
74
|
+
]
|
|
75
|
+
}).zIndex(3)
|
|
56
76
|
|
|
57
77
|
// ── The two traces ──────────────────────────────────────────────────────
|
|
58
78
|
|
|
79
|
+
const tickMarks: Node[] = []
|
|
59
80
|
const frame = (y: number, label: string, color: string): Node => {
|
|
60
81
|
const parts: Node[] = [
|
|
61
82
|
line([PLOT_X, y], [PLOT_X + PLOT_W + 10, y], { stroke: 'faint', width: 1.6 }),
|
|
@@ -65,15 +86,21 @@ export default film({
|
|
|
65
86
|
// Top middle stays clear: at theta = pi, sine is at 0 and cosine is at its lowest.
|
|
66
87
|
tex(label, { size: 36, color, display: false }).moveTo([PLOT_X + PLOT_W * 0.5, y - R + 6]),
|
|
67
88
|
]
|
|
68
|
-
for (const [mark, at] of [['\\
|
|
89
|
+
for (const [mark, at] of [['\\pi/2', 0.25], ['\\pi', 0.5], ['3\\pi/2', 0.75], ['2\\pi', 1]] as const) {
|
|
69
90
|
const x = PLOT_X + at * PLOT_W
|
|
70
91
|
parts.push(line([x, y - 6], [x, y + 6], { stroke: 'faint', width: 1.6 }))
|
|
71
|
-
|
|
92
|
+
const tick = tex(mark, { size: 28, color: 'dim', display: false }).moveTo([x + (at === 1 ? -8 : 0), y + 36])
|
|
93
|
+
const tb = tick.bounds()
|
|
94
|
+
tickMarks.push(
|
|
95
|
+
rect(tb.width + 24, tb.height + 22, { fill: 'bg', stroke: null, radius: 5 }).at(tb.x + tb.width / 2, tb.y + tb.height / 2),
|
|
96
|
+
tick,
|
|
97
|
+
)
|
|
72
98
|
}
|
|
73
99
|
return new Node().add(...parts)
|
|
74
100
|
}
|
|
75
101
|
const sinFrame = frame(SIN_Y, '\\sin\\theta', 'pink')
|
|
76
102
|
const cosFrame = frame(COS_Y, '\\cos\\theta', 'blue')
|
|
103
|
+
const waveTicks = new Node().add(...tickMarks).zIndex(3)
|
|
77
104
|
|
|
78
105
|
const traces = dynamic(() => {
|
|
79
106
|
const end = theta.value
|
|
@@ -94,7 +121,7 @@ export default film({
|
|
|
94
121
|
dot(8, 'pink').at(x, sy),
|
|
95
122
|
dot(8, 'blue').at(x, cy),
|
|
96
123
|
]
|
|
97
|
-
})
|
|
124
|
+
}).zIndex(1)
|
|
98
125
|
|
|
99
126
|
// ── Readouts, under the circle ──────────────────────────────────────────
|
|
100
127
|
|
|
@@ -104,14 +131,14 @@ export default film({
|
|
|
104
131
|
const t = theta.value
|
|
105
132
|
const clean = (v: number) => (Math.abs(v) < 0.005 ? 0 : v).toFixed(3).padStart(6, ' ')
|
|
106
133
|
return [
|
|
107
|
-
readLabel(
|
|
108
|
-
readLabel(`cos
|
|
109
|
-
readLabel(`sin
|
|
134
|
+
readLabel(`θ ${clean(t)}`, 36, 'yellow'),
|
|
135
|
+
readLabel(`cos ${clean(Math.cos(t))}`, 80, 'blue'),
|
|
136
|
+
readLabel(`sin ${clean(Math.sin(t))}`, 124, 'pink'),
|
|
110
137
|
]
|
|
111
138
|
})
|
|
112
139
|
const note = text('A complex number with length one is a point on this circle. Its angle is the exponent.', {
|
|
113
|
-
size:
|
|
114
|
-
}).alignTo([LEFT, 0], 'left').alignTo([0,
|
|
140
|
+
size: 26, color: 'dim', maxWidth: 420, leading: 1.36,
|
|
141
|
+
}).alignTo([LEFT, 0], 'left').alignTo([0, 196], 'top')
|
|
115
142
|
|
|
116
143
|
// ── Words and equations ─────────────────────────────────────────────────
|
|
117
144
|
|
|
@@ -144,16 +171,31 @@ export default film({
|
|
|
144
171
|
// ── Timeline ────────────────────────────────────────────────────────────
|
|
145
172
|
|
|
146
173
|
s.chapter('The point')
|
|
174
|
+
s.add(unit, hand, thetaTag)
|
|
147
175
|
s.play(write(title), draw(axisH), draw(axisV), draw(ring), { duration: 1.8 })
|
|
148
|
-
s.play(
|
|
176
|
+
s.play(unitAlpha.to(1), handAlpha.to(1), { duration: 0.8 })
|
|
149
177
|
s.play(write(general), fadeIn(note, { shift: [0, 8] }), { duration: 1.8 })
|
|
150
178
|
s.play(theta.to(0.85), fadeIn(reads), { duration: 1.8 })
|
|
151
179
|
s.wait(0.6)
|
|
152
180
|
|
|
153
181
|
s.chapter('Two shadows')
|
|
154
|
-
s.play(draw(sinFrame, { lag: 0.03 }), draw(cosFrame, { lag: 0.03 }), { duration: 1.6 })
|
|
182
|
+
s.play(draw(sinFrame, { lag: 0.03 }), draw(cosFrame, { lag: 0.03 }), fadeIn(waveTicks), { duration: 1.6 })
|
|
155
183
|
s.add(traces)
|
|
156
184
|
s.play(fadeIn(traces), { duration: 0.4 })
|
|
185
|
+
// The matching terms pulse with their projections while the point completes its turn.
|
|
186
|
+
for (const [offset, fragment, color, words] of [
|
|
187
|
+
[1, '\\cos\\theta', 'blue', 'The horizontal projection is the real part: cosine.'],
|
|
188
|
+
[4.4, '\\sin\\theta', 'pink', 'The vertical projection is the imaginary component: sine.'],
|
|
189
|
+
] as const) {
|
|
190
|
+
const term = general.part(fragment)
|
|
191
|
+
const mark = surroundingBox(term, { follow: true, color, pad: 8, width: 2 })
|
|
192
|
+
s.at(s.time + offset, () => {
|
|
193
|
+
s.caption(words, 3)
|
|
194
|
+
s.play(fadeIn(mark), { duration: 0.2 })
|
|
195
|
+
s.play(indicate(term, { color, scale: 1.08 }), { duration: 1.8 })
|
|
196
|
+
s.play(fadeOut(mark), { duration: 0.2 })
|
|
197
|
+
})
|
|
198
|
+
}
|
|
157
199
|
s.play(theta.to(TAU, { ease: linear }), { duration: 8 })
|
|
158
200
|
s.wait(0.8)
|
|
159
201
|
|
|
@@ -164,15 +206,17 @@ export default film({
|
|
|
164
206
|
s.play(morphMatching(general, atPi), { duration: 1.4 })
|
|
165
207
|
s.wait(0.9)
|
|
166
208
|
s.play(morphMatching(atPi, values), { duration: 1.4 })
|
|
167
|
-
s.
|
|
209
|
+
s.caption('At half a turn, the imaginary component is zero. Only minus one remains.', 4)
|
|
210
|
+
s.play(indicate(values.part('i \\cdot 0'), { color: 'pink', scale: 1.08 }), { duration: 0.9 })
|
|
168
211
|
s.play(morphMatching(values, reduced), { duration: 1.2 })
|
|
169
212
|
s.wait(0.7)
|
|
170
213
|
|
|
171
214
|
s.chapter('The identity')
|
|
215
|
+
s.play(unitAlpha.to(0), handAlpha.to(0), fadeOut([title, note, reads, traces, sinFrame, cosFrame, waveTicks, axisH, axisV]), { duration: 0.85 })
|
|
172
216
|
s.play(
|
|
173
217
|
morphMatching(reduced, identity),
|
|
174
|
-
|
|
175
|
-
|
|
218
|
+
to(ring, (r) => r.moveTo([0, 10]).scale(3.15).opacity(0.14)),
|
|
219
|
+
{ duration: 1.7 },
|
|
176
220
|
)
|
|
177
221
|
s.play(fadeIn(caption, { shift: [0, 14] }), { duration: 1.2 })
|
|
178
222
|
s.wait(3.2)
|