agentcut 0.2.3 → 0.2.5

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 (35) hide show
  1. package/dist/studio/tools.js +17 -2
  2. package/dist/studio/tools.js.map +1 -1
  3. package/dist/studio/workspace.js +4 -0
  4. package/dist/studio/workspace.js.map +1 -1
  5. package/package.json +1 -1
  6. package/template/components/CATALOG.md +52 -0
  7. package/template/components/README.md +70 -61
  8. package/template/components/STYLES.md +2 -0
  9. package/template/components/catalog.json +477 -0
  10. package/template/components/catalog.ts +4 -0
  11. package/template/components/cinematic/Cinematic.tsx +1139 -0
  12. package/template/components/cinematic/Device3D.tsx +299 -0
  13. package/template/components/cinematic/devices3d/display-model.ts +184 -0
  14. package/template/components/cinematic/devices3d/iphone-model.ts +643 -0
  15. package/template/components/cinematic/devices3d/macbook-model.ts +553 -0
  16. package/template/components/cinematic/devices3d/models.ts +612 -0
  17. package/template/components/cinematic/devices3d/runtime.ts +258 -0
  18. package/template/components/cinematic/math.ts +100 -0
  19. package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -0
  20. package/template/components/dot-trace-title/meta.json +51 -0
  21. package/template/components/generate/GenerateReveal.tsx +381 -0
  22. package/template/components/index.ts +36 -0
  23. package/template/components/lib.ts +18 -6
  24. package/template/components/loops/LoopCanvas.tsx +132 -0
  25. package/template/components/loops/engine.ts +184 -0
  26. package/template/components/loops/library.ts +667 -0
  27. package/template/components/loops/library2.ts +777 -0
  28. package/template/components/motion-loop/MotionLoop.tsx +37 -0
  29. package/template/components/motion-loop/meta.json +312 -0
  30. package/template/runtime/composition.tsx +927 -920
  31. package/template/skill/SKILL.md +20 -3
  32. package/template/skill/references/browser-export.md +61 -61
  33. package/template/skill/references/cinematic.md +171 -0
  34. package/template/skill/references/loops.md +151 -0
  35. package/template/skill/references/performance.md +81 -0
