blockyard 0.0.9 → 0.1.1

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 (97) hide show
  1. package/CHANGELOG.md +359 -1
  2. package/README.md +48 -27
  3. package/SECURITY.md +2 -2
  4. package/bin/blockyard.js +2 -1
  5. package/docs/API.md +17 -15
  6. package/docs/ARCHITECTURE.md +128 -10
  7. package/docs/CONFIGURATION.md +39 -30
  8. package/docs/DEFECTS.md +4 -1
  9. package/docs/GETTING-STARTED.md +18 -8
  10. package/docs/INSTALL.md +97 -37
  11. package/docs/MEASUREMENTS.md +147 -0
  12. package/docs/PLAN-SCORCHED-YARD.md +456 -0
  13. package/docs/PLAN-SKIES.md +142 -0
  14. package/docs/SECURITY-AUDIT-2026-09-16.md +647 -0
  15. package/docs/SECURITY.md +58 -22
  16. package/docs/TROUBLESHOOTING.md +44 -5
  17. package/docs/USER-GUIDE.md +505 -35
  18. package/package.json +4 -2
  19. package/public/404.html +1 -1
  20. package/public/css/app.css +393 -82
  21. package/public/donate-qr.png +0 -0
  22. package/public/index.html +353 -109
  23. package/public/js/agents.js +228 -51
  24. package/public/js/app.js +131 -16
  25. package/public/js/blockanoid.js +15 -7
  26. package/public/js/blockout.js +15 -7
  27. package/public/js/blockscene3d.js +230 -38
  28. package/public/js/charts.js +21 -21
  29. package/public/js/depthchart.js +31 -27
  30. package/public/js/details3d.js +1481 -73
  31. package/public/js/doom.js +31 -0
  32. package/public/js/dosaudio.js +48 -0
  33. package/public/js/dosgame.js +389 -0
  34. package/public/js/dosio.js +186 -0
  35. package/public/js/dospc.js +1353 -0
  36. package/public/js/dosworker.js +196 -0
  37. package/public/js/explorer.js +7 -1
  38. package/public/js/livingsky.js +494 -0
  39. package/public/js/login.js +8 -2
  40. package/public/js/markets.js +46 -8
  41. package/public/js/mining.js +314 -36
  42. package/public/js/panels.js +41 -28
  43. package/public/js/pricechart.js +14 -13
  44. package/public/js/quake.js +20 -0
  45. package/public/js/safenext.js +14 -0
  46. package/public/js/scorched.js +1051 -0
  47. package/public/js/scorchedai.js +227 -0
  48. package/public/js/scorchedair.js +286 -0
  49. package/public/js/scorchedfx.js +376 -0
  50. package/public/js/scorchedshop.js +105 -0
  51. package/public/js/scorchedwind.js +69 -0
  52. package/public/js/scorchedyard.js +1338 -0
  53. package/public/js/settings.js +368 -100
  54. package/public/js/soundcard.js +459 -0
  55. package/public/js/tetrust.js +15 -6
  56. package/public/js/tetsound.js +35 -5
  57. package/public/js/theme.js +235 -0
  58. package/public/js/wolf3d.js +22 -0
  59. package/public/js/x86.js +1978 -0
  60. package/scripts/check.js +46 -0
  61. package/scripts/donate-qr.py +12 -9
  62. package/scripts/dos-bench.js +56 -0
  63. package/scripts/index-build.js +9 -2
  64. package/scripts/pool-map.js +152 -36
  65. package/scripts/setup.js +142 -22
  66. package/scripts/shots.mjs +27 -0
  67. package/scripts/smoke.sh +7 -6
  68. package/scripts/tls.js +31 -0
  69. package/scripts/ui.js +4 -2
  70. package/server/auth/sessions.js +33 -13
  71. package/server/chain/blockfile.js +64 -5
  72. package/server/chain/index/build.js +451 -58
  73. package/server/chain/index/heights.js +29 -3
  74. package/server/chain/index/live.js +13 -7
  75. package/server/chain/index/rows.js +6 -1
  76. package/server/chain/index/store.js +28 -5
  77. package/server/chain/index/worker.js +23 -11
  78. package/server/collect/logparse.js +65 -18
  79. package/server/collect/markets.js +76 -7
  80. package/server/collect/mining.js +32 -0
  81. package/server/collect/monitor.js +54 -12
  82. package/server/collect/network.js +305 -0
  83. package/server/config.js +53 -22
  84. package/server/http/api.js +119 -18
  85. package/server/http/games.js +77 -0
  86. package/server/http/server.js +30 -5
  87. package/server/http/sse.js +53 -7
  88. package/server/main.js +66 -11
  89. package/server/rpc/allowlist.js +26 -0
  90. package/server/rpc/client.js +30 -2
  91. package/server/store/audit.js +6 -1
  92. package/server/store/history.js +19 -3
  93. package/server/store/ledger.js +15 -4
  94. package/server/tls/selfsigned.js +160 -0
  95. package/systemd/blockyard.service +41 -8
  96. package/docs/PRIVATE-LEADERBOARD.md +0 -230
  97. package/docs/STATE-2026-09-09.md +0 -200
@@ -14,11 +14,12 @@
14
14
  // 3. Zero dependencies, no CDN.
15
15
 
16
16
  import { packBlock, packExact, vbytesPerUnit, vsizeForSide } from './blockpack.js';
17
- import { planTransition, frameAt, fitToBox, project, fxFront, TRANSITION, SLAB_H, TILE_H, surfaceNormal, cellTops } from './blockscene3d.js';
17
+ import { planTransition, frameAt, fitToBox, project, fxFront, TRANSITION, SLAB_H, TILE_H, surfaceNormal, cellTops, fxHash } from './blockscene3d.js';
18
18
  // THE AGENTS (agents.js): the effects that are something happening rather than a pattern.
19
19
  // This module keeps three seams and nothing else -- build here in startFx, frame in fxNow,
20
20
  // draw in paintFrame -- so fifty agents do not become fifty `if`s in the renderer.
21
- import { AGENTS, isAgent, rng } from './agents.js';
21
+ import { AGENTS, isAgent, rng, lensFlare, saucerAbove } from './agents.js';
22
+ import { drawLivingSky } from './livingsky.js';
22
23
 
23
24
  const STATE = new WeakMap();
24
25
 
