Orb Swarm
Kinetic typography scene with glass orbs: a sentence told one beat at a time while four orbs burst out of it, split into eight and sixteen, wind into a clockwise vortex, collapse into a knot, pay out as a chain, loop around the closing words and shrink away bead by bead. Every phase was measured frame by frame off a 24fps reference and is replayed on the same clock; the orbs are shaded per pixel into a canvas (a scrolling band texture bowed like latitude lines, a soft glass edge) and the type is drawn into the same canvas four times finer than the frame so its baselines land between pixels.
Source
components/kuchi/orb-swarm.tsx
1"use client";23import { getInfo } from "@remotion/google-fonts/InterTight";4import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";5import {6 AbsoluteFill,7 continueRender,8 delayRender,9 useCurrentFrame,10 useVideoConfig,11} from "remotion";12import {13 oklchToRgb,14 parseColor,15 resolveFont,16 rgbToOklch,17 type KuchiTheme,18 useKuchiTheme,19} from "@/lib/kuchi-ui";2021/**22 * A sentence told one beat at a time while a field of glass orbs splits,23 * swarms, and threads itself into a ring around the last words.24 *25 * Four orbs burst out of the first line, split into eight, then sixteen; the26 * sixteen drift out, wind into a vortex, collapse into a knot, pay out as a27 * chain, and the chain loops around the closing card before it shrinks away28 * bead by bead.29 *30 * ## Everything is on the reference's clock31 *32 * The choreography was measured off a 24fps recording, beat by beat, so every33 * table below is indexed in *beats* (1/24 s) and read at fractional beats —34 * a 30fps composition samples between them and gets motion the recording35 * could not show, rather than a pulldown judder it did.36 *37 * ## The orbs are drawn, not styled38 *39 * Each orb carries a band texture that scrolls down its face once every40 * fourteen beats, and the bands bow toward the rim like latitude lines on a41 * sphere. A CSS gradient cannot bend, so the orbs are shaded per pixel into a42 * canvas — the same function the reference was fitted with, which is the only43 * way the two can agree to the pixel.44 */4546/**47 * Inter Tight, registered as the variable face it is. The reference sets it a48 * hair under 500, and a canvas has no `font-variation-settings` — the weight49 * has to come from the face's own range, so the face declares the whole range.50 */51const FACE = "Orb Swarm Inter Tight";52export const WEIGHT = 490;53let faceLoad: Promise<unknown> | null = null;54function loadFace(): Promise<unknown> {55 if (faceLoad) return faceLoad;56 const url = getInfo().fonts.normal?.["500"]?.latin;57 if (typeof FontFace === "undefined" || !url) {58 faceLoad = Promise.resolve();59 return faceLoad;60 }61 const face = new FontFace(FACE, `url(${url}) format("woff2")`, {62 weight: "100 900",63 });64 document.fonts.add(face);65 faceLoad = face.load().catch(() => undefined);66 return faceLoad;67}6869/* ─────────────────────────────────────────────────────────────────────────70 The card, in the reference's own 714 × 392 pixels71 ───────────────────────────────────────────────────────────────────────── */7273export const REF_W = 714;74export const REF_H = 392;75/** The recording's frame rate: one beat. */76export const BEATS_PER_SECOND = 24;77/** The recording runs out here. */78export const END_BEAT = 128;7980/* ─────────────────────────────────────────────────────────────────────────81 Tables82 ───────────────────────────────────────────────────────────────────────── */8384type Table = readonly number[];8586/**87 * Catmull-Rom through a table sampled at whole beats, clamped at both ends.88 * A frame between two beats gets the curve between them, not a straight line89 * with a corner at every beat.90 */91export function sample(table: Table, at: number): number {92 const n = table.length;93 if (n === 0) return 0;94 if (at <= 0) return table[0] as number;95 if (at >= n - 1) return table[n - 1] as number;96 const i = Math.floor(at);97 const t = at - i;98 const p0 = table[Math.max(0, i - 1)] as number;99 const p1 = table[i] as number;100 const p2 = table[i + 1] as number;101 const p3 = table[Math.min(n - 1, i + 2)] as number;102 return (103 0.5 *104 (2 * p1 +105 (-p0 + p2) * t +106 (2 * p0 - 5 * p1 + 4 * p2 - p3) * t * t +107 (-p0 + 3 * p1 - 3 * p2 + p3) * t * t * t)108 );109}110111/* ─────────────────────────────────────────────────────────────────────────112 The orb shader113 ───────────────────────────────────────────────────────────────────────── */114115/** Radius the tables below are measured at, in card pixels. */116export const ORB_R = 20.12;117/**118 * The band texture, one period, 32 RGB stops. Read with Catmull-Rom so the119 * bands have no facets however large the orb is drawn.120 */121const TEX: Table = [122 227.8, 187.4, 247.2, 223.8, 183.2, 248.2, 220.8, 178.5, 247.4, 215.0, 173.3,123 249.4, 210.4, 167.4, 249.1, 203.6, 161.0, 250.2, 196.9, 153.9, 250.2, 190.1,124 146.9, 249.1, 182.7, 139.5, 249.2, 176.8, 132.8, 247.3, 169.6, 127.1, 247.9,125 166.0, 122.7, 247.7, 161.7, 120.9, 247.8, 160.5, 119.9, 248.9, 159.3, 120.7,126 248.6, 159.3, 122.5, 249.0, 160.7, 125.2, 250.3, 162.8, 130.6, 249.0, 168.1,127 136.1, 252.8, 173.5, 145.6, 249.4, 181.0, 153.3, 253.1, 187.8, 162.6, 251.7,128 196.0, 171.2, 252.9, 203.1, 179.4, 253.2, 211.3, 186.9, 252.9, 217.0, 192.7,129 253.9, 223.1, 196.4, 252.2, 225.7, 198.1, 251.9, 228.6, 197.8, 250.7, 229.7,130 196.6, 249.2, 230.2, 194.3, 248.6, 229.4, 191.3, 247.9,131];132const TEX_N = TEX.length / 3;133/**134 * How far the bands lag behind at radius r (every 2px from the centre), in135 * card pixels. Zero through the middle and nine at the rim: the bands bow.136 */137const WARP: Table = [138 0.95, 0.9, 0.84, 0.75, 0.68, 0.68, 0.93, 1.95, 4.17, 7.59, 11.02, 11.14,139];140/** One band period, in card pixels, and the beats it takes to scroll by. */141const PERIOD = 40.98;142const SCROLL_BEATS = 14;143/**144 * Coverage of the silhouette from r = 14.5 to 23 in half pixels: the orb's145 * edge is two pixels soft in the recording, and that softness is the look.146 * The last few pixels inside it are faintly see-through, which is what reads147 * as glass rather than paint.148 */149const COVER: Table = [150 1, 0.9698, 0.9633, 0.9566, 0.949, 0.9435, 0.9351, 0.9343, 0.9346, 0.9115,151 0.8077, 0.5824, 0.3101, 0.1139, 0.0331, 0, 0, 0,152];153/**154 * And a shade added on top across the same band, as a multiple of155 * `SHADE_TINT`: a dark ring just inside the edge, a breath of light outside.156 */157const SHADE: Table = [158 0, -1.517, -1.692, -2.088, -2.275, -2.52, -2.843, -2.97, -2.758, -1.804,159 -0.457, -0.016, -0.013, -0.206, 0.352, 0.088, 0.17, 0.211,160];161const SHADE_TINT = [2.87, 1.67, 1.43] as const;162const COVER_FROM = 14.5;163164/**165 * The colour the orbs were measured in: the deep band of the texture. Every166 * accent in the scene — the bands, the letter tints, the washes — is turned167 * about the hue wheel by however far `orbColor` sits from this, in OKLCH, and168 * its chroma scaled the same way, so the glass keeps every one of its169 * lightnesses and only the colour changes.170 */171export const MEASURED_ORB = "#9f77f8";172173export type Recolour = (174 rgb: readonly [number, number, number],175) => [number, number, number];176177export function recolourer(target: string): Recolour {178 const from = rgbToOklch(parseColor(MEASURED_ORB));179 const to = rgbToOklch(parseColor(target));180 const turn = (to.h ?? 0) - (from.h ?? 0);181 const gain = from.c > 0 ? to.c / from.c : 1;182 if (Math.abs(turn) < 0.01 && Math.abs(gain - 1) < 0.001) {183 return ([r, g, b]) => [r, g, b];184 }185 return ([r, g, b]) => {186 const o = rgbToOklch({ mode: "rgb", r: r / 255, g: g / 255, b: b / 255 });187 const c = oklchToRgb(o.l, o.c * gain, (o.h ?? 0) + turn);188 return [c.r * 255, c.g * 255, c.b * 255];189 };190}191192function recolourTable(tex: Table, f: Recolour): number[] {193 const out: number[] = [];194 for (let i = 0; i < tex.length; i += 3) {195 out.push(196 ...f([tex[i] as number, tex[i + 1] as number, tex[i + 2] as number]),197 );198 }199 return out;200}201202function recolourHex(hex: string, f: Recolour): string {203 const c = parseColor(hex);204 const [r, g, b] = f([c.r * 255, c.g * 255, c.b * 255]);205 // Slice, not `padStart` (ES2017) — a stock Remotion project types ES2015.206 const h = (v: number) =>207 `0${Math.round(Math.max(0, Math.min(255, v))).toString(16)}`.slice(-2);208 return `#${h(r)}${h(g)}${h(b)}`;209}210211/**212 * A measured word tint, turned over for a dark page. The tints are dark213 * violets that read against the reference's white; on a dark page the same214 * lightness disappears, so it is mirrored and hue and chroma are kept.215 */216function onDark(hex: string): string {217 const o = rgbToOklch(parseColor(hex));218 const c = oklchToRgb(1 - o.l, o.c, o.h ?? 0);219 return recolourHex(hex, () => [c.r * 255, c.g * 255, c.b * 255]);220}221222function texel(tex: Table, s: number, out: Float32Array) {223 const x = (((s % 1) + 1) % 1) * TEX_N;224 const i = Math.floor(x);225 const t = x - i;226 const t2 = t * t;227 const t3 = t2 * t;228 const a = (((i - 1) % TEX_N) + TEX_N) % TEX_N;229 const b = i % TEX_N;230 const c = (i + 1) % TEX_N;231 const d = (i + 2) % TEX_N;232 for (let k = 0; k < 3; k++) {233 const p0 = tex[a * 3 + k] as number;234 const p1 = tex[b * 3 + k] as number;235 const p2 = tex[c * 3 + k] as number;236 const p3 = tex[d * 3 + k] as number;237 out[k] =238 0.5 *239 (2 * p1 +240 (-p0 + p2) * t +241 (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 +242 (-p0 + 3 * p1 - 3 * p2 + p3) * t3);243 }244}245246function linear(table: Table, step: number, from: number, r: number) {247 const x = (r - from) / step;248 if (x <= 0) return table[0] as number;249 const n = table.length - 1;250 if (x >= n) return table[n] as number;251 const i = Math.floor(x);252 const t = x - i;253 return (table[i] as number) * (1 - t) + (table[i + 1] as number) * t;254}255256/* ─────────────────────────────────────────────────────────────────────────257 Choreography258 ───────────────────────────────────────────────────────────────────────── */259260type Pt = readonly [number, number];261type Bead = { x: number; y: number; scale: number };262263/** Four orbs burst out of the first line: each on its own ease. */264const BURST: readonly { s: Pt; d: Pt; p: Table }[] = [265 {266 s: [259.135, 148.78],267 d: [-52.97, -18.2],268 p: [269 0, 0.5593, 0.6832, 0.7541, 0.7975, 0.8274, 0.8509, 0.8667, 0.8808, 0.891,270 0.9002, 0.9096, 0.9176, 0.9245, 0.9323, 0.9399, 0.9459, 0.9532, 0.9617,271 0.9692, 0.9769, 0.9828, 0.9894, 1,272 ],273 },274 {275 s: [408.715, 157.87],276 d: [34.78, -31.73],277 p: [278 0, 0.3817, 0.5072, 0.5909, 0.6524, 0.7043, 0.7449, 0.7807, 0.8101, 0.8347,279 0.853, 0.8753, 0.8929, 0.9108, 0.926, 0.9383, 0.9522, 0.9618, 0.972,280 0.9807, 0.9866, 0.9925, 0.9952, 1,281 ],282 },283 {284 s: [266.665, 218.19],285 d: [-22.67, 55.67],286 p: [287 0, 0.4574, 0.5882, 0.6615, 0.7157, 0.7561, 0.7902, 0.8165, 0.8397, 0.8626,288 0.881, 0.8962, 0.911, 0.9216, 0.9324, 0.9419, 0.9488, 0.9548, 0.9628,289 0.9706, 0.9768, 0.9844, 0.9903, 1,290 ],291 },292 {293 s: [381.535, 239.21],294 d: [37.81, 48.15],295 p: [296 0, 0.3837, 0.5085, 0.5894, 0.6517, 0.6991, 0.7415, 0.7754, 0.806, 0.8347,297 0.8593, 0.8795, 0.8984, 0.9123, 0.9254, 0.9374, 0.9476, 0.9568, 0.9652,298 0.9728, 0.9794, 0.9875, 0.9928, 1,299 ],300 },301];302const BURST_AT = 10;303304/** Eight: every orb splits in two, and the halves share one ease. */305const SPLIT_AT = 34;306const SPLIT_S: Table = [307 212.635, 110.64, 407.595, 119.44, 478.395, 122.11, 185.205, 148.69, 437.065,308 247.54, 477.325, 275.42, 207.395, 277.85, 271.865, 299.96,309];310const SPLIT_D: Table = [311 11.69, -37.49, -65.36, -13.05, 63.35, -8.18, -37.95, 31.45, 32.18, -73.37,312 105.26, -22.8, -66.18, 6.36, 50.69, 46.02,313];314const SPLIT_P: Table = [315 0, 0.2336, 0.4063, 0.5442, 0.6568, 0.7497, 0.8261, 0.8881, 0.9371, 0.9742, 1,316];317318/** Sixteen: split again, drift out, then wind into a vortex. */319const SWARM_AT = 45;320const SWARM_S: Table = [321 211.205, 57.29, 359.035, 87.85, 317.405, 96, 566.885, 99.48, 207.045, 104.52,322 524.555, 122.65, 451.925, 158.7, 492.015, 192.36, 590.495, 228.02, 602.175,323 268.76, 176.965, 286.1, 122.135, 299.41, 290.055, 347.33, 353.835, 346.23,324 121.685, 158.39, 144.305, 153.96,325];326const SWARM_D: Table = [327 -39.77, -48.89, 51.39, -56.79, -74.84, -31.73, 76.25, -44.24, -52.26, 93.87,328 -52.11, 26.16, -52.21, -47.74, 68.83, 54.85, 23.81, -74.78, 58.97, 48.87,329 107.98, 5.27, -58.13, 45.24, -99.09, 3.39, 94.09, -0.04, -77.21, -67.1, -9.15,330 -80.84,331];332const SWARM_P: Table = [333 0, 0.1423, 0.2519, 0.3426, 0.4214, 0.4906, 0.5529, 0.6089, 0.6597, 0.7054,334 0.7474, 0.7853, 0.8198, 0.8509, 0.8788, 0.9037, 0.9259, 0.9452, 0.962, 0.9765,335 0.9888, 0.9996,336];337/** The vortex: degrees clockwise and scale about the centre, per beat. */338const VORTEX_AT = 63;339const VORTEX_CENTRE: Pt = [358.79, 198.69];340const VORTEX_TURN: Table = [341 0, 0.336, 0.822, 1.541, 2.539, 3.859, 5.563, 7.73, 10.461, 13.917, 18.355,342 24.062, 31.779, 42.811, 60.412,343];344const VORTEX_SCALE: Table = [345 1, 1, 1.0001, 0.9998, 0.999, 0.9962, 0.9912, 0.9834, 0.9723, 0.9569, 0.9359,346 0.907, 0.8662, 0.8047, 0.6993,347];348const CHAIN_AT = 76;349350function swarm(beat: number): Bead[] {351 const out: Bead[] = [];352 const p = sample(SWARM_P, beat - SWARM_AT);353 const v = beat - VORTEX_AT;354 const turn = v > 0 ? (sample(VORTEX_TURN, v) * Math.PI) / 180 : 0;355 const k = v > 0 ? sample(VORTEX_SCALE, v) : 1;356 const cos = Math.cos(turn);357 const sin = Math.sin(turn);358 // The orbs shrink with the vortex, a fifth as fast: they fall away as well359 // as in.360 const size = 0.81 + 0.19 * k;361 for (let i = 0; i < SWARM_S.length / 2; i++) {362 const x = (SWARM_S[2 * i] as number) + (SWARM_D[2 * i] as number) * p;363 const y =364 (SWARM_S[2 * i + 1] as number) + (SWARM_D[2 * i + 1] as number) * p;365 const dx = x - VORTEX_CENTRE[0];366 const dy = y - VORTEX_CENTRE[1];367 out.push({368 x: VORTEX_CENTRE[0] + k * (cos * dx - sin * dy),369 y: VORTEX_CENTRE[1] + k * (sin * dx + cos * dy),370 scale: size,371 });372 }373 return out;374}375376/**377 * The constellation is turned this far about the vortex centre, in degrees378 * (negative is counter-clockwise), while the orbs are free — so the layout is379 * this scene's own, not the reference's; only the motion is measured. It eases380 * back to zero as they collapse into the knot, turning the same way the vortex381 * already spins, and the chain and the ring are exactly as measured.382 *383 * Twelve degrees is the most either way that keeps every orb on screen and no384 * closer to the type than the reference's own layout comes, within 2px.385 */386export const LAYOUT_TURN = -12;387const TURN_UNTIL = 82;388const TURN_EASE = 6;389390/** Every orb on screen at `beat`, bottom first. */391export function orbsAt(beat: number, turn: number = LAYOUT_TURN): Bead[] {392 const beads = measuredAt(beat);393 const f = Math.min(1, Math.max(0, (TURN_UNTIL - beat) / TURN_EASE));394 const a = (turn * f * Math.PI) / 180;395 if (a === 0) return beads;396 const cos = Math.cos(a);397 const sin = Math.sin(a);398 return beads.map((b) => {399 const dx = b.x - VORTEX_CENTRE[0];400 const dy = b.y - VORTEX_CENTRE[1];401 return {402 x: VORTEX_CENTRE[0] + cos * dx - sin * dy,403 y: VORTEX_CENTRE[1] + sin * dx + cos * dy,404 scale: b.scale,405 };406 });407}408409function measuredAt(beat: number): Bead[] {410 if (beat < BURST_AT) return [];411 if (beat < SPLIT_AT) {412 return BURST.map(({ s, d, p }) => {413 const q = sample(p, beat - BURST_AT);414 return { x: s[0] + d[0] * q, y: s[1] + d[1] * q, scale: 1 };415 });416 }417 if (beat < SWARM_AT) {418 const q = sample(SPLIT_P, beat - SPLIT_AT);419 const out: Bead[] = [];420 for (let i = 0; i < SPLIT_S.length / 2; i++) {421 out.push({422 x: (SPLIT_S[2 * i] as number) + (SPLIT_D[2 * i] as number) * q,423 y: (SPLIT_S[2 * i + 1] as number) + (SPLIT_D[2 * i + 1] as number) * q,424 scale: 1,425 });426 }427 return out;428 }429 if (beat < CHAIN_AT) return swarm(beat);430 return chainAt(beat);431}432433/**434 * The chain, bead by bead: position and size per beat, head first.435 *436 * From the collapse to the last bead there is no rule the recording follows437 * closely enough to be worth a formula — the knot pays out as a stack, the438 * stack is swept left while its head swings round, the chain reaches round the439 * last card and shrinks away from the tail — so this is the measurement440 * itself, sixteen beads a beat, read with the same curve as every other table.441 */442const CHAIN_BEATS = 52;443const CHAIN: Table = [444 // 76445 231.89, -36.56, 0.963, 295.34, 2.29, 0.963, 352.17, -16.08, 0.963, 363.62,446 55.8, 0.963, 238.47, 86.94, 0.963, 430.84, 169.3, 0.963, 480.83, 127.97,447 0.963, 453.1, 231.4, 0.963, 534.38, 311.6, 0.963, 264.41, 212.99, 0.963,448 451.45, 337.8, 0.963, 104.89, 123.65, 0.963, 176.52, 196.68, 0.963, 330.64,449 334.49, 0.963, 472.15, 434.23, 0.963, 604.98, 269.5, 0.963,450 // 77451 315.5, -29.53, 0.943, 357.19, 18.33, 0.947, 409.53, 17.86, 0.942, 400.21,452 80.66, 0.943, 287.4, 74.23, 0.941, 426.57, 192.62, 0.947, 479.19, 171.25,453 0.943, 428.85, 250.15, 0.944, 475.86, 338.09, 0.945, 276.04, 185.98, 0.943,454 399.62, 338.47, 0.945, 166.15, 70.12, 0.942, 206.88, 149.55, 0.944, 299.51,455 304.4, 0.943, 390.8, 423.58, 0.943, 545.85, 321.3, 0.94,456 // 78457 411.48, 41.63, 0.905, 420.56, 86.89, 0.903, 453.11, 105.09, 0.901, 425.15,458 140.46, 0.903, 357.92, 96.76, 0.901, 401.75, 218.83, 0.901, 441.81, 224.08,459 0.901, 382.75, 255.13, 0.903, 380.54, 325.89, 0.901, 311.29, 161.65, 0.901,460 333.42, 299.18, 0.902, 284.59, 51.53, 0.903, 281.59, 114.78, 0.902, 283.8,461 242.97, 0.902, 298.2, 349.21, 0.904, 429.65, 340.14, 0.904,462 // 79463 428.61, 133.66, 0.861, 420.18, 159.59, 0.875, 432.74, 179.44, 0.792, 406.51,464 188.43, 0.862, 384.75, 146.18, 0.862, 371.38, 221.96, 0.862, 390.33, 236.25,465 0.862, 350.7, 234.86, 0.863, 328.79, 270.71, 0.862, 341.66, 165.76, 0.863,466 312.34, 243.13, 0.86, 360.38, 101.36, 0.86, 340.14, 133.04, 0.86, 303.42,467 199.61, 0.861, 279.41, 258.52, 0.86, 349.75, 292.49, 0.86,468 // 80469 407.88, 172.4, 0.836, 404.23, 186.67, 0.514, 400.44, 200.26, 0.866, 383.05,470 202.31, 0.841, 379.47, 172.44, 0.849, 356.35, 219.26, 0.987, 363.63, 228.7,471 0.857, 340.21, 219.84, 0.866, 314.88, 238.09, 0.705, 349.17, 180.94, 1.1,472 325.22, 219.34, 1.083, 371.4, 138.99, 0.844, 353.79, 155.71, 0.908, 316.86,473 189.74, 0.864, 290.05, 221.41, 0.843, 327.3, 256.38, 0.841,474 // 81475 384.87, 188.05, 0.759, 373.83, 205.28, 0.904, 374.42, 200.36, 0.834, 363.32,476 205.89, 0.826, 381.75, 189.07, 0.837, 330.94, 212.24, 0.844, 345.95, 221.33,477 0.815, 343.23, 211.54, 0.849, 317.68, 234.94, 0.82, 341.66, 183.53, 0.843,478 322.5, 212.49, 1.1, 362.99, 161.21, 0.827, 349.52, 173.03, 1.011, 319.36,479 188.8, 0.863, 296.67, 206.22, 0.822, 318.36, 221.14, 1.036,480 // 82481 363.41, 194.89, 0.578, 354.73, 205.18, 0.959, 361.27, 207.01, 0.993, 349.74,482 204.27, 0.974, 358.07, 197.25, 0.848, 320.05, 207.07, 0.83, 329.37, 215.37,483 0.778, 308.62, 221.21, 0.802, 309.55, 214.36, 0.968, 323.93, 187.06, 0.718,484 322.68, 202.19, 1.1, 346.33, 174.98, 0.816, 338.28, 184.29, 1.1, 315.83,485 193.52, 1.037, 296.33, 199.83, 0.814, 307.39, 222.72, 0.75,486 // 83487 365.43, 220.18, 0.596, 366.92, 215.6, 0.684, 361.34, 211.92, 0.931, 367.65,488 211.9, 0.656, 360.06, 214.16, 0.94, 356.43, 213.71, 0.87, 350.76, 209.49,489 1.003, 347.56, 208.96, 0.93, 341.77, 206.27, 0.997, 339.03, 206.52, 0.918,490 329.53, 202.16, 1.033, 313.67, 201.82, 1.096, 319.94, 203.15, 0.758, 311.07,491 192.31, 1.096, 290, 198.16, 0.901, 299.82, 207.85, 1.065,492 // 84493 359.41, 221.69, 0.989, 354.89, 220.22, 0.968, 348.72, 217.63, 1, 344.69,494 216.32, 0.941, 337.96, 213.58, 0.993, 333.01, 211.77, 0.966, 327.1, 209.53,495 0.994, 322.39, 207.67, 0.967, 316.42, 205.83, 0.985, 310.4, 203.7, 0.995,496 305.86, 202.84, 0.947, 299.82, 201.59, 0.94, 294.96, 190.41, 0.879, 290.41,497 203.59, 0.875, 279.87, 190.9, 0.708, 275.3, 201.44, 1.079,498 // 85499 355.88, 231.99, 0.992, 347.7, 229.23, 1.01, 334, 224.09, 1.005, 325.98,500 221.08, 0.989, 309.48, 214.58, 0.988, 318.5, 218.49, 0.993, 297.61, 210.25,501 1.002, 304.32, 213.53, 0.958, 287.95, 206.87, 0.995, 278.96, 202.58, 0.924,502 280.77, 204.63, 0.978, 272.74, 201.84, 0.989, 265.4, 200.46, 0.969, 260.06,503 196.73, 0.994, 249, 199.44, 1.035, 249.8, 201.37, 0.883,504 // 86505 349.51, 243.07, 0.992, 339.17, 240.2, 0.999, 328.64, 236.93, 1, 319.55,506 234.69, 0.951, 318.36, 232.13, 0.928, 308.53, 230.22, 0.995, 298.01, 226.27,507 0.995, 288, 222.69, 0.997, 277.73, 218.84, 0.992, 267.53, 214.8, 0.995,508 257.42, 211.16, 0.992, 247.43, 207.29, 0.991, 237.29, 203.85, 0.993, 226.48,509 200.67, 0.996, 215.64, 198.6, 0.995, 208.41, 199.29, 0.946,510 // 87511 339.22, 253.48, 1.002, 325.35, 250.74, 0.998, 311.5, 247.87, 0.996, 297.13,512 249.52, 0.753, 298.11, 243.8, 0.972, 283.83, 240.43, 0.995, 270.36, 236.14,513 0.999, 256.65, 231.62, 0.997, 243.35, 226.79, 0.998, 229.97, 221.91, 1,514 216.62, 216.86, 0.995, 203.05, 211.71, 1, 189.85, 206.85, 0.999, 176.06,515 202.29, 0.999, 162.46, 199.07, 0.995, 154, 199.31, 0.896,516 // 88517 325.39, 258.9, 0.996, 307.09, 258.24, 0.999, 288.61, 256.6, 1.002, 270.03,518 254.02, 1.001, 253.33, 243.44, 0.598, 251.99, 250.66, 0.994, 234.12, 246.53,519 1.002, 216.13, 241.64, 1, 198.2, 236.29, 1.002, 180.7, 230.4, 1.002, 163.61,520 224.25, 0.995, 146.18, 217.67, 1.001, 128.76, 211.08, 0.998, 111.31, 204.78,521 1.001, 93.77, 199.79, 1.003, 81.97, 198.9, 0.848,522 // 89523 312.27, 251.51, 1.003, 287.94, 256.23, 1.034, 253.85, 259.25, 1.1, 218.38,524 258.04, 1.018, 187.57, 254.6, 1.1, 153.76, 248.18, 1.087, 124.47, 240.04,525 1.024, 95.7, 230.44, 1.1, 63.61, 219.14, 1.088, 35.91, 208.6, 1.013, 12.75,526 200.82, 1.004, -19.77, 190.47, 1.089, -47.4, 163.54, 1.061, -72.83, 145.84,527 1.061, -97.92, 126.62, 1.061, -122.7, 105.86, 1.061,528 // 90529 311.54, 219.2, 0.998, 284.19, 232.03, 0.996, 255.97, 243.04, 1, 226.26, 251.8,530 1.022, 186.6, 257.35, 1.1, 143.73, 259.02, 1.1, 107.35, 255.62, 1.013, 77.01,531 250.12, 1.006, 47.57, 242.88, 1.007, 18.4, 233.91, 1.007, -10.8, 223.37,532 1.027, -46.71, 203.51, 1.02, -75.97, 186.53, 1.02, -104.16, 168.11, 1.02,533 -132.49, 147.6, 1.02, -159.74, 126.02, 1.02,534 // 91535 335.25, 163.48, 1.001, 302.76, 183.63, 1.002, 269.88, 202.73, 1.002, 236.15,536 220.56, 1.002, 201.45, 236.25, 1.002, 165.44, 248.64, 1.002, 128.12, 256.2,537 1.004, 90.09, 259, 1.003, 52, 257.54, 1.006, 14.4, 252.14, 1.004, -16.56,538 246.65, 0.985, -50, 237, 1, -82, 230, 1, -113, 222, 1, -143, 215, 1, -174,539 208, 1,540 // 92541 388.42, 94.19, 1.003, 348.25, 119.02, 1.002, 308.54, 144.62, 1.002, 268.71,542 170, 1.001, 228.35, 194.5, 1.003, 186.92, 217.12, 1.003, 143.97, 236.76,543 1.005, 99.05, 251.31, 1.003, 52.26, 258.19, 1.004, 5.23, 258.22, 0.999,544 -29.62, 258.47, 1, -70.53, 258.41, 1, -111.44, 258.35, 1, -152.35, 258.29, 1,545 -193.26, 258.23, 1, -234.17, 258.17, 1,546 // 93547 473.27, 47.97, 1.002, 417.8, 57.86, 0.999, 366.62, 82.42, 1.003, 317.8,548 111.56, 0.999, 270.03, 142.15, 1.001, 222.15, 172.71, 1, 173.35, 201.76,549 1.001, 122.82, 227.68, 1.001, 69.76, 247.93, 1.003, 13.98, 258.06, 0.998,550 -37.86, 268.35, 1, -91.63, 278.42, 1, -145.4, 288.49, 1, -199.17, 298.56, 1,551 -252.94, 308.63, 1, -306.71, 318.7, 1,552 // 94553 554.45, 102.54, 0.999, 503.59, 62.08, 0.998, 439.85, 47.93, 1, 376.27, 61.8,554 0.998, 318.01, 92.04, 0.999, 262.28, 126.72, 0.996, 207.04, 162.24, 0.998,555 151, 196.41, 0.999, 92.93, 226.94, 0.999, 31.42, 249.76, 0.999, -30.18,556 272.85, 1, -91.73, 295.8, 1, -153.28, 318.75, 1, -214.83, 341.7, 1, -276.38,557 364.65, 1, -337.93, 387.6, 1,558 // 95559 559.83, 207.85, 1, 549.14, 136.34, 0.998, 506.63, 78.21, 0.997, 439.96, 50.22,560 0.999, 368.05, 55.77, 0.997, 302.36, 87.3, 0.998, 240.18, 125.58, 0.998,561 178.81, 165, 0.997, 116.23, 202.6, 1, 50.79, 234.94, 0.999, -15.71, 254.5,562 0.858, -80.06, 299.41, 1, -145.48, 331.68, 1, -210.9, 363.95, 1, -276.32,563 396.22, 1, -341.74, 428.49, 1,564 // 96565 515.86, 294.25, 0.997, 541.2, 220.94, 0.999, 533.88, 143.4, 1, 490.35, 79.37,566 0.997, 418.57, 49.61, 1, 341.5, 58.99, 1, 271.65, 94.84, 0.999, 205.13,567 136.75, 1, 138.82, 178.89, 0.997, 70.41, 217.54, 0.997, -2.08, 247.46, 0.995,568 -54.82, 277.3, 1, -117.42, 307.17, 1, -180.02, 337.04, 1, -242.62, 366.91, 1,569 -305.22, 396.78, 1,570 // 97571 444.69, 338.22, 0.999, 507.61, 287.2, 0.999, 529.1, 208.44, 1.001, 514.97,572 127.94, 0.998, 460.32, 67.77, 0.998, 380.95, 47.76, 0.999, 302.35, 70.7,573 0.997, 230.78, 111.97, 0.998, 161.18, 156.63, 0.998, 90.61, 199.64, 0.997,574 16.54, 236.32, 0.996, -55.73, 272.8, 1, -128.88, 309.39, 1, -202.03, 345.98,575 1, -275.18, 382.57, 1, -348.33, 419.16, 1,576 // 98577 376.97, 349.09, 0.999, 458.52, 327.06, 0.997, 510.52, 261.7, 0.999, 519.17,578 177.68, 0.999, 488.39, 99.46, 0.999, 417.84, 53.93, 0.997, 333.7, 53.92,579 0.999, 256.86, 90.59, 0.998, 184.5, 135.81, 0.998, 112.42, 181.5, 0.994,580 37.77, 222.79, 0.988, -37.04, 263.93, 1, -111.72, 305.21, 1, -186.4, 346.49,581 1, -261.08, 387.77, 1, -335.76, 429.05, 1,582 // 99583 322.95, 345.61, 0.999, 409.11, 344.24, 0.998, 482.62, 301.22, 0.997, 513.26,584 221.55, 0.996, 503.47, 136.32, 0.998, 449.61, 70.24, 0.996, 366.97, 47.64,585 0.998, 284.54, 72.09, 0.996, 209.64, 115.85, 0.996, 136.66, 162.72, 0.989,586 62.16, 207.16, 0.982, -19.29, 243.58, 1.1, -87.07, 295.71, 1, -161.63, 340.07,587 1, -236.19, 384.43, 1, -310.75, 428.79, 1,588 // 100589 282.45, 333.52, 0.997, 367.3, 349.04, 1, 450.38, 326.5, 0.998, 502.23, 258.97,590 0.998, 509.43, 173.03, 0.998, 475.17, 94.57, 0.999, 400.82, 51.9, 0.997,591 315.19, 57.04, 0.995, 237.67, 96.45, 0.991, 164.17, 142.95, 0.984, 90.43,592 189.15, 0.971, 13.35, 229.8, 0.955, -59.83, 270.25, 1, -134.96, 310.85, 1,593 -210.09, 351.45, 1, -285.22, 392.05, 1,594 // 101595 252.94, 314.94, 0.999, 331.47, 347.44, 1, 416.99, 341.01, 1, 485.5, 291.51, 1,596 509.84, 209.93, 0.999, 494.79, 125.88, 0.998, 436.03, 64.87, 0.995, 352.29,597 47.81, 0.989, 271.47, 76.6, 0.982, 197.37, 120.84, 0.971, 124.73, 167.46,598 0.956, 50.33, 211.22, 0.935, -24.15, 254.98, 1, -98.57, 298.78, 1, -172.99,599 342.58, 1, -247.41, 386.38, 1,600 // 102601 234.21, 294.27, 1, 302.5, 341.5, 1, 386.54, 347.36, 1, 463.87, 315.84, 1,602 505.37, 243.77, 1, 506.14, 159.77, 0.996, 466.53, 86.48, 0.994, 391.31, 50.16,603 0.983, 308.32, 59.26, 0.971, 233.22, 98.44, 0.957, 161.74, 143.82, 0.935,604 89.94, 188.7, 0.908, 15.06, 228.44, 0.871, -58.26, 268.23, 0, -132.36, 307.95,605 0, -206.46, 347.67, 0,606 // 103607 222.91, 274.73, 1, 279.46, 332.59, 1, 359.7, 349.13, 1, 439.69, 331.85, 1,608 495.54, 273.33, 0.996, 509.98, 192.88, 0.993, 488.55, 114.27, 0.985, 427.38,609 60.86, 0.974, 346.51, 48.52, 0.959, 269.65, 77.57, 0.938, 198.84, 119.95,610 0.907, 129.34, 164.55, 0.868, 58.41, 206.82, 0.807, -12.52, 249.18, 0, -83.42,611 291.45, 0, -154.32, 333.72, 0,612 // 104613 216.38, 258.17, 1, 262.16, 322.1, 1, 337.15, 348.04, 1, 416.66, 341.02, 0.998,614 481.79, 296.64, 0.994, 508.82, 222.24, 0.985, 501.64, 143.02, 0.978, 456.71,615 78.08, 0.961, 382.92, 49.01, 0.939, 304.61, 60.77, 0.91, 233.69, 98.15, 0.867,616 165.94, 141.14, 0.809, 98.14, 183.85, 0.708, 27.84, 222.66, 0.503, -42.34,617 261.5, 0, -112.56, 300.19, 0,618 // 105619 212.72, 245.03, 1, 249.87, 312.15, 1, 319.21, 345.54, 1, 396.88, 345.86,620 0.996, 466.65, 313.27, 0.988, 504.67, 246.67, 0.976, 507.89, 169.34, 0.96,621 477.6, 98.61, 0.939, 413.7, 55.74, 0.91, 336.68, 50.25, 0.872, 264.87, 80.19,622 0.807, 198.07, 120.48, 0.706, 132.47, 162.71, 0.501, 65.53, 202.98, 0.301,623 -0.96, 243.23, 0, -67.61, 283.34, 0,624 // 106625 210.7, 235.34, 1, 241.57, 303.59, 0.999, 305.56, 342.48, 0.993, 380.99,626 348.15, 0.986, 452.44, 324.46, 0.973, 498.74, 265.78, 0.957, 509.96, 191.24,627 0.939, 491.02, 118.53, 0.911, 437.77, 65.98, 0.866, 364.66, 47.8, 0.808,628 291.69, 66.55, 0.705, 225.31, 103.37, 0.503, 161.18, 144.47, 0.297, 96.59,629 184.93, 0.194, 32.3, 225.18, 0, -32.12, 265.45, 0,630 // 107631 209.68, 228.78, 0.998, 236.2, 297.08, 0.991, 295.68, 339.49, 0.985, 368.92,632 349.04, 0.973, 440.45, 331.56, 0.959, 492.25, 280.19, 0.937, 509.83, 208.82,633 0.907, 499.07, 136.19, 0.868, 455.53, 77.39, 0.807, 387.42, 49.78, 0.706,634 314.52, 57.02, 0.504, 248.11, 89.82, 0.295, 185.36, 128.95, 0.199, 122.06,635 167.97, 0, 59.09, 206.95, 0, -3.88, 245.93, 0,636 // 108637 209.22, 225.08, 0.989, 233.05, 292.73, 0.983, 289.11, 337.04, 0.972, 360.21,638 349.31, 0.958, 431.09, 335.99, 0.935, 486.21, 290.54, 0.908, 508.82, 222.44,639 0.865, 503.84, 150.65, 0.806, 468.26, 88.43, 0.705, 405.57, 53.58, 0.501,640 333.9, 51.08, 0.307, 267, 79.02, 0.209, 200.02, 107.42, 0, 133.17, 135.52, 0,641 66.32, 163.62, 0, -0.53, 191.72, 0,642 // 109643 208.91, 222.65, 0.98, 230.95, 289.5, 0.971, 284.3, 334.99, 0.955, 353.49,644 349.23, 0.935, 423.58, 338.91, 0.908, 480.75, 298.18, 0.866, 507.41, 233.17,645 0.804, 506.66, 162.55, 0.702, 477.49, 98.56, 0.5, 420.16, 58.16, 0.29, 350.06,646 48.49, 0.194, 279.79, 38.81, 0, 209.7, 29.15, 0, 139.61, 19.49, 0, 69.52,647 9.83, 0, -0.57, 0.17, 0,648 // 110649 208.65, 220.38, 0.968, 229.22, 286.58, 0.956, 280.15, 333.02, 0.934, 347.81,650 349.01, 0.905, 417.03, 341.15, 0.864, 475.63, 304.39, 0.804, 505.79, 242.25,651 0.705, 508.47, 172.76, 0.5, 484.48, 107.94, 0.296, 431.96, 62.7, 0.199, 379.1,652 18.24, 0, 326.48, -26.52, 0, 273.86, -71.28, 0, 221.24, -116.04, 0, 168.62,653 -160.8, 0, 116, -205.56, 0,654 // 111655 208.57, 218.23, 0.954, 227.61, 283.88, 0.932, 276.55, 331.17, 0.904, 342.83,656 348.68, 0.864, 411.38, 342.76, 0.804, 470.96, 309.39, 0.701, 504.08, 249.89,657 0.502, 509.68, 181.49, 0.297, 489.93, 116.01, 0.209, 469.6, 50.8, 0, 449.77,658 -14.48, 0, 429.94, -79.76, 0, 410.11, -145.04, 0, 390.28, -210.32, 0, 370.45,659 -275.6, 0, 350.62, -340.88, 0,660 // 112661 208.38, 216.13, 0.932, 226.26, 281.39, 0.905, 273.43, 329.44, 0.865, 338.47,662 348.35, 0.804, 406.42, 344.02, 0.703, 466.72, 313.59, 0.502, 502.25, 256.41,663 0.301, 510.03, 188.98, 0.209, 517.45, 121.54, 0, 525.2, 54.21, 0, 532.95,664 -13.12, 0, 540.7, -80.45, 0, 548.45, -147.78, 0, 556.2, -215.11, 0, 563.95,665 -282.44, 0, 571.7, -349.77, 0,666 // 113667 208.24, 214.25, 0.904, 225.06, 279.06, 0.864, 270.57, 327.73, 0.802, 334.69,668 347.92, 0.705, 402.16, 345.11, 0.505, 463.11, 317.22, 0.304, 500.49, 262,669 0.197, 537.52, 206.37, 0, 574.9, 151.19, 0, 612.28, 96.01, 0, 649.66, 40.83,670 0, 687.04, -14.35, 0, 724.42, -69.53, 0, 761.8, -124.71, 0, 799.18, -179.89,671 0, 836.56, -235.07, 0,672 // 114673 208.12, 212.24, 0.863, 223.99, 276.94, 0.805, 268.12, 326.21, 0.705, 331.35,674 347.57, 0.501, 398.37, 345.86, 0.3, 459.46, 319.93, 0.196, 520.13, 293.43, 0,675 581.16, 267.36, 0, 642.19, 241.29, 0, 703.22, 215.22, 0, 764.25, 189.15, 0,676 825.28, 163.08, 0, 886.31, 137.01, 0, 947.34, 110.94, 0, 1008.37, 84.87, 0,677 1069.4, 58.8, 0,678 // 115679 208.03, 210.4, 0.804, 223, 274.88, 0.706, 265.9, 324.95, 0.505, 328.37,680 347.36, 0.302, 394.91, 346.62, 0.206, 461.17, 345.52, 0, 527.65, 344.75, 0,681 594.13, 343.98, 0, 660.61, 343.21, 0, 727.09, 342.44, 0, 793.57, 341.67, 0,682 860.05, 340.9, 0, 926.53, 340.13, 0, 993.01, 339.36, 0, 1059.49, 338.59, 0,683 1125.97, 337.82, 0,684 // 116685 207.92, 208.25, 0.705, 222.21, 272.76, 0.504, 263.98, 323.5, 0.311, 325.69,686 346.7, 0.208, 386.92, 369.81, 0, 448.46, 393.16, 0, 510, 416.51, 0, 571.54,687 439.86, 0, 633.08, 463.21, 0, 694.62, 486.56, 0, 756.16, 509.91, 0, 817.7,688 533.26, 0, 879.24, 556.61, 0, 940.78, 579.96, 0, 1002.32, 603.31, 0, 1063.86,689 626.66, 0,690 // 117691 207.9, 205.78, 0.502, 221.41, 270.17, 0.3, 262.03, 321.64, 0.218, 302.67,692 372.28, 0, 343.35, 423.39, 0, 384.03, 474.5, 0, 424.71, 525.61, 0, 465.39,693 576.72, 0, 506.07, 627.83, 0, 546.75, 678.94, 0, 587.43, 730.05, 0, 628.11,694 781.16, 0, 668.79, 832.27, 0, 709.47, 883.38, 0, 750.15, 934.49, 0, 790.83,695 985.6, 0,696 // 118697 207.96, 202.75, 0.29, 220.54, 266.99, 0.198, 233.19, 330.94, 0, 245.93,698 394.99, 0, 258.67, 459.04, 0, 271.41, 523.09, 0, 284.15, 587.14, 0, 296.89,699 651.19, 0, 309.63, 715.24, 0, 322.37, 779.29, 0, 335.11, 843.34, 0, 347.85,700 907.39, 0, 360.59, 971.44, 0, 373.33, 1035.49, 0, 386.07, 1099.54, 0, 398.81,701 1163.59, 0,702 // 119703 207.94, 198.97, 0.21, 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0,704 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0,705 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0,706 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0, 207.65, 198.96, 0,707 // 120708 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,709 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,710 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,711 // 121712 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,713 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,714 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,715 // 122716 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,717 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,718 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,719 // 123720 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,721 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,722 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,723 // 124724 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,725 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,726 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,727 // 125728 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,729 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,730 208, 200, 0, 208, 200, 0, 208, 200, 0, 208, 200, 0,731 // 126732 305.31, 118.88, 0, 376.91, 118.45, 0, 444.9, 118.65, 0, 516.65, 118.86, 0,733 588.4, 119.07, 0, 660.15, 119.28, 0, 731.9, 119.49, 0, 803.65, 119.7, 0,734 875.4, 119.91, 0, 947.15, 120.12, 0, 1018.9, 120.33, 0, 1090.65, 120.54, 0,735 1162.4, 120.75, 0, 1234.15, 120.96, 0, 1305.9, 121.17, 0, 1377.65, 121.38, 0,736 // 127737 340.65, 61.56, 0, 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0,738 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0,739 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0,740 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0, 339.06, 61.24, 0,741];742/** Draw order per beat, bottom first, as chain indices in hex. */743const CHAIN_ORDER: readonly string[] = [744 "fedcba9876543210",745 "fedcba9876543210",746 "0123456789abcdef",747 "10dcb9e8a574f362",748 "fedcba9876543210",749 "fedcba9876543210",750 "fedcba9876543210",751 "0123456789abcdef",752 "0123456789abcdef",753 "0123456789abcdef",754 "0123456789abcdef",755 "0123456789abcdef",756 "0123456789abcdef",757 "0123456789abcdef",758 "0123456789abcdef",759 "0123456789abcdef",760 "fedcba9876543210",761 "fedcba9876543210",762 "fedcba9876543210",763 "fedcba9876543210",764 "fedcba9876543210",765 "fedcba9876543210",766 "fedcba9876543210",767 "fedcba9876543210",768 "fedcba9876543210",769 "fedcba9876543210",770 "fedcba9876543210",771 "fedcba9876543210",772 "fedcba9876543210",773 "fedcba9876543210",774 "fedcba9876543210",775 "fedcba9876543210",776 "fedcba9876543210",777 "fedcba9876543210",778 "fedcba9876543210",779 "fedcba9876543210",780 "fedcba9876543210",781 "fedcba9876543210",782 "fedcba9876543210",783 "fedcba9876543210",784 "fedcba9876543210",785 "fedcba9876543210",786 "fedcba9876543210",787 "fedcba9876543210",788 "fedcba9876543210",789 "fedcba9876543210",790 "fedcba9876543210",791 "fedcba9876543210",792 "fedcba9876543210",793 "fedcba9876543210",794 "fedcba9876543210",795 "fedcba9876543210",796];797798function chainAt(beat: number): Bead[] {799 const at = Math.min(Math.max(beat - CHAIN_AT, 0), CHAIN_BEATS - 1);800 const i = Math.floor(at);801 const t = at - i;802 const out: Bead[] = [];803 const read = (b: number, k: number, c: number) =>804 CHAIN[Math.max(0, Math.min(CHAIN_BEATS - 1, b)) * 48 + k * 3 + c] as number;805 for (let k = 0; k < 16; k++) {806 const pos = (c: number) => {807 const p0 = read(i - 1, k, c);808 const p1 = read(i, k, c);809 const p2 = read(i + 1, k, c);810 const p3 = read(i + 2, k, c);811 return (812 0.5 *813 (2 * p1 +814 (-p0 + p2) * t +815 (2 * p0 - 5 * p1 + 4 * p2 - p3) * t * t +816 (-p0 + 3 * p1 - 3 * p2 + p3) * t * t * t)817 );818 };819 const scale = Math.max(0, read(i, k, 2) * (1 - t) + read(i + 1, k, 2) * t);820 out.push({ x: pos(0), y: pos(1), scale });821 }822 // While the chain is a stack the tail lies on top; once it opens out, the823 // head. The knot in between is whatever the recording shows.824 const order = CHAIN_ORDER[i] ?? "";825 return Array.from(order, (c) => out[Number.parseInt(c, 16)] as Bead);826}827828/* ─────────────────────────────────────────────────────────────────────────829 The canvas830 ───────────────────────────────────────────────────────────────────────── */831832/** One letter, ready to paint: card pixels, its baseline, and its scale. */833export type Glyph = {834 ch: string;835 x: number;836 y: number;837 scale: number;838 colour: string;839};840841/** The type is drawn this many times finer than the frame, then reduced. */842const TYPE_SUPERSAMPLE = 4;843844function Stage({845 beat,846 width,847 height,848 k,849 left,850 top,851 background,852 glyphs,853 font,854 alpha,855 blur,856 tex,857}: {858 beat: number;859 width: number;860 height: number;861 k: number;862 left: number;863 top: number;864 background: readonly [number, number, number];865 glyphs: readonly Glyph[];866 font: string;867 alpha: number;868 blur: number;869 tex: Table;870}) {871 const ref = useRef<HTMLCanvasElement>(null);872 const typeRef = useRef<HTMLCanvasElement | null>(null);873 const softRef = useRef<HTMLCanvasElement | null>(null);874 const beads = useMemo(() => orbsAt(beat), [beat]);875 useLayoutEffect(() => {876 const canvas = ref.current;877 const ctx = canvas?.getContext("2d");878 if (!canvas || !ctx) return;879 ctx.clearRect(0, 0, width, height);880 paintOrbs(ctx, beads, beat, width, height, k, left, top, background, tex);881 if (glyphs.length === 0 || alpha <= 0) return;882 // Glyph baselines snap to whole device pixels, in a canvas as on the883 // page; drawn four times finer and reduced, they land where they were884 // measured to within a quarter of one.885 const type = typeRef.current ?? document.createElement("canvas");886 typeRef.current = type;887 const tctx = type.getContext("2d");888 if (!tctx) return;889 let x0 = Infinity;890 let x1 = -Infinity;891 let y0 = Infinity;892 let y1 = -Infinity;893 for (const g of glyphs) {894 x0 = Math.min(x0, g.x - FONT_SIZE * g.scale);895 x1 = Math.max(x1, g.x + 2 * FONT_SIZE * g.scale);896 y0 = Math.min(y0, g.y - 1.4 * FONT_SIZE * g.scale);897 y1 = Math.max(y1, g.y + 0.8 * FONT_SIZE * g.scale);898 }899 const ss = TYPE_SUPERSAMPLE;900 // Whole device pixels at both ends, so the reduction is exact.901 const X0 = Math.floor(left + x0 * k);902 const Y0 = Math.floor(top + y0 * k);903 const W = Math.ceil(left + x1 * k) - X0;904 const H = Math.ceil(top + y1 * k) - Y0;905 type.width = W * ss;906 type.height = H * ss;907 tctx.clearRect(0, 0, type.width, type.height);908 tctx.font = font;909 tctx.textBaseline = "alphabetic";910 for (const g of glyphs) {911 const f = ss * k * g.scale;912 tctx.setTransform(913 f,914 0,915 0,916 f,917 (left + g.x * k - X0) * ss,918 (top + g.y * k - Y0) * ss,919 );920 tctx.fillStyle = g.colour;921 tctx.fillText(g.ch, 0, 0);922 }923 // Blur at the fine scale too: a blur of under a pixel is a no-op in924 // Skia, and a coarse one steps in whole-kernel jumps that a quarter925 // pixel hides.926 let src: HTMLCanvasElement = type;927 if (blur > 0) {928 const soft = softRef.current ?? document.createElement("canvas");929 softRef.current = soft;930 const sctx = soft.getContext("2d");931 if (sctx) {932 soft.width = type.width;933 soft.height = type.height;934 sctx.clearRect(0, 0, soft.width, soft.height);935 sctx.filter = `blur(${blur * k * ss}px)`;936 sctx.drawImage(type, 0, 0);937 src = soft;938 }939 }940 ctx.save();941 ctx.globalAlpha = alpha;942 ctx.imageSmoothingEnabled = true;943 ctx.imageSmoothingQuality = "high";944 ctx.drawImage(src, X0, Y0, W, H);945 ctx.restore();946 }, [947 beads,948 beat,949 width,950 height,951 k,952 left,953 top,954 background,955 glyphs,956 font,957 alpha,958 blur,959 tex,960 ]);961 return (962 <canvas963 ref={ref}964 width={width}965 height={height}966 style={{ position: "absolute", inset: 0, width, height }}967 />968 );969}970971function paintOrbs(972 ctx: CanvasRenderingContext2D,973 beads: readonly Bead[],974 beat: number,975 width: number,976 height: number,977 k: number,978 left: number,979 top: number,980 background: readonly [number, number, number],981 tex: Table,982) {983 // Each orb's box in device pixels, then boxes that touch merged into one984 // region: overlapping orbs have to be painted into the same pixels in draw985 // order, and orbs that do not overlap should not cost a frame-sized buffer.986 type Box = { x0: number; y0: number; x1: number; y1: number; of: number[] };987 const boxes: Box[] = [];988 beads.forEach((b, i) => {989 if (b.scale <= 0.001) return;990 const reach = (COVER_FROM + 8) * b.scale;991 const x0 = Math.max(0, Math.floor(left + (b.x - reach) * k));992 const y0 = Math.max(0, Math.floor(top + (b.y - reach) * k));993 const x1 = Math.min(width, Math.ceil(left + (b.x + reach) * k));994 const y1 = Math.min(height, Math.ceil(top + (b.y + reach) * k));995 if (x1 > x0 && y1 > y0) boxes.push({ x0, y0, x1, y1, of: [i] });996 });997 for (let merged = true; merged; ) {998 merged = false;999 for (let i = 0; i < boxes.length && !merged; i++) {1000 for (let j = i + 1; j < boxes.length && !merged; j++) {1001 const a = boxes[i] as Box;1002 const c = boxes[j] as Box;1003 if (a.x0 < c.x1 && c.x0 < a.x1 && a.y0 < c.y1 && c.y0 < a.y1) {1004 a.x0 = Math.min(a.x0, c.x0);1005 a.y0 = Math.min(a.y0, c.y0);1006 a.x1 = Math.max(a.x1, c.x1);1007 a.y1 = Math.max(a.y1, c.y1);1008 a.of = a.of.concat(c.of).sort((m, n) => m - n);1009 boxes.splice(j, 1);1010 merged = true;1011 }1012 }1013 }1014 }1015 const col = new Float32Array(3);1016 const phase = beat / SCROLL_BEATS;1017 for (const box of boxes) {1018 const w = box.x1 - box.x0;1019 const h = box.y1 - box.y0;1020 const buf = new Float32Array(w * h * 3);1021 for (let i = 0; i < w * h; i++) {1022 buf[i * 3] = background[0];1023 buf[i * 3 + 1] = background[1];1024 buf[i * 3 + 2] = background[2];1025 }1026 for (const index of box.of) {1027 const b = beads[index] as Bead;1028 const reach = (COVER_FROM + 8) * b.scale;1029 const bx0 = Math.max(box.x0, Math.floor(left + (b.x - reach) * k));1030 const by0 = Math.max(box.y0, Math.floor(top + (b.y - reach) * k));1031 const bx1 = Math.min(box.x1, Math.ceil(left + (b.x + reach) * k));1032 const by1 = Math.min(box.y1, Math.ceil(top + (b.y + reach) * k));1033 for (let py = by0; py < by1; py++) {1034 // Card-pixel coordinates of this device pixel's centre, in the1035 // orb's own frame (its scale shrinks the whole orb, texture and all).1036 const ly = ((py + 0.5 - top) / k - b.y) / b.scale;1037 for (let px = bx0; px < bx1; px++) {1038 const lx = ((px + 0.5 - left) / k - b.x) / b.scale;1039 const r = Math.hypot(lx, ly);1040 if (r >= COVER_FROM + 8) continue;1041 const cov = linear(COVER, 0.5, COVER_FROM, r);1042 const shade = linear(SHADE, 0.5, COVER_FROM, r);1043 texel(1044 tex,1045 (ly - linear(WARP, 2, 0, Math.min(r, 22))) / PERIOD - phase,1046 col,1047 );1048 const o = ((py - box.y0) * w + (px - box.x0)) * 3;1049 for (let c = 0; c < 3; c++) {1050 buf[o + c] =1051 (buf[o + c] as number) * (1 - cov) +1052 (col[c] as number) * cov +1053 shade * (SHADE_TINT[c] as number);1054 }1055 }1056 }1057 }1058 const img = ctx.createImageData(w, h);1059 for (let i = 0; i < w * h; i++) {1060 img.data[i * 4] = buf[i * 3] as number;1061 img.data[i * 4 + 1] = buf[i * 3 + 1] as number;1062 img.data[i * 4 + 2] = buf[i * 3 + 2] as number;1063 img.data[i * 4 + 3] = 255;1064 }1065 ctx.putImageData(img, box.x0, box.y0);1066 }1067}10681069/* ─────────────────────────────────────────────────────────────────────────1070 Type1071 ───────────────────────────────────────────────────────────────────────── */10721073/** Font size and the line's advance-box centre and baseline, in card pixels. */1074export const FONT_SIZE = 28.54;1075export const LINE_CX = 358.87;1076export const BASELINE = 206.46;1077/** The scale pivot: the middle of the x-height, above the baseline. */1078const PIVOT = 7.8;10791080/** One beat of the script: which card, how many of its words are showing. */1081type Segment = {1082 at: number;1083 card: number;1084 /** Words of the card on screen; more than the card has means all of them. */1085 words: number;1086 /** Line scale per beat from `at`, about the middle of the x-height. */1087 scale: Table;1088 /** Advance-box centre offset from `LINE_CX` per beat from `at`. */1089 dx: Table;1090 /** Baseline offset from `BASELINE` per beat from `at`. */1091 dy?: Table;1092 /**1093 * Letters thrown off the baseline, in card pixels per beat from `at`. On the1094 * way out they alternate up and down by the full amount; on the way in they1095 * rise from below by it, weighted per letter by `rise`.1096 */1097 wave?: { amp: Table; enter: boolean };1098 /**1099 * The words this segment adds wear these, letter by letter, left to right —1100 * a few indigos and a violet, never the same twice in a row — and turn to1101 * ink the moment the next word lands.1102 */1103 tint?: readonly string[];1104 /** The whole line in one colour, per beat from `at`; `""` is no override. */1105 wash?: readonly string[];1106 /** Opacity per beat from `at`. */1107 alpha?: Table;1108 /** Extra blur in card pixels per beat from `at`. */1109 blur?: Table;1110};11111112/**1113 * How far each letter of an arriving card sits below the line, relative to1114 * the card's mean: every second letter twice as far, and the left of the1115 * line lower than the right.1116 */1117export function rise(j: number, n: number): number {1118 const w = (i: number) =>1119 (i % 2 ? 2.1 : 1) * (1 - (0.6 * i) / Math.max(1, n - 1));1120 let sum = 0;1121 for (let i = 0; i < n; i++) sum += w(i);1122 return (w(j) * n) / sum;1123}11241125const PINK = "#e5d1e4";1126const LAVENDER = "#a495d9";1127const WASH = "#8b7cc0";11281129const SEGMENTS: readonly Segment[] = [1130 {1131 at: 0,1132 card: 0,1133 words: 99,1134 scale: [1135 1.0003, 1.0008, 1.0017, 1.0049, 1.0086, 1.0159, 1.0261, 1.0422, 1.0688,1136 1.1476,1137 ],1138 dx: [0.41],1139 wave: {1140 amp: [0, 0, 0, 0.02, 0.35, 0.56, 0.85, 1.34, 2.3, 5.4],1141 enter: false,1142 },1143 },1144 {1145 at: 10,1146 card: 1,1147 words: 99,1148 scale: [1149 0.8914, 0.9367, 0.9577, 0.9689, 0.9759, 0.9813, 0.9868, 0.9897, 0.9933,1150 0.9965, 0.9997, 1.0004,1151 ],1152 dx: [0.04, 0, 0, 0.02, -0.02, -0.02, 0, -0.05, -0.18, -0.54, -1.18, -3.8],1153 dy: [0.42],1154 wave: { amp: [3.94, 2.04, 1.15, 0.71, 0.33, 0.21, 0.08, 0], enter: true },1155 tint: ["#232232", "#2b2546", "#503878", "#46347a", "#2e2a4a", "#1d193f"],1156 },1157 {1158 at: 22,1159 card: 2,1160 words: 1,1161 scale: [1.0052, 1.0081, 1.0091, 1.0109, 1.0119, 1.0138],1162 dx: [2.2, 1.02, 0.43, -0.12, -1.0, -3.67],1163 tint: ["#3a3450", "#625881", "#5c417f", "#432b61", "#30284a"],1164 },1165 {1166 at: 28,1167 card: 2,1168 words: 2,1169 scale: [0.9819, 0.9969, 1.0021, 1.0061, 1.0088, 1.011],1170 dx: [1.32, 0.61, 0.2, -0.3, -1.12, -3.78],1171 tint: ["#473b61", "#453c6a", "#322c5e"],1172 },1173 {1174 at: 34,1175 card: 3,1176 words: 1,1177 scale: [1.0183, 1.0186, 1.0175],1178 dx: [-0.6, -1.41, -3.97],1179 tint: ["#433861", "#3d3357"],1180 },1181 {1182 at: 37,1183 card: 3,1184 words: 2,1185 scale: [0.9867, 1.0046, 1.0131, 1.0177, 1.0202, 1.0248, 1.0259, 1.0283],1186 dx: [0.85, 0.49, 0.31, 0.23, 0.08, -0.36, -1.12, -3.75],1187 tint: ["#2f2941", "#483a5e", "#553f79", "#30274c"],1188 },1189 {1190 at: 45,1191 card: 4,1192 words: 1,1193 scale: [1.0351, 1.0367, 1.0381],1194 dx: [1.86, -0.06, -3.13],1195 tint: ["#463961", "#4f3b75", "#47376e"],1196 },1197 {1198 at: 48,1199 card: 4,1200 words: 2,1201 scale: [1.0023, 1.0216, 1.0289, 1.0318],1202 dx: [1.49, 0.56, -0.51, -3.31],1203 tint: ["#372a5b", "#493e6b"],1204 },1205 {1206 at: 52,1207 card: 4,1208 words: 3,1209 scale: [1210 1.0193, 1.031, 1.0357, 1.0393, 1.0416, 1.0445, 1.046, 1.0476, 1.0496,1211 1.0504, 1.0514, 1.0524, 1.053, 1.0544, 1.0554, 1.0563, 1.0575, 1.0578,1212 1.0596, 1.0601,1213 ],1214 dx: [1215 1.15, 0.56, 0.35, 0.24, 0.22, 0.16, 0.12, 0.1, 0.08, 0.05, 0.05, 0.04,1216 0.04, 0.04, 0.05, 0.04, 0.03, 0.02, 0.03,1217 ],1218 tint: ["#322a4c", "#584670", "#78609b", "#5e4a82", "#3a2f58", "#3d3751"],1219 },1220 {1221 // The card washes to lavender and is gone in three beats.1222 at: 71,1223 card: 4,1224 words: 3,1225 scale: [1.0601, 1.0601, 1.0608],1226 dx: [0.08, 0.08, 0.03],1227 wash: [WASH],1228 alpha: [1, 1, 0.5, 0],1229 },1230 { at: 74, card: -1, words: 0, scale: [1], dx: [0] },1231 {1232 // The last card slides in from the right, holds, and lifts away.1233 at: 88,1234 card: 5,1235 words: 99,1236 scale: [1.0023],1237 dx: [1238 659.98, 362.82, 214.9, 141.01, 96.92, 67.35, 46.34, 31.09, 19.81, 11.74,1239 6.09, 2.35, 0.36, -0.22,1240 ],1241 dy: [1242 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7,1243 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.53,1244 1.71, 0.27, -1.9, -5.05, -9.35, -15.23, -23.3, -34.65, -51.57, -75,1245 ],1246 wash: [PINK, PINK, PINK, LAVENDER, LAVENDER, ""],1247 blur: [1248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.25, 0.45, 0.6, 0.87, 1.2,1250 ],1251 alpha: [1252 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1253 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.62, 0,1254 ],1255 },1256];12571258/** Step lookup: the value at the last whole beat, holding past the end. */1259function step<T>(list: readonly T[] | undefined, at: number): T | undefined {1260 if (!list || list.length === 0) return undefined;1261 return list[Math.max(0, Math.min(list.length - 1, Math.floor(at + 1e-6)))];1262}12631264type Letter = { ch: string; x: number; word: number };1265/** Letters with their advance from the card's left edge, and the advance1266 * width of the card with its first n words showing. */1267type LineLayout = { letters: Letter[]; ends: number[] };12681269function layoutCard(1270 words: readonly string[],1271 measure: (s: string) => number,1272): LineLayout {1273 const text = words.join(" ");1274 const letters: Letter[] = [];1275 let word = 0;1276 for (let i = 0; i < text.length; i++) {1277 const ch = text[i] as string;1278 if (ch === " ") {1279 word++;1280 continue;1281 }1282 letters.push({ ch, x: measure(text.slice(0, i)), word });1283 }1284 return {1285 letters,1286 ends: words.map((_, n) => measure(words.slice(0, n + 1).join(" "))),1287 };1288}12891290/** Parse `a b | c d | …` into cards of words. */1291export function parseScript(script: string): string[][] {1292 return script1293 .split("|")1294 .map((c) => c.trim().split(/\s+/).filter(Boolean))1295 .filter((c) => c.length > 0);1296}12971298/* ─────────────────────────────────────────────────────────────────────────1299 The component1300 ───────────────────────────────────────────────────────────────────────── */13011302export interface OrbSwarmProps {1303 /**1304 * Six cards, split with `|`. Cards three to five reveal word by word on the1305 * reference's beats; the first, second and last arrive whole.1306 */1307 script?: string;1308 /** The page. Defaults to the theme's `background`. */1309 background?: string;1310 /** The type, once a word has settled. Defaults to the theme's `foreground`. */1311 ink?: string;1312 /**1313 * The orbs' colour. The whole glass — its bands, its rim, and the tints the1314 * newest words wear — is turned to this hue and chroma; every lightness1315 * stays as measured. `#9f77f8` is the reference's own violet. Defaults to1316 * the theme's `primary`.1317 */1318 orbColor?: string;1319 theme?: Partial<KuchiTheme>;1320 mode?: "light" | "dark";1321 fontFamily?: string;1322 /**1323 * How soft the type is, in card pixels of blur. The reference is a screen1324 * capture and its type is this soft; 0 is crisp.1325 */1326 softness?: number;1327 speed?: number;1328 className?: string;1329}13301331const DEFAULT_SCRIPT =1332 "one command | what if | every launch | you shipped | got a video | in seconds";13331334export function OrbSwarm({1335 script = DEFAULT_SCRIPT,1336 background: backgroundProp,1337 ink: inkProp,1338 orbColor: orbProp,1339 fontFamily,1340 softness = 0.7,1341 speed = 1,1342 className,1343 theme,1344 mode,1345}: OrbSwarmProps) {1346 const t = useKuchiTheme(theme, mode);1347 const background = backgroundProp ?? t.background;1348 const ink = inkProp ?? t.foreground;1349 const orbColor = orbProp ?? t.primary;1350 // Read off the page, not the prop: a provider or a dark `background` alone1351 // must flip the tints too.1352 const dark = rgbToOklch(parseColor(background)).l < 0.5;1353 const frame = useCurrentFrame();1354 const { width, height, fps } = useVideoConfig();1355 const beat = (frame / fps) * BEATS_PER_SECOND * speed;1356 const custom = resolveFont(fontFamily);1357 const font = `${WEIGHT} ${FONT_SIZE}px ${custom ?? `"${FACE}"`}`;1358 const bg = useMemo((): readonly [number, number, number] => {1359 const c = parseColor(background);1360 return [c.r * 255, c.g * 255, c.b * 255];1361 }, [background]);1362 const tex = useMemo(1363 () => recolourTable(TEX, recolourer(orbColor)),1364 [orbColor],1365 );13661367 // `cover`, so a 16:9 composition crops the card rather than letterboxing it.1368 const k = Math.max(width / REF_W, height / REF_H);1369 const left = (width - REF_W * k) / 2;1370 const top = (height - REF_H * k) / 2;13711372 const cards = useMemo(() => parseScript(script), [script]);13731374 // Letter advances come from the face itself, so the measurement waits for1375 // it — and the frame waits for the measurement.1376 const [handle] = useState(() => delayRender("orb-swarm: measuring type"));1377 const [layouts, setLayouts] = useState<LineLayout[] | null>(null);1378 useEffect(() => {1379 let live = true;1380 const run = async () => {1381 await loadFace();1382 await document.fonts.load(font).catch(() => undefined);1383 const ctx = document.createElement("canvas").getContext("2d");1384 if (!ctx || !live) return;1385 ctx.font = font;1386 setLayouts(1387 cards.map((c) => layoutCard(c, (s) => ctx.measureText(s).width)),1388 );1389 };1390 run();1391 return () => {1392 live = false;1393 };1394 }, [cards, font]);1395 useEffect(() => {1396 if (layouts) continueRender(handle);1397 }, [layouts, handle]);13981399 const { glyphs, alpha, blur } = useMemo(1400 () => typeAt(beat, layouts, ink, orbColor, dark),1401 [beat, layouts, ink, orbColor, dark],1402 );14031404 return (1405 <AbsoluteFill1406 className={className}1407 style={{ background, overflow: "hidden" }}1408 >1409 <Stage1410 beat={beat}1411 width={width}1412 height={height}1413 k={k}1414 left={left}1415 top={top}1416 background={bg}1417 glyphs={glyphs}1418 font={font}1419 alpha={alpha}1420 blur={Math.hypot(blur, softness)}1421 tex={tex}1422 />1423 </AbsoluteFill>1424 );1425}14261427/** Every letter on screen at `beat`, and the line's opacity and extra blur. */1428export function typeAt(1429 beat: number,1430 layouts: readonly LineLayout[] | null,1431 ink: string,1432 orbColor: string = MEASURED_ORB,1433 dark = false,1434): { glyphs: Glyph[]; alpha: number; blur: number } {1435 const f = recolourer(orbColor);1436 const paint = (hex: string) =>1437 dark ? onDark(recolourHex(hex, f)) : recolourHex(hex, f);1438 const none = { glyphs: [], alpha: 1, blur: 0 };1439 let segment: Segment | null = null;1440 for (const seg of SEGMENTS) if (beat >= seg.at) segment = seg;1441 if (!layouts || !segment || segment.card < 0) return none;1442 const layout = layouts[segment.card];1443 if (!layout) return none;1444 const local = beat - segment.at;1445 const s = sample(segment.scale, local);1446 const dx = sample(segment.dx, local);1447 const dy = segment.dy ? sample(segment.dy, local) : 0;1448 const blur = segment.blur ? Math.max(0, sample(segment.blur, local)) : 0;1449 const alpha = segment.alpha1450 ? Math.max(0, Math.min(1, step(segment.alpha, local) ?? 1))1451 : 1;1452 const shown = layout.letters.filter((l) => l.word < segment.words);1453 const n = Math.min(segment.words, layout.ends.length);1454 const span = layout.ends[n - 1] ?? 0;1455 const cx = LINE_CX + dx;1456 const x0 = cx - span / 2;1457 const y = BASELINE + dy - PIVOT + PIVOT * s;1458 const amp = segment.wave ? sample(segment.wave.amp, local) : 0;1459 // The words this segment adds, as opposed to the ones already down.1460 const before = SEGMENTS.filter(1461 (g) => g.card === segment.card && g.at < segment.at,1462 ).reduce((m, g) => Math.max(m, Math.min(g.words, layout.ends.length)), 0);1463 const fresh = shown.filter((l) => l.word >= before);1464 const wash = step(segment.wash, local) || "";1465 const glyphs = shown.map((l, i): Glyph => {1466 const lift = !segment.wave1467 ? 01468 : segment.wave.enter1469 ? amp * rise(i, shown.length)1470 : i % 21471 ? -amp1472 : amp;1473 let colour = ink;1474 if (wash) colour = paint(wash);1475 else if (segment.tint && l.word >= before) {1476 const j = fresh.indexOf(l);1477 const m = segment.tint.length;1478 const at =1479 fresh.length > 1 ? Math.round((j * (m - 1)) / (fresh.length - 1)) : 0;1480 const tint = segment.tint[at];1481 colour = tint ? paint(tint) : ink;1482 }1483 return {1484 ch: l.ch,1485 x: cx + (x0 + l.x - cx) * s,1486 y: y + lift,1487 scale: s,1488 colour,1489 };1490 });1491 return { glyphs, alpha, blur };1492}









