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.
Files changed (99) hide show
  1. package/PROMPT.md +32 -0
  2. package/README.md +8 -3
  3. package/ROADMAP.md +4 -2
  4. package/SCIENCE.md +69 -3
  5. package/dist/chunk-6JI55YX4.js +604 -0
  6. package/dist/{chunk-LTX44BAE.js → chunk-BYKXNUX7.js} +25 -4
  7. package/dist/{chunk-4MXGLMBG.js → chunk-EPZLNABN.js} +107 -37
  8. package/dist/chunk-EWCO6ZT6.js +696 -0
  9. package/dist/{chunk-JZPMGVBP.js → chunk-G7HRSKHV.js} +1 -1
  10. package/dist/{chunk-RPAHMKAR.js → chunk-JTWC2OPN.js} +7 -5
  11. package/dist/chunk-LJZO36IR.js +124 -0
  12. package/dist/chunk-REL2BZ2B.js +88 -0
  13. package/dist/chunk-RLPEOWST.js +1 -0
  14. package/dist/chunk-VMHOWCDL.js +296 -0
  15. package/dist/chunk-YDD63HHD.js +1 -0
  16. package/dist/{chunk-I745F4QK.js → chunk-YNGDEARY.js} +1134 -643
  17. package/dist/cli.js +80 -543
  18. package/dist/gpu-selection-CDWCZH27.js +1 -0
  19. package/dist/gpu-selection-MX6NHMNA.js +635 -0
  20. package/dist/index.cjs +473 -155
  21. package/dist/index.d.cts +30 -239
  22. package/dist/index.d.ts +30 -239
  23. package/dist/index.js +410 -457
  24. package/dist/math-E7W5LFWO.js +1 -0
  25. package/dist/{math-LXB4FH4E.js → math-NEFQUPRV.js} +3 -1
  26. package/dist/scene-browser.js +17 -17
  27. package/dist/scene-cli.js +1 -1
  28. package/dist/scene-runtime.cjs +4 -2
  29. package/dist/scene-runtime.js +2 -2
  30. package/dist/stage-browser/browser.d.ts +1206 -854
  31. package/dist/stage-browser/gpu-renderer.js +138 -0
  32. package/dist/stage-browser/{math-4WFNHVV2.js → math-KYHUOK7A.js} +46 -10
  33. package/dist/stage-browser/stage.js +107 -19
  34. package/dist/stage-export.cjs +8221 -6784
  35. package/dist/stage-export.d.cts +13 -5
  36. package/dist/stage-export.d.ts +13 -5
  37. package/dist/stage-export.js +111 -601
  38. package/dist/stage.cjs +6243 -3474
  39. package/dist/stage.d.cts +1064 -765
  40. package/dist/stage.d.ts +1064 -765
  41. package/dist/stage.js +3571 -2405
  42. package/dist/{svg-import-B5BGbC1t.d.cts → svg-import-CSCFWYaB.d.cts} +21 -12
  43. package/dist/{svg-import-B5BGbC1t.d.ts → svg-import-CSCFWYaB.d.ts} +21 -12
  44. package/dist/teaching-math-DTKc0XsB.d.cts +243 -0
  45. package/dist/teaching-math-ydDBhJ2M.d.ts +243 -0
  46. package/dist/{video-CiN1MDCS.d.cts → theme-DhVdDQKO.d.cts} +4 -237
  47. package/dist/{video-CiN1MDCS.d.ts → theme-DhVdDQKO.d.ts} +4 -237
  48. package/dist/video-BYCeOz8F.d.ts +259 -0
  49. package/dist/video-CGLxJXqu.d.cts +259 -0
  50. package/examples/catalog-science-physics.tsx +6 -6
  51. package/examples/films/_boltzmann-entropy/model.ts +63 -0
  52. package/examples/films/_catalysis/model.ts +49 -0
  53. package/examples/films/_gravitational-waves/model.ts +32 -0
  54. package/examples/films/_heat-equation/model.ts +54 -0
  55. package/examples/films/_hydrogen-orbitals/model.ts +31 -0
  56. package/examples/films/_maxwell/model.ts +84 -0
  57. package/examples/films/_planetary-orbits/appearance.ts +71 -0
  58. package/examples/films/_planetary-orbits/model.ts +152 -0
  59. package/examples/films/_planetary-orbits/saturn.ts +142 -0
  60. package/examples/films/_quantum-tunneling/model.ts +58 -0
  61. package/examples/films/_reaction-diffusion/model.ts +61 -0
  62. package/examples/films/_stationary-action/model.ts +38 -0
  63. package/examples/films/attention.ts +309 -253
  64. package/examples/films/beam-search.ts +321 -49
  65. package/examples/films/boltzmann-entropy.ts +104 -0
  66. package/examples/films/cache-miss.ts +387 -394
  67. package/examples/films/catalog.json +238 -77
  68. package/examples/films/catalysis.ts +128 -0
  69. package/examples/films/central-limit.ts +27 -22
  70. package/examples/films/complex-maps.ts +70 -56
  71. package/examples/films/deck-example.ts +261 -200
  72. package/examples/films/euler-circle.ts +72 -28
  73. package/examples/films/flash-attention.ts +549 -0
  74. package/examples/films/forecast.ts +2 -2
  75. package/examples/films/fourier-epicycles.ts +21 -20
  76. package/examples/films/gradient-descent.ts +23 -49
  77. package/examples/films/gravitational-waves.ts +179 -0
  78. package/examples/films/heat-equation.ts +124 -0
  79. package/examples/films/hydrogen-orbitals.ts +135 -0
  80. package/examples/films/io-uring.ts +635 -0
  81. package/examples/films/linear-maps.ts +42 -31
  82. package/examples/films/lorenz.ts +42 -79
  83. package/examples/films/maxwell.ts +197 -0
  84. package/examples/films/pathlines.ts +85 -0
  85. package/examples/films/planetary-orbits.ts +146 -0
  86. package/examples/films/pythagoras.ts +18 -10
  87. package/examples/films/quantum-tunneling.ts +116 -0
  88. package/examples/films/rag-citations.ts +423 -0
  89. package/examples/films/reaction-diffusion.ts +70 -0
  90. package/examples/films/ring-allreduce.ts +531 -0
  91. package/examples/films/stationary-action.ts +170 -0
  92. package/examples/films/svd-3d.ts +605 -0
  93. package/examples/films/taylor-series.ts +9 -9
  94. package/examples/films/vizmatic-title.ts +1 -0
  95. package/examples/vizmatic-hero.tsx +102 -32
  96. package/package.json +3 -1
  97. package/dist/chunk-3F2VQ7NW.js +0 -1
  98. package/dist/chunk-GGFDBJ25.js +0 -88
  99. package/dist/math-QVCETQDQ.js +0 -1