@@ -145,10 +146,14 @@ function sizeCanvas(canvas, maxDpr = Infinity) {
145
146
  // and one toggle in settings.js (the `effects` and `marketEffects` groups), and the lists are checked against each other
146
147
  // by a test, so an effect cannot ship without a switch or a switch without an effect.
147
148
  const FX_MS = {
148
- ripple: 5200, outline: 4400, tide: 5200, cascade: 5600, twinkle: 3800, scan: 4200,
149
+ ripple: 5200, outline: 4400, tide: 5200, cascade: 5600, twinkle: 3800, scan: 16800, // 8400 -> 16800: top-down it pans OUT AND BACK, so two traversals at the same unhurried speed // scan 4200 -> 6000 -> 8400: the sweep now starts and ends off-panel, so the span grew and the duration follows it (below)
150
+ xray: 6500, // the board goes x-ray behind a sweeping front, and develops back
149
151
  lightcycle: 6500, ball: 5600, pulse: 9000, // pulse 7000 -> 9000 (2026-09-14: "make it a bit slower")
150
152
  bulge: 16000, // a sphere rolling through the price line; half speed (was 8000)
151
- shockwave: 4200, nova: 5200, firework: 5600, flare: 3600, wave: 6000, quake: 3200,
153
+ breathe: 9000, // the price line breathes: three slow swells between the wire and the pulse's heat
154
+ saber: 8000, // the price line ignites as a light saber, hums, and retracts
155
+ blackhole: 26000, // the chart collapses into a black hole and is let go again
156
+ shockwave: 4200, nova: 5200, firework: 5600, flare: 16000, wave: 6000, quake: 3200, // flare 3600 -> 8000 -> 16000 (2026-09-15: it is a supernova now, and the cloud disperses slowly)
152
157
  rain: 6400, sparkle: 4600, checker: 4400, radar: 6000, vortex: 6400, powerup: 5000, combo: 4800, aurora: 7200, plasma: 6400,
153
158
  // THE AGENTS (agents.js): effects that are a thing MOVING rather than a pattern over the board.
154
159
  // Longer than the fields, because something that travels needs time to be watched -- a field
@@ -162,10 +167,38 @@ const FX_MS = {
162
167
  // stormball replaced portal (2026-09-14); slow on purpose -- it drifts across the whole view
163
168
  boulderdash: 6400, stormball: 11000,};
164
169
  export const FX_KINDS = Object.keys(FX_MS);
170
+ // the price board's own lengths, where they differ: ball lightning crosses it at a third of the
171
+ // block board's speed -- 11 s there; a third slower (16.5 s, operator 2026-09-15: "cut the speed
172
+ // by 33% now that it's slower"), then 40% slower again (27.5 s: "Slow it down movement by 40%")
173
+ // THE DURATION FOLLOWS THE SPAN, or widening the travel speeds up the picture (operator,
174
+ // 2026-09-15: "why does it transit the market view so quick? I didn't ask for that"). When the
175
+ // sweep was made to start and end beyond the panel, the distance grew but the clock did not, so
176
+ // the part you actually watch -- the crossing of the board -- got 1.52x faster on Markets and
177
+ // 1.40x on Block space. These restore the crossing to the speed it had: measured, 9145 ms and
178
+ // 8400 ms for the two boards. Markets needs the longer one because its panel is wide and its board
179
+ // is shallow, so proportionally more of the journey happens off-screen.
180
+ // ...and then slower still on Markets (operator, 2026-09-15: "It's still way too fast on the
181
+ // markets display. Slow it down at least 50%"). 9150 restored the pacing the effect had BEFORE the
182
+ // travel change, which turns out not to have been slow enough either -- restoring a speed is not
183
+ // the same as it being right. 14600 makes the on-screen crossing 8451 ms against 5297, i.e. 60%
184
+ // slower, which clears the "at least 50%" asked for.
185
+ // AN EFFECT'S SIZE ON A SMALL BOARD (2026-09-15, the Kiosk): a radius in grid units, capped at a
186
+ // share of the board's width, so the same effect on a small panel never covers it
187
+ export function boundedRadius(units, share, gridW) { return Math.min(units, share * gridW); }
188
+ // effects that read as the same thing: never one right after the other
189
+ const FX_KIN = { scan: ['tractor'], tractor: ['scan'] };
190
+ export const MARKET_MS = { stormball: 27500, firework: 14000, flare: 24000, scan: 29200 }; // and a fireworks display of five shells, each with its smoke, needs the time
165
191
  // The longest a refresh will ever wait for an effect to finish, plus a second of slack. Taken from
166
192
  // the table rather than written as a number, so culling or adding an effect cannot leave the cap
167
193
  // shorter than the effect it is meant to outlast. See the deferral in render3d.
168
194
  const FX_DEFER_MAX = Math.max(...Object.values(FX_MS)) + 1000;
195
+ // A BREATH BETWEEN AN EFFECT AND THE REFRESH IT HELD BACK (operator, 2026-09-15, of the black
196
+ // hole: "snapping into place on last frame to drop in"): the parked layout took the stage on the
197
+ // very frame the effect ended, so the board's cubes were seen arriving home and, in the same
198
+ // instant, lifting off for the refresh -- one motion read as the other's last frame. The layout
199
+ // now waits a moment and a half after the effect, with the board whole and still
200
+ const FX_REST_MS = 1500;
201
+ const fxResting = (st, t) => st.fxEndedAt != null && t - st.fxEndedAt < FX_REST_MS;
169
202
  // THE PULSE RIDES THE PRICE LINE (operator, 2026-09-12: "the energy pulse effect needs to run
170
203
  // across the yellow line, not through space on an invisible grid ... travel the yellow line from
171
204
  // one end to the other leaving a electric blue tint on the yellow line that starts fading back to
@@ -209,9 +242,12 @@ const hash01 = (n) => { const x = Math.sin(n * 12.9898) * 43758.5453; return x -
209
242
  // where they stand (cascade, twinkle, the flare), or is the price line's own (pulse, bulge, ball
210
243
  // lightning). The rest -- riders and walkers, the field patterns, anything that falls down the
211
244
  // depth or turns in place, anything that moves a tile -- stays on the block board.
212
- const ON_CANDLES = new Set(['ripple', 'outline', 'tide', 'cascade', 'twinkle', 'scan', 'pulse', 'bulge', 'firework', 'flare', 'wave', 'stormball']);
245
+ const ON_CANDLES = new Set(['ripple', 'outline', 'tide', 'cascade', 'twinkle', 'scan', 'xray', 'pulse', 'bulge', 'breathe', 'saber', 'blackhole', 'firework', 'flare', 'wave', 'stormball']);
213
246
  // effects that are drawn on the price line and nowhere else: never offered to a board of blocks
214
- const LINE_ONLY = new Set(['pulse', 'bulge']);
247
+ // the black hole is back on the price board only (operator, 2026-09-15, after a day of it hovering
248
+ // over the block board: "still snapping into place. Just remove the black hole effect from block
249
+ // space if you can't fix it")
250
+ const LINE_ONLY = new Set(['pulse', 'bulge', 'breathe', 'saber', 'blackhole']);
215
251
  // EACH BOARD ITS OWN LIST (operator, 2026-09-14: "I want the markets tab to have a separate effects
216
252
  // list ... the Block Space effects specific to that panel, and settings specific to market panel"):
217
253
  // settings.js keeps one group of switches per list (`effects` for the block board, `marketEffects`
@@ -258,7 +294,7 @@ function startFx(st, kind, now) {
258
294
  const tiles = st.restTiles || [];
259
295
  agent = spec.build({ st, seed, W, H, tiles, tops: cellTops(tiles, W, H), rnd: rng(seed) });
260
296
  }
261
- st.fx = { kind, t0: now, ms: FX_MS[kind] ?? 4500, x: origin.x, y: origin.y, dx: d[0], dy: d[1], rank, seed, agent,
297
+ st.fx = { kind, t0: now, ms: (onPriceBoard(st) ? MARKET_MS[kind] : null) ?? FX_MS[kind] ?? 4500, x: origin.x, y: origin.y, dx: d[0], dy: d[1], rank, seed, agent,
262
298
  // `paths`/`crashes` stay on the record because drawCycles reads view.fx.cycles, which the
263
299
  // agent's frame() produces from them; nothing outside agents.js builds them any more.
264
300
  paths: agent?.paths ?? null, crashes: agent?.crashes ?? null };
@@ -281,6 +317,95 @@ function fxNow(st, t) {
281
317
  const reach = Math.hypot(Math.max(f.x, st.gridW - f.x), Math.max(f.y, st.gridH - f.y));
282
318
  Object.assign(out, { x: f.x, y: f.y, r: reach * (1 - Math.pow(1 - u, 2)), w: 2.2 + 2.4 * u });
283
319
  }
320
+ // THE FIREWORKS LIGHT THEIR SURROUNDINGS IN THEIR OWN COLOUR (operator, 2026-09-15: "emissive
321
+ // colored lighting illuminating the explosion area in the explosion color"): every live shell is a
322
+ // head at its burst point, in its colour, as wide as the shell has spread, fading as it dies
323
+ if (f.kind === 'firework') {
324
+ const price = (st.axes?.line?.length ?? 0) > 1;
325
+ const heads = [];
326
+ for (const sh of fireworkShells(f.seed, st.gridW, st.gridH, price, 1, price ? (st.axes?.zTop ?? 34) : 16)) {
327
+ const v = (u - sh.t0) / sh.life;
328
+ if (!(v > 0.2 && v < 1.15)) continue;
329
+ const s2 = Math.min(1, (v - 0.2) / 0.8);
330
+ const spread = 1 - Math.exp(-3.4 * s2);
331
+ heads.push({ x: sh.bx, y: sh.by, color: sh.cols[0], alpha: Math.pow(Math.max(0, 1 - s2), 1.2) * (v < 0.28 ? 1 : 0.85), r: (price ? 7 : 8) * sh.size * (0.5 + 0.9 * spread) });
332
+ }
333
+ out.heads = heads;
334
+ }
335
+ // THE BLACK HOLE (2026-09-15): where it sits on the chart, how big its horizon is this frame,
336
+ // and -- through a head that HIDES -- which candles it has swallowed; the tiles near it glow the
337
+ // disk's orange. Everything the renderer needs rides on `out.blackhole`.
338
+ if (f.kind === 'blackhole' && st.axes?.line?.length > 1) {
339
+ const line = st.axes.line;
340
+ // IT CROSSES (operator, 2026-09-15: "get the black hole effect on the market display to slowly
341
+ // move from one side to the other"): from a fifth of the way in on one side to a fifth from
342
+ // the other, the way the front effects go (f.dx), easing in and out so it is still while it
343
+ // opens and while it closes; the candles' orbits ride along with it
344
+ // ...AND IT STOPS BEFORE IT LETS GO (operator, 2026-09-15: "the front faces of the lowest
345
+ // blocks just snap into place instead of dropping"): the crossing ran to 0.9 while the release
346
+ // began at 0.82, so a cube was let go not by the release curve but by the hole moving out of
347
+ // reach of it -- dropped in a few frames as the hole passed. The crossing is done by 0.8 now,
348
+ // and the release is the only thing that lets anything go
349
+ const travel = u < 0.1 ? 0 : u > 0.8 ? 1 : (() => { const t = (u - 0.1) / 0.7; return t * t * (3 - 2 * t); })();
350
+ const dir = (f.dx || 0) !== 0 ? Math.sign(f.dx) : hash01(f.seed + 5) < 0.5 ? 1 : -1;
351
+ const xa = st.gridW * (dir > 0 ? 0.18 : 0.82), xb = st.gridW * (dir > 0 ? 0.82 : 0.18);
352
+ const hx = xa + (xb - xa) * travel;
353
+ let hy, hz, lo = 0, hi = 0;
354
+ if (line) {
355
+ // THROUGH SPACE, NOT ALONG THE LINE (operator, 2026-09-15: "I don't want the black hole
356
+ // moving along the yellow line. I want it moving through space from point A to point B, and
357
+ // have everything warp around it ... riding the line hides that amazing effect"): a straight
358
+ // run from one height to another, both drawn from the seed inside the line's own range, so
359
+ // the hole crosses the line's path rather than sitting on it and the line is seen bending
360
+ // round the shadow as it passes
361
+ lo = Infinity; hi = -Infinity; for (const p of line) { lo = Math.min(lo, p.z); hi = Math.max(hi, p.z); }
362
+ const R = Math.max(1, hi - lo);
363
+ const za = lo + R * (0.15 + 0.85 * hash01(f.seed + 6)), zb = lo + R * (0.15 + 0.85 * hash01(f.seed + 7));
364
+ hz = za + (zb - za) * travel;
365
+ hy = st.axes.y ?? st.gridH / 2;
366
+ }
367
+ // ...AND ALL THE WAY HOME BEFORE THE END (operator, 2026-09-15: "still snapping into place on
368
+ // last frame to drop in"): the release curve reached zero only at u = 1, so on the last frame
369
+ // a cube was still a few pixels off home at nine tenths size, and the effect's end put it
370
+ // there in one step. It is a smoothstep now, done by 0.97 -- zero speed as it arrives -- and
371
+ // the last three hundredths draw nothing at all
372
+ const growIn = u < 0.22 ? Math.pow(u / 0.22, 1.6) : 1;
373
+ const growOut = u <= 0.82 ? 1 : u >= 0.97 ? 0 : (() => { const t = 1 - (u - 0.82) / 0.15; return t * t * (3 - 2 * t); })();
374
+ const grow = growIn * growOut;
375
+ const rs = boundedRadius(2.3, 0.047, st.gridW) * grow; // the horizon, in grid units (4.8 on 2026-09-15 -- "double the size" -- then 3.4: "obscuring too much" -- then 2.3: "shrink up the black hole by 33%"), and never more than 4.7% of the board
376
+ out.blackhole = { x: hx, y: hy, z: hz, rs, grow, lo, hi };
377
+ // SWALLOWED SMOOTHLY (operator, 2026-09-15: "the candles just blinking out of existence looks
378
+ // bad"): not `hide`, which is a threshold, but `scale: 0`, which fxAt applies by reach -- a
379
+ // candle shrinks toward nothing as it nears the horizon and grows back as the hole recedes
380
+ const reach = 1.5;
381
+ // LIFTED OUT WHOLE, NOT SHEARED, on the block board (operator, 2026-09-15: "too much bad
382
+ // shearing of the blocks around the black hole on the block space page. instead of stretching,
383
+ // can it just lift the blocks out?"): no corner lean there (lean 0 -- buildScene's orbit
384
+ // carries the cube toward the hole as one piece, its own shape, and it shrinks away into it).
385
+ // Not `lift` either: that extrudes a cube into a column from the floor, which read as an even
386
+ // longer stretch
387
+ // ...and `shrink` on the block board: the scale alone flattens a cube into a plate (it is a
388
+ // height override), and a plate sliding toward the hole was the "shearing"; shrunk in
389
+ // footprint as well it stays a cube, a smaller one, all the way in
390
+ // LET GO SMOOTHLY (operator, 2026-09-15: "The boxes are snapping into view when they come to
391
+ // rest on the board"): the release used to come from the head's reach shrinking with the
392
+ // hole, which let go of the outer cubes gently and the ones right under it all at once in the
393
+ // last frames -- they stayed on their rings at nothing, then popped home full size. The reach
394
+ // now holds its full size through the release and `release` (growOut) fades the pull and the
395
+ // scale themselves, so every cube glides home and grows back over the whole last fifth
396
+ const R = boundedRadius(2.3, 0.047, st.gridW) * reach;
397
+ out.heads = grow > 0.02 ? [{ x: hx, y: hy, z: hz, color: [255, 160, 60], alpha: grow, r: R * growIn, rPeak: R, scale: 0, pull: 1, release: growOut, lean: line ? 1 : 0, shrink: !line }] : [];
398
+ }
399
+ // THE PULSE LIGHTS WHAT IT PASSES (operator, 2026-09-15: "interfering with the affected areas"):
400
+ // its head is a light on the board, so the candles under it glow warm as it goes by (fxAt's
401
+ // heads branch, as the agents do)
402
+ if (f.kind === 'pulse' && st.axes?.line?.length > 1) {
403
+ const line = st.axes.line, headAt = u / PULSE_TRAVEL;
404
+ const k = Math.max(0, Math.min(1, headAt)) * (line.length - 1), i = Math.min(line.length - 2, Math.floor(k)), fr = k - i;
405
+ const x = line[i].x + (line[i + 1].x - line[i].x) * fr;
406
+ const fade = headAt <= 1 ? 1 : Math.max(0, 1 - (headAt - 1) / 0.34);
407
+ out.heads = [{ x, y: st.axes.y ?? st.gridH / 2, color: [255, 225, 150], alpha: fade, r: 3.2 }];
408
+ }
284
409
  // AN AGENT'S FRAME comes from its own spec (agents.js). Everything it publishes lands on the
285
410
  // frame object: `heads` (how it lights the cubes -- fxAt's heads branch), plus whatever its
286
411
  // draw reads, such as `cycles` for the light walls or `ball` for the plasma ball.
@@ -312,7 +437,18 @@ export function chooseIdleFx(kinds, st, now, rnd = Math.random, noRepeat = 12) {
312
437
  if (!kinds.length) return null;
313
438
  const recent = st.recentFx ?? (st.recentFx = []);
314
439
  const window = Math.max(0, Math.min(Math.floor(noRepeat), kinds.length - 1));
315
- const blocked = new Set(recent.slice(recent.length - window));
440
+ // FROM THE START, NOT FROM THE END (operator, 2026-09-15: "I keep seeing the same effect being
441
+ // played before new ones"). This was `recent.slice(recent.length - window)`, and while fewer
442
+ // effects had played than the window is wide that index was negative -- which slice counts from
443
+ // the END: nine plays under a window of eleven blocked only the last two. The rule was weakest
444
+ // right after the page opened, which is exactly when anyone is watching. Measured before the
445
+ // fix on the Markets list: a repeat at the tenth pick; after it: every effect plays once before
446
+ // any comes round again.
447
+ const blocked = new Set(recent.slice(Math.max(0, recent.length - window)));
448
+ // KINDS THAT LOOK ALIKE SHARE THE WINDOW (operator, 2026-09-15: "I just saw the UFO effect get
449
+ // triggered twice in a row on the block space" -- the scan's searchlight and the tractor beam
450
+ // fly the same saucer, so one after the other read as a repeat though the rule saw two kinds)
451
+ for (const k of [...blocked]) for (const kin of FX_KIN[k] ?? []) blocked.add(kin);
316
452
  let pool = kinds.filter((k) => !blocked.has(k));
317
453
  if (!pool.length) {
318
454
  // every kind is inside the window: the ones played least recently
@@ -757,6 +893,1003 @@ function chargeTrail(ctx, segs, lw, now, seedBase = 0, pale = false) {
757
893
  ctx.lineWidth = lw;
758
894
  }
759
895
 
896
+ // A FIREWORKS DISPLAY (operator, 2026-09-15: "the fireworks effect doesn't work at all on the
897
+ // market screen", then "Make the fireworks much more impressive with further effects. Make them
898
+ // Arc. instead of just going straight up. Add the nebula smoke effect that fades out as it
899
+ // disperses ... Make a visually stunning fireworks display for the markets page"). The effect
900
+ // only ever LIT tiles -- fxAt's ring over the cubes was the picture on the block board, and on
901
+ // eight rows of candles it was a candle blinking. Every shell is drawn now, on both boards:
902
+ // * the LAUNCH is an arc, not a line: the rocket leaves the floor to one side and climbs a
903
+ // parabola to its burst point, a comet with a glowing tail and exhaust sparks falling behind;
904
+ // * the BURST is a white flash and a shockwave ring racing out and thinning;
905
+ // * the SHELL is one of four kinds by turn -- peony (round, two colours), chrysanthemum (long
906
+ // glittering trails that crackle white late), willow (heavy droop under gravity, long
907
+ // trails), ring (a hoop that keeps its shape as it falls) -- sixty to ninety sparks, each a
908
+ // curved trail of the last few positions, slowing and pulled down, twinkling, fading;
909
+ // * the SMOKE is a nebula: soft gradient blobs that leave the burst outward, growing, drifting
910
+ // up, in the shell's colour gone grey, and fade as they disperse -- on after the sparks;
911
+ // * up to ten shells on the price board, five on the block board (fireworkShells), overlapping,
912
+ // of every size, at every height of the picture, each lighting the candles under it in its
913
+ // own colour. Deterministic in fx.seed, as every effect is, so it replays and can be tested;
914
+ // only the twinkle reads the clock.
915
+ const SHELL_COLS = [[[255, 170, 110], [255, 235, 160]], [[140, 220, 255], [220, 245, 255]], [[220, 160, 255], [255, 200, 240]], [[130, 255, 190], [235, 255, 220]], [[255, 120, 150], [255, 210, 120]], [[255, 215, 90], [255, 250, 210]], [[120, 200, 255], [255, 140, 200]]];
916
+
917
+ // THE SHELLS OF A DISPLAY, from the seed: where and when each bursts, how big, what kind, what
918
+ // colour. Shared by the drawing (drawFireworks) and the lighting (fxNow's heads), so the candles
919
+ // glow in a shell's own colour exactly where and when it bursts. Up to ten on the price board
920
+ // (operator, 2026-09-15: "have more than 1 firework going off at a time. 10 max. Vary the size ...
921
+ // vary the height. Use the entire vertical viewport"), five on the block board; each launches at
922
+ // its own moment in the first half of the run and lives long enough to overlap the next.
923
+ export const FIREWORK_KINDS = ['peony', 'chrysanthemum', 'willow', 'ring', 'crossette', 'strobe']; // no pinwheel: sparks fly straight (2026-09-15)
924
+ export function fireworkShells(seed, gridW, gridH, price, zLo, zHi) {
925
+ const count = price ? 10 : 5, life = price ? 0.28 : 0.33, SMOKE = 1.35;
926
+ const out = [];
927
+ for (let i = 0; i < count; i++) {
928
+ const H = (k) => hash01(seed + i * 131 + k);
929
+ out.push({
930
+ i, life, smoke: SMOKE,
931
+ t0: 0.02 + H(0) * (price ? 0.5 : 0.4),
932
+ bx: 0.08 * gridW + H(1) * 0.84 * gridW, by: H(2) * gridH,
933
+ zc: zLo + (zHi - zLo) * (0.15 + 0.8 * H(3)),
934
+ size: 0.45 + 0.85 * H(4), // of the board's shell radius: small to big
935
+ kind: FIREWORK_KINDS[Math.floor(H(8) * FIREWORK_KINDS.length)],
936
+ cols: SHELL_COLS[Math.floor(H(9) * SHELL_COLS.length)],
937
+ drift: (H(5) < 0.5 ? -1 : 1) * (0.12 + 0.2 * H(6)) * gridW,
938
+ H,
939
+ });
940
+ }
941
+ return out;
942
+ }
943
+ // THE SHELL KINDS, by turn: how the sparks fly. (operator, 2026-09-15: "Make more varied
944
+ // explosions. More effects. Lensflare? Really think stunning to see.")
945
+ // peony round, two colours
946
+ // chrysanthemum long glittering trails that crackle white late
947
+ // willow heavy droop under gravity, the longest trails
948
+ // ring a hoop that keeps its shape as it falls
949
+ // crossette a peony whose sparks each split four ways partway out
950
+ // strobe the sparks blink in unison, white, on a beat
951
+ // pinwheel every spark curls the same way -- a spiral opening out
952
+ const SHELL_KINDS = ['peony', 'chrysanthemum', 'willow', 'ring', 'crossette', 'strobe']; // pinwheel is gone (2026-09-15: "a spiral effect ... defies physics of fireworks")
953
+ // SMOOTH BY LAYERING, NOT BY GRADIENT (operator, 2026-09-15: "gradient visible! We need smooth
954
+ // fills. no gradient shit!" -- then, of the block board: "what is still with the gradient fill
955
+ // shit?!"). createRadialGradient bands on this rasteriser: the rings are plainly visible, and
956
+ // worst on exactly the large soft blobs the effects are made of. Nested flat discs do not band --
957
+ // each is a plain rgba fill and the SUM is the curve.
958
+ //
959
+ // Takes the same `stops` a radial gradient would, so a conversion is mechanical and the colours
960
+ // are unchanged: it walks outward-in, interpolating the stop list, painting N flat rings.
961
+ export function softStops(ctx, x, y, r, stops, N = 0) {
962
+ // THE STEP MUST LAND UNDER A PIXEL, or the cure is the disease (operator, 2026-09-15: "What is
963
+ // with the gradient garbage?" -- of fills I had already converted). Twenty flat discs over a
964
+ // 300px radius is a 15px step: concentric rings, which is exactly the banding a gradient makes,
965
+ // only coarser. The layer count therefore comes from the RADIUS, not from a constant: about one
966
+ // ring per 1.2px, floored so a small sprite is not wasteful and capped so a huge nebula cannot
967
+ // cost thousands of fills.
968
+ if (!N) N = Math.max(16, Math.min(220, Math.round(Math.abs(r) / 1.2)));
969
+ const at = (t) => {
970
+ let a = stops[0], b = stops[stops.length - 1];
971
+ for (let i = 0; i < stops.length - 1; i++) if (t >= stops[i][0] && t <= stops[i + 1][0]) { a = stops[i]; b = stops[i + 1]; break; }
972
+ const span = b[0] - a[0], k = span > 1e-6 ? (t - a[0]) / span : 0;
973
+ const pa = String(a[1]).match(/rgba?\(([^)]+)\)/), pb = String(b[1]).match(/rgba?\(([^)]+)\)/);
974
+ if (!pa || !pb) return String(a[1]);
975
+ const va = pa[1].split(',').map(Number), vb = pb[1].split(',').map(Number);
976
+ const m = (i, d) => (va[i] ?? d) + (((vb[i] ?? d) - (va[i] ?? d)) * k);
977
+ return `rgba(${Math.round(m(0, 0))},${Math.round(m(1, 0))},${Math.round(m(2, 0))},${m(3, 1).toFixed(4)})`;
978
+ };
979
+ // THE DISCS ADD UP (2026-09-15: "far too much solid white" on the Kiosk -- the supernova's pool
980
+ // and glow were opaque discs). Each nested disc was painted at the stop's whole alpha, and a
981
+ // point at radius t lies under EVERY disc of radius >= t: two hundred discs at 0.08 stack to
982
+ // solid. What the caller means by a stop is the opacity of everything painted at that radius,
983
+ // so each disc carries only the INCREMENT -- painted from the outside in, the disc at t adds
984
+ // 1 - (1 - a(t)) / (1 - a(t_outer)), and the cumulative opacity at every radius is exactly a(t).
985
+ const alphaAt = (t) => { const m = at(t).match(/rgba\([^,]+,[^,]+,[^,]+,([^)]+)\)/); return m ? Math.min(0.999, Math.max(0, Number(m[1]))) : 1; };
986
+ let outer = 0; // the cumulative opacity just outside the current disc
987
+ for (let i = N; i >= 1; i--) {
988
+ const t = i / N, want = alphaAt(t);
989
+ const inc = want > outer ? 1 - (1 - want) / (1 - outer) : 0;
990
+ if (want > outer) outer = want;
991
+ if (inc < 0.0005) continue;
992
+ ctx.fillStyle = at(t).replace(/,([^,]+)\)$/, `,${inc.toFixed(4)})`);
993
+ ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r * t), 0, Math.PI * 2); ctx.fill();
994
+ }
995
+ }
996
+
997
+ function drawFireworks(ctx, view, lw) {
998
+ const fx = view.fx;
999
+ if (!fx || fx.kind !== 'firework') return;
1000
+ const U = view.unit ?? 8;
1001
+ const P = (x, y, z) => project(x, y, z, view);
1002
+ const line = view.axes?.line;
1003
+ const price = line?.length > 1;
1004
+ // THE WHOLE HEIGHT of the picture: the floor to the chart's top on the price board, the floor
1005
+ // to well above the cubes on the block board
1006
+ const zLo = 1, zHi = price ? (view.axes?.zTop ?? 34) : 16;
1007
+ const gf = Math.min(1, (1 - fx.u) / 0.1); // the run's own fade-out
1008
+ // still a real gradient maker, because gasCloud() takes one as a callback and uses it for the
1009
+ // smoke puffs; every FILL in this function is layered flat discs now (softStops)
1010
+ const gradientOf = (x, y, r, stops) => {
1011
+ const g = typeof ctx.createRadialGradient === 'function' ? ctx.createRadialGradient(x, y, 0, x, y, r) : null;
1012
+ if (!g || typeof g.addColorStop !== 'function') return stops[0][1];
1013
+ for (const [o, col] of stops) g.addColorStop(o, col);
1014
+ return g;
1015
+ };
1016
+ const linearOf = (x0, y0, x1, y1, stops) => {
1017
+ const g = typeof ctx.createLinearGradient === 'function' ? ctx.createLinearGradient(x0, y0, x1, y1) : null;
1018
+ if (!g || typeof g.addColorStop !== 'function') return stops[Math.floor(stops.length / 2)][1];
1019
+ for (const [o, col] of stops) g.addColorStop(o, col);
1020
+ return g;
1021
+ };
1022
+ const disc = (x, y, r, fill) => { ctx.fillStyle = fill; ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r), 0, Math.PI * 2); ctx.fill(); };
1023
+ const seg = (a, b, col, w) => { ctx.strokeStyle = col; ctx.lineWidth = Math.max(lw * 0.8, w); ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); ctx.stroke(); };
1024
+ const now = view.now ?? 0;
1025
+ const cx0 = (view.boardW ?? 0) / 2, cy0 = -(view.boardH ?? 0) / 4;
1026
+ for (const sh of fireworkShells(fx.seed, fx.gridW, fx.gridH, price, zLo, zHi)) {
1027
+ const { H, life, smoke: SMOKE, kind } = sh;
1028
+ const v = (fx.u - sh.t0) / life;
1029
+ if (!(v > 0 && v < SMOKE)) continue;
1030
+ const [col, col2] = sh.cols;
1031
+ const c1 = col.join(','), c2 = col2.join(',');
1032
+ const top = P(sh.bx, sh.by, sh.zc);
1033
+ const R0 = U * boundedRadius(price ? 4.5 : 6, 0.09, fx.gridW) * sh.size; // 7 and 8 until 2026-09-15 ("same with fireworks" -- on the Kiosk's panel ten shells carpeted it); never more than 9% of the board
1034
+ // --- the launch: a parabola from the floor, off to one side, to the burst point
1035
+ const RISE = 0.2;
1036
+ const arc = (f) => P(sh.bx - sh.drift * (1 - f), sh.by, zLo + (sh.zc - zLo) * (1 - (1 - f) * (1 - f)));
1037
+ if (v < RISE) {
1038
+ const f = v / RISE;
1039
+ const head = arc(f);
1040
+ const tail = [];
1041
+ for (let k = 0; k <= 8; k++) tail.push(arc(Math.max(0, f - (k / 8) * 0.22)));
1042
+ for (let k = 0; k < 8; k++) {
1043
+ const a = (1 - k / 8) * gf;
1044
+ seg(tail[k], tail[k + 1], `rgba(${c1},${(0.35 * a).toFixed(3)})`, U * 0.26 * a * sh.size);
1045
+ seg(tail[k], tail[k + 1], `rgba(255,240,210,${(0.9 * a).toFixed(3)})`, U * 0.08 * a);
1046
+ }
1047
+ for (let k = 0; k < 10; k++) {
1048
+ const age = ((f * 6 + k / 10) % 1), back = arc(Math.max(0, f - age * 0.18));
1049
+ const sx = back.x + (H(50 + k) - 0.5) * U * 0.8, sy = back.y + age * U * 1.6;
1050
+ disc(sx, sy, U * 0.06 * (1 - age), `rgba(255,220,160,${(0.8 * (1 - age) * gf).toFixed(3)})`);
1051
+ }
1052
+ softStops(ctx, head.x, head.y, U * 0.32, [[0, `rgba(255,255,255,${gf.toFixed(3)})`], [0.4, `rgba(${c2},${(0.9 * gf).toFixed(3)})`], [1, `rgba(${c1},0)`]]);
1053
+ continue;
1054
+ }
1055
+ const s = Math.min(1, (v - RISE) / (1 - RISE)); // 0 at the burst, 1 when the sparks are out
1056
+ const ss = (v - RISE) / (SMOKE - RISE); // the smoke's own clock, 0..1 over the longer life
1057
+ // --- THE DISSIPATION (operator: "The dissipation effects need to be more detailed"): a nebula
1058
+ // of sixteen lumps, each two gradient discs offset so it is not round, leaving the burst
1059
+ // outward and curling as it goes, the shell's colour gone grey with the colour still in its
1060
+ // heart; embers falling slowly through it, flickering; ash sinking after them; all of it
1061
+ // fading as it disperses and gone before the run ends
1062
+ const smokeRc = [Math.round(col[0] * 0.45 + 95), Math.round(col[1] * 0.45 + 95), Math.round(col[2] * 0.45 + 105)];
1063
+ const smokeCol = smokeRc.join(',');
1064
+ // THE SMOKE IS A VOLUME OF GAS (operator, 2026-09-15: "Use the gas cloud for the fireworks
1065
+ // smoke too"): the supernova's renderer, smaller -- a sphere of soft blobs carried out from
1066
+ // the burst, drifting up, going from the shell's colour toward grey as it disperses
1067
+ {
1068
+ const sr = R0 * (0.3 + 1.1 * (1 - Math.exp(-2.2 * ss))), rise = R0 * 0.3 * ss;
1069
+ // TONED DOWN (operator, 2026-09-15: "the fireworks nebulas are too prominent. they need to be
1070
+ // toned down by half at least. Too opaque for too long"): half the alpha, a steeper fade,
1071
+ // fewer blobs, and the smoke lives 1.35 shell-lives rather than 1.7
1072
+ const sa = 0.45 * Math.pow(1 - ss, 2.2) * (0.4 + 0.6 * Math.min(1, ss * 6)) * gf;
1073
+ if (sa > 0.01) gasCloud(ctx, top.x, top.y - rise, sr, ss, now, fx.seed + sh.i * 977, sa * 1.1, smokeRc, gradientOf, disc, 60, [50, 50, 58]);
1074
+ }
1075
+ if (ss > 0.15) {
1076
+ const em = (ss - 0.15) / 0.85;
1077
+ for (let k = 0; k < 18; k++) {
1078
+ const ang = H(300 + k) * Math.PI * 2, d = R0 * (0.25 + 0.75 * H(320 + k));
1079
+ const x = top.x + Math.cos(ang) * d + Math.sin(now * 0.002 + k) * U * 0.35, y = top.y + Math.sin(ang) * d * 0.7 + R0 * (0.15 + 1.2 * em) * (0.5 + 0.5 * H(340 + k));
1080
+ const flick = 0.5 + 0.5 * Math.sin(now * 0.02 + k * 2.3);
1081
+ const a = (1 - em) * gf;
1082
+ if (a > 0.02) {
1083
+ softStops(ctx, x, y, U * 0.11 * (1 - 0.5 * em), [[0, `rgba(255,255,255,${(0.9 * a * flick).toFixed(3)})`], [0.5, `rgba(${c2},${(0.7 * a * flick).toFixed(3)})`], [1, `rgba(${c1},0)`]]);
1084
+ if (k % 3 === 0) disc(x + U * 0.2, y + U * 0.5 * em, U * 0.03, `rgba(${smokeCol},${(0.6 * a).toFixed(3)})`); // ash
1085
+ }
1086
+ }
1087
+ }
1088
+ if (v >= 1) continue; // only the dissipation is left
1089
+ // --- the burst: a flash, a lens flare, and a shockwave ring racing out and thinning
1090
+ if (s < 0.14) {
1091
+ const f = (1 - s / 0.14) * gf;
1092
+ const r = R0 * 0.5 * (1.3 - f * 0.6);
1093
+ softStops(ctx, top.x, top.y, r, [[0, `rgba(255,255,255,${(0.95 * f).toFixed(3)})`], [0.3, `rgba(${c2},${(0.7 * f).toFixed(3)})`], [1, `rgba(${c1},0)`]]);
1094
+ }
1095
+ if (s < 0.35) {
1096
+ const f = Math.pow(1 - s / 0.35, 1.5) * gf;
1097
+ const L = R0 * 2.6;
1098
+ ctx.strokeStyle = linearOf(top.x - L, top.y, top.x + L, top.y, [[0, `rgba(${c2},0)`], [0.35, `rgba(${c2},${(0.35 * f).toFixed(3)})`], [0.5, `rgba(255,255,255,${(0.9 * f).toFixed(3)})`], [0.65, `rgba(${c2},${(0.35 * f).toFixed(3)})`], [1, `rgba(${c2},0)`]]);
1099
+ ctx.lineWidth = Math.max(lw, U * 0.09); ctx.beginPath(); ctx.moveTo(top.x - L, top.y); ctx.lineTo(top.x + L, top.y); ctx.stroke();
1100
+ ctx.lineWidth = Math.max(lw * 3, U * 0.3); ctx.strokeStyle = linearOf(top.x - L, top.y, top.x + L, top.y, [[0, `rgba(${c1},0)`], [0.5, `rgba(${c1},${(0.25 * f).toFixed(3)})`], [1, `rgba(${c1},0)`]]);
1101
+ ctx.beginPath(); ctx.moveTo(top.x - L * 0.7, top.y); ctx.lineTo(top.x + L * 0.7, top.y); ctx.stroke();
1102
+ const rays = 4, spin = now * 0.0004 + H(11) * Math.PI;
1103
+ for (let k = 0; k < rays; k++) {
1104
+ const ang = spin + (k / rays) * Math.PI, rl = R0 * (0.9 + 0.5 * H(12 + k));
1105
+ const x0 = top.x - Math.cos(ang) * rl, y0 = top.y - Math.sin(ang) * rl, x1 = top.x + Math.cos(ang) * rl, y1 = top.y + Math.sin(ang) * rl;
1106
+ ctx.strokeStyle = linearOf(x0, y0, x1, y1, [[0, 'rgba(255,255,255,0)'], [0.5, `rgba(255,255,255,${(0.5 * f).toFixed(3)})`], [1, 'rgba(255,255,255,0)']]);
1107
+ ctx.lineWidth = Math.max(lw * 0.8, U * 0.03); ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x1, y1); ctx.stroke();
1108
+ }
1109
+ for (let k = 1; k <= 5; k++) {
1110
+ const t = k * 0.35, gx = top.x + (cx0 - top.x) * t, gy = top.y + (cy0 - top.y) * t;
1111
+ const gr = R0 * (0.08 + 0.1 * H(20 + k)) * (0.6 + t), ga = 0.16 * f * (1 - k / 7);
1112
+ softStops(ctx, gx, gy, gr, [[0, `rgba(${k % 2 ? c1 : c2},${(ga * 0.5).toFixed(3)})`], [0.7, `rgba(${k % 2 ? c1 : c2},${ga.toFixed(3)})`], [1, `rgba(${k % 2 ? c1 : c2},0)`]]);
1113
+ }
1114
+ }
1115
+ if (s < 0.4) {
1116
+ const f = s / 0.4;
1117
+ ctx.strokeStyle = `rgba(255,255,255,${(0.55 * (1 - f) * gf).toFixed(3)})`; ctx.lineWidth = Math.max(lw, U * 0.12 * (1 - f));
1118
+ ctx.beginPath(); ctx.arc(top.x, top.y, R0 * 1.25 * f, 0, Math.PI * 2); ctx.stroke();
1119
+ }
1120
+ // --- EMISSIVE LIGHT on the explosion's surroundings (operator: "emissive colored lighting
1121
+ // illuminating the explosion area in the explosion color"): a wide soft pool of the shell's
1122
+ // colour over everything near the burst, strongest at the burst and fading with the shell
1123
+ // (the candles under it glow in the colour too, through fxNow's heads)
1124
+ {
1125
+ const f = Math.pow(1 - s, 1.3) * gf, r = R0 * 2.4;
1126
+ softStops(ctx, top.x, top.y + R0 * 0.2 * s, r, [[0, `rgba(${c1},${(0.32 * f).toFixed(3)})`], [0.4, `rgba(${c1},${(0.14 * f).toFixed(3)})`], [1, `rgba(${c1},0)`]]);
1127
+ }
1128
+ // --- the shell
1129
+ const N = kind === 'ring' ? 60 : kind === 'crossette' ? 36 : 84;
1130
+ const fade = Math.pow(1 - s, kind === 'willow' ? 0.8 : 1.2) * gf;
1131
+ const spreadAt = (sq) => (kind === 'ring' ? Math.min(1, sq * 3) : 1 - Math.exp(-3.4 * sq));
1132
+ const gscale = kind === 'willow' ? 1.9 : kind === 'ring' ? 0.7 : 1;
1133
+ const pos = (k, sq, scale) => {
1134
+ const jitter = kind === 'ring' ? 0.03 : 0.25;
1135
+ const curl = kind === 'pinwheel' ? 2.4 * sq : 0;
1136
+ const ang = (k / N) * Math.PI * 2 + (H(100 + k) - 0.5) * jitter + curl;
1137
+ const len = R0 * (kind === 'ring' ? 0.9 : 0.6 + 0.5 * H(200 + k)) * scale;
1138
+ const sp = spreadAt(sq);
1139
+ return { x: top.x + Math.cos(ang) * len * sp, y: top.y + Math.sin(ang) * len * sp * (kind === 'ring' ? 0.55 : 1) + R0 * 0.9 * gscale * sq * sq };
1140
+ };
1141
+ const blink = kind === 'strobe' ? (Math.sin(now * 0.03) > 0.2 ? 1 : 0.15) : 1;
1142
+ for (let k = 0; k < N; k++) {
1143
+ const inner = k % 3 === 0;
1144
+ const c = inner ? c2 : c1;
1145
+ const scale = inner ? 0.62 : 1;
1146
+ const long = kind === 'chrysanthemum' || kind === 'willow';
1147
+ const steps = long ? 5 : 3, back = long ? 0.22 : 0.12;
1148
+ let prev = null;
1149
+ for (let q = steps; q >= 0; q--) {
1150
+ const p = pos(k, Math.max(0, s - (q / steps) * back), scale);
1151
+ if (prev) {
1152
+ const a = (1 - q / (steps + 1)) * blink;
1153
+ seg(prev, p, `rgba(${c},${(0.28 * fade * a).toFixed(3)})`, U * 0.2 * a * sh.size);
1154
+ seg(prev, p, `rgba(${c},${(0.95 * fade * a).toFixed(3)})`, U * 0.07 * a);
1155
+ }
1156
+ prev = p;
1157
+ }
1158
+ const tw = 0.55 + 0.45 * Math.sin(now * 0.02 + k * 1.7);
1159
+ const pop = kind === 'chrysanthemum' && s > 0.3 && hash01(fx.seed + k * 7 + Math.floor(now / 50)) < 0.12;
1160
+ disc(prev.x, prev.y, U * (pop ? 0.2 : 0.075) * scale, `rgba(255,255,255,${(fade * blink * (pop ? 1 : 0.9 * tw)).toFixed(3)})`);
1161
+ if (kind === 'crossette' && s > 0.42) {
1162
+ const s2 = (s - 0.42) / 0.58, f2 = Math.pow(1 - s2, 1.3) * gf;
1163
+ for (let m = 0; m < 4; m++) {
1164
+ const ang = (m / 4) * Math.PI * 2 + H(400 + k) * 1.5, d = R0 * 0.22 * (1 - Math.exp(-3 * s2));
1165
+ const e = { x: prev.x + Math.cos(ang) * d, y: prev.y + Math.sin(ang) * d + R0 * 0.2 * s2 * s2 };
1166
+ seg(prev, e, `rgba(${c2},${(0.8 * f2).toFixed(3)})`, U * 0.05);
1167
+ disc(e.x, e.y, U * 0.06, `rgba(255,255,255,${(0.9 * f2).toFixed(3)})`);
1168
+ }
1169
+ }
1170
+ }
1171
+ disc(top.x, top.y + R0 * 0.25 * s, U * 0.16 * fade, `rgba(255,255,255,${(0.7 * fade).toFixed(3)})`);
1172
+ }
1173
+ ctx.lineWidth = lw;
1174
+ }
1175
+
1176
+ // THE SCAN IS A LIGHT CURTAIN (operator, 2026-09-15: "Suggest a way to drastically improve the
1177
+ // visuals on the scan line effect. Again, create new render tools" -- then "do it"). The front
1178
+ // was a tight line on the floor that lit each tile for a frame. Now it is a vertical SHEET of
1179
+ // light standing on the board, floor to the chart's top, sweeping across: a hard white core
1180
+ // with soft cyan falloff on both faces, faint raster lines rippling down it on the clock, a bar
1181
+ // of light along its top edge it hangs from with glints at the ends, a glowing foot on the floor
1182
+ // with a green-cyan phosphor tail fading behind it, motes drifting in the beam, sparks thrown up
1183
+ // from the foot, and a thin volumetric haze inside its thickness. The tiles keep lighting through
1184
+ // fxAt as before, and the price line flares white where the curtain crosses it (scanFlare).
1185
+ function curtainEnds(fx, z) {
1186
+ // the front is the set of board points with x*dx + y*dy = p; its ends are where that line
1187
+ // leaves the board, at height z
1188
+ const n = fx.gridW, rows = fx.gridH, p = fxFront(fx);
1189
+ const c0x = n / 2 + (p - (n / 2) * fx.dx - (rows / 2) * fx.dy) * fx.dx;
1190
+ const c0y = rows / 2 + (p - (n / 2) * fx.dx - (rows / 2) * fx.dy) * fx.dy;
1191
+ const L = Math.hypot(n, rows);
1192
+ let a = null, b = null;
1193
+ for (let i = -60; i <= 60; i++) {
1194
+ const gx = c0x - fx.dy * (L * i) / 60, gy = c0y + fx.dx * (L * i) / 60;
1195
+ if (gx >= -0.01 && gx <= n + 0.01 && gy >= -0.01 && gy <= rows + 0.01) { if (!a) a = { x: gx, y: gy, z }; b = { x: gx, y: gy, z }; }
1196
+ }
1197
+ return a && b && (a.x !== b.x || a.y !== b.y) ? [a, b] : null;
1198
+ }
1199
+ // THE LINE UNDER THE CURTAIN: the stretch the scan is crossing flares white and rings out
1200
+ // either side, so the wire reads as struck by the sheet of light as it passes
1201
+ function scanFlare(ctx, pts, axes, view, lw) {
1202
+ const fx = view.fx, line = axes.line ?? [];
1203
+ if (!fx || fx.dx === 0 || line.length !== pts.length) return;
1204
+ const xf = fxFront(fx) * fx.dx; // the front's x on the board (dy is 0 on the price board)
1205
+ for (let i = 0; i < pts.length - 1; i++) {
1206
+ const mx = (line[i].x + line[i + 1].x) / 2, d = Math.abs(mx - xf);
1207
+ const k = Math.exp(-(d * d) / 6);
1208
+ if (k < 0.03) continue;
1209
+ ctx.strokeStyle = `rgba(160,230,255,${(0.6 * k).toFixed(3)})`; ctx.lineWidth = lw * 14 * k;
1210
+ ctx.beginPath(); ctx.moveTo(pts[i].x, pts[i].y); ctx.lineTo(pts[i + 1].x, pts[i + 1].y); ctx.stroke();
1211
+ ctx.strokeStyle = `rgba(255,255,255,${(0.95 * k).toFixed(3)})`; ctx.lineWidth = lw * 4;
1212
+ ctx.beginPath(); ctx.moveTo(pts[i].x, pts[i].y); ctx.lineTo(pts[i + 1].x, pts[i + 1].y); ctx.stroke();
1213
+ }
1214
+ }
1215
+ // THE BEAM'S ALTITUDE AND WIDTH, decided once. fxAt lights the swath while buildScene runs, and
1216
+ // drawScanCurtain draws the cone afterwards; if each worked its own numbers out they would drift
1217
+ // apart and the lit blocks would not be the ones under the light.
1218
+ function scanBeamGeom(view) {
1219
+ const price = (view.axes?.line?.length ?? 0) > 1;
1220
+ const top = price ? (view.axes?.zTop ?? 34) : 9;
1221
+ const line = view.axes?.line ?? [];
1222
+ const peak = line.length > 1 ? line.reduce((h, q) => Math.max(h, q.z ?? 0), 0) : top * 0.8;
1223
+ const clearance = Math.max(2.5, top * 0.1);
1224
+ const z = Math.max(peak + 1, Math.min(peak + clearance, top * 0.95));
1225
+ const spread = price ? Math.max(3, Math.min(11, z * 0.32)) : Math.max(2, Math.min(5, z * 0.45));
1226
+ return { price, top, z, spread };
1227
+ }
1228
+
1229
+ function drawScanCurtain(ctx, view, lw) {
1230
+ const fx = view.fx;
1231
+ if (!fx || fx.kind !== 'scan') return;
1232
+ const U = view.unit ?? 8, now = view.now ?? 0;
1233
+ const { price, top } = scanBeamGeom(view);
1234
+ const P = (q) => project(q.x, q.y, q.z, view);
1235
+ // NO FADE WHILE IT IS IN SIGHT (operator, 2026-09-15: "it still fades in and out ... with the
1236
+ // effects properly transitioning before being killed"). fx.amp is the shared envelope every
1237
+ // effect dims by at its start and end -- which for a thing that TRAVELS means it materialises in
1238
+ // the middle of the picture and dissolves there. The craft and its beam now hold full strength
1239
+ // and let POSITION do the transition: the front enters and leaves beyond the panel's edge
1240
+ // (fxFront's margin), so there is nothing on screen to fade.
1241
+ const amp = 1;
1242
+ void fx.amp;
1243
+ // IT MUST LEAVE THE VIEWPORT, NOT BLINK OUT AT THE EDGE (operator, 2026-09-15: "it disappears at
1244
+ // the edge of the screen. Have it move entirely off the viewport before you delete it").
1245
+ // curtainEnds returns null the moment the front stops crossing the board, so everything below --
1246
+ // the craft included -- simply stopped being drawn while it was still in frame. The craft's
1247
+ // position comes from the front itself now, which fxFront carries four units past each edge, so
1248
+ // the saucer flies in from off-board and out the far side under its own power.
1249
+ const fp = fxFront(fx);
1250
+ const fcx = fx.gridW / 2 + (fp - (fx.gridW / 2) * fx.dx - (fx.gridH / 2) * fx.dy) * fx.dx;
1251
+ const fcy = fx.gridH / 2 + (fp - (fx.gridW / 2) * fx.dx - (fx.gridH / 2) * fx.dy) * fx.dy;
1252
+ const ends = curtainEnds(fx, 0);
1253
+ const [A, B] = ends ?? [{ x: fcx, y: fcy, z: 0 }, { x: fcx, y: fcy, z: 0 }];
1254
+
1255
+ // A CONE, NOT A STACK OF SHEETS (operator, 2026-09-15: "that leaning portion and the
1256
+ // cross-hatching is not working. Can we make it a conical beam. instead, and do something
1257
+ // volumetric effect?").
1258
+ //
1259
+ // WHY THE OLD ONE HATCHED. The curtain was twenty-one PARALLEL flat quads (k = -10..10, each
1260
+ // offset k*0.5 along the sweep) with fourteen raster lines drawn across them. Under the oblique
1261
+ // camera parallel sheets project to parallelograms offset by a constant, so their translucent
1262
+ // edges land on near-parallel screen lines and read as a lattice -- a leaning cross-hatch. No
1263
+ // amount of alpha tuning fixes that; the geometry itself is a grid.
1264
+ //
1265
+ // A cone has no parallel edges. Its body is a fan of triangles that all converge on the apex,
1266
+ // so overlap -- and therefore density -- rises smoothly toward the axis on its own. That is the
1267
+ // volumetric part: nothing is faked with a gradient across a flat face, the light is thick where
1268
+ // the geometry is thick. Three nested shells give the falloff depth, a bright pool marks where
1269
+ // it lands, and motes drift inside the volume rather than on a sheet.
1270
+ const mx = fcx, my = fcy; // the front's own centre, on or off the board
1271
+ const half = Math.hypot(B.x - A.x, B.y - A.y) / 2; // reach along the front line
1272
+ const ax = -fx.dy, ay = fx.dx; // unit vector ALONG the front
1273
+ const sx = fx.dx, sy = fx.dy; // unit vector along the SWEEP
1274
+ // PROPORTIONS ARE THE WHOLE EFFECT (operator, 2026-09-15: the first cut "is fucked"). It put the
1275
+ // apex at top*1.5 -- z = 51 on the price board -- over a base barely 5 units across, which draws
1276
+ // 49px wide by 147px tall: a needle, not a beam. A spotlight reads as a spotlight when its height
1277
+ // and the width where it lands are comparable, so the apex sits just under the chart's own top
1278
+ // and the pool is wide enough to look like something landed in it.
1279
+ // ABOVE THE PEAK, not level with it (operator, 2026-09-15: "It needs to fly a bit higher than
1280
+ // the price line peak"). `top` is the chart's axis ceiling, which the line can come close to --
1281
+ // a craft at 0.9 of it flies through the high candles. So the ceiling is the taller of the axis
1282
+ // top and the line's own highest point, and the saucer clears it by 15%.
1283
+ // ABOVE THE PEAK, BUT UNDER THE CEILING (operator, 2026-09-15: "It needs to fly a bit higher
1284
+ // than the price line peak", then -- when I raised it past the chart's own top -- "It's flying at
1285
+ // the top of teh screen. don't do that ... set it lower with some above tolerances").
1286
+ //
1287
+ // Both mistakes were the same one: taking a single bound and scaling it. Too low and the craft
1288
+ // flies through the high candles; too high and it leaves the frame. It wants a clearance over the
1289
+ // line AND a hard ceiling under the chart's top, so it rides above the price wherever the price
1290
+ // happens to be and never reaches the edge.
1291
+ const apex = { x: mx, y: my, z: scanBeamGeom(view).z };
1292
+ const SPREAD = scanBeamGeom(view).spread;
1293
+ const RING = 44;
1294
+ // a point on the base ellipse: `f` scales the shell, `th` runs around it
1295
+ const ring = (th, f) => ({
1296
+ x: mx + Math.cos(th) * half * f * ax + Math.sin(th) * SPREAD * f * sx,
1297
+ y: my + Math.cos(th) * half * f * ay + Math.sin(th) * SPREAD * f * sy,
1298
+ z: 0,
1299
+ });
1300
+ const tri = (a, b, c, fill) => {
1301
+ const p0 = P(a), p1 = P(b), p2 = P(c);
1302
+ ctx.fillStyle = fill;
1303
+ ctx.beginPath(); ctx.moveTo(p0.x, p0.y); ctx.lineTo(p1.x, p1.y); ctx.lineTo(p2.x, p2.y); ctx.closePath(); ctx.fill();
1304
+ };
1305
+ const seg = (a, b, col, w) => { const p = P(a), q = P(b); ctx.strokeStyle = col; ctx.lineWidth = Math.max(lw * 0.8, w); ctx.beginPath(); ctx.moveTo(p.x, p.y); ctx.lineTo(q.x, q.y); ctx.stroke(); };
1306
+ // SMOOTH BY LAYERING, NOT BY GRADIENT (operator, 2026-09-15: "gradient visible! We need smooth
1307
+ // fills. no gradient shit!"). A radial gradient bands on this rasteriser -- the rings are
1308
+ // plainly visible, and worst on a large fill like the beam's pool. Many nested flat discs do not
1309
+ // band: each is a plain rgba fill and the SUM is the curve. Same doctrine as bloom() in
1310
+ // agents.js, with far more steps because the pool is large.
1311
+ // one ring per ~1.2px, same rule as softStops: a fixed count bands on a large pool
1312
+ const soft = (x, y, r, rgb, a) => {
1313
+ const N = Math.max(16, Math.min(220, Math.round(Math.abs(r) / 1.2)));
1314
+ for (let i = N; i >= 1; i--) {
1315
+ ctx.fillStyle = `rgba(${rgb},${(a / N).toFixed(4)})`;
1316
+ ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r * (i / N)), 0, Math.PI * 2); ctx.fill();
1317
+ }
1318
+ };
1319
+ const disc = (x, y, r, fill) => { ctx.fillStyle = fill; ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r), 0, Math.PI * 2); ctx.fill(); };
1320
+
1321
+ // off the board there is nothing to light, so the beam is not drawn -- but the craft still is,
1322
+ // which is what carries it out of the viewport
1323
+ const onBoard = !!ends;
1324
+ // --- the volume: nested cone shells, widest and faintest first
1325
+ // DIMMER (operator, 2026-09-15: "the brightness of the scanner cone in the block space view needs
1326
+ // to be toned down. It's too bright. Actually tone down beam brightness on both"): the shells,
1327
+ // the axis, the pool and the rim all at a little over half of what they were
1328
+ const DIM = 0.55;
1329
+ if (onBoard) for (const [f, a] of [[1, 0.018], [0.88, 0.019], [0.76, 0.021], [0.64, 0.023], [0.53, 0.026], [0.43, 0.029], [0.34, 0.033], [0.26, 0.038], [0.19, 0.044], [0.13, 0.05]]) {
1330
+ const fill = `rgba(120,220,255,${(a * DIM * amp).toFixed(3)})`;
1331
+ for (let i = 0; i < RING; i++) {
1332
+ tri(apex, ring((i / RING) * Math.PI * 2, f), ring(((i + 1) / RING) * Math.PI * 2, f), fill);
1333
+ }
1334
+ }
1335
+ // the hot axis: a thin cone down the middle, and the shaft itself
1336
+ if (onBoard) for (let i = 0; i < RING; i++) {
1337
+ tri(apex, ring((i / RING) * Math.PI * 2, 0.08), ring(((i + 1) / RING) * Math.PI * 2, 0.08), `rgba(235,250,255,${(0.10 * DIM * amp).toFixed(3)})`);
1338
+ }
1339
+
1340
+ // --- where it lands: a pool on the floor, brightest at the axis
1341
+ if (onBoard) {
1342
+ const c = P({ x: mx, y: my, z: 0 });
1343
+ const r = U * Math.max(half, SPREAD) * 1.35;
1344
+ soft(c.x, c.y, r, '150,225,255', 1.5 * DIM * amp);
1345
+ soft(c.x, c.y, r * 0.42, '225,248,255', 1.1 * DIM * amp);
1346
+ }
1347
+ // the rim of the pool, so the cone reads as landing on something
1348
+ if (onBoard) for (let i = 0; i < RING; i++) {
1349
+ seg(ring((i / RING) * Math.PI * 2, 1), ring(((i + 1) / RING) * Math.PI * 2, 1), `rgba(170,235,255,${(0.28 * DIM * amp).toFixed(3)})`, U * 0.05);
1350
+ }
1351
+
1352
+ // --- the source: the UFO, flying the beam (operator, 2026-09-15: "The top-down view in block
1353
+ // space coming from a sphere does not look good. Can we re-purpose the UFO"). A glowing ball
1354
+ // seen from directly above is just a blob -- it has no orientation, so top-down it reads as a
1355
+ // smudge where the light starts. The saucer has a rim and a dome, so it stays a craft at any
1356
+ // camera angle. Same craft the tractor beam flies (agents.js saucer()), so the board has one
1357
+ // ship rather than two unrelated light sources.
1358
+ {
1359
+ const p = P(apex);
1360
+ // (no glow round the craft: operator, 2026-09-15, "remove the light around the UFO. We have
1361
+ // enough lights for that effect")
1362
+ // TOP-DOWN (operator, 2026-09-15: "We need a top-down rendering of the UFO for this scene").
1363
+ // The board's camera looks DOWN, so a dome-and-rim craft drawn edge-on is a smear; from above
1364
+ // a saucer is concentric, and `squash` is the camera's own depth foreshortening so its circles
1365
+ // are the ellipses everything else on the board is drawn in.
1366
+ saucerAbove(ctx, p.x, p.y, U * 1.9, amp, view.oblique?.dy ?? 1, now * 0.0009);
1367
+ }
1368
+
1369
+ // --- motes INSIDE the volume: placed by angle and depth, so they sit in the cone rather than
1370
+ // on a face. Each drifts up the shaft and is reseeded by its own hash, never by Math.random.
1371
+ // ...and only while the beam is on the board (operator, 2026-09-15: "I don't like how the
1372
+ // particles are kept when the scanner is off"): off it, the craft flies alone
1373
+ if (onBoard) for (let k = 0; k < 30; k++) {
1374
+ const H = (q) => hash01(fx.seed + 700 + k * 13 + q);
1375
+ const climb = ((H(1) + now * 0.00007 * (0.5 + H(2))) % 1); // 0 at the floor, 1 at the apex
1376
+ const th = H(3) * Math.PI * 2, rad = Math.sqrt(H(4)) * (1 - climb);
1377
+ const b = ring(th, rad);
1378
+ const q = { x: b.x + (apex.x - b.x) * climb, y: b.y + (apex.y - b.y) * climb, z: apex.z * climb };
1379
+ const p = P(q), tw = 0.5 + 0.5 * Math.sin(now * 0.008 + k * 1.7);
1380
+ disc(p.x, p.y, U * 0.06 * (1 - 0.5 * climb), `rgba(230,250,255,${(0.75 * tw * (1 - climb) * amp).toFixed(3)})`);
1381
+ }
1382
+
1383
+ // --- sparks thrown from where it lands, as before: the beam is doing something to the board
1384
+ const STEP = 160, LIFE = 900, kNow = Math.floor(now / STEP);
1385
+ if (onBoard) for (let k = kNow - Math.ceil(LIFE / STEP); k <= kNow; k++) {
1386
+ if (hash01(fx.seed + k * 5) > 0.5) continue;
1387
+ const age = (now - k * STEP) / LIFE;
1388
+ if (age < 0 || age >= 1) continue;
1389
+ const t = hash01(fx.seed + k * 5 + 1);
1390
+ const q = { x: A.x + (B.x - A.x) * t, y: A.y + (B.y - A.y) * t, z: 0 };
1391
+ const p = P(q), rise = U * 2.2 * age * (1 - age) * 4, drift = (hash01(fx.seed + k * 5 + 2) - 0.5) * U * 1.2 * age;
1392
+ disc(p.x + drift, p.y - rise, U * 0.07 * (1 - age), `rgba(255,255,255,${(0.9 * (1 - age) * amp).toFixed(3)})`);
1393
+ }
1394
+ ctx.lineWidth = lw;
1395
+ }
1396
+
1397
+ // THE BLACK HOLE (operator, 2026-09-15: "Simulate the price chart turning into a black hole",
1398
+ // reference svs.gsfc.nasa.gov/14576 -- NASA's visualisation: an orange accretion disk of hot gas
1399
+ // spiralling in, brighter on the side coming toward us, a photon ring inside it, the far side of
1400
+ // the disk lensed into an arch over the top of the shadow and a thinner one under it, the sky
1401
+ // behind bent into arcs). On the chart:
1402
+ // collapse 0 - 0.22 a point of darkness opens on the price line; the line bends round it
1403
+ // (lensPoints) and the candles nearest are swallowed (fxNow's head hides
1404
+ // them) as the horizon grows
1405
+ // accretion 0.22 - 0.82 the disk: the chart's own colours -- gold, and the candles' green and
1406
+ // red -- spiralling in, Keplerian (faster inside), Doppler-bright on
1407
+ // the approaching side; the far side arched over and under the shadow;
1408
+ // the photon ring; lensed starlight in arcs round the horizon; the
1409
+ // shadow, black, soft-edged
1410
+ // release 0.82 - 1 the hole shrinks to nothing, the disk spins away, the line straightens
1411
+ // and the candles come back
1412
+ // Screen-space, gradients and strokes under transforms, no clip or composite modes.
1413
+ function holeOnScreen(view) {
1414
+ const b = view.fx?.blackhole;
1415
+ if (!b) return null;
1416
+ const c = project(b.x, b.y, b.z, view);
1417
+ const U = view.unit ?? 8;
1418
+ return { c, U, rs: b.rs * U, grow: b.grow };
1419
+ }
1420
+ function lensPoints(pts, view) {
1421
+ const h = holeOnScreen(view);
1422
+ if (!h || h.rs <= 0.5) return pts;
1423
+ const rE = h.rs * 1.9;
1424
+ return pts.map((p) => {
1425
+ const dx = p.x - h.c.x, dy = p.y - h.c.y, r = Math.hypot(dx, dy) || 1e-6;
1426
+ const r2 = Math.sqrt(r * r + rE * rE);
1427
+ return { x: h.c.x + (dx / r) * r2, y: h.c.y + (dy / r) * r2 };
1428
+ });
1429
+ }
1430
+ function drawBlackHole(ctx, view, lw) {
1431
+ const fx = view.fx;
1432
+ if (!fx || fx.kind !== 'blackhole') return;
1433
+ const h = holeOnScreen(view);
1434
+ if (!h || h.rs <= 0.5) return;
1435
+ const { c, U, rs, grow } = h;
1436
+ const now = view.now ?? 0;
1437
+ const disc = (x, y, r, fill) => { ctx.fillStyle = fill; ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r), 0, Math.PI * 2); ctx.fill(); };
1438
+ const canT = typeof ctx.save === 'function' && typeof ctx.rotate === 'function' && typeof ctx.scale === 'function';
1439
+ // THE LOOK OF THE REFERENCE (operator, 2026-09-15, with NASA's still of the disk: "Is there any
1440
+ // way we can get it looking closer to this?"): the disk seen well above its plane, not edge-on;
1441
+ // a broad continuous body, white-yellow at its inner edge through orange to a dark red rim that
1442
+ // fades to nothing; FIBROUS -- hundreds of thin streaks spiralling inward over it, sheared by
1443
+ // the Keplerian flow, brightest on the approaching side; the shadow in the middle with a thin
1444
+ // photon ring, a gap, and the far side's thin lensed arch hugging it over the top.
1445
+ // ...then the Interstellar view (operator, with a second still: "need it to look more like this"):
1446
+ // the disk nearly edge-on, a thin band crossing in front of the shadow, the far side thrown
1447
+ // into a great arch over the top and a smaller one beneath
1448
+ const TILT = 0.04, SQUASH = 0.17;
1449
+ const inner = rs * 1.5, outer = rs * 5; // 6.4 horizons at the largest ("twice as large"), then 5 ("obscuring too much")
1450
+ const doppler = (ang) => 0.55 + 0.75 * Math.max(0, Math.cos(ang - Math.PI)); // the left side comes toward us: brightest at ang = pi
1451
+ const H = (k) => hash01(fx.seed + k);
1452
+ softStops(ctx, c.x, c.y, outer * 1.15, [[0, `rgba(255,170,70,${(0.22 * grow).toFixed(3)})`], [0.5, `rgba(255,130,50,${(0.08 * grow).toFixed(3)})`], [1, 'rgba(255,100,40,0)']]);
1453
+ const toScreen = (rr, ang) => {
1454
+ const px = rr * Math.cos(ang), py = rr * Math.sin(ang) * SQUASH;
1455
+ return { x: c.x + px * Math.cos(TILT) - py * Math.sin(TILT), y: c.y + px * Math.sin(TILT) + py * Math.cos(TILT) };
1456
+ };
1457
+ // the fibres: thin streaks spiralling inward, each sheared along the flow, in the disk's plane
1458
+ const streaks = [];
1459
+ for (let k = 0; k < 520; k++) {
1460
+ const hk = (q) => hash01(fx.seed + 400 + k * 13 + q);
1461
+ const r0 = inner + (outer - inner) * Math.pow(hk(1), 1.3);
1462
+ const omega = 0.0016 * Math.pow(inner / r0, 1.5);
1463
+ const a0 = hk(2) * Math.PI * 2 + now * omega;
1464
+ const span = (0.25 + 0.9 * hk(3)) * Math.pow(inner / r0, 0.4), heat = 1 - (r0 - inner) / (outer - inner);
1465
+ streaks.push({ r0, a0, span, heat, w: rs * (0.02 + 0.045 * hk(4)), bright: 0.4 + 0.6 * hk(5), kind: hk(6), k });
1466
+ }
1467
+ const drawStreaks = (far) => {
1468
+ if (!canT) return;
1469
+ ctx.save(); ctx.translate(c.x, c.y); ctx.rotate(TILT); ctx.scale(1, SQUASH); ctx.lineCap = 'round';
1470
+ for (const st of streaks) {
1471
+ const mid = st.a0 + st.span / 2, isFar = Math.sin(mid) < 0;
1472
+ if (isFar !== far) continue;
1473
+ const dop = doppler(mid), heat = st.heat;
1474
+ const col = st.kind < 0.06 ? '120,240,170' : st.kind < 0.12 ? '255,110,110' : heat > 0.7 ? '255,250,225' : heat > 0.35 ? '255,215,120' : '255,120,50';
1475
+ ctx.strokeStyle = `rgba(${col},${(0.7 * grow * st.bright * Math.min(1.2, dop) / 1.2 * (0.35 + 0.65 * heat)).toFixed(3)})`; ctx.lineWidth = st.w * (0.8 + 0.6 * heat);
1476
+ ctx.beginPath();
1477
+ for (let i = 0; i <= 10; i++) { const t = i / 10, rr = st.r0 * (1 - 0.07 * t), ang = st.a0 + st.span * t; const x = rr * Math.cos(ang), y = rr * Math.sin(ang); if (i) ctx.lineTo(x, y); else ctx.moveTo(x, y); }
1478
+ ctx.stroke();
1479
+ }
1480
+ ctx.restore();
1481
+ };
1482
+ // --- THE FAR HALF, LIFTED INTO THE ARCH (operator, 2026-09-15: "the disc above is not merging
1483
+ // with the sides, and looks really bad" -- the arch was a circle drawn round the shadow while
1484
+ // the disk is an ellipse in its own plane, two surfaces that met by accident). The arch IS the
1485
+ // far half of the disk now: every point keeps its x on the disk (rr cos ang) and is raised over
1486
+ // the top by an amount that grows with its radius -- 1.1 horizons at the inner edge, 2.7 at the
1487
+ // outer -- so at the sides, where sin ang -> 0, the arch comes down exactly onto the flat band.
1488
+ // The second image under the hole is the same, mirrored, smaller and dimmer.
1489
+ const lift = (rr) => rs * (1.1 + 1.6 * (rr - inner) / (outer - inner));
1490
+ const farPt = (rr, ang, under) => {
1491
+ // the second image is a MIRROR, x as well as y: it turns with the band above it, not against
1492
+ // (2026-09-15: "the two discs are spinning in opposite directions")
1493
+ // CONTINUOUS INTO THE BAND (2026-09-15: "The transition between the two discs is not steady
1494
+ // or continuous"): the arch's height starts at the flat band's own slope (rr * SQUASH per
1495
+ // radian) and the lift takes over with |sin|^2.4, so the surface bends smoothly up from the
1496
+ // band rather than kinking where the two meet
1497
+ const sn = Math.abs(Math.sin(ang)), top = under ? rs * (1.05 + 0.45 * (rr - inner) / (outer - inner)) : lift(rr);
1498
+ const sx = Math.cos(ang) * rr * (under ? -0.78 : 1), sy = rr * SQUASH * sn + Math.max(0, top - rr * SQUASH) * Math.pow(sn, 2.4);
1499
+ return { x: c.x + sx * Math.cos(TILT) - sy * (under ? 1 : -1) * Math.sin(TILT), y: c.y + sx * Math.sin(TILT) + (under ? sy : -sy) * Math.cos(TILT) };
1500
+ };
1501
+ // ONE SET OF STRIPS FOR THE WHOLE DISK (operator, 2026-09-15, of a hard line across the middle:
1502
+ // "that harsh line does not work"): the near half was a radial gradient in the disk's plane
1503
+ // and the arch forty colour strips, and where they met at the midline the two disagreed. The
1504
+ // near half is the same strips now, laid on the flat ellipse, so the colour at any radius is
1505
+ // the same on both sides of the line and there is no line.
1506
+ const archBody = (mode) => {
1507
+ // 'ring': ONE CLOSED POLYGON PER STRIP round the whole disk -- the flat mapping over the near
1508
+ // half, the lifted mapping over the far -- so there is no interior edge at the midline at all
1509
+ // (2026-09-15: "still see harsh line bisecting" -- two fills sharing an edge draw that edge,
1510
+ // antialiased twice, however well their colours agree). 'under' is the second image alone.
1511
+ const under = mode === 'under';
1512
+ const STRIPS = under ? 16 : 40, dim = under ? 0.55 : 1;
1513
+ const at = (rr, ang) => (under ? farPt(rr, ang, true) : ang <= Math.PI ? toScreen(rr, ang) : farPt(rr, ang, false));
1514
+ const a0 = under ? Math.PI : 0, aSpan = under ? Math.PI : Math.PI * 2, N = under ? 24 : 72;
1515
+ // the second image FADES IN FROM THE MIDLINE (2026-09-15: "Still seeing the gradient" -- its
1516
+ // top edge lay exactly on the disk's midline): it is drawn in sectors, each at an alpha that
1517
+ // rises with |sin| from nothing at the line, so it has no edge there
1518
+ const SECT = under ? N : 1;
1519
+ for (let k = 0; k < STRIPS; k++) {
1520
+ const t0 = k / STRIPS, t1 = (k + 1) / STRIPS, r0 = inner + (outer - inner) * t0, r1 = inner + (outer - inner) * t1, heat = 1 - (t0 + t1) / 2;
1521
+ for (let sct = 0; sct < SECT; sct++) {
1522
+ const s0 = a0 + (aSpan * sct) / SECT, s1 = a0 + (aSpan * (sct + 1)) / SECT, n = under ? 1 : N;
1523
+ const fadeIn = under ? Math.pow(Math.abs(Math.sin((s0 + s1) / 2)), 0.8) : 1;
1524
+ ctx.beginPath();
1525
+ for (let i = 0; i <= n; i++) { const ang = s0 + ((s1 - s0) * i) / n; const p = at(r1, ang); if (i) ctx.lineTo(p.x, p.y); else ctx.moveTo(p.x, p.y); }
1526
+ for (let i = n; i >= 0; i--) { const ang = s0 + ((s1 - s0) * i) / n; const p = at(r0, ang); ctx.lineTo(p.x, p.y); }
1527
+ ctx.closePath();
1528
+ // bright, never brown: the rim stays a saturated orange rather than a dark red at low alpha
1529
+ const R = 255, G = Math.round(95 + 160 * Math.pow(heat, 0.7)), B = Math.round(25 + 200 * Math.pow(heat, 2.2));
1530
+ const alpha = grow * dim * fadeIn * (0.55 + 0.42 * Math.pow(heat, 0.8));
1531
+ // the Doppler side across the strip: a linear gradient, bright left, dark right
1532
+ const dg = typeof ctx.createLinearGradient === 'function' ? ctx.createLinearGradient(c.x - outer, 0, c.x + outer, 0) : null;
1533
+ if (dg && typeof dg.addColorStop === 'function') { dg.addColorStop(0, `rgba(${Math.min(255, R)},${Math.min(255, G + 50)},${Math.min(255, B + 70)},${alpha.toFixed(3)})`); dg.addColorStop(0.5, `rgba(${R},${G},${B},${(alpha * 0.85).toFixed(3)})`); dg.addColorStop(1, `rgba(${Math.round(R * 0.7)},${Math.round(G * 0.45)},${Math.round(B * 0.4)},${(alpha * 0.7).toFixed(3)})`); ctx.fillStyle = dg; }
1534
+ else ctx.fillStyle = `rgba(${R},${G},${B},${alpha.toFixed(3)})`;
1535
+ ctx.fill();
1536
+ }
1537
+ }
1538
+ };
1539
+ const archStreaks = (under) => {
1540
+ ctx.lineCap = 'round';
1541
+ for (const st of streaks) {
1542
+ const mid = st.a0 + st.span / 2;
1543
+ if (Math.sin(mid) >= 0) continue; // the far half only
1544
+ const dop = doppler(mid), heat = st.heat;
1545
+ const col = st.kind < 0.06 ? '120,240,170' : st.kind < 0.12 ? '255,110,110' : heat > 0.7 ? '255,250,225' : heat > 0.35 ? '255,215,120' : '255,120,50';
1546
+ const fadeIn = under ? Math.pow(Math.abs(Math.sin(mid)), 0.8) : 1;
1547
+ ctx.strokeStyle = `rgba(${col},${(0.7 * grow * (under ? 0.5 : 1) * fadeIn * st.bright * Math.min(1.2, dop) / 1.2 * (0.35 + 0.65 * heat)).toFixed(3)})`; ctx.lineWidth = Math.max(lw * 0.8, st.w * (0.8 + 0.6 * heat) * 1.6);
1548
+ ctx.beginPath();
1549
+ for (let i = 0; i <= 10; i++) { const t = i / 10, rr = st.r0 * (1 - 0.07 * t), ang = st.a0 + st.span * t; const p = farPt(rr, ang, under); if (i) ctx.lineTo(p.x, p.y); else ctx.moveTo(p.x, p.y); }
1550
+ ctx.stroke();
1551
+ }
1552
+ };
1553
+ archBody('under'); archStreaks(true); // the second image, under
1554
+ // the shadow, then the whole disk over it -- the far half is lifted clear of the shadow, the
1555
+ // near half crosses in front of it -- then the fibres, then the photon ring over everything
1556
+ softStops(ctx, c.x, c.y, rs * 1.1, [[0, 'rgba(0,0,0,1)'], [0.88, 'rgba(0,0,0,1)'], [1, 'rgba(0,0,0,0)']]);
1557
+ archBody('ring');
1558
+ archStreaks(false);
1559
+ drawStreaks(false);
1560
+ ctx.strokeStyle = `rgba(255,245,215,${(0.95 * grow).toFixed(3)})`; ctx.lineWidth = Math.max(lw, rs * 0.045);
1561
+ ctx.beginPath(); ctx.arc(c.x, c.y, rs * 1.07, 0, Math.PI * 2); ctx.stroke();
1562
+ ctx.strokeStyle = `rgba(255,190,100,${(0.45 * grow).toFixed(3)})`; ctx.lineWidth = Math.max(lw * 2, rs * 0.14);
1563
+ ctx.beginPath(); ctx.arc(c.x, c.y, rs * 1.11, 0, Math.PI * 2); ctx.stroke();
1564
+ // --- lensed starlight: short arcs of white round the horizon, the sky behind bent into rings
1565
+ for (let k = 0; k < 26; k++) {
1566
+ const hk = (q) => hash01(fx.seed + 800 + k * 7 + q);
1567
+ const rr = rs * (1.15 + 1.6 * hk(1)), a0 = hk(2) * Math.PI * 2 + now * 0.00008 * (hk(3) - 0.5), span = 0.08 + 0.35 * hk(4);
1568
+ ctx.strokeStyle = `rgba(255,255,255,${(0.45 * grow * (0.4 + 0.6 * hk(5))).toFixed(3)})`; ctx.lineWidth = Math.max(lw * 0.8, U * 0.03);
1569
+ ctx.beginPath(); ctx.arc(c.x, c.y, rr, a0, a0 + span); ctx.stroke();
1570
+ }
1571
+ ctx.lineWidth = lw;
1572
+ }
1573
+
1574
+ // A STAR'S GLINT (for the supernova's progenitor; 2026-09-15, operator: "The flashing dot as a
1575
+ // supernova looks bad. The star is blue-shifted before it blows up. Can we have a better glint
1576
+ // effect there?"). A soft halo, a hot core, four long diffraction spikes and two shorter
1577
+ // diagonals, each a gradient fading to its tip, all of it twinkling on the clock; `col` is the
1578
+ // star's colour and `f` its strength. Gradients only.
1579
+ function starGlint(ctx, x, y, size, col, f, now, lw) {
1580
+ if (f <= 0.003) return;
1581
+ const c = col.join(','), tw = 0.85 + 0.15 * Math.sin(now * 0.017) * Math.sin(now * 0.031 + 1);
1582
+ const grad = (r, stops) => { const g = typeof ctx.createRadialGradient === 'function' ? ctx.createRadialGradient(x, y, 0, x, y, r) : null; if (!g || typeof g.addColorStop !== 'function') return stops[0][1]; for (const [o, cc] of stops) g.addColorStop(o, cc); return g; };
1583
+ const lin = (x0, y0, x1, y1, stops) => { const g = typeof ctx.createLinearGradient === 'function' ? ctx.createLinearGradient(x0, y0, x1, y1) : null; if (!g || typeof g.addColorStop !== 'function') return stops[1][1]; for (const [o, cc] of stops) g.addColorStop(o, cc); return g; };
1584
+ ctx.fillStyle = grad(size * 3, [[0, `rgba(255,255,255,${(0.9 * f * tw).toFixed(3)})`], [0.12, `rgba(${c},${(0.7 * f * tw).toFixed(3)})`], [0.4, `rgba(${c},${(0.18 * f).toFixed(3)})`], [1, `rgba(${c},0)`]]);
1585
+ ctx.beginPath(); ctx.arc(x, y, size * 3, 0, Math.PI * 2); ctx.fill();
1586
+ const spikes = [[0, 1, 0.09], [Math.PI / 2, 1, 0.09], [Math.PI / 4, 0.45, 0.05], [-Math.PI / 4, 0.45, 0.05]];
1587
+ for (const [ang, len, w] of spikes) {
1588
+ const L = size * 9 * len * tw, x0 = x - Math.cos(ang) * L, y0 = y - Math.sin(ang) * L, x1 = x + Math.cos(ang) * L, y1 = y + Math.sin(ang) * L;
1589
+ ctx.strokeStyle = lin(x0, y0, x1, y1, [[0, `rgba(${c},0)`], [0.5, `rgba(255,255,255,${(0.85 * f * tw).toFixed(3)})`], [1, `rgba(${c},0)`]]);
1590
+ ctx.lineWidth = Math.max(lw * 0.8, size * w); ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x1, y1); ctx.stroke();
1591
+ ctx.strokeStyle = lin(x0, y0, x1, y1, [[0, `rgba(${c},0)`], [0.5, `rgba(${c},${(0.4 * f).toFixed(3)})`], [1, `rgba(${c},0)`]]);
1592
+ ctx.lineWidth = Math.max(lw * 2, size * w * 3.5); ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x1, y1); ctx.stroke();
1593
+ }
1594
+ ctx.fillStyle = `rgba(255,255,255,${(f * tw).toFixed(3)})`; ctx.beginPath(); ctx.arc(x, y, size * 0.45, 0, Math.PI * 2); ctx.fill();
1595
+ }
1596
+
1597
+ // A VOLUME OF GAS (for the supernova's debris, the fireworks' smoke, the pulsar's wind; 2026-09-15).
1598
+ // `n` blobs with fixed places in the unit sphere -- radius biased toward the rim, so the limb reads
1599
+ // brighter, the way a shell does when seen through -- projected with the sphere's depth kept: the
1600
+ // blobs are drawn back to front, the back ones darker, the front ones paler and hotter. The whole
1601
+ // thing expands homologously (every blob's distance in proportion to its own), grows, boils
1602
+ // slowly on the clock, and cools from `rc` toward `dark` as `f` runs 0..1. No strokes: gradients.
1603
+ // ORGANIC, NOT CIRCULAR (operator, 2026-09-15: "Everything is too circular RN. It needs to look
1604
+ // more organic like the video"): the blobs gather in CLUMPS rather than spreading evenly, each is
1605
+ // an ELLIPSE stretched along its own radial line (a streak of gas blown outward) and turned to
1606
+ // it, and the sphere's silhouette is LUMPY -- every blob's radius carries a low-order wobble by
1607
+ // its direction, so the cloud has lobes and bays rather than an outline. `colorAt(front, f, H)`,
1608
+ // if given, decides each blob's colour from its depth, the run and its own hashes.
1609
+ function gasCloud(ctx, cx, cy, shell, f, now, seed, bright, rc, grad, disc, n = 150, dark = [90, 20, 25], colorAt = null, blobScale = 1, stretchMax = 2.4) {
1610
+ const blobs = [];
1611
+ const clumps = Math.max(4, Math.round(n / 14));
1612
+ const cdir = [];
1613
+ for (let q = 0; q < clumps; q++) { const H = (k) => hash01(seed + 900 + q * 17 + k); cdir.push({ th: H(1) * Math.PI * 2, ph: Math.acos(2 * H(2) - 1), w: 0.35 + 0.5 * H(3) }); }
1614
+ const lumpA = hash01(seed + 77) * Math.PI * 2, lumpB = hash01(seed + 78) * Math.PI * 2;
1615
+ for (let k = 0; k < n; k++) {
1616
+ const H = (q) => hash01(seed + 5000 + k * 37 + q);
1617
+ const cl = cdir[Math.floor(H(6) * clumps)];
1618
+ // a gaussian-ish scatter round the clump's direction, wider for some clumps
1619
+ const th = cl.th + (H(2) + H(7) - 1) * cl.w * 1.6, ph = Math.max(0.05, Math.min(Math.PI - 0.05, cl.ph + (H(3) + H(8) - 1) * cl.w * 1.2));
1620
+ const lump = 1 + 0.22 * Math.sin(3 * th + lumpA) * Math.sin(2 * ph + lumpB) + 0.14 * Math.sin(5 * th - lumpB) + 0.1 * Math.cos(4 * ph + lumpA);
1621
+ const rho = (0.3 + 0.7 * Math.sqrt(H(1))) * lump;
1622
+ blobs.push({ x: rho * Math.sin(ph) * Math.cos(th), y: rho * Math.sin(ph) * Math.sin(th), z: rho * Math.cos(ph), s: 0.16 + 0.2 * H(4), w: H(5) * Math.PI * 2, stretch: 1 + (stretchMax - 1) * (0.3 + 0.7 * H(9)), H, k });
1623
+ }
1624
+ blobs.sort((a, b) => a.z - b.z); // back to front
1625
+ const canTransform = typeof ctx.save === 'function' && typeof ctx.rotate === 'function' && typeof ctx.scale === 'function';
1626
+ for (const b of blobs) {
1627
+ const wob = 0.035 * Math.sin(now * 0.0013 + b.w) + 0.02 * Math.sin(now * 0.0029 + b.k);
1628
+ const x = cx + (b.x + wob) * shell, y = cy + (b.y - wob * 0.6) * shell * 0.85;
1629
+ const r = shell * b.s * (0.8 + 0.7 * f) * blobScale;
1630
+ const front = (b.z + 1) / 2; // 0 at the back, 1 at the front
1631
+ let col, core;
1632
+ if (colorAt) { col = colorAt(front, f, b.H); core = col.map((v) => Math.round(v + (255 - v) * 0.45)); }
1633
+ else {
1634
+ const heat = Math.max(0, Math.min(1, 0.5 + 0.55 * front - 0.45 * f));
1635
+ col = rc.map((v, i) => Math.round(dark[i] + (v - dark[i]) * heat));
1636
+ core = col.map((v) => Math.round(v + (255 - v) * 0.5 * heat));
1637
+ }
1638
+ const a = bright * (0.32 + 0.3 * front) * (1 - 0.25 * f);
1639
+ if (a < 0.004) continue;
1640
+ const fill = (rr) => grad(0, 0, rr, [[0, `rgba(${core.join(',')},${a.toFixed(3)})`], [0.45, `rgba(${col.join(',')},${(a * 0.7).toFixed(3)})`], [1, `rgba(${col.join(',')},0)`]]);
1641
+ if (canTransform) {
1642
+ const ang = Math.atan2(y - cy, x - cx); // stretched along its own radial line
1643
+ ctx.save(); ctx.translate(x, y); ctx.rotate(ang); ctx.scale(b.stretch, 1 / Math.sqrt(b.stretch));
1644
+ ctx.fillStyle = grad(0, 0, r, [[0, `rgba(${core.join(',')},${a.toFixed(3)})`], [0.45, `rgba(${col.join(',')},${(a * 0.7).toFixed(3)})`], [1, `rgba(${col.join(',')},0)`]]);
1645
+ ctx.beginPath(); ctx.arc(0, 0, Math.max(0.5, r), 0, Math.PI * 2); ctx.fill();
1646
+ ctx.restore();
1647
+ } else softStops(ctx, x, y, r, [[0, `rgba(${core.join(',')},${a.toFixed(3)})`], [0.45, `rgba(${col.join(',')},${(a * 0.7).toFixed(3)})`], [1, `rgba(${col.join(',')},0)`]]);
1648
+ void fill;
1649
+ }
1650
+ // the limb: a soft brightening at the sphere's edge
1651
+ const R = shell * 1.02;
1652
+ softStops(ctx, cx, cy, R, [[0, `rgba(${rc.join(',')},0)`], [0.78, `rgba(${rc.join(',')},0)`], [0.92, `rgba(${rc.join(',')},${(0.16 * bright).toFixed(3)})`], [1, `rgba(${rc.join(',')},0)`]]);
1653
+ }
1654
+
1655
+ // A SUPERNOVA (operator, 2026-09-15: "build the supernova" -- the solar flare only ever lit a cube
1656
+ // and its neighbours, and on a chart of candles that was one candle blinking). MODELLED ON NASA
1657
+ // GODDARD'S ANIMATION (svs.gsfc.nasa.gov/20413, the operator's reference, 2026-09-15: "Look at
1658
+ // this video of the explosive supernova. Model something similar"): a star, a blinding flash
1659
+ // that whites out the whole picture, a turbulent debris cloud of knots and filaments expanding
1660
+ // and reddening as it dims, and, as the cloud thins, a PULSAR -- a point of light pulsing at the
1661
+ // centre inside a small blue pulsar-wind nebula that grows. Drawn on both boards, on the same
1662
+ // star fxAt lights (fxHash(seed + 7, 8)), whose shockwave throws the candles it crosses:
1663
+ // ignition 0 - 0.12 the star swells white-hot, crackle rising over it
1664
+ // breakout 0.12 - 0.34 the white-out: the whole picture goes white and comes back (no flare)
1665
+ // debris 0.14 - 1 the cloud: a volume of gas (gasCloud), a sphere of soft blobs
1666
+ // carried out by the expansion, white-gold, orange, then deep red,
1667
+ // the shock band at its leading edge
1668
+ // pulsar 0.45 - 1 the point pulsing at the centre, its blue nebula growing
1669
+ // Everything is a function of fx.u, the seed and the clock; the run fades in its last tenth.
1670
+ // a radial-gradient maker and a disc filler bound to a given context (gasCloud takes both)
1671
+ function gradFor(c) {
1672
+ return (x, y, r, stops) => {
1673
+ const g = typeof c.createRadialGradient === 'function' ? c.createRadialGradient(x, y, 0, x, y, r) : null;
1674
+ if (!g || typeof g.addColorStop !== 'function') return stops[0][1];
1675
+ for (const [o, col] of stops) g.addColorStop(o, col);
1676
+ return g;
1677
+ };
1678
+ }
1679
+ function discFor(c) { return (x, y, r, fill) => { c.fillStyle = fill; c.beginPath(); c.arc(x, y, Math.max(0.5, r), 0, Math.PI * 2); c.fill(); }; }
1680
+ // a half-size offscreen layer matching the board's canvas and transform, cleared for this frame;
1681
+ // null where there is no real canvas to make one from
1682
+ function plumeLayer(ctx, fx) {
1683
+ const cv = ctx.canvas;
1684
+ if (!cv || !cv.width || typeof ctx.getTransform !== 'function' || typeof ctx.drawImage !== 'function' || typeof document === 'undefined') return null;
1685
+ const w = Math.ceil(cv.width / 2), h = Math.ceil(cv.height / 2);
1686
+ let L = fx._plumes;
1687
+ if (!L || L.canvas.width !== w || L.canvas.height !== h) {
1688
+ const canvas = document.createElement('canvas'); canvas.width = w; canvas.height = h;
1689
+ const c2 = canvas.getContext('2d');
1690
+ if (!c2) return null;
1691
+ L = fx._plumes = { canvas, ctx: c2 };
1692
+ }
1693
+ const m = ctx.getTransform();
1694
+ L.ctx.setTransform(1, 0, 0, 1, 0, 0); L.ctx.clearRect(0, 0, w, h);
1695
+ L.ctx.setTransform(m.a / 2, m.b / 2, m.c / 2, m.d / 2, m.e / 2, m.f / 2);
1696
+ return L;
1697
+ }
1698
+ function drawSupernova(ctx, view, lw) {
1699
+ const fx = view.fx;
1700
+ if (!fx || fx.kind !== 'flare') return;
1701
+ const U = view.unit ?? 8, u = fx.u, now = view.now ?? 0;
1702
+ const line = view.axes?.line, price = line?.length > 1;
1703
+ const sx = fxHash(fx.seed + 7) * fx.gridW, sy = price ? (view.axes.y ?? fx.gridH / 2) : fxHash(fx.seed + 8) * fx.gridH;
1704
+ let sz = 3;
1705
+ if (price) { // the star sits on the price line at that hour
1706
+ let best = line[0]; for (const p of line) if (Math.abs(p.x - sx) < Math.abs(best.x - sx)) best = p;
1707
+ sz = best.z;
1708
+ }
1709
+ const c = project(sx, sy, sz, view);
1710
+ // BOUNDED (operator, 2026-09-15: "supernova and black hole nebula effects take up too much
1711
+ // screen space ... it's obscuring too much"): the shell was sized at half the board and the
1712
+ // white-out was the whole frame, which on the Kiosk's panel was the whole panel; the shell is
1713
+ // about a third of the board now and the flash a soft disc round the star
1714
+ // ...and never more than 7% of the board's width, whatever the board (the Kiosk's block-space
1715
+ // panel is 44 units across and small on screen: at 4.5 units the cloud covered most of it)
1716
+ const R0 = U * boundedRadius(price ? 3.4 : 4.5, 0.07, fx.gridW);
1717
+ const gf = Math.min(1, (1 - u) / 0.1);
1718
+ // still a real gradient maker, because gasCloud() takes one as a callback for its puffs; every
1719
+ // FILL drawn directly by this function is layered flat discs now (softStops)
1720
+ const grad = (x, y, r, stops) => {
1721
+ const g = typeof ctx.createRadialGradient === 'function' ? ctx.createRadialGradient(x, y, 0, x, y, r) : null;
1722
+ if (!g || typeof g.addColorStop !== 'function') return stops[0][1];
1723
+ for (const [o, col] of stops) g.addColorStop(o, col);
1724
+ return g;
1725
+ };
1726
+ const disc = (x, y, r, fill) => { ctx.fillStyle = fill; ctx.beginPath(); ctx.arc(x, y, Math.max(0.5, r), 0, Math.PI * 2); ctx.fill(); };
1727
+ const mixc = (a, b, t) => a.map((v, i) => Math.round(v + (b[i] - v) * t));
1728
+ // the cloud's colour with the run, as in the reference (operator: "the cloud is white at the
1729
+ // start, shifting towards blue, then purple/violet"): white, blue, then violet
1730
+ const cool = Math.max(0, Math.min(1, (u - 0.14) / 0.86));
1731
+ const rc = cool < 0.3 ? mixc([255, 255, 255], [150, 195, 255], cool / 0.3) : mixc([150, 195, 255], [175, 110, 255], (cool - 0.3) / 0.7);
1732
+ const rcs = rc.join(',');
1733
+ // --- ignition: a white nebula, not a ball (operator, 2026-09-15: "Don't use a white ball visual
1734
+ // at the beginning of the animation. Use white nebula effects"): a small cloud of white gas
1735
+ // gathering and brightening round the star, blue-shifting as the blast nears
1736
+ if (u < 0.14) {
1737
+ const f = Math.min(1, u / 0.12), ease = f * f;
1738
+ const col = [Math.round(255 - 70 * ease), Math.round(255 - 30 * ease), 255];
1739
+ gasCloud(ctx, c.x, c.y, R0 * (0.35 + 0.9 * ease), 0.2, now, fx.seed + 555, 0.25 + 0.75 * ease, col, grad, disc, 70, [120, 150, 230]);
1740
+ }
1741
+ // --- THE DEBRIS CLOUD AS A VOLUME OF GAS (operator, 2026-09-15: "Overall it needs to look
1742
+ // more like the NASA video. I don't think the ejecta/fireworks is working well ... The thin
1743
+ // white lines shifting at the edges does not hold up well"). No lines of any kind. The cloud
1744
+ // is gasCloud: a sphere of soft gradient blobs, each with a fixed place in the unit sphere
1745
+ // (denser toward the rim, so the limb is brighter, as a shell seen through is), carried
1746
+ // outward by the expansion -- every blob at a radius in proportion to its own, as a real
1747
+ // remnant expands -- growing as it goes, the front ones hotter and paler than the ones behind,
1748
+ // the whole cooling white-gold -> orange -> red as it dims, its surface boiling on the clock.
1749
+ const band = (r, w, col, a) => {
1750
+ if (r <= 0 || a <= 0.003) return;
1751
+ const R = r + w;
1752
+ softStops(ctx, c.x, c.y, R, [[0, `rgba(${col},0)`], [Math.max(0, (r - w) / R), `rgba(${col},0)`], [Math.max(0, (r - w * 0.35) / R), `rgba(${col},${a.toFixed(3)})`], [r / R, `rgba(240,245,255,${(a * 0.8).toFixed(3)})`], [Math.min(1, (r + w * 0.5) / R), `rgba(${col},${(a * 0.6).toFixed(3)})`], [1, `rgba(${col},0)`]]);
1753
+ };
1754
+ if (u >= 0.14) {
1755
+ const f = (u - 0.14) / 0.86;
1756
+ const shell = R0 * (0.5 + 4.2 * (1 - Math.exp(-1.3 * f))); // the cloud's radius: slower than the first cut (operator: "the cloud dispersion is too fast")
1757
+ // LINGERING (operator, 2026-09-15: "make the violet nebula linger longer into the blink
1758
+ // phase"): the cloud holds full weight until four fifths of the run -- well into the pulsar's
1759
+ // beat -- and only thins over the last fifth, so the purple stays round the blinking star
1760
+ const bright = (f < 0.08 ? f / 0.08 : f < 0.8 ? 1 : Math.pow(1 - (f - 0.8) / 0.2, 1.2)) * gf;
1761
+ // THE MORPHING (operator, 2026-09-15: "as it shifts from blue to white initially, then the
1762
+ // purples and violets start appearing, as the blue clouds continue to disperse ahead of
1763
+ // everything else"): three clouds. The BLUE one is out in front, expanding fastest and
1764
+ // thinning first; the MAIN one behind it is white at the start, and violet grows into it
1765
+ // patch by patch, each blob turning on its own schedule, until the whole is purple; the
1766
+ // INNER one is the deep violet heart that shows as the others thin.
1767
+ const blueShell = R0 * (0.6 + 4.6 * (1 - Math.exp(-1.9 * f)));
1768
+ const blueBright = bright * 0.7 * Math.pow(1 - f, 1.6);
1769
+ // SMOOTH (operator, 2026-09-15: "We see too much of the radial texture. Lets try to smoothen
1770
+ // that up"): more and larger blobs at a lower weight, barely stretched, so they melt into one
1771
+ // another instead of reading as radial streaks
1772
+ gasCloud(ctx, c.x, c.y, blueShell, f, now, fx.seed + 31337, blueBright * 0.32, [150, 195, 255], grad, disc, 140, [70, 110, 220], (front, ff, H) => {
1773
+ const t = Math.min(1, ff / 0.5);
1774
+ return [Math.round(215 - 65 * t), Math.round(235 - 40 * t), 255].map((v, i) => Math.round(v * (0.75 + 0.25 * front) + (i === 2 ? 0 : 0)));
1775
+ }, 0.85, 1.25);
1776
+ // THIN, NOT SOLID (2026-09-15, the Kiosk: "far too much solid white"): overlapping discs sum
1777
+ // toward opaque however faint each is -- 320 blobs saturated, and 170 at a third still did --
1778
+ // so the cloud is ninety blobs at an eighth of the weight, which peaks near half opacity at the
1779
+ // centre and reads as gas the chart shows through
1780
+ gasCloud(ctx, c.x, c.y, shell, f, now, fx.seed, bright * 0.17, rc, grad, disc, 220, [60, 30, 120], (front, ff, H) => {
1781
+ // SOONER (operator, 2026-09-15: "we need more of the third stage purple and violet nebula
1782
+ // becoming prominent as it starts the blink phase"): the patches turn violet between a tenth
1783
+ // and four tenths of the run, so the cloud is mostly purple by the time the pulsar wakes
1784
+ const start = 0.1 + 0.3 * H(11), on = Math.max(0, Math.min(1, (ff - start) / 0.2)); // when this patch turns violet
1785
+ const white = [225, 235, 255], violet = [170, 105, 255], deep = [95, 45, 170]; // blue-white, not solid white (2026-09-15)
1786
+ const c1 = white.map((v, i) => v + (violet[i] - v) * on);
1787
+ const shade = 0.55 + 0.45 * front;
1788
+ return c1.map((v, i) => Math.round(deep[i] + (v - deep[i]) * shade));
1789
+ }, 0.85, 1.25);
1790
+ if (f > 0.2) {
1791
+ // the violet heart, sooner and heavier (the same request): rising from a fifth of the run,
1792
+ // full by the blink, and a second wider violet cloud behind it that keeps growing
1793
+ const inner = Math.min(1, (f - 0.2) / 0.18);
1794
+ gasCloud(ctx, c.x, c.y, shell * 0.7, f, now, fx.seed + 777, bright * 0.3 * inner, [160, 90, 255], grad, disc, 90, [60, 25, 130], null, 0.9, 1.25);
1795
+ gasCloud(ctx, c.x, c.y, shell * 1.05, f, now, fx.seed + 778, bright * 0.16 * inner, [175, 115, 255], grad, disc, 90, [70, 30, 140], null, 1.1, 1.3);
1796
+ }
1797
+ // and the interior glow: the cloud lit from within
1798
+ softStops(ctx, c.x, c.y, shell * 0.8, [[0, `rgba(${rcs},${(0.1 * bright).toFixed(3)})`], [0.6, `rgba(${rcs},${(0.05 * bright).toFixed(3)})`], [1, `rgba(${rcs},0)`]]);
1799
+ // the shock band at the cloud's leading edge, soft, in the cloud's colour
1800
+ if (u < 0.6) {
1801
+ const fr = (u - 0.14) / 0.46, r = R0 * 4.5 * (1 - Math.pow(1 - fr, 2.2));
1802
+ softStops(ctx, c.x, c.y, r, [[0, 'rgba(235,240,255,0)'], [0.7, `rgba(235,240,255,${(0.05 * (1 - fr) * gf).toFixed(3)})`], [1, `rgba(240,245,255,${(0.14 * (1 - fr) * gf).toFixed(3)})`]]);
1803
+ band(r, R0 * (0.3 + 0.6 * (1 - fr)), rcs, 0.4 * (1 - fr) * gf);
1804
+ }
1805
+ // a wide pool of the cloud's colour on everything near
1806
+ softStops(ctx, c.x, c.y, shell * 1.9, [[0, `rgba(${rcs},${(0.08 * bright).toFixed(3)})`], [1, `rgba(${rcs},0)`]]);
1807
+ }
1808
+ // --- the breakout: the whole picture goes white and comes back
1809
+ if (u >= 0.12 && u < 0.4) {
1810
+ const t = (u - 0.12) / 0.28, f = t < 0.1 ? t / 0.1 : Math.pow(1 - (t - 0.1) / 0.9, 1.5);
1811
+ // THE FLASH ITSELF (operator, 2026-09-15: "It's missing the bright white flash!"): a bright,
1812
+ // brief one -- full white at the heart for an instant, gone in a third of the breakout -- so
1813
+ // it reads as a flash, not as a solid glow that sits on the Kiosk's panel
1814
+ const fl = t < 0.04 ? t / 0.04 : t < 0.12 ? 1 : Math.pow(Math.max(0, 1 - (t - 0.12) / 0.3), 2);
1815
+ // WHITE-HOT (operator, 2026-09-15: "We need to add the white-hot-flash to the explosion
1816
+ // again"): the heart goes fully white and holds for a moment, and a wide veil of light
1817
+ // washes twice as far out for the same instant -- bounded to the star's neighbourhood, so
1818
+ // the Kiosk's panel flashes bright but never sits solid
1819
+ if (fl > 0) {
1820
+ const V = R0 * 8;
1821
+ disc(c.x, c.y, V, grad(c.x, c.y, V, [[0, `rgba(255,255,252,${(0.45 * fl).toFixed(3)})`], [0.4, `rgba(255,252,246,${(0.18 * fl).toFixed(3)})`], [1, 'rgba(255,248,240,0)']]));
1822
+ }
1823
+ // a soft flash round the star, not the whole frame -- and NOT SOLID (operator, 2026-09-15, via
1824
+ // his wife on the Kiosk: "far too much solid white"): a modest disc, at most half opaque at its
1825
+ // heart, thin by three shells out, and the white gas thrown with it at a third of the weight
1826
+ const W = R0 * 4;
1827
+ // PRESENCE BACK (operator, 2026-09-15: "We've removed so much of the initial white nebula
1828
+ // emission that it's lost much of its presence and intensity") -- now that the discs add up
1829
+ // honestly, the flash and the white gas can carry weight again without going solid
1830
+ disc(c.x, c.y, W, grad(c.x, c.y, W, [[0, `rgba(255,255,252,${Math.min(1, 0.3 * f + 1.0 * fl).toFixed(3)})`], [0.35, `rgba(255,252,244,${Math.min(1, 0.15 * f + 0.6 * fl).toFixed(3)})`], [0.7, `rgba(255,248,235,${(0.05 * f + 0.06 * fl).toFixed(3)})`], [1, 'rgba(255,245,230,0)']]));
1831
+ // MORE GAS OFF THE FLASH (operator, 2026-09-15: "Opening white flash needs more dispersing
1832
+ // nebula gas"): two clouds thrown with it -- a dense one at the flash and a wider, thinner
1833
+ // one racing ahead of it -- both flying out faster than the flash fades, so the white
1834
+ // disperses into the dark rather than shrinking back into the star
1835
+ // A BURST OF PLUMES, not two clouds (operator, 2026-09-15: "need much more than two clouds of
1836
+ // white gas in the initial explosion"): the dense cloud at the flash, and the plumes of
1837
+ // white gas thrown from it in every direction (below), each its own cloud flying outward on
1838
+ // its own speed and growing as it goes, the fast ones out ahead and thinning first
1839
+ gasCloud(ctx, c.x, c.y, R0 * (1.0 + 2.2 * t), t, now, fx.seed + 999, 0.1 * f, [255, 255, 255], grad, disc, 80, [200, 210, 240], null, 0.9, 1.25);
1840
+ // (no lens flare here: its turning rays were the "opening rotating glints" the operator had
1841
+ // taken out on 2026-09-15; the white-out alone is the breakout)
1842
+ }
1843
+ // FURTHER AND LONGER (operator, 2026-09-15: "the plumes need to disperse further out and linger
1844
+ // longer ... Double the amount"): thirty-two plumes on their own clock, outliving the flash by
1845
+ // half again -- they reach nine star radii, keep flying after the flash has gone, and only
1846
+ // thin out slowly, so the white gas is still drifting outward when the blue debris rises
1847
+ // AND AGAIN (operator, 2026-09-15: "the white plumes still fade too fast, make them linger
1848
+ // longer. Double the amount again" -- then "Double the white ejecta again. We're getting
1849
+ // closer!"): a hundred and twenty-eight plumes, holding full for the first fifth of
1850
+ // their flight and thinning slowly over the rest, still drifting at nine tenths of the effect
1851
+ if (u >= 0.12 && u < 0.9) {
1852
+ const t = (u - 0.12) / 0.78, g = t < 0.04 ? t / 0.04 : t < 0.2 ? 1 : Math.pow(1 - (t - 0.2) / 0.8, 0.7);
1853
+ // AT HALF RESOLUTION: a hundred and twenty-eight clouds of soft gradient discs is the costliest
1854
+ // thing any effect draws, so the plumes go onto a half-size layer (a quarter of the pixels to
1855
+ // fill) and are blitted up -- gas is blurry to begin with, so nothing is lost; where there is
1856
+ // no offscreen canvas (the tests' stub context) they draw straight onto the board
1857
+ const layer = plumeLayer(ctx, fx), pc = layer ? layer.ctx : ctx;
1858
+ const pgrad = layer ? gradFor(pc) : grad, pdisc = layer ? discFor(pc) : disc;
1859
+ for (let k = 0; k < 128; k++) {
1860
+ const H = (q) => hash01(fx.seed + 4400 + k * 19 + q);
1861
+ const ang = (k / 128) * Math.PI * 2 + (H(1) - 0.5) * 0.2, sp = 0.4 + 1.2 * H(2);
1862
+ const reach = R0 * (0.6 + 9 * t) * sp, ease = 1 - Math.exp(-2.2 * t);
1863
+ const px = c.x + Math.cos(ang) * reach * ease, py = c.y + Math.sin(ang) * 0.75 * reach * ease;
1864
+ const shell = R0 * (0.5 + 2.8 * t) * (0.7 + 0.6 * H(3));
1865
+ gasCloud(pc, px, py, shell, t, now, fx.seed + 5000 + k * 131, 0.09 * g * (1 - 0.3 * sp), [245, 248, 255], pgrad, pdisc, 10, [180, 195, 235], null, 1.3, 1.3);
1866
+ }
1867
+ if (layer) { ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.drawImage(layer.canvas, 0, 0, ctx.canvas.width, ctx.canvas.height); ctx.restore(); }
1868
+ }
1869
+ // --- the pulsar: as the cloud dims, a point pulsing at the centre, its blue nebula growing
1870
+ if (u >= 0.45) {
1871
+ const f = (u - 0.45) / 0.55, on = Math.min(1, f / 0.1) * gf;
1872
+ const period = 140, ph = ((now % period) / period), pulse = Math.pow(Math.max(0, 1 - Math.abs(ph - 0.5) * 6), 2); // a sharp beat, seven a second (operator: "Pulsar needs to pulse quicker")
1873
+ const neb = R0 * (0.25 + 1.1 * f);
1874
+ // THE WIND NEBULA IS A GAS CLOUD TOO (operator, 2026-09-15: "The pulsar nebula needs the gas
1875
+ // cloud too"): a small blue-white sphere of blobs blown outward from the pulsar, growing with
1876
+ // it, lit from the centre, the pulsar's beat showing in its brightness
1877
+ softStops(ctx, c.x, c.y, neb, [[0, `rgba(190,225,255,${(0.28 * on).toFixed(3)})`], [0.5, `rgba(120,175,255,${(0.12 * on).toFixed(3)})`], [1, 'rgba(80,130,255,0)']]);
1878
+ gasCloud(ctx, c.x, c.y, neb, f, now, fx.seed + 4242, on * (0.75 + 0.25 * pulse), [170, 215, 255], grad, disc, 70, [40, 70, 170]);
1879
+ const rp = R0 * (0.12 + 0.25 * pulse);
1880
+ softStops(ctx, c.x, c.y, rp * 2.4, [[0, `rgba(255,255,255,${((0.5 + 0.5 * pulse) * on).toFixed(3)})`], [0.3, `rgba(200,235,255,${(0.55 * pulse * on).toFixed(3)})`], [1, 'rgba(140,200,255,0)']]);
1881
+ disc(c.x, c.y, rp * 0.5, `rgba(255,255,255,${on.toFixed(3)})`);
1882
+ // the beam: two thin rays sweeping round with the beat
1883
+ const sweep = now * 0.004;
1884
+ for (const side of [0, Math.PI]) {
1885
+ const ang = sweep + side, L = neb * (0.8 + 0.8 * pulse);
1886
+ ctx.strokeStyle = `rgba(220,240,255,${(0.35 * pulse * on).toFixed(3)})`; ctx.lineWidth = Math.max(lw, U * 0.04);
1887
+ ctx.beginPath(); ctx.moveTo(c.x, c.y); ctx.lineTo(c.x + Math.cos(ang) * L, c.y + Math.sin(ang) * L); ctx.stroke();
1888
+ }
1889
+ }
1890
+ ctx.lineWidth = lw;
1891
+ }
1892
+
760
1893
  // THE LIGHTNING BALL, over the cubes: the grid line it has traced burning behind it and cooling