@@ -0,0 +1,667 @@
1
+ // Agentcut's motion loop library: original seamless loops (12 s, every period divides 12) drawn on a
2
+ // 2D canvas from the brand palette. Backgrounds fill the frame; shapes are one centered subject.
3
+ import type { LoopCategory, LoopDef, LoopDraw, LoopPalette } from "./engine";
4
+ import { LOOPS_MORE } from "./library2";
5
+
6
+ /** Second motif colour that still reads in every tone. */
7
+ const second = (P: LoopPalette) => (P.tone === "accent" ? P.paper : P.fg2);
8
+
9
+ // ─── Backgrounds ─────────────────────────────────────────────────────────────────────────────────
10
+
11
+ const perspectiveGrid: LoopDraw = (ctx, w, h, t, P, M) => {
12
+ const u = h / 100;
13
+ const cx = w / 2;
14
+ const hy = h * 0.4;
15
+ const g = ctx.createRadialGradient(cx, hy, 0, cx, hy, w * 0.55);
16
+ g.addColorStop(0, M.rgba(P.fg, 0.38));
17
+ g.addColorStop(1, M.rgba(P.fg, 0));
18
+ ctx.fillStyle = g;
19
+ ctx.fillRect(0, 0, w, h);
20
+ const p = M.phase(t, 1.5);
21
+ const depth = (z: number) => M.smoothstep(0.32, 0.7, z) * (1 - M.smoothstep(6, 16, z));
22
+ ctx.lineWidth = Math.max(1, 0.22 * u);
23
+ // Rows stream toward the camera: one row spacing per 1.5 s.
24
+ for (let k = 0; k < 40; k++) {
25
+ const z = 0.3 + (k + 1 - p) * 0.45;
26
+ const y = hy + (h * 0.5) / z;
27
+ if (y > h + 2) continue;
28
+ ctx.strokeStyle = M.rgba(P.fg, 0.75 * depth(z));
29
+ ctx.beginPath();
30
+ ctx.moveTo(0, y);
31
+ ctx.lineTo(w, y);
32
+ ctx.stroke();
33
+ }
34
+ // Rails toward the vanishing point, faded into the horizon in depth segments.
35
+ const zs = [0.3, 0.5, 0.8, 1.3, 2.2, 4, 8, 16];
36
+ for (let i = -26; i <= 26; i++) {
37
+ for (let s = 0; s < zs.length - 1; s++) {
38
+ const a = zs[s];
39
+ const b = zs[s + 1];
40
+ ctx.strokeStyle = M.rgba(P.fg, 0.55 * depth((a + b) / 2));
41
+ ctx.beginPath();
42
+ ctx.moveTo(cx + (i * w * 0.09) / a, hy + (h * 0.5) / a);
43
+ ctx.lineTo(cx + (i * w * 0.09) / b, hy + (h * 0.5) / b);
44
+ ctx.stroke();
45
+ }
46
+ }
47
+ };
48
+
49
+ const dotWave: LoopDraw = (ctx, w, h, t, P, M) => {
50
+ const cols = 34;
51
+ const s = w / cols;
52
+ const rows = Math.ceil(h / s) + 1;
53
+ for (let j = 0; j < rows; j++) {
54
+ for (let i = 0; i < cols; i++) {
55
+ const x = (i + 0.5) * s;
56
+ const y = (j + 0.5) * s;
57
+ const v = 0.5 + 0.5 * Math.sin(M.TAU * (t / 4) - (x / w) * 7 - (y / h) * 4);
58
+ ctx.fillStyle = M.mixColor(P.mid, P.fg, v);
59
+ ctx.beginPath();
60
+ ctx.arc(x, y, s * (0.06 + 0.32 * M.ease.inOutSine(v)), 0, M.TAU);
61
+ ctx.fill();
62
+ }
63
+ }
64
+ };
65
+
66
+ const flowLines: LoopDraw = (ctx, w, h, t, P, M, seed) => {
67
+ const u = h / 100;
68
+ const n = 16;
69
+ const periods = [3, 4, 6, 12];
70
+ ctx.lineCap = "round";
71
+ for (let i = 0; i < n; i++) {
72
+ const y0 = (h * (i + 0.5)) / n;
73
+ const T = periods[Math.floor(M.rand(i, seed + 1) * periods.length)];
74
+ const k = 1 + Math.floor(M.rand(i, seed + 2) * 3);
75
+ const amp = u * (2 + 5 * M.rand(i, seed + 3)) * (0.7 + 0.3 * Math.sin(M.TAU * (t / 12) + i));
76
+ ctx.strokeStyle = i % 5 === 2 ? M.rgba(second(P), 0.9) : M.rgba(P.fg, i % 2 ? 0.35 : 0.75);
77
+ ctx.lineWidth = u * (i % 5 === 2 ? 0.6 : 0.3);
78
+ ctx.beginPath();
79
+ for (let x = 0; x <= w; x += w / 90) {
80
+ const y = y0 + Math.sin(M.TAU * ((x / w) * k + M.phase(t, T)) + i) * amp;
81
+ if (x === 0) ctx.moveTo(x, y);
82
+ else ctx.lineTo(x, y);
83
+ }
84
+ ctx.stroke();
85
+ }
86
+ };
87
+
88
+ const gradientBlobs: LoopDraw = (ctx, w, h, t, P, M, seed) => {
89
+ const colors = [P.fg, second(P), M.mixColor(P.fg, second(P), 0.5), P.fg, M.mixColor(P.bg, P.paper, 0.5)];
90
+ colors.forEach((c, i) => {
91
+ const a = 1 + Math.floor(M.rand(i, seed + 4) * 2);
92
+ const b = 1 + Math.floor(M.rand(i, seed + 5) * 2);
93
+ const x = w * (0.5 + 0.34 * Math.sin(M.TAU * (a * t) / 12 + M.rand(i, seed + 6) * M.TAU));
94
+ const y = h * (0.5 + 0.32 * Math.cos(M.TAU * (b * t) / 12 + M.rand(i, seed + 7) * M.TAU));
95
+ const r = Math.max(w, h) * (0.32 + 0.12 * M.loopNoise(t, i + seed * 7, 6));
96
+ const g = ctx.createRadialGradient(x, y, 0, x, y, r);
97
+ g.addColorStop(0, M.rgba(c, P.tone === "light" ? 0.45 : 0.6));
98
+ g.addColorStop(1, M.rgba(c, 0));
99
+ ctx.fillStyle = g;
100
+ ctx.fillRect(0, 0, w, h);
101
+ });
102
+ };
103
+
104
+ const stripesScroll: LoopDraw = (ctx, w, h, t, P, M) => {
105
+ const s = h / 9;
106
+ const unit = s * 5;
107
+ const off = M.phase(t, 3) * unit;
108
+ const L = Math.hypot(w, h);
109
+ ctx.save();
110
+ ctx.translate(w / 2, h / 2);
111
+ ctx.rotate(-Math.PI / 6);
112
+ for (let x = -L - unit; x < L + unit; x += s) {
113
+ const k = Math.round((x + L + unit) / s) % 5;
114
+ ctx.fillStyle = k === 4 ? second(P) : k % 2 ? P.mid : P.bg;
115
+ ctx.fillRect(x + off, -L, s + 1, 2 * L);
116
+ }
117
+ ctx.restore();
118
+ };
119
+
120
+ const concentricPulse: LoopDraw = (ctx, w, h, t, P, M) => {
121
+ const u = h / 100;
122
+ const cx = w / 2;
123
+ const cy = h / 2;
124
+ const d = h / 9;
125
+ const p = M.phase(t, 1.5);
126
+ const R = Math.hypot(w, h) / 2;
127
+ for (let k = 0; k * d < R + d; k++) {
128
+ const r = (k + p) * d;
129
+ const fade = 1 - M.smoothstep(R * 0.4, R, r);
130
+ // Colour follows the ring, not the slot, so the pattern doesn't jump each cycle.
131
+ const hot = M.mod(k - Math.floor(t / 1.5), 4) === 0;
132
+ ctx.strokeStyle = M.rgba(hot ? second(P) : P.fg, (hot ? 0.9 : 0.45) * fade * M.smoothstep(0, d, r));
133
+ ctx.lineWidth = u * (hot ? 0.9 : 0.35);
134
+ ctx.beginPath();
135
+ ctx.arc(cx, cy, r, 0, M.TAU);
136
+ ctx.stroke();
137
+ }
138
+ const beat = M.ease.outBack(M.win(p, 0, 0.35)) * (1 - M.ease.inCubic(M.win(p, 0.6, 1)));
139
+ ctx.fillStyle = P.fg;
140
+ ctx.beginPath();
141
+ ctx.arc(cx, cy, u * (2.5 + 2 * beat), 0, M.TAU);
142
+ ctx.fill();
143
+ };
144
+
145
+ const checkerTwist: LoopDraw = (ctx, w, h, t, P, M) => {
146
+ const cols = 14;
147
+ const s = w / cols;
148
+ const rows = Math.ceil(h / s);
149
+ for (let j = 0; j < rows; j++) {
150
+ for (let i = 0; i < cols; i++) {
151
+ const x = (i + 0.5) * s;
152
+ const y = (j + 0.5) * s;
153
+ const p = M.phase(t, 3, -(i + j) * 0.035);
154
+ const k = M.ease.inOutCubic(M.win(p, 0, 0.45));
155
+ ctx.save();
156
+ ctx.translate(x, y);
157
+ ctx.rotate((k * Math.PI) / 2);
158
+ const sc = 1 - 0.32 * Math.sin(k * Math.PI);
159
+ ctx.fillStyle = (i + j) % 2 ? P.fg : P.mid;
160
+ ctx.fillRect((-s / 2) * sc * 0.92, (-s / 2) * sc * 0.92, s * sc * 0.92, s * sc * 0.92);
161
+ ctx.restore();
162
+ }
163
+ }
164
+ };
165
+
166
+ const halftoneSweep: LoopDraw = (ctx, w, h, t, P, M) => {
167
+ const cols = 44;
168
+ const s = w / cols;
169
+ const rows = Math.ceil(h / s) + 1;
170
+ // Two bands half a cycle apart, so one is always crossing the frame.
171
+ const bandAt = (o: number) => -0.35 + 1.7 * M.ease.inOutSine(M.phase(t, 4, o));
172
+ const bands = [bandAt(0), bandAt(0.5)];
173
+ for (let j = 0; j < rows; j++) {
174
+ for (let i = 0; i < cols; i++) {
175
+ const x = (i + 0.5) * s;
176
+ const y = (j + 0.5) * s;
177
+ const along = (x / w) * 0.75 + (y / h) * 0.25;
178
+ const v = Math.max(...bands.map((b) => Math.exp(-((along - b) * (along - b)) / 0.012)));
179
+ ctx.fillStyle = v > 0.5 ? second(P) : M.rgba(P.fg, 0.25 + 0.75 * v);
180
+ ctx.beginPath();
181
+ ctx.arc(x, y, s * (0.08 + 0.36 * v), 0, M.TAU);
182
+ ctx.fill();
183
+ }
184
+ }
185
+ };
186
+
187
+ const terrainRidges: LoopDraw = (ctx, w, h, t, P, M, seed) => {
188
+ const u = h / 100;
189
+ const n = 26;
190
+ const p = M.phase(t, 2);
191
+ const cycle = Math.floor(t / 2);
192
+ // Far to near; each ridge hides the ones behind it.
193
+ for (let k = n; k >= 0; k--) {
194
+ const depth = k + 1 - p;
195
+ const y0 = h * 0.12 + (h * 0.95 * (n - depth)) / n;
196
+ const id = M.mod(k + cycle, 6);
197
+ const near = 1 - depth / n;
198
+ ctx.beginPath();
199
+ ctx.moveTo(-2, h + 2);
200
+ for (let x = 0; x <= w; x += w / 120) {
201
+ const c = Math.exp(-Math.pow((x - w / 2) / (w * 0.22), 2));
202
+ const noise =
203
+ Math.sin((x / w) * 19 + M.rand(id, seed + 1) * 6.28) * 0.5 +
204
+ Math.sin((x / w) * 41 + M.rand(id, seed + 2) * 6.28) * 0.3 +
205
+ Math.sin((x / w) * 77 + M.rand(id, seed + 3) * 6.28) * 0.2;
206
+ ctx.lineTo(x, y0 - c * (4 + 10 * Math.abs(noise)) * u * (0.5 + near));
207
+ }
208
+ ctx.lineTo(w + 2, h + 2);
209
+ ctx.closePath();
210
+ ctx.fillStyle = P.bg;
211
+ ctx.fill();
212
+ ctx.strokeStyle = M.rgba(id === 3 ? second(P) : P.fg, M.smoothstep(0, 4, depth) * (1 - M.smoothstep(n - 4, n, depth)));
213
+ ctx.lineWidth = u * 0.3;
214
+ ctx.stroke();
215
+ }
216
+ };
217
+
218
+ const starfieldWarp: LoopDraw = (ctx, w, h, t, P, M, seed) => {
219
+ const u = h / 100;
220
+ const cx = w / 2;
221
+ const cy = h / 2;
222
+ const R = Math.hypot(w, h) * 0.6;
223
+ ctx.lineCap = "round";
224
+ for (let i = 0; i < 260; i++) {
225
+ const a = M.rand(i, seed + 1) * M.TAU;
226
+ const life = M.phase(t, 3, M.rand(i, seed + 2));
227
+ const r = M.ease.inCubic(life) * R;
228
+ const r0 = r * 0.82;
229
+ ctx.strokeStyle = M.rgba(M.rand(i, seed + 3) > 0.8 ? second(P) : P.fg, M.smoothstep(0, 0.25, life));
230
+ ctx.lineWidth = u * (0.15 + 0.5 * life);
231
+ ctx.beginPath();
232
+ ctx.moveTo(cx + Math.cos(a) * r0, cy + Math.sin(a) * r0);
233
+ ctx.lineTo(cx + Math.cos(a) * r, cy + Math.sin(a) * r);
234
+ ctx.stroke();
235
+ }
236
+ };
237
+
238
+ const bokehDrift: LoopDraw = (ctx, w, h, t, P, M, seed) => {
239
+ const u = h / 100;
240
+ for (let i = 0; i < 34; i++) {
241
+ const speed = 1 + Math.floor(M.rand(i, seed + 1) * 2);
242
+ const y = h * 1.15 - M.fract(M.rand(i, seed + 2) + (t / 12) * speed) * h * 1.3;
243
+ const x = M.rand(i, seed + 3) * w + Math.sin(M.TAU * M.phase(t, 6) + i) * u * 3;
244
+ const r = u * (2 + 9 * M.rand(i, seed + 4));
245
+ const c = [P.fg, second(P), P.paper][i % 3];
246
+ const g = ctx.createRadialGradient(x, y, 0, x, y, r);
247
+ g.addColorStop(0, M.rgba(c, 0.5));
248
+ g.addColorStop(0.7, M.rgba(c, 0.32));
249
+ g.addColorStop(1, M.rgba(c, 0));
250
+ ctx.fillStyle = g;
251
+ ctx.beginPath();
252
+ ctx.arc(x, y, r, 0, M.TAU);
253
+ ctx.fill();
254
+ }
255
+ };
256
+
257
+ const isoCubes: LoopDraw = (ctx, w, h, t, P, M) => {
258
+ const s = w / 18;
259
+ const top = M.mixColor(P.fg, P.paper, P.tone === "light" ? 0 : 0.25);
260
+ const left = M.mixColor(P.fg, "#000000", 0.35);
261
+ const right = M.mixColor(P.fg, "#000000", 0.6);
262
+ const cols = 22;
263
+ const rows = 22;
264
+ for (let j = 0; j < rows; j++) {
265
+ for (let i = 0; i < cols; i++) {
266
+ const ix = i - cols / 2;
267
+ const iy = j - rows / 2;
268
+ const x = w / 2 + (ix - iy) * s * 0.866;
269
+ const y = h * 0.55 + (ix + iy) * s * 0.5;
270
+ if (x < -s * 2 || x > w + s * 2 || y < -s * 3 || y > h + s * 3) continue;
271
+ const d = Math.hypot(ix, iy);
272
+ const lift = s * (0.4 + 1.1 * Math.pow(0.5 + 0.5 * Math.sin(M.TAU * (t / 4) - d * 0.7), 2));
273
+ const yt = y - lift;
274
+ ctx.fillStyle = left;
275
+ ctx.beginPath();
276
+ ctx.moveTo(x - s * 0.866, yt);
277
+ ctx.lineTo(x, yt + s * 0.5);
278
+ ctx.lineTo(x, y + s * 0.5);
279
+ ctx.lineTo(x - s * 0.866, y);
280
+ ctx.fill();
281
+ ctx.fillStyle = right;
282
+ ctx.beginPath();
283
+ ctx.moveTo(x + s * 0.866, yt);
284
+ ctx.lineTo(x, yt + s * 0.5);
285
+ ctx.lineTo(x, y + s * 0.5);
286
+ ctx.lineTo(x + s * 0.866, y);
287
+ ctx.fill();
288
+ ctx.fillStyle = (i * 7 + j * 3) % 11 === 0 ? second(P) : top;
289
+ ctx.beginPath();
290
+ ctx.moveTo(x, yt - s * 0.5);
291
+ ctx.lineTo(x + s * 0.866, yt);
292
+ ctx.lineTo(x, yt + s * 0.5);
293
+ ctx.lineTo(x - s * 0.866, yt);
294
+ ctx.fill();
295
+ }
296
+ }
297
+ };
298
+
299
+ const ribbonWeave: LoopDraw = (ctx, w, h, t, P, M, seed) => {
300
+ const u = h / 100;
301
+ const periods = [4, 6, 12, 6, 4];
302
+ const colors = [P.fg, second(P), P.mid, P.fg, M.mixColor(P.fg, P.paper, 0.4)];
303
+ ctx.lineCap = "round";
304
+ for (let i = 0; i < 5; i++) {
305
+ const cy = h * (0.2 + 0.15 * i);
306
+ const f = 0.6 + M.rand(i, seed + 1) * 0.9;
307
+ ctx.strokeStyle = M.rgba(colors[i], 0.85);
308
+ ctx.lineWidth = u * (3 + 4 * M.rand(i, seed + 2));
309
+ ctx.beginPath();
310
+ for (let x = -u * 10; x <= w + u * 10; x += w / 80) {
311
+ const y = cy + Math.sin(M.TAU * ((x / w) * f + M.phase(t, periods[i])) + i * 1.3) * u * 9;
312
+ if (x <= -u * 10) ctx.moveTo(x, y);
313
+ else ctx.lineTo(x, y);
314
+ }
315
+ ctx.stroke();
316
+ }
317
+ };
318
+
319
+ const tileMosaic: LoopDraw = (ctx, w, h, t, P, M, seed) => {
320
+ const cols = 15;
321
+ const s = w / cols;
322
+ const rows = Math.ceil(h / s);
323
+ const gap = s * 0.08;
324
+ for (let j = 0; j < rows; j++) {
325
+ for (let i = 0; i < cols; i++) {
326
+ const id = j * cols + i;
327
+ const p = M.phase(t, 6, M.rand(id, seed + 1));
328
+ const a = M.win(p, 0, 0.1);
329
+ const b = M.win(p, 0.5, 0.6);
330
+ const flipped = (a >= 0.5 ? 1 : 0) - (b >= 0.5 ? 1 : 0);
331
+ const squash = Math.abs(Math.cos(Math.PI * (a < 1 ? a : b)));
332
+ const base = M.rand(id, seed + 2) > 0.85 ? second(P) : P.mid;
333
+ ctx.fillStyle = flipped ? P.fg : base;
334
+ const hh = (s - gap) * squash;
335
+ ctx.beginPath();
336
+ ctx.roundRect(i * s + gap / 2, j * s + (s - hh) / 2, s - gap, hh, s * 0.18);
337
+ ctx.fill();
338
+ }
339
+ }
340
+ };
341
+
342
+ // ─── Shapes ──────────────────────────────────────────────────────────────────────────────────────
343
+
344
+ const orbitRings: LoopDraw = (ctx, w, h, t, P, M) => {
345
+ const s = Math.min(w, h) / 100;
346
+ const cx = w / 2;
347
+ const cy = h / 2;
348
+ const rings = [
349
+ { rx: 30, ry: 9, rot: -0.35, T: 3, c: P.fg },
350
+ { rx: 36, ry: 13, rot: 0.5, T: 4, c: second(P) },
351
+ { rx: 25, ry: 20, rot: 1.4, T: 6, c: P.mid },
352
+ ];
353
+ const drawRing = (front: boolean) => {
354
+ rings.forEach((r, i) => {
355
+ ctx.save();
356
+ ctx.translate(cx, cy);
357
+ ctx.rotate(r.rot);
358
+ ctx.strokeStyle = M.rgba(r.c, 0.7);
359
+ ctx.lineWidth = s * 0.5;
360
+ ctx.beginPath();
361
+ ctx.ellipse(0, 0, r.rx * s, r.ry * s, 0, front ? 0 : Math.PI, front ? Math.PI : M.TAU);
362
+ ctx.stroke();
363
+ const a = M.TAU * M.phase(t, r.T, i * 0.3);
364
+ if (Math.sin(a) >= 0 === front) {
365
+ ctx.fillStyle = r.c;
366
+ ctx.beginPath();
367
+ ctx.arc(Math.cos(a) * r.rx * s, Math.sin(a) * r.ry * s, s * (2 + Math.sin(a)), 0, M.TAU);
368
+ ctx.fill();
369
+ }
370
+ ctx.restore();
371
+ });
372
+ };
373
+ drawRing(false);
374
+ const R = s * (14 + 0.8 * Math.sin(M.TAU * M.phase(t, 3)));
375
+ const g = ctx.createRadialGradient(cx - R * 0.35, cy - R * 0.4, R * 0.1, cx, cy, R);
376
+ g.addColorStop(0, M.mixColor(P.fg, P.paper, 0.55));
377
+ g.addColorStop(1, P.fg);
378
+ ctx.fillStyle = g;
379
+ ctx.beginPath();
380
+ ctx.arc(cx, cy, R, 0, M.TAU);
381
+ ctx.fill();
382
+ drawRing(true);
383
+ };
384
+
385
+ const morphBlob: LoopDraw = (ctx, w, h, t, P, M, seed) => {
386
+ const s = Math.min(w, h) / 100;
387
+ const cx = w / 2;
388
+ const cy = h / 2;
389
+ const R = s * 30;
390
+ const rot = M.TAU * (t / 12);
391
+ ctx.beginPath();
392
+ for (let k = 0; k <= 120; k++) {
393
+ const a = (k / 120) * M.TAU;
394
+ const r =
395
+ R *
396
+ (1 +
397
+ 0.09 * Math.sin(2 * a + M.TAU * M.phase(t, 6) + M.rand(1, seed) * 6) +
398
+ 0.07 * Math.sin(3 * a - M.TAU * M.phase(t, 4) + M.rand(2, seed) * 6) +
399
+ 0.04 * Math.sin(5 * a + M.TAU * M.phase(t, 3) + M.rand(3, seed) * 6));
400
+ const x = cx + Math.cos(a + rot) * r;
401
+ const y = cy + Math.sin(a + rot) * r;
402
+ if (k === 0) ctx.moveTo(x, y);
403
+ else ctx.lineTo(x, y);
404
+ }
405
+ ctx.closePath();
406
+ const g = ctx.createLinearGradient(cx - R, cy - R, cx + R, cy + R);
407
+ g.addColorStop(0, P.fg);
408
+ g.addColorStop(1, second(P));
409
+ ctx.fillStyle = g;
410
+ ctx.fill();
411
+ const hl = ctx.createRadialGradient(cx - R * 0.35, cy - R * 0.45, 0, cx - R * 0.35, cy - R * 0.45, R * 0.7);
412
+ hl.addColorStop(0, M.rgba(P.paper, 0.45));
413
+ hl.addColorStop(1, M.rgba(P.paper, 0));
414
+ ctx.fillStyle = hl;
415
+ ctx.fill();
416
+ };
417
+
418
+ const bouncingBall: LoopDraw = (ctx, w, h, t, P, M) => {
419
+ const s = Math.min(w, h) / 100;
420
+ const cx = w / 2;
421
+ const ground = h / 2 + s * 24;
422
+ const p = M.phase(t, 1.5);
423
+ const air = 4 * p * (1 - p);
424
+ const r = s * 9;
425
+ const contact = 1 - M.smoothstep(0, 0.09, Math.min(p, 1 - p));
426
+ const v = Math.abs(1 - 2 * p);
427
+ const sy = 1 - 0.32 * contact + 0.18 * v * (1 - contact);
428
+ const sx = 1 / Math.pow(sy, 0.75);
429
+ const y = ground - r * sy - air * s * 38;
430
+ ctx.fillStyle = M.rgba(P.tone === "light" ? P.ink : "#000000", 0.25 * (1 - 0.6 * air));
431
+ ctx.beginPath();
432
+ ctx.ellipse(cx, ground, r * (1.3 - 0.6 * air), r * 0.25 * (1 - 0.5 * air), 0, 0, M.TAU);
433
+ ctx.fill();
434
+ const g = ctx.createRadialGradient(cx - r * 0.35, y - r * 0.4, r * 0.1, cx, y, r * 1.1);
435
+ g.addColorStop(0, M.mixColor(P.fg, P.paper, 0.5));
436
+ g.addColorStop(1, P.fg);
437
+ ctx.fillStyle = g;
438
+ ctx.beginPath();
439
+ ctx.ellipse(cx, y, r * sx, r * sy, 0, 0, M.TAU);
440
+ ctx.fill();
441
+ };
442
+
443
+ const spinnerPetals: LoopDraw = (ctx, w, h, t, P, M) => {
444
+ const s = Math.min(w, h) / 100;
445
+ const cx = w / 2;
446
+ const cy = h / 2;
447
+ const p = M.phase(t, 1.5);
448
+ const base = (M.TAU / 4) * (Math.floor(t / 1.5) + M.ease.inOutCubic(M.win(p, 0.1, 0.7)));
449
+ const pulse = 0.85 + 0.15 * Math.sin(M.TAU * p);
450
+ for (let k = 0; k < 8; k++) {
451
+ ctx.save();
452
+ ctx.translate(cx, cy);
453
+ ctx.rotate(base + (k * M.TAU) / 8);
454
+ ctx.fillStyle = k % 2 ? second(P) : P.fg;
455
+ ctx.beginPath();
456
+ ctx.ellipse(0, -s * 16 * pulse, s * 5, s * 13 * pulse, 0, 0, M.TAU);
457
+ ctx.fill();
458
+ ctx.restore();
459
+ }
460
+ ctx.fillStyle = P.paper;
461
+ ctx.beginPath();
462
+ ctx.arc(cx, cy, s * 5, 0, M.TAU);
463
+ ctx.fill();
464
+ };
465
+
466
+ const stackedSquares: LoopDraw = (ctx, w, h, t, P, M) => {
467
+ const s = Math.min(w, h) / 100;
468
+ const cx = w / 2;
469
+ const cy = h / 2;
470
+ const colors = [P.mid, P.fg, second(P), P.paper];
471
+ for (let i = 0; i < 4; i++) {
472
+ const p = M.phase(t, 3, -i * 0.07);
473
+ const turn = M.ease.outBack(M.win(p, 0.1, 0.55));
474
+ const size = s * (44 - i * 10);
475
+ ctx.save();
476
+ ctx.translate(cx, cy);
477
+ ctx.rotate((turn * Math.PI) / 2 + Math.PI / 4);
478
+ ctx.fillStyle = colors[i];
479
+ ctx.beginPath();
480
+ ctx.roundRect(-size / 2, -size / 2, size, size, size * 0.14);
481
+ ctx.fill();
482
+ ctx.restore();
483
+ }
484
+ };
485
+
486
+ const rippleDrop: LoopDraw = (ctx, w, h, t, P, M) => {
487
+ const s = Math.min(w, h) / 100;
488
+ const cx = w / 2;
489
+ const cy = h / 2 + s * 8;
490
+ const p = M.phase(t, 3);
491
+ const fall = M.ease.inCubic(M.win(p, 0, 0.28));
492
+ if (p < 0.28) {
493
+ // Fade the drop in at the top so the loop point doesn't pop.
494
+ ctx.fillStyle = M.rgba(P.fg, M.smoothstep(0, 0.08, p));
495
+ ctx.beginPath();
496
+ ctx.ellipse(cx, cy - s * 40 * (1 - fall), s * 2.2, s * (2.2 + 2 * fall), 0, 0, M.TAU);
497
+ ctx.fill();
498
+ }
499
+ for (let k = 0; k < 3; k++) {
500
+ const q = M.win(p, 0.28 + k * 0.08, 0.95);
501
+ if (q <= 0 || q >= 1) continue;
502
+ const r = M.ease.outCubic(q) * s * (34 - k * 6);
503
+ ctx.strokeStyle = M.rgba(k === 1 ? second(P) : P.fg, 1 - q);
504
+ ctx.lineWidth = s * (1.2 - k * 0.3);
505
+ ctx.beginPath();
506
+ ctx.ellipse(cx, cy, r, r * 0.32, 0, 0, M.TAU);
507
+ ctx.stroke();
508
+ }
509
+ };
510
+
511
+ const cubeSpin: LoopDraw = (ctx, w, h, t, P, M) => {
512
+ const s = Math.min(w, h) / 100;
513
+ const cx = w / 2;
514
+ const cy = h / 2 + Math.sin(M.TAU * M.phase(t, 3)) * s * 2;
515
+ const a = M.TAU * (t / 6);
516
+ const tilt = -0.5;
517
+ const V = [-1, 1].flatMap((x) => [-1, 1].flatMap((y) => [-1, 1].map((z) => [x, y, z])));
518
+ const pts = V.map(([x, y, z]) => {
519
+ const x1 = x * Math.cos(a) - z * Math.sin(a);
520
+ const z1 = x * Math.sin(a) + z * Math.cos(a);
521
+ const y1 = y * Math.cos(tilt) - z1 * Math.sin(tilt);
522
+ const z2 = y * Math.sin(tilt) + z1 * Math.cos(tilt);
523
+ return { ...M.proj(x1 * s * 16, y1 * s * 16, z2 * 16 + 70, 70, cx, cy), z: z2 };
524
+ });
525
+ const faces = [
526
+ [0, 1, 3, 2],
527
+ [4, 5, 7, 6],
528
+ [0, 1, 5, 4],
529
+ [2, 3, 7, 6],
530
+ [0, 2, 6, 4],
531
+ [1, 3, 7, 5],
532
+ ];
533
+ // Shade from the motif colour toward black and white, so every face reads in every tone.
534
+ const c = P.fg;
535
+ const shades = [c, M.mixColor(c, "#000000", 0.3), second(P), M.mixColor(c, "#ffffff", 0.35), M.mixColor(c, "#000000", 0.5), M.mixColor(second(P), "#000000", 0.25)];
536
+ faces
537
+ .map((f, i) => ({ f, i, z: f.reduce((sum, k) => sum + pts[k].z, 0) / 4 }))
538
+ .sort((p1, p2) => p2.z - p1.z)
539
+ .forEach(({ f, i }) => {
540
+ ctx.fillStyle = shades[i];
541
+ ctx.strokeStyle = M.rgba(P.paper, 0.35);
542
+ ctx.lineWidth = s * 0.3;
543
+ ctx.beginPath();
544
+ f.forEach((k, j) => (j ? ctx.lineTo(pts[k].x, pts[k].y) : ctx.moveTo(pts[k].x, pts[k].y)));
545
+ ctx.closePath();
546
+ ctx.fill();
547
+ ctx.stroke();
548
+ });
549
+ };
550
+
551
+ const dnaHelix: LoopDraw = (ctx, w, h, t, P, M) => {
552
+ const s = Math.min(w, h) / 100;
553
+ const cy = h / 2;
554
+ const n = 26;
555
+ const span = Math.min(w * 0.8, s * 140);
556
+ const x0 = w / 2 - span / 2;
557
+ const items: { x: number; y: number; z: number; c: string; r: number }[] = [];
558
+ for (let i = 0; i < n; i++) {
559
+ const a = i * 0.48 + M.TAU * M.phase(t, 3);
560
+ const x = x0 + (i / (n - 1)) * span;
561
+ const y1 = cy + Math.sin(a) * s * 14;
562
+ const y2 = cy - Math.sin(a) * s * 14;
563
+ ctx.strokeStyle = M.rgba(P.mid, 0.9);
564
+ ctx.lineWidth = s * 0.5;
565
+ ctx.beginPath();
566
+ ctx.moveTo(x, y1);
567
+ ctx.lineTo(x, y2);
568
+ ctx.stroke();
569
+ items.push({ x, y: y1, z: Math.cos(a), c: P.fg, r: s * (2 + Math.cos(a)) });
570
+ items.push({ x, y: y2, z: -Math.cos(a), c: second(P), r: s * (2 - Math.cos(a)) });
571
+ }
572
+ items
573
+ .sort((a, b) => a.z - b.z)
574
+ .forEach((d) => {
575
+ ctx.fillStyle = d.c;
576
+ ctx.beginPath();
577
+ ctx.arc(d.x, d.y, Math.max(s * 0.6, d.r), 0, M.TAU);
578
+ ctx.fill();
579
+ });
580
+ };
581
+
582
+ const pieBurst: LoopDraw = (ctx, w, h, t, P, M) => {
583
+ const s = Math.min(w, h) / 100;
584
+ const cx = w / 2;
585
+ const cy = h / 2;
586
+ const p = M.phase(t, 3);
587
+ const out = M.ease.outBack(M.win(p, 0.08, 0.32)) * (1 - M.ease.inCubic(M.win(p, 0.62, 0.86)));
588
+ // Half a turn per cycle: the three-colour pattern repeats every three slices.
589
+ const rot = (M.TAU / 2) * (Math.floor(t / 3) + M.ease.inOutCubic(M.win(p, 0.62, 0.9)));
590
+ const colors = [P.fg, second(P), P.mid];
591
+ for (let k = 0; k < 6; k++) {
592
+ const a0 = rot + (k * M.TAU) / 6;
593
+ const mid = a0 + M.TAU / 12;
594
+ const d = out * s * 6;
595
+ ctx.fillStyle = colors[k % 3];
596
+ ctx.beginPath();
597
+ ctx.moveTo(cx + Math.cos(mid) * d, cy + Math.sin(mid) * d);
598
+ ctx.arc(cx + Math.cos(mid) * d, cy + Math.sin(mid) * d, s * 26, a0, a0 + M.TAU / 6);
599
+ ctx.closePath();
600
+ ctx.fill();
601
+ }
602
+ };
603
+
604
+ const waveBars: LoopDraw = (ctx, w, h, t, P, M) => {
605
+ const s = Math.min(w, h) / 100;
606
+ const n = 26;
607
+ const span = Math.min(w * 0.82, s * 150);
608
+ const bw = span / n;
609
+ const cy = h / 2;
610
+ for (let i = 0; i < n; i++) {
611
+ const env = Math.sin((Math.PI * (i + 0.5)) / n);
612
+ const v = (0.5 + 0.5 * Math.sin(M.TAU * M.phase(t, 1.5) - i * 0.55)) * (0.7 + 0.3 * Math.sin(M.TAU * (t / 6) + i));
613
+ const bh = s * (3 + 34 * env * v);
614
+ ctx.fillStyle = M.mixColor(P.fg, second(P), i / (n - 1));
615
+ ctx.beginPath();
616
+ ctx.roundRect(w / 2 - span / 2 + i * bw + bw * 0.18, cy - bh / 2, bw * 0.64, bh, bw * 0.32);
617
+ ctx.fill();
618
+ }
619
+ };
620
+
621
+ const LOOPS_BASE: LoopDef[] = [
622
+ { id: "perspective-grid", name: "Perspective Grid", kind: "background", draw: perspectiveGrid, tags: ["grid", "3d", "tech", "retro", "synthwave"], description: "A grid floor streaming toward the camera under a glowing horizon. Tech launches, retro, gaming, energetic intros." },
623
+ { id: "dot-wave", name: "Dot Wave", kind: "background", draw: dotWave, tags: ["dots", "wave", "pattern", "calm"], description: "A field of dots swelling in a diagonal wave. Calm, modern product backdrops behind titles." },
624
+ { id: "flow-lines", name: "Flow Lines", kind: "background", draw: flowLines, tags: ["lines", "waves", "calm", "data"], description: "Thin horizontal lines drifting like a breathing signal. Data, finance, calm explainers." },
625
+ { id: "gradient-blobs", name: "Gradient Blobs", kind: "background", draw: gradientBlobs, tags: ["gradient", "mesh", "soft", "premium"], description: "Big soft brand-colour blobs drifting into each other: a living mesh gradient. The safe premium backdrop for titles and product shots." },
626
+ { id: "stripes-scroll", name: "Stripe Scroll", kind: "background", draw: stripesScroll, tags: ["stripes", "bold", "sport", "loud"], description: "Bold diagonal stripes sliding past, with an accent stripe every fifth. Loud promos, sport, sales." },
627
+ { id: "concentric-pulse", name: "Concentric Pulse", kind: "background", draw: concentricPulse, tags: ["rings", "radar", "beat", "focus"], description: "Rings rippling out from a pulsing center on the beat. Draws the eye to the middle: reveals, notifications, music." },
628
+ { id: "checker-twist", name: "Checker Twist", kind: "background", draw: checkerTwist, tags: ["checker", "tiles", "playful", "pattern"], description: "A checkerboard whose tiles twist a quarter turn in a diagonal wave. Playful, design-y, transitions." },
629
+ { id: "halftone-sweep", name: "Halftone Sweep", kind: "background", draw: halftoneSweep, tags: ["halftone", "print", "sweep", "editorial"], description: "A halftone dot field with a band of light swelling across it. Editorial, print, comic energy." },
630
+ { id: "terrain-ridges", name: "Terrain Ridges", kind: "background", draw: terrainRidges, tags: ["ridges", "terrain", "music", "moody"], description: "Stacked ridgelines rolling toward the viewer, peaks in the middle. Moody, music, data, night." },
631
+ { id: "starfield-warp", name: "Starfield Warp", kind: "background", draw: starfieldWarp, tags: ["stars", "warp", "speed", "space"], description: "Streaks rushing out of the center at warp speed. Hype intros, launches, 'faster' messages." },
632
+ { id: "bokeh-drift", name: "Bokeh Drift", kind: "background", draw: bokehDrift, tags: ["bokeh", "soft", "dreamy", "light"], description: "Soft out-of-focus lights rising slowly. Dreamy, warm, lifestyle, behind 3D devices." },
633
+ { id: "iso-cubes", name: "Iso Cubes", kind: "background", draw: isoCubes, tags: ["isometric", "cubes", "3d", "tech", "blocks"], description: "An isometric city of cubes rising and settling in a wave from the center. Infrastructure, building, data, dev tools." },
634
+ { id: "ribbon-weave", name: "Ribbon Weave", kind: "background", draw: ribbonWeave, tags: ["ribbons", "waves", "fluid", "playful"], description: "Thick colour ribbons waving across the frame. Playful, fluid, consumer apps." },
635
+ { id: "tile-mosaic", name: "Tile Mosaic", kind: "background", draw: tileMosaic, tags: ["tiles", "flip", "grid", "pattern"], description: "Rounded tiles flipping colour at random moments. Busy-but-tidy energy: marketplaces, many features." },
636
+ { id: "orbit-rings", name: "Orbit Rings", kind: "shape", draw: orbitRings, tags: ["orbit", "planet", "atom", "ai"], description: "A glowing sphere with three tilted rings and moons orbiting it. AI, platforms, 'everything connects'." },
637
+ { id: "morph-blob", name: "Morph Blob", kind: "shape", draw: morphBlob, tags: ["blob", "organic", "soft", "ai"], description: "A glossy gradient blob slowly morphing and turning. AI assistants, organic brands, a soft centerpiece." },
638
+ { id: "bouncing-ball", name: "Bouncing Ball", kind: "shape", draw: bouncingBall, tags: ["bounce", "playful", "loading", "beat"], description: "A ball bouncing with squash and stretch and a contact shadow. Playful beats, loading, kids, games." },
639
+ { id: "spinner-petals", name: "Spinner Petals", kind: "shape", draw: spinnerPetals, tags: ["flower", "spinner", "loading", "playful"], description: "Eight petals snapping a quarter turn with a breath. Loading, blooming, wellness, playful logos." },
640
+ { id: "stacked-squares", name: "Stacked Squares", kind: "shape", draw: stackedSquares, tags: ["squares", "stack", "layers", "design"], description: "Four nested rounded squares turning in a staggered overshoot. Layers, design tools, structure." },
641
+ { id: "ripple-drop", name: "Ripple Drop", kind: "shape", draw: rippleDrop, tags: ["drop", "ripple", "water", "calm"], description: "A drop falls and sends ripples across a surface. Calm, impact, 'one change spreads'." },
642
+ { id: "cube-spin", name: "Cube Spin", kind: "shape", draw: cubeSpin, tags: ["cube", "3d", "product", "tech"], description: "A shaded 3D cube spinning and bobbing. Products, packages, building blocks, tech." },
643
+ { id: "dna-helix", name: "DNA Helix", kind: "shape", draw: dnaHelix, tags: ["helix", "science", "data", "health"], description: "Two strands of dots twisting around each other. Science, health, data, 'in our DNA'." },
644
+ { id: "pie-burst", name: "Pie Burst", kind: "shape", draw: pieBurst, tags: ["pie", "chart", "burst", "data"], description: "A pie that bursts into slices, turns and snaps back. Data, analytics, splitting, sharing." },
645
+ { id: "wave-bars", name: "Wave Bars", kind: "shape", draw: waveBars, tags: ["equalizer", "audio", "music", "voice"], description: "Equalizer bars rolling in a wave. Audio, voice, music, podcasts, 'listening'." },
646
+ ];
647
+
648
+ /** Every loop, each with its gallery category. */
649
+ export const LOOPS: (LoopDef & { category: LoopCategory })[] = [...LOOPS_BASE, ...LOOPS_MORE].map((l) => ({
650
+ ...l,
651
+ category: l.category ?? (l.kind === "shape" ? "Shapes" : "Backgrounds"),
652
+ }));
653
+
654
+ export const LOOP_IDS = LOOPS.map((l) => l.id);
655
+ /** The loop `motion-loop` defaults to, and what an unknown id falls back to. */
656
+ export const DEFAULT_LOOP_ID = "gradient-blobs";
657
+ const warned = new Set<string>();
658
+ /** A loop by id; an unknown id warns once and falls back to DEFAULT_LOOP_ID. */
659
+ export const getLoop = (id: string) => {
660
+ const found = LOOPS.find((l) => l.id === id);
661
+ if (found) return found;
662
+ if (!warned.has(id)) {
663
+ warned.add(id);
664
+ console.warn(`Unknown motion loop "${id}", using "${DEFAULT_LOOP_ID}". Ids: ${LOOP_IDS.join(", ")}`);
665
+ }
666
+ return LOOPS.find((l) => l.id === DEFAULT_LOOP_ID) ?? LOOPS[0];
667
+ };