@@ -43,37 +43,48 @@ export default film({
43
43
  grid.major.opacity(0.62)
44
44
  grid.axes.opacity(0.85)
45
45
 
46
- const chip = (label: Node, at: Vec, pad = 8): Node[] => {
47
- label.moveTo(at)
46
+ const basisAlpha = s.value(0)
47
+ const squareAlpha = s.value(0)
48
+
49
+ const chip = (label: Node, at: Vec, alpha: number, pad = 14): Node[] => {
50
+ label.moveTo(at).opacity(alpha)
48
51
  const b = label.bounds()
49
52
  const back = rect(b.width + pad * 2, b.height + pad * 2, { fill: 'bg', stroke: null, radius: 6 })
50
- .at(b.x + b.width / 2, b.y + b.height / 2).opacity(0.88)
53
+ .at(b.x + b.width / 2, b.y + b.height / 2)
51
54
  return [back, label]
52
55
  }
53
56
  /** Label beside an arrow tip, not past it, so the chip never breaks the axis the arrow lies on. */
54
- const tipLabel = (x: number, y: number, source: string, color: string, side: 1 | -1): Node[] => {
57
+ const tipLabel = (x: number, y: number, source: string, color: string, side: 1 | -1, alpha: number): Node[] => {
55
58
  const [tx, ty] = Pm(x, y)
56
59
  const length = Math.hypot(tx - ORIGIN_X, ty) || 1
57
60
  const dx = (tx - ORIGIN_X) / length, dy = ty / length
58
61
  const normalX = -dy * side, normalY = dx * side
59
- return chip(tex(source, { size: 34, color, display: false }), [tx - dx * 10 + normalX * 34, ty - dy * 10 + normalY * 34])
62
+ return chip(tex(source, { size: 34, color, display: false }), [tx - dx * 20 + normalX * 46, ty - dy * 20 + normalY * 46], alpha)
60
63
  }
61
64
 
62
- const basis = dynamic(() => [
65
+ const basisArrows = dynamic(() => [
63
66
  arrow(P(0, 0), Pm(1, 0), { stroke: 'green', width: 5, tip: 22 }),
64
67
  arrow(P(0, 0), Pm(0, 1), { stroke: 'red', width: 5, tip: 22 }),
65
- ...tipLabel(1, 0, '\\hat{\\imath}', 'green', 1),
66
- ...tipLabel(0, 1, '\\hat{\\jmath}', 'red', -1),
67
- ])
68
+ ]).zIndex(2)
69
+ const basisLabels = dynamic(() => {
70
+ const a = basisAlpha.value
71
+ if (a <= 0.001) return null
72
+ return [
73
+ ...tipLabel(1, 0, '\\hat{\\imath}', 'green', 1, a),
74
+ ...tipLabel(0, 1, '\\hat{\\jmath}', 'red', -1, a),
75
+ ]
76
+ }).zIndex(3)
68
77
 
69
78
  const square = dynamic(() => {
79
+ const a = squareAlpha.value
80
+ if (a <= 0.001) return null
70
81
  const corners = [Pm(0, 0), Pm(1, 0), Pm(1, 1), Pm(0, 1)]
71
82
  const cx = corners.reduce((sum, c) => sum + c[0], 0) / 4, cy = corners.reduce((sum, c) => sum + c[1], 0) / 4
72
83
  return [
73
- shape(polyPath(corners, true), { fill: 'yellow', stroke: 'yellow', width: 2.5 }).set('fillOpacity', 0.32),
74
- ...chip(tex(determinant().toFixed(2), { size: 30, color: 'yellow', display: false }), [cx, cy], 6),
84
+ shape(polyPath(corners, true), { fill: 'yellow', stroke: 'yellow', width: 2.5 }).set('fillOpacity', 0.32 * a).opacity(a),
85
+ ...chip(tex(determinant().toFixed(2), { size: 30, color: 'yellow', display: false }), [cx, cy], a, 13),
75
86
  ]
76
- })
87
+ }).zIndex(1)
77
88
 
78
89
  // The fan: one short arrow per direction, tinted by direction, all from the origin.
79
90
  const FAN = 56
@@ -107,38 +118,38 @@ export default film({
107
118
  node.zIndex(6)
108
119
  return node
109
120
  }
110
- const title = place(text('A matrix moves the whole plane.', { font: 'text-serif', size: 46, maxWidth: 440, leading: 1.08 }), -490)
111
- const matrix = place(tex('A = \\begin{bmatrix} 2 & 1 \\\\ 0.5 & 1.5 \\end{bmatrix}', { size: 44 }), -340)
121
+ const title = place(text('A matrix moves the whole plane.', { font: 'text-serif', size: 44, maxWidth: 430, leading: 1.08 }), -496)
122
+ const matrix = place(tex('A = \\begin{bmatrix} 2 & 1 \\\\ 0.5 & 1.5 \\end{bmatrix}', { size: 42 }), -362)
112
123
  // Column one is where the first arrow lands. Column two is where the second lands.
113
124
  for (const i of [3, 5, 6, 7]) matrix.glyphs[i]!.fill('green')
114
125
  for (const i of [4, 8, 9, 10]) matrix.glyphs[i]!.fill('red')
115
126
 
116
- const label = (content: string, top: number) => place(text(content, { size: 19, color: 'dim', uppercase: true, tracking: 0.08, weight: 600 }), top)
117
- const tracksLabel = label('Where the arrows land', -196)
127
+ const label = (content: string, top: number) => place(text(content, { size: 26, color: 'dim', weight: 600 }), top)
128
+ const tracksLabel = label('Where the arrows land', -218)
118
129
  const reads = dynamic(() => {
119
130
  const [ix, iy] = moved(1, 0), [jx, jy] = moved(0, 1)
120
131
  const row = (name: string, x: number, y: number, color: string, top: number) =>
121
132
  place(text(`${name} (${x.toFixed(2)}, ${y.toFixed(2)})`, { font: 'mono', size: 30, color }), top)
122
- return [row('i', ix, iy, 'green', -162), row('j', jx, jy, 'red', -116)]
133
+ return [row('i', ix, iy, 'green', -180), row('j', jx, jy, 'red', -136)]
123
134
  }).zIndex(6)
124
- const areaLabel = label('Area of the unit square', -42)
125
- const areaRead = dynamic(() => place(text(determinant().toFixed(2), { font: 'mono', size: 72, color: 'yellow' }), -12)).zIndex(6)
126
- const detEq = place(tex('\\det A = 2 \\cdot 1.5 - 1 \\cdot 0.5 = 2.5', { size: 30 }), 96)
135
+ const areaLabel = label('Area of the unit square', -76)
136
+ const areaRead = dynamic(() => place(text(determinant().toFixed(2), { font: 'mono', size: 66, color: 'yellow' }), -42)).zIndex(6)
137
+ const detEq = place(tex('\\det A = 2 \\cdot 1.5 - 1 \\cdot 0.5 = 2.5', { size: 30 }), 56)
127
138
 
128
- const eigenLabel = label('Arrows that keep their line', 180)
129
- const eqA = place(tex('A \\vec{v} = \\lambda \\vec{v}', { size: 48, color: 'ink' }), 214)
130
- const stretchRow = place(tex('\\vec{v} = (2, 1), \\quad \\lambda = 2.5', { size: 30, color: 'yellow' }), 296)
131
- const fixedRow = place(tex('\\vec{v} = (1, -1), \\quad \\lambda = 1', { size: 30, color: 'teal' }), 346)
132
- const closing = place(tex('\\lambda_1 \\lambda_2 = 2.5 \\cdot 1 = \\det A', { size: 34, color: 'ink' }), 416)
139
+ const eigenLabel = label('Arrows that keep their line', 148)
140
+ const eqA = place(tex('A \\vec{v} = \\lambda \\vec{v}', { size: 46, color: 'ink' }), 186)
141
+ const stretchRow = place(tex('\\vec{v} = (2, 1), \\quad \\lambda = 2.5', { size: 30, color: 'yellow' }), 268)
142
+ const fixedRow = place(tex('\\vec{v} = (1, -1), \\quad \\lambda = 1', { size: 30, color: 'teal' }), 318)
143
+ const closing = place(tex('\\lambda_1 \\lambda_2 = 2.5 \\cdot 1 = \\det A', { size: 34, color: 'ink' }), 392)
133
144
 
134
145
  // ── Timeline ────────────────────────────────────────────────────────────
135
146
 
136
- s.add(still, grid)
147
+ s.add(still, grid, square, basisLabels)
137
148
  s.add(column, rule)
138
149
  s.chapter('Two arrows')
139
150
  s.play(write(title), draw(grid.major, { lag: 0.015 }), draw(grid.axes), { duration: 2.4 })
140
- s.play(grow(basis, { from: P(0, 0) }), write(matrix), { duration: 1.4 })
141
- s.play(fadeIn([tracksLabel, reads], { shift: [0, 8] }), { duration: 0.8 })
151
+ s.play(grow(basisArrows, { from: P(0, 0) }), write(matrix), { duration: 1.2 })
152
+ s.play(basisAlpha.to(1), fadeIn([tracksLabel, reads], { shift: [0, 8] }), { duration: 0.8 })
142
153
  s.wait(1.2)
143
154
 
144
155
  s.chapter('The move')
@@ -150,15 +161,15 @@ export default film({
150
161
 
151
162
  s.chapter('Area')
152
163
  s.play(applyMatrix(grid, INVERSE, { origin: [ORIGIN_X, 0] }), k.to(0), { duration: 1.8 })
153
- s.add(square)
154
- s.play(fadeIn(square), fadeIn([areaLabel, areaRead], { shift: [0, 8] }), { duration: 0.8 })
164
+ s.play(squareAlpha.to(1), fadeIn([areaLabel, areaRead], { shift: [0, 8] }), { duration: 0.8 })
155
165
  s.wait(0.5)
156
166
  s.play(applyMatrix(grid, A, { origin: [ORIGIN_X, 0] }), k.to(1), { duration: 3.2 })
157
167
  s.play(write(detEq), { duration: 1.4 })
158
168
  s.wait(1)
159
169
 
160
170
  s.chapter('Lines that stay')
161
- s.play(applyMatrix(grid, INVERSE, { origin: [ORIGIN_X, 0] }), k.to(0), fade(square, 0), fade(basis, 0), { duration: 1.8 })
171
+ s.play(squareAlpha.to(0), basisAlpha.to(0), fade(basisArrows, 0), { duration: 0.55 })
172
+ s.play(applyMatrix(grid, INVERSE, { origin: [ORIGIN_X, 0] }), k.to(0), { duration: 1.6 })
162
173
  s.add(fan)
163
174
  s.play(grow(fan, { from: P(0, 0) }), draw(lineStretch), draw(lineFixed), { duration: 1.4 })
164
175
  s.add(eigen)
@@ -4,7 +4,7 @@
4
4
  * nearby runs part are measured from the same integration that gets drawn.
5
5
  */
6
6
  import {
7
- Node, dot, dynamic, fadeIn, fadeOut, film, line, linear, polyPath, ramp, rect, smoother, text, tex, write,
7
+ Node, axes, dot, dynamic, fadeIn, fadeOut, film, integrateTrajectory, line, linear, polyPath, ramp, rect, smoother, text, tex, write,
8
8
  type Rgba, type Vec,
9
9
  } from 'vizmatic/stage'
10
10
 
@@ -13,37 +13,12 @@ const DT = 0.004
13
13
  const COLUMN = 480
14
14
  const CENTER: Vec = [-232, 8]
15
15
 
16
- type State = readonly [number, number, number]
16
+ type Samples = readonly (readonly number[])[]
17
17
 
18
- function derivative([x, y, z]: State): State {
18
+ function derivative(_time: number, [x, y, z]: readonly number[]): readonly number[] {
19
19
  return [SIGMA * (y - x), x * (RHO - z) - y, x * y - BETA * z]
20
20
  }
21
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
22
  export default film({
48
23
  title: 'The Lorenz attractor',
49
24
  description: 'Many deterministic trajectories fill a butterfly, and two nearby starts part ways.',
@@ -52,22 +27,21 @@ export default film({
52
27
  }, (s) => {
53
28
  const SPAN = 15000
54
29
  // 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)
30
+ const settled = integrateTrajectory(derivative, { initial: [1, 1, 1], to: 6000 * DT, step: DT }).sample(6000 * DT)
57
31
 
58
32
  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)
33
+ const runA = integrateTrajectory(derivative, { initial: settled, to: (SPAN - 1) * DT, step: DT }).states
34
+ const runB = integrateTrajectory(derivative, { initial: [settled[0] + OFFSET, settled[1], settled[2]], to: (SPAN - 1) * DT, step: DT }).states
35
+ const separation = new Float64Array(SPAN)
62
36
  let partedAt = -1
63
37
  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]!)
38
+ separation[i] = Math.hypot(runA[i]![0]! - runB[i]![0]!, runA[i]![1]! - runB[i]![1]!, runA[i]![2]! - runB[i]![2]!)
65
39
  if (partedAt < 0 && separation[i]! > 10) partedAt = i * DT
66
40
  }
67
41
 
68
42
  const CLOUD = 72
69
43
  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))
44
+ const cloud = Array.from({ length: CLOUD }, (_, i) => integrateTrajectory(derivative, { initial: [settled[0] + (i - CLOUD / 2) * 0.012, settled[1], settled[2]], to: (SPAN - 1) * DT, step: DT }).states)
71
45
 
72
46
  const clock = s.value(0)
73
47
  const showSingle = s.value(1)
@@ -88,14 +62,14 @@ export default film({
88
62
  return [CENTER[0] + X * scale, CENTER[1] - (Y * se + Z * ce) * scale]
89
63
  }
90
64
 
91
- const tail = (data: Float32Array, from: number, to: number, stride: number): Vec[] => {
65
+ const tail = (data: Samples, from: number, to: number, stride: number): Vec[] => {
92
66
  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]!))
67
+ for (let i = Math.max(0, from); i <= to; i += stride) out.push(project(data[i]![0]!, data[i]![1]!, data[i]![2]!))
94
68
  return out
95
69
  }
96
70
 
97
71
  /** 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[] => {
72
+ const comet = (data: Samples, head: number, length: number, color: string | Rgba, width: number, stride: number, alpha: number): Node[] => {
99
73
  const out: Node[] = []
100
74
  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
75
  for (const [far, near, opacity] of stops) {
@@ -115,19 +89,19 @@ export default film({
115
89
  // The long trail keeps the shape of the butterfly while one point runs through it.
116
90
  const points = tail(runA, 0, head, 2)
117
91
  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))
92
+ out.push(dot(8, 'yellow').at(project(runA[head]![0]!, runA[head]![1]!, runA[head]![2]!)).glow(12).opacity(showSingle.value))
119
93
  }
120
94
  if (showPair.value > 0) {
121
95
  const a = showPair.value
122
96
  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))
97
+ out.push(dot(8, 'yellow').at(project(runA[head]![0]!, runA[head]![1]!, runA[head]![2]!)).glow(10).opacity(a))
98
+ out.push(dot(8, 'pink').at(project(runB[head]![0]!, runB[head]![1]!, runB[head]![2]!)).glow(10).opacity(a))
125
99
  }
126
100
  if (showCloud.value > 0) {
127
101
  const a = showCloud.value
128
102
  cloud.forEach((data, i) => {
129
103
  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))
104
+ out.push(dot(4.5, cloudColors[i]!).at(project(data[head]![0]!, data[head]![1]!, data[head]![2]!)).opacity(a))
131
105
  })
132
106
  }
133
107
  return out
@@ -141,48 +115,37 @@ export default film({
141
115
  node.zIndex(6)
142
116
  return node
143
117
  }
144
- const label = (content: string, top: number) => place(text(content, { size: 19, color: 'dim', uppercase: true, tracking: 0.08, weight: 600 }), top)
118
+ const label = (content: string, top: number) => place(text(content, { size: 26, color: 'dim', weight: 600 }), top)
145
119
  const column = rect(960 - COLUMN + 70, 1080, { fill: 'bg', stroke: null }).at((COLUMN - 70 + 960) / 2, 0).zIndex(5)
146
120
 
147
- const title = place(text('The rules are exact. The future is not.', { font: 'text-serif', size: 46, maxWidth: 440, 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)
121
+ const title = place(text('The rules are exact. The future is not.', { font: 'text-serif', size: 44, maxWidth: 430, leading: 1.08 }), -496)
122
+ 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: 34 }), -374)
123
+ const constants = place(tex('\\sigma = 10, \\quad \\rho = 28, \\quad \\beta = 8/3', { size: 28, color: 'dim' }), -226)
124
+ const timeLabel = label('Model time (dimensionless)', -172)
125
+ const timeRead = dynamic(() => place(text(clock.value.toFixed(2).padStart(5, ' '), { font: 'mono', size: 42, color: 'ink' }), -138)).zIndex(6)
152
126
 
153
- const gapLabel = label('Distance between the two runs', -20)
127
+ const gapLabel = label('Distance between the two runs', -72)
154
128
  const gapRead = dynamic(() => {
155
129
  const head = Math.min(SPAN - 1, Math.floor(clock.value / DT))
156
130
  const value = separation[head]!
157
131
  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)
132
+ return place(text(body, { font: 'mono', size: 42, color: 'pink' }), -38)
159
133
  }).zIndex(6)
160
134
  // 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)
135
+ const CX = COLUMN + 84, CW = 310, CT = 34, CH = 224
136
+ const chartSpan = Math.max(26, Math.ceil(partedAt + 4))
137
+ const chartAxes = axes({
138
+ x: [0, chartSpan], y: [1e-6, 1e2], yScale: 'log',
139
+ width: CW, height: CH, color: 'faint', tips: false, labelSize: 28,
140
+ xTicks: [], yTicks: [-5, -3, -1, 1].map((power) => 10 ** power),
141
+ yFormat: (value) => `10^{${Math.round(Math.log10(value))}}`,
142
+ }).at(CX + CW / 2, CT + CH / 2).zIndex(6)
143
+ const distanceSeries: Vec[] = []
144
+ for (let i = 0; i < SPAN; i += 12) distanceSeries.push([i * DT, separation[i]!])
145
+ chartAxes.plot(distanceSeries, { to: () => Math.min(clock.value, chartSpan), stroke: 'pink', width: 2.6 })
146
+ const axisNote = place(text('Log distance vs. model time', { size: 26, color: 'dim' }), CT + CH + 16)
147
+ const partedNote = place(text(`Starting ${OFFSET} apart, they are 10 units apart by t = ${partedAt.toFixed(1)}.`, { size: 26, color: 'ink', maxWidth: 420, leading: 1.35 }), 334)
148
+ const cloudNote = place(text(`${CLOUD} starts packed into a line ${(0.012 * (CLOUD - 1)).toFixed(2)} long. Soon they cover the whole shape.`, { size: 26, color: 'ink', maxWidth: 420, leading: 1.35 }), 334)
186
149
 
187
150
  // ── Timeline ────────────────────────────────────────────────────────────
188
151
 
@@ -194,14 +157,14 @@ export default film({
194
157
  s.wait(0.2)
195
158
 
196
159
  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 })
160
+ s.play(showSingle.to(0.22), showPair.to(1), fadeIn([gapLabel, gapRead, chartAxes, axisNote]), azimuth.to(-0.58, { ease: linear }), clock.to(0, { ease: smoother }), { duration: 2.2 })
161
+ s.play(clock.to(Math.min(partedAt + 3.5, SPAN * DT - 1), { ease: linear }), azimuth.to(-1.05, { ease: linear }), { duration: 10.5 })
199
162
  s.play(fadeIn(partedNote, { shift: [0, 8] }), { duration: 0.9 })
200
- s.wait(0.6)
163
+ s.wait(2.8)
201
164
 
202
165
  s.chapter('A crowd')
203
166
  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
167
  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 })
168
+ s.play(clock.to(24, { ease: linear }), azimuth.to(-0.35, { ease: linear }), { duration: 8.5 })
206
169
  s.wait(1.5)
207
170
  })
@@ -0,0 +1,197 @@
1
+ import {
2
+ Box, column, curve3d, dynamic, fadeIn, fadeOut, film, label3d,
3
+ line3d, parametricSurface, place, point3d, row, scene3d, sceneKit, tex,
4
+ text, vector3d, type Vec3,
5
+ } from 'vizmatic/stage'
6
+ import { cross, polarizationAt, verifyPlaneWaves, wave } from './_maxwell/model'
7
+
8
+ verifyPlaneWaves()
9
+
10
+ const DURATION = 42
11
+ const FIELD_SCALE = 1.6
12
+ const X_RANGE = [-5, 5] as const
13
+
14
+ // Separate monochromatic examples are cut at zero visibility. Interpolating
15
+ // their amplitudes in physical time would not obey the displayed vacuum model.
16
+ function cutOpacity(t: number): number {
17
+ let opacity = 1
18
+ for (const cut of [16, 25]) opacity = Math.min(opacity, Math.min(1, Math.abs(t - cut) / 0.28))
19
+ return opacity
20
+ }
21
+
22
+ function tip(x: number, field: Vec3): Vec3 {
23
+ return [x, FIELD_SCALE * field[1], FIELD_SCALE * field[2]]
24
+ }
25
+
26
+ export default film({
27
+ title: 'Maxwell: the shape of light',
28
+ description: 'A vacuum plane wave travels along +x. A fixed observer links its electric and magnetic fields to linear, elliptical, and circular polarization, then to the Poynting vector. Normalized c = 1; cuts compare distinct solutions.',
29
+ look: 'midnight',
30
+ font: 'text-serif',
31
+ fps: 60,
32
+ poster: 29,
33
+ }, (s) => {
34
+ const kit = sceneKit({
35
+ size: 42,
36
+ heading: { size: 64, y: -468 },
37
+ area: { left: -875, right: 875, top: -355, bottom: 295 },
38
+ })
39
+ s.add(kit.heading('Maxwell: the shape of light'))
40
+ s.add(place(text('Vacuum · normalized c = 1, E₀ = 1 · field-tip curves · cuts compare distinct waves', {
41
+ size: 30, color: 'dim',
42
+ }), new Box(-875, -422, 875, -380), 'left'))
43
+ const [chapterBox, pictureBox, mathBox] = kit.area.rows([0.085, 0.70, 0.215], 18)
44
+ const [waveBox, observerBox] = pictureBox.columns([2.22, 1], 55)
45
+ const [waveMath, observerMath] = mathBox.columns([2.22, 1], 55)
46
+ const [legendBox, geometryBox] = waveBox.rows([0.13, 0.87], 12)
47
+ const [observerTitle, observerGeometry] = observerBox.rows([0.13, 0.87], 12)
48
+
49
+ s.add(place(row([
50
+ tex('\\mathbf E', { size: 38, color: 'blue' }),
51
+ text('electric', { size: 30, color: 'blue' }),
52
+ tex('c\\mathbf B', { size: 38, color: 'teal' }),
53
+ text('magnetic', { size: 30, color: 'teal' }),
54
+ text('propagation +x', { size: 30, color: 'yellow' }),
55
+ ], { gap: 24 }), legendBox, 'left'))
56
+ s.add(place(text('x = 0 / view toward −x', { size: 30, weight: 600, color: 'yellow' }), observerTitle))
57
+ s.add(place(column([
58
+ text('Tong · Cambridge', { size: 26, color: 'dim' }),
59
+ text('Electrodynamics §§4.3–4.4', { size: 26, color: 'dim' }),
60
+ ], { gap: 4 }), new Box(410, -505, 875, -425), 'right'))
61
+
62
+ // One clock drives the spatial curves, every field vector and the observer.
63
+ s.add(dynamic((t) => {
64
+ const alpha = cutOpacity(t)
65
+ if (alpha <= 0.001) return []
66
+ const ratio = polarizationAt(t)
67
+ const view = scene3d({
68
+ theta: -1.27, phi: 1.16, unit: 92, perspective: false,
69
+ fog: 0.15, shine: 0.15,
70
+ }).at(geometryBox.cx - 15, geometryBox.cy + 9).opacity(alpha)
71
+
72
+ view.add(line3d([-5.4, 0, 0], [5.6, 0, 0], { color: 'dim', width: 1.6 }))
73
+ view.add(vector3d([5, 0, 0], [5.65, 0, 0], { color: 'yellow', width: 3.5, tip: 15, halo: false }))
74
+ // A transverse observer plane, shared with the face-on view on the right.
75
+ view.add(parametricSurface((angle, radius) => [0, radius * Math.cos(angle), radius * Math.sin(angle)],
76
+ [0, 2 * Math.PI], [0, 1.9], {
77
+ resolution: [48, 1], color: 'yellow', opacity: 0.065, shaded: false,
78
+ }))
79
+ view.add(curve3d((angle) => [0, 1.9 * Math.cos(angle), 1.9 * Math.sin(angle)], 0, 2 * Math.PI,
80
+ { color: 'yellow', width: 1.5, opacity: 0.5, samples: 80 }))
81
+
82
+ for (const [key, color] of [['e', 'blue'], ['cb', 'teal']] as const) {
83
+ view.add(parametricSurface((x, fraction) => {
84
+ const p = tip(x, wave(x, t, ratio)[key])
85
+ return [x, fraction * p[1], fraction * p[2]]
86
+ }, X_RANGE, [0, 1], {
87
+ resolution: [100, 1], color, opacity: 0.12, shaded: false,
88
+ }))
89
+ view.add(curve3d((x) => tip(x, wave(x, t, ratio)[key]), ...X_RANGE,
90
+ { color, width: 4.4, glow: 3, samples: 180 }))
91
+ for (let i = 0; i <= 20; i++) {
92
+ const x = -5 + i / 2
93
+ const field = wave(x, t, ratio)[key]
94
+ if (Math.hypot(...field) < 0.07) continue
95
+ view.add(vector3d([x, 0, 0], tip(x, field), {
96
+ color, width: x === 0 ? 4.5 : 1.7, tip: x === 0 ? 17 : 8,
97
+ halo: false,
98
+ }).opacity(x === 0 ? 1 : 0.52))
99
+ }
100
+ view.add(point3d(tip(0, wave(0, t, ratio)[key]), { color, radius: 6, halo: 1.5, onTop: true }))
101
+ }
102
+ if (t >= 34) {
103
+ for (const x of [-3.6, -1.2, 1.2, 3.6]) {
104
+ const { e, cb } = wave(x, t, ratio)
105
+ const energy = cross(e, cb)[0]
106
+ view.add(vector3d([x, 0, 0], [x + energy, 0, 0], {
107
+ color: 'yellow', width: 5, tip: 17, onTop: true, halo: false,
108
+ }).opacity(Math.min(1, (t - 34) / 0.5)))
109
+ }
110
+ }
111
+ return view
112
+ }))
113
+
114
+ s.add(dynamic((t) => {
115
+ const alpha = cutOpacity(t)
116
+ if (alpha <= 0.001) return []
117
+ const ratio = polarizationAt(t)
118
+ const { e, cb } = wave(0, t, ratio)
119
+ // Camera on +x: +y is screen-right, +z is up, and +x points at the viewer.
120
+ const view = scene3d({ theta: 0, phi: Math.PI / 2, unit: 91, perspective: false, fog: 0 })
121
+ .at(observerGeometry.cx, observerGeometry.cy).opacity(alpha)
122
+ view.add(line3d([0, -1.85, 0], [0, 1.85, 0], { color: 'faint', width: 1.5 }))
123
+ view.add(line3d([0, 0, -1.85], [0, 0, 1.85], { color: 'faint', width: 1.5 }))
124
+ view.add(label3d('+y', [0, 2.15, 0], { size: 28, color: 'dim' }))
125
+ view.add(label3d('+z', [0, 0, 2.1], { size: 28, color: 'dim' }))
126
+ view.add(curve3d((phase) => [0, FIELD_SCALE * ratio * Math.sin(phase), FIELD_SCALE * Math.cos(phase)],
127
+ 0, 2 * Math.PI, { color: 'blue', width: 2, opacity: 0.45, samples: 100 }))
128
+ if (ratio > 0) view.add(curve3d((past) => tip(0, wave(0, t - past, ratio).e), 0, 0.65,
129
+ { color: 'blue', width: 4, glow: 3, opacity: 0.8, samples: 32 }))
130
+ for (const [field, color] of [[e, 'blue'], [cb, 'teal']] as const) {
131
+ if (Math.hypot(...field) > 0.04) view.add(vector3d([0, 0, 0], tip(0, field), {
132
+ color, width: 5, tip: 18, halo: false,
133
+ }))
134
+ view.add(point3d(tip(0, field), { color, radius: 6, halo: 1.2 }))
135
+ }
136
+ view.add(point3d([0, 0, 0], { color: 'yellow', radius: 4, onTop: true }))
137
+ return view
138
+ }))
139
+
140
+ const chapters = [
141
+ {
142
+ start: 0, end: 8, title: '01 / One wave, two fields',
143
+ equations: ['\\nabla\\times\\mathbf E=-\\partial_t\\mathbf B', '\\nabla\\times\\mathbf B=\\partial_t\\mathbf E'],
144
+ note: 'Maxwell’s curl equations, together. c = 1',
145
+ observer: ['Same place.', 'Same instant.'],
146
+ captions: ['Two fields travel together.', 'Maxwell links their curls.'],
147
+ },
148
+ {
149
+ start: 8, end: 16, title: '02 / Linear polarization',
150
+ equations: ['E_z=\\cos\\psi,\\quad E_y=0', '\\psi=kx-\\omega t,\\quad\\omega=ck'],
151
+ note: 'One phase carries both fields along +x.',
152
+ observer: ['A line of electric tips.', 'The field reverses.'],
153
+ captions: ['Linear: a fixed direction.', 'E and B reverse together.'],
154
+ },
155
+ {
156
+ start: 16, end: 25, title: '03 / Elliptical polarization',
157
+ equations: ['E_z=\\cos\\psi,\\quad E_y=\\tfrac12\\sin\\psi', 'c\\mathbf B=\\hat{\\mathbf x}\\times\\mathbf E'],
158
+ note: 'Electric components: 2:1 amplitudes, 90° phase offset.',
159
+ observer: ['An ellipse of tips.', 'The direction turns.'],
160
+ captions: ['A new wave: elliptical.', 'Electric components 90° apart.'],
161
+ },
162
+ {
163
+ start: 25, end: 34, title: '04 / Circular polarization',
164
+ equations: ['E_z=\\cos\\psi,\\quad E_y=\\sin\\psi', 'c\\mathbf B=\\hat{\\mathbf x}\\times\\mathbf E'],
165
+ note: 'Equal electric amplitudes, the same 90° phase offset.',
166
+ observer: ['A circle of tips.', 'Constant magnitude.'],
167
+ captions: ['Equal electric amplitudes.', 'Circular: constant magnitude.'],
168
+ },
169
+ {
170
+ start: 34, end: DURATION, title: '05 / Energy moves forward',
171
+ equations: ['\\mathbf S=\\tfrac{1}{\\mu_0}\\mathbf E\\times\\mathbf B', '\\mathbf S=\\tfrac{|\\mathbf E|^2}{\\mu_0c}\\,\\hat{\\mathbf x}'],
172
+ note: 'The Poynting vector follows +x. Circular: constant flux.',
173
+ observer: ['E × B points at you.', 'Along +x.'],
174
+ captions: ['E × B gives the energy flow.', 'Energy travels along +x.'],
175
+ },
176
+ ]
177
+
178
+ for (const chapter of chapters) {
179
+ const title = place(text(chapter.title, { size: 38, weight: 600 }), chapterBox, 'left')
180
+ const formula = place(column([
181
+ row(chapter.equations.map((equation) => tex(equation, { size: 36 })), { gap: 48 }),
182
+ text(chapter.note, { size: 29, color: 'dim' }),
183
+ ], { gap: 20 }), waveMath, 'left')
184
+ const observation = place(column(chapter.observer.map((line) => text(line, { size: 32 })), { gap: 10 }), observerMath)
185
+ const sceneText = [title, ...formula.nodes, ...observation.nodes]
186
+ s.at(chapter.start, () => {
187
+ s.chapter(chapter.title.slice(6).trim())
188
+ s.play(fadeIn(sceneText, { duration: 0.25 }))
189
+ })
190
+ chapter.captions.forEach((caption, i) => {
191
+ const duration = (chapter.end - chapter.start) / chapter.captions.length
192
+ s.at(chapter.start + i * duration, () => s.caption(caption, duration))
193
+ })
194
+ if (chapter.end < DURATION) s.at(chapter.end - 0.22, () => s.play(fadeOut(sceneText, { duration: 0.18 })))
195
+ }
196
+ s.wait(Math.max(0, DURATION - s.time))
197
+ })
@@ -0,0 +1,85 @@
1
+ /**
2
+ * A time-dependent uniform flow has straight instantaneous streamlines and curved
3
+ * particle histories. Definitions: MIT Unified Engineering, Fluids Lecture 8.
4
+ * https://web.mit.edu/16.unified/www/FALL/fluids/Lectures/f08.pdf
5
+ */
6
+ import {
7
+ Node, arrow, assertEqual, axes, beside, column, dot, dynamic, film, integrateTrajectory,
8
+ linear, parametric, place, sceneKit, tex, text,
9
+ } from 'vizmatic/stage'
10
+
11
+ const END = 2 * Math.PI
12
+ const STEP = 0.01
13
+ const velocity = (time: number, _state: readonly number[]) => [1, Math.sin(time)]
14
+ const orbit = integrateTrajectory(velocity, { initial: [-3, 0], to: END, step: STEP })
15
+ for (const time of [0, 0.83, Math.PI, END]) {
16
+ const [x, y] = orbit.sample(time)
17
+ assertEqual(Math.hypot(x - (-3 + time), y - (1 - Math.cos(time))) < 1e-8, true, 'the pathline agrees with its exact solution')
18
+ }
19
+
20
+ export default film({
21
+ title: 'A flow changes. A particle remembers.',
22
+ description: 'A particle follows the time-dependent velocity (1, sin t). Its curved pathline differs from a straight instantaneous streamline. The RK4 trajectory is checked against the exact solution.',
23
+ font: 'text-serif', fps: 60, poster: 14, bloom: 0.08,
24
+ }, (s) => {
25
+ const kit = sceneKit({ size: 36, heading: { size: 64, y: -465 }, source: { size: 27, y: -405 }, area: { left: -860, right: 860, top: -325, bottom: 350 } })
26
+ s.add(kit.heading('A flow changes. A particle remembers.'))
27
+ s.add(kit.source('Illustrative flow · dimensionless time · MIT Unified Engineering, Fluids Lecture 8'))
28
+ const [picture, side] = kit.area.columns([2.25, 1], 80)
29
+ const [plotBox, legendBox] = picture.rows([0.85, 0.15], 28)
30
+ const [equationBox, definitionBox, readoutBox] = side.rows([0.3, 0.48, 0.22], 30)
31
+ const ax = axes({ x: [-3.5, 3.5], y: [-1, 3], width: plotBox.width - 80, height: plotBox.height - 70, xStep: 1, yStep: 1, grid: true, labels: false, tips: false })
32
+ place(ax, plotBox)
33
+ const now = s.value(0)
34
+ const diagram = new Node().add(ax,
35
+ beside(tex('x', { size: 28, color: 'dim' }), ax.world(3.5, 0), 'right', 16),
36
+ beside(tex('y', { size: 28, color: 'dim' }), ax.world(0, 3), 'above', 16))
37
+ ax.add(dynamic(() => {
38
+ const time = now.value, state = orbit.sample(time)
39
+ const [x, y] = state, slope = velocity(time, state)[1]
40
+ const out: Node[] = []
41
+ // The field arrows show velocity now; they do not slide along frozen streamlines.
42
+ for (let gx = -3; gx <= 3; gx++) for (let gy = -0.5; gy <= 2.5; gy += 0.75) {
43
+ out.push(arrow(ax.p(gx, gy), ax.p(gx + 0.35, gy + slope * 0.35), { stroke: 'dim', width: 1.8, tip: 8 }).opacity(0.38))
44
+ }
45
+ const frozen = ax.plotPath((sx) => y + slope * (sx - x), { adaptive: true, samples: 2 })
46
+ out.push(new Node(frozen).stroke('blue', 3).dash([10, 8]))
47
+ if (time > 0) out.push(parametric((t) => {
48
+ const [px, py] = orbit.sample(t)
49
+ return ax.p(px, py)
50
+ }, 0, time, { adaptive: { tolerance: 0.5, maxSamples: 1024 }, stroke: 'yellow', width: 5 }))
51
+ out.push(dot(9, 'yellow').at(ax.p(x, y)).glow(7))
52
+ return out
53
+ }))
54
+ s.add(diagram)
55
+ s.add(place(column([
56
+ text('Dashed blue: a streamline now', { size: 30, color: 'blue' }),
57
+ text('Solid yellow: the particle’s pathline', { size: 30, color: 'yellow' }),
58
+ ], { gap: 12, align: 'left' }), legendBox, 'left'))
59
+ s.add(place(column([
60
+ tex('\\mathbf u(x,y,t)=(1,\\sin t)', { size: 38 }),
61
+ text('The velocity turns with time.', { size: 30, color: 'dim' }),
62
+ ], { gap: 22, align: 'left' }), equationBox, 'left'))
63
+ s.add(place(column([
64
+ text('One instant', { size: 36, color: 'blue', weight: 600 }),
65
+ text('A streamline is tangent to the velocity field at one fixed time.', { size: 30, maxWidth: side.width, leading: 1.25 }),
66
+ text('One particle', { size: 36, color: 'yellow', weight: 600 }),
67
+ text('A pathline records its motion as the velocity changes.', { size: 30, maxWidth: side.width, leading: 1.25 }),
68
+ ], { gap: 18, align: 'left' }), definitionBox, 'left'))
69
+ s.add(dynamic(() => place(column([
70
+ text(`t = ${now.value.toFixed(2)}`, { size: 36, font: 'mono' }),
71
+ tex('x=-3+t,\\quad y=1-\\cos t', { size: 29, color: 'dim' }),
72
+ ], { gap: 16, align: 'left' }), readoutBox, 'left').nodes))
73
+
74
+ s.chapter('One instant')
75
+ s.caption('The dashed line is tangent to the velocity at this instant. The yellow dot is one particle.', 6)
76
+ s.wait(2)
77
+ s.chapter('A changing field')
78
+ s.caption('The velocity changes with time. The particle integrates that changing velocity and leaves a curved path.', 10)
79
+ s.play(now.to(Math.PI, { ease: linear }), { duration: 10 })
80
+ s.wait(1)
81
+ s.chapter('A particle history')
82
+ s.caption('The streamline turns again. The pathline keeps the history of where this particle has been.', 12)
83
+ s.play(now.to(END, { ease: linear }), { duration: 10 })
84
+ s.wait(3)
85
+ })