761
1894
  // over 16 units, a plasma ball of one pale gradient with a white-hot heart, and bolts jumping from it
762
1895
  // to the grid crossings round it, new every frame. Plain rgba fills and strokes only.
@@ -801,17 +1934,16 @@ function drawBall(ctx, view, lw) {
801
1934
  // thin so the ball is light on the board rather than a shadow over it.
802
1935
  const flick = 0.85 + 0.15 * Math.random();
803
1936
  const R = 4.2 * U;
804
- const g = typeof ctx.createRadialGradient === 'function' ? ctx.createRadialGradient(c.x, c.y, 0, c.x, c.y, R) : null;
805
- if (g && typeof g.addColorStop === 'function') {
806
- g.addColorStop(0, 'rgba(255,255,255,1)');
807
- g.addColorStop(0.1, 'rgba(240,250,255,1)');
808
- g.addColorStop(0.22, 'rgba(200,236,255,0.85)');
809
- g.addColorStop(0.4, `rgba(170,220,255,${(0.32 * flick).toFixed(3)})`);
810
- g.addColorStop(0.68, `rgba(160,205,255,${(0.1 * flick).toFixed(3)})`);
811
- g.addColorStop(1, 'rgba(160,200,255,0)');
812
- ctx.fillStyle = g;
813
- } else ctx.fillStyle = 'rgba(220,240,255,0.5)';
814
- ctx.beginPath(); ctx.arc(c.x, c.y, R, 0, Math.PI * 2); ctx.fill();
1937
+ // layered flat discs, not a radial gradient: this is the biggest soft blob on the board and it
1938
+ // banded visibly (operator, 2026-09-15: "what is still with the gradient fill shit?!")
1939
+ softStops(ctx, c.x, c.y, R, [
1940
+ [0, 'rgba(255,255,255,1)'],
1941
+ [0.1, 'rgba(240,250,255,1)'],
1942
+ [0.22, 'rgba(200,236,255,0.85)'],
1943
+ [0.4, `rgba(170,220,255,${(0.32 * flick).toFixed(3)})`],
1944
+ [0.68, `rgba(160,205,255,${(0.1 * flick).toFixed(3)})`],
1945
+ [1, 'rgba(160,200,255,0)'],
1946
+ ], 26);
815
1947
  const z0 = b.z - 0.9;
816
1948
  const bolts = 4 + ((Math.random() * 4) | 0);
817
1949
  for (let i = 0; i < bolts; i++) {
@@ -980,7 +2112,7 @@ function drawGrid(ctx, view, opts, n, blockRows, rows = n) {
980
2112
  polyline(pts, 16, `rgba(80,255,190,${(0.12 * fx.amp).toFixed(3)})`);
981
2113
  polyline(pts, 3, `rgba(180,255,230,${(0.45 * fx.amp).toFixed(3)})`);
982
2114
  }
983
- if (fx && (fx.kind === 'outline' || fx.kind === 'scan' || fx.kind === 'tide')) {
2115
+ if (fx && (fx.kind === 'outline' || fx.kind === 'tide')) { // the scan draws its own foot (drawScanCurtain)
984
2116
  // the front itself, drawn across the floor where it is
985
2117
  const p = fxFront(fx);
986
2118
  const L = Math.hypot(n, rows);
@@ -1297,20 +2429,37 @@ function curveByLength(pts, samples = 400) {
1297
2429
  let lo = 0, hi = samples;
1298
2430
  while (hi - lo > 1) { const mid = (lo + hi) >> 1; if (table[mid].len < L) lo = mid; else hi = mid; }
1299
2431
  const a = table[lo], b = table[hi], f = b.len > a.len ? (L - a.len) / (b.len - a.len) : 0;
1300
- return curveAt(pts, a.s + (b.s - a.s) * f);
2432
+ // never exactly 1: curveAt's last segment is pts[n-1]..pts[n], and s = 1 would ask for pts[n+1]
2433
+ // (the pulse's head bulge sits at the very end of the line once the head has run off it)
2434
+ return curveAt(pts, Math.min(0.999999, a.s + (b.s - a.s) * f));
2435
+ };
2436
+ // the length along the curve at parameter s (0..1 by point index, as headPoint and curveAt count):
2437
+ // the pulse's bulge is placed with this, so it sits ON the head rather than a share of the length
2438
+ // along -- which drifted from the head wherever the candles' hops were unequal (operator,
2439
+ // 2026-09-15: "the bulge effect is lagging behind the energy. They should be on top of each other")
2440
+ const lenAt = (sv) => {
2441
+ const S = Math.max(0, Math.min(1, sv));
2442
+ let lo = 0, hi = samples;
2443
+ while (hi - lo > 1) { const mid = (lo + hi) >> 1; if (table[mid].s < S) lo = mid; else hi = mid; }
2444
+ const a = table[lo], b = table[hi], f = b.s > a.s ? (S - a.s) / (b.s - a.s) : 0;
2445
+ return a.len + (b.len - a.len) * f;
1301
2446
  };
1302
- return { total, at, travel: bulgeTravel(table) };
2447
+ return { total, at, lenAt, travel: bulgeTravel(table) };
1303
2448
  }
1304
2449
 
1305
2450
  function drawBulge(ctx, pts, lw0, u, layers, ms = FX_MS.bulge) {
1306
2451
  const lw = Number.isFinite(lw0) && lw0 > 0 ? lw0 : 1; // a canvas that will not say: one pixel
1307
2452
  const { t } = bulgeAt(u, ms);
1308
2453
  const coreR = (lw * 5.5) / 2;
1309
- const Rfull = coreR * BULGE_BALL;
1310
2454
  const curve = curveByLength(pts);
1311
2455
  // the ball's centre travels the whole line, quicker downhill and slower up (bulgeTravel); the ball
1312
2456
  // is as big as fits between it and the nearer end
1313
- const centre = curve.travel(t);
2457
+ drawBulgeAt(ctx, pts, lw, curve.travel(t), coreR * BULGE_BALL, layers, curve);
2458
+ }
2459
+ /** The swell itself, at `centre` along the curve with a full radius of `Rfull`: the pulse's head borrows it. */
2460
+ function drawBulgeAt(ctx, pts, lw0, centre, Rfull, layers, curve = curveByLength(pts)) {
2461
+ const lw = Number.isFinite(lw0) && lw0 > 0 ? lw0 : 1; // a canvas that will not say: one pixel
2462
+ const coreR = (lw * 5.5) / 2;
1314
2463
  const R = bulgeFit(Math.min(centre, curve.total - centre), Rfull, coreR);
1315
2464
  const amp = (R - coreR) / (Rfull - coreR || 1);
1316
2465
  if (amp < 0.002) return;
@@ -1406,9 +2555,83 @@ function electrifyLine(ctx, pts, view, lw) {
1406
2555
  }
1407
2556
  }
1408
2557
 
2558
+
2559
+ // A LIGHT SABER (operator, 2026-09-15: "add another markets effect that really rips off a star wars
2560
+ // light saber visual somehow"). The price line is the blade. It IGNITES from the left end -- the
2561
+ // blade extends along the line with a flash at the hilt and a bright tip -- HUMS for most of the
2562
+ // run (the glow breathes on two fast sines, the core shimmers, and now and then a spark spits off
2563
+ // the blade), and RETRACTS to the hilt. One of four colours a run, hashed from the seed: blue,
2564
+ // green, red, purple. The unlit rest of the line stays as the faint wire. Nothing here is the
2565
+ // price line's resting look, which is the steady neon glow (markets.test.js keeps it so).
2566
+ const SABER_COLS = [[80, 170, 255], [90, 255, 130], [255, 70, 70], [200, 100, 255]];
2567
+ function drawSaberLine(ctx, pts, lw, fx, view, GLOW, CORE) {
2568
+ const u = fx.u, now = view.now ?? 0;
2569
+ const col = SABER_COLS[Math.floor(hash01(fx.seed + 7) * SABER_COLS.length)];
2570
+ const c = col.join(',');
2571
+ const pale = col.map((v) => Math.round(v + (255 - v) * 0.55)).join(',');
2572
+ const IGN = 0.14, RET = 0.86;
2573
+ const ease = (t) => 1 - Math.pow(1 - t, 3);
2574
+ const ext = u < IGN ? ease(u / IGN) : u > RET ? 1 - ease((u - RET) / (1 - RET)) : 1;
2575
+ // the faint wire under it all
2576
+ const stroke = (w, colour, path) => { ctx.strokeStyle = colour; ctx.lineWidth = lw * w; ctx.beginPath(); path(); ctx.stroke(); };
2577
+ const wire = () => traceCurve(ctx, pts);
2578
+ for (const [w, cc, a] of [...GLOW, ...CORE]) stroke(w, `rgba(${cc[0]},${cc[1]},${cc[2]},${(a * 0.3).toFixed(3)})`, wire);
2579
+ if (ext <= 0.002) return;
2580
+ // the lit part: the curve up to `ext` of its length
2581
+ const curve = curveByLength(pts);
2582
+ const len = curve.total * ext;
2583
+ const N = Math.max(2, Math.ceil(64 * ext));
2584
+ const blade = [];
2585
+ for (let k = 0; k <= N; k++) blade.push(curve.at((len * k) / N));
2586
+ const along = () => { ctx.moveTo(blade[0].x, blade[0].y); for (let k = 1; k < blade.length; k++) ctx.lineTo(blade[k].x, blade[k].y); };
2587
+ // the hum: the glow breathes on two fast sines, never still
2588
+ const hum = 1 + 0.06 * Math.sin(now * 0.05) + 0.035 * Math.sin(now * 0.131 + 1);
2589
+ const bright = 0.9 + 0.1 * Math.sin(now * 0.021);
2590
+ // a third thicker than the first cut (operator, 2026-09-15: "make the saber effect a bit thicker")
2591
+ stroke(44 * hum, `rgba(${c},${(0.11 * bright).toFixed(3)})`, along);
2592
+ stroke(27 * hum, `rgba(${c},${(0.24 * bright).toFixed(3)})`, along);
2593
+ stroke(15 * hum, `rgba(${c},${(0.58 * bright).toFixed(3)})`, along);
2594
+ stroke(8.8, `rgba(${pale},0.92)`, along);
2595
+ stroke(4.4, `rgba(255,255,255,${(0.95 * bright).toFixed(3)})`, along);
2596
+ // the core shimmers: a thin white thread whose brightness runs along the blade
2597
+ for (let k = 0; k < blade.length - 1; k++) {
2598
+ const f = 0.5 + 0.5 * Math.sin(now * 0.03 + k * 0.9);
2599
+ ctx.strokeStyle = `rgba(255,255,255,${(0.35 * f).toFixed(3)})`; ctx.lineWidth = lw * 1.9;
2600
+ ctx.beginPath(); ctx.moveTo(blade[k].x, blade[k].y); ctx.lineTo(blade[k + 1].x, blade[k + 1].y); ctx.stroke();
2601
+ }
2602
+ // the tip: a bright point with the colour's bloom round it
2603
+ const tip = blade[blade.length - 1];
2604
+ for (const [r, colour, a] of [[12, c, 0.25], [6.8, pale, 0.7], [3.2, '255,255,255', 1]]) {
2605
+ ctx.fillStyle = `rgba(${colour},${a})`; ctx.beginPath(); ctx.arc(tip.x, tip.y, lw * r, 0, Math.PI * 2); ctx.fill();
2606
+ }
2607
+ // the hilt flashes at ignition and again as the blade comes home
2608
+ const flash = u < IGN ? 1 - u / IGN : u > RET ? (u - RET) / (1 - RET) : 0;
2609
+ if (flash > 0) {
2610
+ const h = blade[0];
2611
+ for (const [r, colour, a] of [[26, c, 0.18], [14, pale, 0.45], [6, '255,255,255', 0.9]]) {
2612
+ ctx.fillStyle = `rgba(${colour},${(a * flash).toFixed(3)})`; ctx.beginPath(); ctx.arc(h.x, h.y, lw * r * (0.6 + 0.4 * flash), 0, Math.PI * 2); ctx.fill();
2613
+ }
2614
+ }
2615
+ // now and then a spark spits off the blade: a few short lines from one point, gone in a beat
2616
+ const beat = Math.floor(now / 90);
2617
+ if (ext >= 1 && hash01(fx.seed + beat) < 0.3) {
2618
+ const at = curve.at(curve.total * hash01(fx.seed + beat * 3 + 1));
2619
+ const srnd = (k) => hash01(fx.seed + beat * 7 + k);
2620
+ for (let k = 0; k < 6; k++) {
2621
+ const ang = srnd(k) * Math.PI * 2, r = lw * (6 + 12 * srnd(k + 20));
2622
+ ctx.strokeStyle = `rgba(${pale},${(0.8 * (0.5 + 0.5 * srnd(k + 40))).toFixed(3)})`; ctx.lineWidth = lw * 1.2;
2623
+ ctx.beginPath(); ctx.moveTo(at.x, at.y); ctx.lineTo(at.x + Math.cos(ang) * r, at.y + Math.sin(ang) * r); ctx.stroke();
2624
+ }
2625
+ }
2626
+ }
1409
2627
  function priceLine(ctx, view, axes) {
1410
- const pts = (axes.line ?? []).map((q) => project(q.x, axes.y ?? 0, q.z, view));
2628
+ let pts = (axes.line ?? []).map((q) => project(q.x, axes.y ?? 0, q.z, view));
1411
2629
  if (pts.length < 2) return;
2630
+ // THE LINE BENDS ROUND THE BLACK HOLE (2026-09-15): every point is pushed out from the hole's
2631
+ // centre the way a lens pushes a background image -- r' = sqrt(r^2 + rE^2), the Einstein
2632
+ // radius rE growing with the hole -- so the chart warps into an arc round the shadow, and
2633
+ // the stretch inside the horizon is drawn under the shadow, which covers it
2634
+ if (view.fx?.kind === 'blackhole' && view.fx.blackhole) pts = lensPoints(pts, view);
1412
2635
  const lw = ctx.lineWidth;
1413
2636
  const join = ctx.lineJoin, cap = ctx.lineCap;
1414
2637
  ctx.lineJoin = 'round';
@@ -1445,6 +2668,28 @@ function priceLine(ctx, view, axes) {
1445
2668
  const CORE = [[5.5, [255, 236, 70], 0.78, 'core'], [3, [255, 246, 150], 1, 'core'], [1.3, [255, 255, 240], 1, 'core']];
1446
2669
  const fx = view.fx && view.fx.kind === 'pulse' ? view.fx : null;
1447
2670
  const done = () => { ctx.lineWidth = lw; ctx.lineJoin = join; ctx.lineCap = cap; };
2671
+ const HOT = [255, 255, 215]; // the flash: whiter than the wire
2672
+ // THE LINE BREATHES (operator, 2026-09-15: "an effect for the markets page that makes the line
2673
+ // breathe in-and-out between those two extents"): three slow swells over the run, each easing
2674
+ // the tube from the plain wire to the pulse's heat -- wider, whiter, brighter -- and back.
2675
+ if (view.fx?.kind === 'breathe') {
2676
+ const bre = 0.5 - 0.5 * Math.cos(view.fx.u * Math.PI * 2 * 3);
2677
+ const env = Math.sin(Math.PI * view.fx.u); // in from nothing and out to nothing over the run
2678
+ const k = bre * env;
2679
+ for (const [w, c, a] of [...GLOW, ...CORE]) {
2680
+ const mix = (j) => Math.round(c[j] + (HOT[j] - c[j]) * 0.8 * k);
2681
+ stroke(w * (1 + 0.9 * k), `rgba(${mix(0)},${mix(1)},${mix(2)},${Math.min(1, a * (1 + 0.6 * k))})`);
2682
+ }
2683
+ done();
2684
+ return;
2685
+ }
2686
+ if (view.fx?.kind === 'saber') { drawSaberLine(ctx, pts, lw, view.fx, view, GLOW, CORE); done(); return; }
2687
+ if (view.fx?.kind === 'scan') {
2688
+ for (const [w, c, a] of [...GLOW, ...CORE]) stroke(w, `rgba(${c[0]},${c[1]},${c[2]},${a})`);
2689
+ scanFlare(ctx, pts, axes, view, lw);
2690
+ done();
2691
+ return;
2692
+ }
1448
2693
  if (view.fx?.kind === 'bulge') {
1449
2694
  for (const [w, c, a] of [...GLOW, ...CORE]) stroke(w, `rgba(${c[0]},${c[1]},${c[2]},${a})`);
1450
2695
  drawBulge(ctx, pts, lw, view.fx.u, [...GLOW, ...CORE], view.fx.ms);
@@ -1465,9 +2710,13 @@ function priceLine(ctx, view, axes) {
1465
2710
  // surround reads as pure blue instead of the washed periwinkle it was. The tail's shape is
1466
2711
  // untouched -- every pass still blends wire-yellow through these to HOT at the overshoot; only
1467
2712
  // how blue "blue" is has changed.
1468
- const BLUE = [120, 225, 255]; // the core: electric neon
1469
- const DEEP = [0, 120, 255]; // the bloom: pure saturated blue
1470
- const HOT = [255, 255, 215]; // the flash: whiter than the wire
2713
+ // NO BLUE (operator, 2026-09-15: "during the energy pulse, I don't like the blue shift/tint it's
2714
+ // adding on everything. Get rid of that, and add a bulge effect around the energy pulse"). The
2715
+ // surge is heat now: behind the head the tube goes white-hot through hot gold and cools back to
2716
+ // the wire, the cloud behind it is warm, the crackle and the motes are gold and white, and the
2717
+ // head is a swell in the pipe (drawBulgeAt) with a white-hot core, not a blue dot.
2718
+ const BLUE = [255, 255, 235]; // the core behind the head: white-hot
2719
+ const DEEP = [255, 205, 90]; // the bloom behind the head: hot gold
1471
2720
  // THE NEBULA BEHIND THE SURGE (operator, 2026-09-12: "like a blue nebula behind the energy pulse
1472
2721
  // that starts expanding and fading out to black"). Drawn FIRST, so it sits behind the wire: soft
1473
2722
  // nested discs on every charged segment, their radius growing with that stretch's age and their
@@ -1488,37 +2737,32 @@ function priceLine(ctx, view, axes) {
1488
2737
  // large"). Puffs spread about half as far from the line (4 + 78 * age line-widths -> 3 + 38), are
1489
2738
  // a bit over half the radius and grow less with age, and sit at three-quarters of the alpha, so the
1490
2739
  // cloud hugs the wire instead of billowing over the chart. Fewer of them, since each covers less.
1491
- const PUFFS = 160;
1492
- for (let k = 0; k < PUFFS; k++) {
2740
+ // THE MIST, NOT A PATH OF CIRCLES (operator, 2026-09-15: "the energy pulse effect trail looks
2741
+ // really bad. it looks like a path of circles rather than emissive nebula/mist"). The cloud was
2742
+ // 160 flat discs, and flat discs of one alpha have edges the eye joins into circles however they
2743
+ // are scattered. Each puff is a radial gradient now -- bright at its heart, gone at its rim, so
2744
+ // no puff has an edge -- larger, fewer, and laid so they overlap into one glowing haze behind
2745
+ // the head that thins and cools down the tail. Hashed, so it holds its shape frame to frame.
2746
+ const MIST = 54;
2747
+ for (let k = 0; k < MIST; k++) {
1493
2748
  const u = hash01(k * 7 + 13); // how far back down the tail it sits
1494
2749
  const at = headAt - u * PULSE_TAIL;
1495
2750
  if (at < 0) continue;
1496
- // PAST THE END IT FADES, IT DOES NOT VANISH (operator: "The nebula effects should also fade out
1497
- // instead of just disappearing"). This was `at > 1 -> continue`, so the cloud was culled the
1498
- // instant its stretch ran off the last candle and the whole trail blinked out together.
1499
2751
  const off = at > 1 ? (at - 1) / 0.34 : 0;
1500
2752
  if (off >= 1) continue;
1501
- const edge = 1 - off;
1502
- const tint = Math.pow(1 - u, 1.4) * edge;
1503
- const age = u;
1504
- // positioned along the same flight the head takes, so the cloud follows it off the end
1505
- // instead of piling up on the last candle
2753
+ const tint = Math.pow(1 - u, 1.3) * (1 - off);
1506
2754
  const hp = headPoint(pts, at, 0.34);
1507
2755
  if (!hp) continue;
1508
- const mx = hp.x, my = hp.y;
1509
2756
  const a1 = hash01(k * 31 + 101) * Math.PI * 2;
1510
- const spread = lw * (3 + 38 * age) * (0.2 + 0.8 * hash01(k * 17 + 5));
1511
- const rad = lw * (5 + 19 * hash01(k * 13 + 67)) * (1 + 0.7 * age);
1512
- const al = 0.13 * tint * (1 - 0.5 * age) * (0.45 + 0.55 * hash01(k * 5 + 29));
1513
- const px = mx + Math.cos(a1) * spread, py = my + Math.sin(a1) * spread;
1514
- ctx.fillStyle = `rgba(48,110,255,${al.toFixed(3)})`;
1515
- ctx.beginPath();
1516
- ctx.arc(px, py, rad, 0, Math.PI * 2);
1517
- ctx.fill();
1518
- if (k % 2 === 0) {
1519
- ctx.fillStyle = `rgba(120,180,255,${(al * 0.7).toFixed(3)})`;
1520
- ctx.beginPath(); ctx.arc(px, py, rad * 0.5, 0, Math.PI * 2); ctx.fill();
1521
- }
2757
+ const spread = lw * (2 + 22 * u) * (0.2 + 0.8 * hash01(k * 17 + 5));
2758
+ const rad = lw * (9 + 16 * hash01(k * 13 + 67)) * (1 + 0.9 * u);
2759
+ const al = 0.16 * tint * (0.5 + 0.5 * hash01(k * 5 + 29));
2760
+ const px = hp.x + Math.cos(a1) * spread, py = hp.y + Math.sin(a1) * spread;
2761
+ const warm = u < 0.35 ? '255,236,170' : '255,185,70';
2762
+ ctx.fillStyle = gradientOr(ctx, () => ctx.createRadialGradient(px, py, 0, px, py, rad),
2763
+ [[0, `rgba(${warm},${al.toFixed(3)})`], [0.4, `rgba(255,185,70,${(al * 0.55).toFixed(3)})`], [1, 'rgba(255,150,40,0)']],
2764
+ `rgba(255,185,70,${(al * 0.5).toFixed(3)})`);
2765
+ ctx.beginPath(); ctx.arc(px, py, rad, 0, Math.PI * 2); ctx.fill();
1522
2766
  }
1523
2767
  // THE TUBE, AS ONE STROKE PER LAYER WITH A GRADIENT ALONG IT.
1524
2768
  //
@@ -1540,10 +2784,13 @@ function priceLine(ctx, view, axes) {
1540
2784
  const tailStop = clamp01(headAt - PULSE_TAIL);
1541
2785
  for (const [w, c, a, kind] of [...GLOW, ...CORE]) {
1542
2786
  const B = kind === 'glow' ? DEEP : BLUE;
1543
- // the charged stretch is FAT: a pulse is a thing travelling the line, not a colour on it.
1544
- // One width for the whole stroke now, so it swells while the head is on the line.
1545
- const onLine = headAt >= 0 && headAt <= 1 + PULSE_TAIL;
1546
- ctx.lineWidth = lw * w * (1 + (onLine ? 0.9 : 0));
2787
+ // NO WHOLE-LINE SWELL (operator, 2026-09-15: "the energy pulse effect makes the yellow line
2788
+ // entirely grow at the start of the animation, and instantly snap back into the prior size.
2789
+ // I want the energy pulse effect growing the thickness of the yellow line in an arced radius
2790
+ // around it"). One stroke has one width, so a swell here was the whole wire jumping fat at
2791
+ // the start and thin at the end; the swell is the head's bulge (drawBulgeAt), round the head
2792
+ // and nowhere else, and the wire keeps its width.
2793
+ ctx.lineWidth = lw * w;
1547
2794
  const at = (passed) => {
1548
2795
  const tint = passed >= 0 && passed < PULSE_TAIL ? Math.pow(1 - passed / PULSE_TAIL, 1.4) : 0;
1549
2796
  const past = passed - PULSE_TAIL * 0.55;
@@ -1572,7 +2819,49 @@ function priceLine(ctx, view, axes) {
1572
2819
  if (path) ctx.stroke(path);
1573
2820
  else { ctx.beginPath(); traceCurve(ctx, pts); ctx.stroke(); }
1574
2821
  }
1575
- // SHIMMER on the charged stretch: a thin white-blue core whose brightness flickers per segment
2822
+ // THE BULGE AT THE HEAD: the pipe swells round the surge as it passes, the same stretched skin
2823
+ // and fish-eyed core as the bulge effect, at a smaller radius, in the heat's own colours
2824
+ {
2825
+ const headFrac = Math.max(0, Math.min(1, headAt));
2826
+ const curve = curveByLength(pts);
2827
+ const coreR = (lw * 5.5) / 2;
2828
+ const hotLayers = [...GLOW, ...CORE].map(([w, c, a, kind]) => [w, c.map((v, j) => Math.round(v + (HOT[j] - v) * 0.75)), a, kind]);
2829
+ const fadeIn = headAt < 0 ? 0 : headAt > 1 ? Math.max(0, 1 - (headAt - 1) / 0.2) : 1;
2830
+ // PROMINENT (operator, 2026-09-15: "the bulging effect is not prominent enough ... It needs a
2831
+ // lot more vibrance, presence, and effect"): the swell is the bulge effect's own full size now
2832
+ // ...then THREE TIMES THAT (operator: "make the bulge 3 times larger for the energy pulse. It's
2833
+ // not obvious the line is being deformed"), then half of that ("reduce the bulge by half")
2834
+ // ...then a third bigger ("the bulge effect on the energy pulse is getting lost in the animation.
2835
+ // Increase in size by 33%")
2836
+ if (fadeIn > 0) drawBulgeAt(ctx, pts, lw, curve.lenAt(headFrac), (Number.isFinite(coreR) && coreR > 0 ? coreR : 2.75) * (1 + 2 * (BULGE_BALL - 1) * fadeIn), hotLayers, curve);
2837
+ }
2838
+ // THE HAZE (operator, 2026-09-15: "haze effects of some sort for the energy blurring and
2839
+ // interfering with the affected areas"): three ghost copies of the charged stretch, each thrown
2840
+ // off the wire by a slow wave that runs along it and drifts with the clock, faint and warm, so
2841
+ // the wire seems to shimmer through hot air -- and a wide soft light over the whole stretch
2842
+ {
2843
+ const now0 = view.now ?? 0;
2844
+ const i0 = Math.max(0, Math.floor((headAt - PULSE_TAIL) * n)), i1 = Math.min(n, Math.ceil(Math.min(1, headAt) * n));
2845
+ if (i1 - i0 >= 1) {
2846
+ for (let g = 0; g < 3; g++) {
2847
+ ctx.strokeStyle = `rgba(255,220,140,${(0.10 + 0.04 * g).toFixed(3)})`; ctx.lineWidth = lw * (7 - 2 * g);
2848
+ ctx.beginPath();
2849
+ for (let i = i0; i <= i1; i++) {
2850
+ const passed = headAt - i / n;
2851
+ const tint = passed >= 0 && passed < PULSE_TAIL ? Math.pow(1 - passed / PULSE_TAIL, 1.4) : 0;
2852
+ const wob = lw * (3.5 + 2 * g) * tint * Math.sin(now0 * (0.004 + 0.0015 * g) + i * 0.9 + g * 2.1);
2853
+ const p = pts[i];
2854
+ if (i === i0) ctx.moveTo(p.x, p.y + wob); else ctx.lineTo(p.x, p.y + wob);
2855
+ }
2856
+ ctx.stroke();
2857
+ }
2858
+ // the light over the affected area: a wide soft warm glow along the charged stretch
2859
+ const mid = pts[Math.floor((i0 + i1) / 2)], span = Math.hypot(pts[i1].x - pts[i0].x, pts[i1].y - pts[i0].y) * 0.7 + lw * 20;
2860
+ ctx.fillStyle = gradientOr(ctx, () => ctx.createRadialGradient(mid.x, mid.y, 0, mid.x, mid.y, span), [[0, 'rgba(255,225,160,0.14)'], [0.5, 'rgba(255,200,110,0.06)'], [1, 'rgba(255,180,80,0)']], 'rgba(255,215,140,0.04)');
2861
+ ctx.beginPath(); ctx.arc(mid.x, mid.y, span, 0, Math.PI * 2); ctx.fill();
2862
+ }
2863
+ }
2864
+ // SHIMMER on the charged stretch: a thin white-gold core whose brightness flickers per segment
1576
2865
  // on the frame clock, scaled by that segment's tint so it dies out exactly as the blue does.
1577
2866
  //
1578
2867
  // These were removed on 2026-09-12 ("the particle effects ... looks terrible ... get rid of the
@@ -1588,7 +2877,7 @@ function priceLine(ctx, view, axes) {
1588
2877
  if (tint < 0.08) continue;
1589
2878
  const p = pts[i], q = pts[i + 1];
1590
2879
  const flick = 0.55 + 0.45 * Math.abs(Math.sin(now * 0.023 + i * 1.7) * Math.sin(now * 0.041 + i * 0.9));
1591
- ctx.strokeStyle = `rgba(210,240,255,${(0.9 * tint * flick).toFixed(3)})`;
2880
+ ctx.strokeStyle = `rgba(255,250,225,${(0.9 * tint * flick).toFixed(3)})`;
1592
2881
  ctx.lineWidth = lw * 2.4;
1593
2882
  ctx.beginPath(); ctx.moveTo(p.x, p.y); ctx.lineTo(q.x, q.y); ctx.stroke();
1594
2883
 
@@ -1626,9 +2915,9 @@ function priceLine(ctx, view, axes) {
1626
2915
  for (let m = 1; m <= upto; m++) ctx.lineTo(pl[m].x, pl[m].y);
1627
2916
  ctx.stroke();
1628
2917
  };
1629
- arc(legs, 2.4, `rgba(90,170,255,${(0.3 * tint).toFixed(3)})`);
1630
- arc(legs, 0.95, `rgba(185,230,255,${(0.92 * tint).toFixed(3)})`);
1631
- arc(Math.max(1, legs - 1), 0.5, `rgba(245,252,255,${(0.95 * tint).toFixed(3)})`);
2918
+ arc(legs, 2.4, `rgba(255,170,60,${(0.3 * tint).toFixed(3)})`);
2919
+ arc(legs, 0.95, `rgba(255,225,150,${(0.92 * tint).toFixed(3)})`);
2920
+ arc(Math.max(1, legs - 1), 0.5, `rgba(255,255,240,${(0.95 * tint).toFixed(3)})`);
1632
2921
  }
1633
2922
  // PARTICLES: a spray of motes streaming off the charged wire, each on its own heading,
1634
2923
  // spreading wider and fading as its stretch of the line ages. Placed by a HASH of segment and
@@ -1643,7 +2932,7 @@ function priceLine(ctx, view, axes) {
1643
2932
  const ang = hash01(i * 17 + k * 13 + 101) * Math.PI * 2;
1644
2933
  const dist = lw * (4 + 62 * age) * (0.6 + 0.4 * hash01(i + k * 3 + 7));
1645
2934
  const r = lw * (0.6 + 1.3 * hash01(i * 5 + k + 41)) * (1 - 0.45 * age);
1646
- ctx.fillStyle = `rgba(200,236,255,${(0.75 * tint * (1 - 0.5 * age)).toFixed(3)})`;
2935
+ ctx.fillStyle = `rgba(255,235,190,${(0.75 * tint * (1 - 0.5 * age)).toFixed(3)})`;
1647
2936
  ctx.beginPath(); ctx.arc(bx + Math.cos(ang) * dist, by + Math.sin(ang) * dist, r, 0, Math.PI * 2); ctx.fill();
1648
2937
  }
1649
2938
  }
@@ -1663,7 +2952,7 @@ function priceLine(ctx, view, axes) {
1663
2952
  const r = lw * (0.6 + 1.3 * hash01(m * 7 + 19));
1664
2953
  const a = 0.7 * hp.fade * (1 - back / (PULSE_TAIL * 0.6));
1665
2954
  if (a <= 0.01) continue;
1666
- ctx.fillStyle = `rgba(200,236,255,${a.toFixed(3)})`;
2955
+ ctx.fillStyle = `rgba(255,235,190,${a.toFixed(3)})`;
1667
2956
  ctx.beginPath();
1668
2957
  ctx.arc(hp.x + Math.cos(ang) * spread, hp.y + Math.sin(ang) * spread, r, 0, Math.PI * 2);
1669
2958
  ctx.fill();
@@ -1693,10 +2982,84 @@ function priceLine(ctx, view, axes) {
1693
2982
  // ball with a blue halo, which is exactly what was reported. Every layer is blue-dominant
1694
2983
  // now, the hot centre included -- it is the brightest, palest blue rather than white, so the
1695
2984
  // head still reads as the hottest point on the line without going colourless.
1696
- for (const [r, c0, a0] of [[28, '0,150,255', 0.20], [15, '40,190,255', 0.48], [7, '80,220,255', 0.95], [3, '150,240,255', 1]]) {
2985
+ // AN UNSTABLE, CRACKLING BALL OF PLASMA (operator, 2026-09-15: "It needs a lot more vibrance,
2986
+ // presence, and effect. An unstable crackling ball of plasma"): a sphere of one gradient,
2987
+ // white-hot heart through gold to a rim that is not quite there, breathing on two quick
2988
+ // sines; three warm wisps of nebula wobbling round it; filaments of discharge skittering over
2989
+ // its surface, re-rolled on a 60 ms beat; and every so often it SPITS -- a few sparks thrown
2990
+ // up and out that arc under gravity, slow, and fade (their flights are pure functions of the
2991
+ // clock and the moment they were spat, so nothing is kept between frames).
2992
+ const nowH = view.now ?? 0;
2993
+ const breathe = 1 + 0.08 * Math.sin(nowH * 0.011) + 0.05 * Math.sin(nowH * 0.023 + 1);
2994
+ const RB = lw * 16 * (0.6 + 0.4 * f) * breathe;
2995
+ const wispsH = [['255,170,60', 0.34, 1.0], ['255,120,80', 0.26, -0.7], ['255,230,150', 0.22, 0.5]];
2996
+ wispsH.forEach(([wc, wa, spin], k) => {
2997
+ const t = nowH * 0.0011;
2998
+ const wx = hp.x + Math.cos(t * spin * 0.6 + k * 2.1) * RB * 0.5, wy = hp.y + Math.sin(t * spin * 0.45 + k * 1.3) * RB * 0.4;
2999
+ const base = RB * (1.7 + 0.4 * k);
3000
+ ctx.beginPath();
3001
+ for (let i = 0; i <= 36; i++) {
3002
+ const th = (i / 36) * Math.PI * 2;
3003
+ const wob = 1 + 0.26 * Math.sin(th * 3 + t * spin * 3 + k) + 0.15 * Math.sin(th * 5 - t * 2.4 * spin + k * 3);
3004
+ const rr = base * wob, x = wx + Math.cos(th) * rr, y = wy + Math.sin(th) * rr;
3005
+ if (i) ctx.lineTo(x, y); else ctx.moveTo(x, y);
3006
+ }
3007
+ ctx.closePath();
3008
+ ctx.fillStyle = gradientOr(ctx, () => ctx.createRadialGradient(wx, wy, 0, wx, wy, base * 1.4), [[0, `rgba(${wc},${(wa * f).toFixed(3)})`], [0.4, `rgba(${wc},${(wa * 0.6 * f).toFixed(3)})`], [1, `rgba(${wc},0)`]], `rgba(${wc},${(wa * 0.3 * f).toFixed(3)})`);
3009
+ ctx.fill();
3010
+ });
3011
+ ctx.fillStyle = gradientOr(ctx, () => ctx.createRadialGradient(hp.x, hp.y, 0, hp.x, hp.y, RB * 1.35), [
3012
+ [0, `rgba(255,255,255,${f.toFixed(3)})`], [0.16, `rgba(255,250,225,${f.toFixed(3)})`], [0.38, `rgba(255,232,150,${(0.95 * f).toFixed(3)})`],
3013
+ [0.6, `rgba(255,190,80,${(0.8 * f).toFixed(3)})`], [0.82, `rgba(255,140,50,${(0.4 * f).toFixed(3)})`], [1, 'rgba(255,120,40,0)'],
3014
+ ], `rgba(255,232,150,${(0.95 * f).toFixed(3)})`);
3015
+ ctx.beginPath(); ctx.arc(hp.x, hp.y, RB * 1.35, 0, Math.PI * 2); ctx.fill();
3016
+ // the discs the tests know the head by: its hot centre and its white point, over the sphere
3017
+ for (const [r, c0, a0] of [[7, '255,232,150', 0.95], [3, '255,252,225', 1]]) {
1697
3018
  ctx.fillStyle = `rgba(${c0},${(a0 * f).toFixed(3)})`;
1698
3019
  ctx.beginPath(); ctx.arc(hp.x, hp.y, lw * r * (0.55 + 0.45 * f), 0, Math.PI * 2); ctx.fill();
1699
3020
  }
3021
+ // the crackle over its surface: short filaments between two points on and just off the ball
3022
+ {
3023
+ const beat = Math.floor(nowH / 60);
3024
+ let x = ((fx.seed ?? 1) ^ (beat * 2654435761)) >>> 0 || 1;
3025
+ const rr = () => ((x = (Math.imul(x, 1103515245) + 12345) >>> 0) / 4294967296);
3026
+ for (let i = 0; i < 12; i++) {
3027
+ const ang = rr() * Math.PI * 2, r0 = RB * (0.35 + 0.5 * rr()), r1 = RB * (1.05 + 0.6 * rr());
3028
+ const p = { x: hp.x + Math.cos(ang) * r0, y: hp.y + Math.sin(ang) * r0 };
3029
+ const q = { x: hp.x + Math.cos(ang + (rr() - 0.5) * 0.9) * r1, y: hp.y + Math.sin(ang + (rr() - 0.5) * 0.9) * r1 };
3030
+ const mid = { x: (p.x + q.x) / 2 + (rr() - 0.5) * RB * 0.35, y: (p.y + q.y) / 2 + (rr() - 0.5) * RB * 0.35 };
3031
+ for (const [w, col] of [[2.2, `rgba(255,170,60,${(0.55 * f).toFixed(3)})`], [0.9, `rgba(255,250,225,${(0.95 * f).toFixed(3)})`]]) {
3032
+ ctx.strokeStyle = col; ctx.lineWidth = lw * w; ctx.beginPath(); ctx.moveTo(p.x, p.y); ctx.lineTo(mid.x, mid.y); ctx.lineTo(q.x, q.y); ctx.stroke();
3033
+ }
3034
+ }
3035
+ }
3036
+ // THE SPIT: every 140 ms there is a one-in-three chance the ball throws three sparks; each
3037
+ // flight is (birth, angle, speed) and the clock, so it is drawn from those alone
3038
+ {
3039
+ const STEP = 140, LIFE = 1500;
3040
+ const t0 = nowH - (fx.u ?? 0) * (fx.ms ?? FX_MS.pulse);
3041
+ const kNow = Math.floor(nowH / STEP);
3042
+ for (let k = kNow - Math.ceil(LIFE / STEP); k <= kNow; k++) {
3043
+ if (hash01((fx.seed ?? 1) + k * 3) > 0.33) continue;
3044
+ const born = k * STEP, age = (nowH - born) / LIFE;
3045
+ if (age < 0 || age >= 1) continue;
3046
+ const uk = (born - t0) / (fx.ms ?? FX_MS.pulse);
3047
+ const bp = headPoint(pts, uk / PULSE_TRAVEL, OVERRUN);
3048
+ if (!bp) continue;
3049
+ for (let m = 0; m < 3; m++) {
3050
+ const hh = (q) => hash01((fx.seed ?? 1) + k * 31 + m * 7 + q);
3051
+ const ang = -Math.PI / 2 + (hh(1) - 0.5) * 2.2, sp = lw * (14 + 16 * hh(2));
3052
+ const ease = 1 - Math.exp(-3 * age);
3053
+ const sx = bp.x + Math.cos(ang) * sp * ease * 2.2, sy = bp.y + Math.sin(ang) * sp * ease * 2.2 + lw * 34 * age * age;
3054
+ const px = bp.x + Math.cos(ang) * sp * Math.max(0, ease - 0.12) * 2.2, py = bp.y + Math.sin(ang) * sp * Math.max(0, ease - 0.12) * 2.2 + lw * 34 * Math.max(0, age - 0.08) ** 2;
3055
+ const al = (1 - age) * f;
3056
+ ctx.strokeStyle = `rgba(255,200,100,${(0.7 * al).toFixed(3)})`; ctx.lineWidth = lw * 1.6;
3057
+ ctx.beginPath(); ctx.moveTo(px, py); ctx.lineTo(sx, sy); ctx.stroke();
3058
+ ctx.fillStyle = `rgba(255,250,225,${(0.95 * al).toFixed(3)})`;
3059
+ ctx.beginPath(); ctx.arc(sx, sy, lw * 1.3 * (1 - 0.5 * age), 0, Math.PI * 2); ctx.fill();
3060
+ }
3061
+ }
3062
+ }
1700
3063
  // THE HEAD CRACKLES (operator, 2026-09-13: "Did you copy the energy crackle from the grid
1701
3064
  // effect, and add to the head of the energy ball travelling along the yellow price line?").
1702
3065
  // It had not been. The crackle above is emitted per wire SEGMENT, gated on that segment's
@@ -1730,9 +3093,9 @@ function priceLine(ctx, view, axes) {
1730
3093
  for (let m = 1; m <= upto; m++) ctx.lineTo(bp[m].x, bp[m].y);
1731
3094
  ctx.stroke();
1732
3095
  };
1733
- bolt(legs, 2.4, `rgba(70,190,255,${(0.32 * f).toFixed(3)})`);
1734
- bolt(legs, 0.95, `rgba(160,235,255,${(0.9 * f).toFixed(3)})`);
1735
- bolt(Math.max(1, legs - 1), 0.5, `rgba(250,255,255,${(0.95 * f).toFixed(3)})`);
3096
+ bolt(legs, 2.4, `rgba(255,170,60,${(0.32 * f).toFixed(3)})`);
3097
+ bolt(legs, 0.95, `rgba(255,225,150,${(0.9 * f).toFixed(3)})`);
3098
+ bolt(Math.max(1, legs - 1), 0.5, `rgba(255,255,245,${(0.95 * f).toFixed(3)})`);
1736
3099
  }
1737
3100
  }
1738
3101
  }
@@ -1770,7 +3133,14 @@ const NO_CANVAS = {};
1770
3133
  // line, so turning the stars off through it RESTYLED THE WHOLE BOARD -- which is not what a switch
1771
3134
  // labelled "Star field" should do. `stars` gates the sky alone; where it is absent the old
1772
3135
  // meaning stands, so every caller that never heard of it behaves exactly as before.
1773
- const starsOn = (o) => !!(o.stars ?? o.space);
3136
+ // THE LIVING SKY IS NOT THE STAR FIELD (operator, 2026-09-16: "The sky is not drawing for me ...
3137
+ // The background is all black for me"). With the living sky chosen and the Star field switch off,
3138
+ // this gate turned off the day as well: a blue afternoon and a moonrise were being hidden by a
3139
+ // switch about stars. A board that asks for the living sky draws it whatever that switch says;
3140
+ // `stars` still decides the star field, which the living sky brings out at night by itself.
3141
+ // the Earth sky (settings.js calls it 'earth'; 'living' was its name for a day and still answers)
3142
+ const earthSky = (o) => o.skyType === 'earth' || o.skyType === 'living';
3143
+ const starsOn = (o) => earthSky(o) || !!(o.stars ?? o.space);
1774
3144
  // THE GALAXY (operator, 2026-09-12: "I want all the starts slowly rotating to form a spiral
1775
3145
  // galaxy in the background ... Make it a toggle").
1776
3146
  //
@@ -2326,7 +3696,12 @@ function paintFrame(ctx, geom, frame, opts, view, gridN, blockRows, gridH = grid
2326
3696
  ctx.clearRect(0, 0, pw, ph);
2327
3697
  ctx.fillStyle = opts.background;
2328
3698
  ctx.fillRect(0, 0, pw, ph);
2329
- if (starsOn(opts)) drawStars(ctx, pw, ph, dpr || 1, view.now ?? 0, opts);
3699
+ // THE SKY: the star field, or the living sky (livingsky.js: a real day from the clock, with the
3700
+ // star field coming out at night through the same drawStars)
3701
+ if (starsOn(opts)) {
3702
+ if (earthSky(opts)) drawLivingSky(ctx, pw, ph, dpr || 1, view.now ?? 0, opts, { softStops, drawStars: (o) => drawStars(ctx, pw, ph, dpr || 1, view.now ?? 0, o) });
3703
+ else drawStars(ctx, pw, ph, dpr || 1, view.now ?? 0, opts);
3704
+ }
2330
3705
  // with nothing on the board -- every block in the air between two layouts (a viewer-mode switch)
2331
3706
  // -- the oblique board still draws itself: its transform is a constant, not fitted to the blocks
2332
3707
  if (!frame.bounds && !opts.oblique) return;
@@ -2394,7 +3769,14 @@ function paintFrame(ctx, geom, frame, opts, view, gridN, blockRows, gridH = grid
2394
3769
  // name and calls it with a hand-built view -- and the registry simply points at them.
2395
3770
  const agentDraw = view.fx?.kind ? AGENTS[view.fx.kind]?.draw : null;
2396
3771
  if (agentDraw) agentDraw(ctx, view, ctx.lineWidth, { drawCycles, drawBall, project });
2397
- else { drawCycles(ctx, view, ctx.lineWidth); drawBall(ctx, view, ctx.lineWidth); }
3772
+ else { drawCycles(ctx, view, ctx.lineWidth); drawBall(ctx, view, ctx.lineWidth); drawFireworks(ctx, view, ctx.lineWidth); drawSupernova(ctx, view, ctx.lineWidth); drawBlackHole(ctx, view, ctx.lineWidth); drawScanCurtain(ctx, view, ctx.lineWidth); }
3773
+ // A CALLER'S OWN LAYER, over the board and in the board's own projection (operator, 2026-09-16:
3774
+ // "We have fucking firework and nebula effects and you're doing shitty block and sprite
3775
+ // explosions?"). The effects above are the renderer's, chosen by cadence and seed; a game needs
3776
+ // to draw ITS events -- a shell landing here, at this instant -- with the same primitives. The
3777
+ // hook hands over the projector and softStops, so an explosion is built the way the fireworks
3778
+ // are rather than out of tiles, and lands exactly where the cell it destroyed was.
3779
+ if (typeof opts.overlay === 'function') opts.overlay(ctx, view, { project, softStops, lw: ctx.lineWidth });
2398
3780
  ctx.setTransform(1, 0, 0, 1, 0, 0);
2399
3781
  }
2400
3782
 
@@ -2742,6 +4124,7 @@ export function render3d(canvas, cells, options = {}) {
2742
4124
  opts.starDensity, opts.starBrightness, opts.galaxy === true, opts.galaxyAt,
2743
4125
  opts.nebulae !== false, opts.galaxies !== false, opts.dust !== false, opts.clusters !== false,
2744
4126
  opts.starColours !== false, opts.starGlints !== false,
4127
+ opts.skyType, opts.skyClock, opts.skyHour, opts.skyWeather, opts.skyCover, opts.skyLat, opts.skyRays !== false, opts.skyRainbow === true, opts.skyShooting !== false, opts.skyHorizon, opts.skyMoon,
2745
4128
  opts.neon === true, opts.sheen === true, opts.sheenStyle, opts.overheadLight === true, opts.light,
2746
4129
  opts.neonSource, opts.neonColour, opts.neonBrightness, opts.wireWidth,
2747
4130
  opts.transition ? `${opts.transition.rise}/${opts.transition.travel}/${opts.transition.drop}` : 'default'].join('|');
@@ -2784,8 +4167,12 @@ export function render3d(canvas, cells, options = {}) {
2784
4167
  // Nothing can overtake the parked layout: scheduleFx treats a pending render as `busy` and
2785
4168
  // re-arms its timer instead of starting another effect, so an effect cannot chain ahead of a
2786
4169
  // refresh that is already waiting.
2787
- const fxHolding = !!fxNow(st, now) && sig !== st.sig
2788
- && (st.pendingAt == null || now - st.pendingAt < FX_DEFER_MAX);
4170
+ // the cap runs from the later of the parking and the effect's own start: a layout parked
4171
+ // before an effect was forced (triggerIdle) must still wait that effect out, not lift off
4172
+ // under it because the clock started early
4173
+ const heldSince = st.pendingAt == null ? null : Math.max(st.pendingAt, st.fx?.t0 ?? 0);
4174
+ const fxHolding = (!!fxNow(st, now) || fxResting(st, now)) && sig !== st.sig
4175
+ && (heldSince == null || now - heldSince < FX_DEFER_MAX);
2789
4176
  if (!unchanged && st.plan && !still && st.raf != null && (now < st.plan.settleAt || fxHolding)) {
2790
4177
  st.pending = { cells, options };
2791
4178
  st.pendingAt ??= now;
@@ -2846,6 +4233,8 @@ export function render3d(canvas, cells, options = {}) {
2846
4233
  neon: opts.neon === true, sheen: opts.sheen === true, sheenStyle: opts.sheenStyle,
2847
4234
  overheadLight: opts.overheadLight === true, // the lamp straight above (Tetrust)
2848
4235
  light: opts.light, // or wherever settings.js space.light puts it
4236
+ lightHeight: opts.lightHeight,
4237
+ lightGain: opts.lightGain, topLight: opts.topLight, // how hard the lamp is, and how bright the tops sit under it
2849
4238
  neonSource: opts.neonSource, neonColour: opts.neonColour, neonBrightness: opts.neonBrightness,
2850
4239
  wireWidth: opts.wireWidth,
2851
4240
  // the paint order's memory across frames (blockscene3d obliqueOrder): a tangle keeps the
@@ -2856,6 +4245,20 @@ export function render3d(canvas, cells, options = {}) {
2856
4245
  // uses: the textured sphere is laid over all of it (drawGrid), and an
2857
4246
  // arrival starts wholly outside it (offscreenLift)
2858
4247
  if (opts.oblique) view.viewRect = obliqueFit(geom.pw, geom.ph, st.gridW, st.gridH, opts).rect;
4248
+ // how far the PANEL reaches beyond the board, so a sweeping front enters and leaves out of
4249
+ // sight instead of appearing in the middle of the picture (fxFront)
4250
+ if (view.fx && view.viewRect) {
4251
+ const r = view.viewRect;
4252
+ view.fx.margin = Math.max(0 - r.x0, r.x1 - st.gridW, 0 - r.y0, r.y1 - st.gridH, 4) + 3;
4253
+ // the scan's beam: its half-width, so fxAt lights exactly the swath the cone covers, and
4254
+ // whether it PANS -- a searchlight sweeping out and back, which is the top-down board's
4255
+ // motion; the price chart keeps its single pass along the hours
4256
+ if (view.fx.kind === 'scan') {
4257
+ const g = scanBeamGeom(view);
4258
+ view.fx.beamR = g.spread;
4259
+ view.fx.pan = !g.price;
4260
+ }
4261
+ }
2859
4262
  const frame = frameAt(st.plan, t, view);
2860
4263
  paintFrame(ctx, geom, frame, opts, view, st.gridW, st.blockRows, st.gridH);
2861
4264
  st.lastFit = frame.__fit ?? st.lastFit;
@@ -2890,7 +4293,7 @@ export function render3d(canvas, cells, options = {}) {
2890
4293
  // landed -- cutting the effect off exactly as before. It is also the live path: stars ship on
2891
4294
  // by default, so this is the branch a real board takes, and guarding only the entry above
2892
4295
  // would have looked correct and done nothing.
2893
- if (starsOn(opts) && frame.settled && st.pending && !fxNow(st, t)) { const p = st.pending; st.pending = null; st.pendingAt = null; st.raf = null; render3d(canvas, p.cells, p.options); return; }
4296
+ if (starsOn(opts) && frame.settled && st.pending && !fxNow(st, t) && !fxResting(st, t)) { const p = st.pending; st.pending = null; st.pendingAt = null; st.raf = null; render3d(canvas, p.cells, p.options); return; }
2894
4297
  // keep the loop alive while the choreography runs OR the camera is moving;
2895
4298
  // park otherwise, because repainting a still picture is a heater
2896
4299
  if (frame.settled && !st.dirty && !fxNow(st, t)) {
@@ -2898,13 +4301,18 @@ export function render3d(canvas, cells, options = {}) {
2898
4301
  // but ONCE, on the frame it arrives, or a running loop would re-arm the timer for ever
2899
4302
  if (!st.atRest) {
2900
4303
  const afterEffect = st.fx != null; // an effect just ended -- or it has only now settled
4304
+ if (afterEffect) st.fxEndedAt = t; // the rest before a held refresh runs from here
2901
4305
  st.fx = null;
2902
4306
  st.atRest = true;
2903
4307
  scheduleFx(canvas, st, opts, !afterEffect);
2904
4308
  }
2905
4309
  if (!starsOn(opts) && !glowAnimating(st, t)) {
2906
4310
  st.raf = null;
2907
- if (st.pending) { const p = st.pending; st.pending = null; st.pendingAt = null; render3d(canvas, p.cells, p.options); return; }
4311
+ if (st.pending) {
4312
+ // the loop parks here (no stars to keep it running), so the rest is kept by a timer
4313
+ if (fxResting(st, t)) { setTimeout(() => { if (st.pending && st.raf == null) { const p = st.pending; st.pending = null; st.pendingAt = null; render3d(canvas, p.cells, p.options); } }, FX_REST_MS - (t - st.fxEndedAt) + 20); return; }
4314
+ const p = st.pending; st.pending = null; st.pendingAt = null; render3d(canvas, p.cells, p.options); return;
4315
+ }
2908
4316
  return;
2909
4317
  }
2910
4318
  if (st.pending) { const p = st.pending; st.pending = null; st.pendingAt = null; st.raf = null; render3d(canvas, p.cells, p.options); return; }