procedural-bot-animations 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +167 -47
  2. package/dist/animation.d.ts +90 -0
  3. package/dist/animation.js +396 -0
  4. package/dist/brain.d.ts +194 -35
  5. package/dist/brain.js +578 -54
  6. package/dist/character.d.ts +123 -0
  7. package/dist/character.js +916 -0
  8. package/dist/characters/berry.d.ts +2 -0
  9. package/dist/characters/berry.js +38 -0
  10. package/dist/characters/flame.d.ts +2 -0
  11. package/dist/characters/flame.js +46 -0
  12. package/dist/delta.d.ts +16 -0
  13. package/dist/delta.js +146 -0
  14. package/dist/examples.d.ts +4 -0
  15. package/dist/examples.js +208 -0
  16. package/dist/focus.d.ts +46 -0
  17. package/dist/focus.js +284 -0
  18. package/dist/gaze.d.ts +41 -53
  19. package/dist/gaze.js +125 -82
  20. package/dist/index.d.ts +18 -11
  21. package/dist/index.js +18 -11
  22. package/dist/interactions.d.ts +30 -0
  23. package/dist/interactions.js +100 -0
  24. package/dist/library.d.ts +18 -0
  25. package/dist/library.js +14 -0
  26. package/dist/moods.d.ts +78 -46
  27. package/dist/moods.js +48 -73
  28. package/dist/motion.d.ts +93 -0
  29. package/dist/motion.js +167 -0
  30. package/dist/mount.d.ts +90 -0
  31. package/dist/mount.js +707 -0
  32. package/dist/parts.d.ts +36 -0
  33. package/dist/parts.js +131 -0
  34. package/dist/reactions.d.ts +184 -44
  35. package/dist/reactions.js +1851 -116
  36. package/dist/rig.d.ts +119 -0
  37. package/dist/rig.js +59 -0
  38. package/dist/scroll-traveler.js +1 -1
  39. package/dist/ticker.d.ts +10 -0
  40. package/dist/ticker.js +42 -0
  41. package/dist/transformations.d.ts +21 -0
  42. package/dist/transformations.js +306 -0
  43. package/package.json +7 -11
  44. package/dist/bind.d.ts +0 -27
  45. package/dist/bind.js +0 -42
  46. package/dist/blink.d.ts +0 -25
  47. package/dist/blink.js +0 -48
  48. package/dist/fake3d.d.ts +0 -20
  49. package/dist/fake3d.js +0 -24
  50. package/dist/noise.d.ts +0 -16
  51. package/dist/noise.js +0 -17
  52. package/dist/render.d.ts +0 -29
  53. package/dist/render.js +0 -97
  54. package/dist/rng.d.ts +0 -10
  55. package/dist/rng.js +0 -18
  56. package/dist/spring.d.ts +0 -21
  57. package/dist/spring.js +0 -33
  58. package/dist/types.d.ts +0 -63
  59. package/dist/types.js +0 -46
package/dist/reactions.js CHANGED
@@ -1,120 +1,1855 @@
1
- import { clamp } from "./spring.js";
2
- function squashLaunchLand(t, launchWindow = 0.15, landWindow = 0.15) {
3
- const launch = clamp(1 - t / launchWindow, 0, 1);
4
- const land = clamp((t - (1 - landWindow)) / landWindow, 0, 1);
5
- return { squash: launch * 0.5 + land, stretch: 1 - launch - land * 0.3 };
1
+ import { clamp, fromTracks, track } from './motion.js';
2
+ import { TRANSFORMATIONS } from './transformations.js';
3
+ function success(level) {
4
+ const h = { exercise: 110, lesson: 170, module: 220 }[level];
5
+ const part = { exercise: 20, lesson: 26, module: 32 }[level];
6
+ const base = fromTracks({
7
+ rootY: [
8
+ [0, 0],
9
+ [0.1, 0, 'easeOut'],
10
+ [0.333, -h],
11
+ [0.433, -h, 'easeIn'],
12
+ [0.6, 0],
13
+ ],
14
+ bodySx: [
15
+ [0, 0],
16
+ [0.1, 0.12],
17
+ [0.2, -0.1],
18
+ [0.333, 0],
19
+ [0.433, -0.04],
20
+ [0.6, 0.14],
21
+ [0.7, -0.03],
22
+ [0.82, 0.02],
23
+ [1, 0],
24
+ ],
25
+ bodySy: [
26
+ [0, 0],
27
+ [0.1, -0.16],
28
+ [0.2, 0.14],
29
+ [0.333, 0],
30
+ [0.433, 0.05],
31
+ [0.6, -0.18],
32
+ [0.7, 0.05],
33
+ [0.82, -0.02],
34
+ [1, 0],
35
+ ],
36
+ partL: [
37
+ [0, 0],
38
+ [0.1, -10],
39
+ [0.333, part],
40
+ [0.6, -12],
41
+ [0.75, 6],
42
+ [1, 0],
43
+ ],
44
+ partR: [
45
+ [0, 0],
46
+ [0.1, 10],
47
+ [0.333, -part],
48
+ [0.6, 12],
49
+ [0.75, -6],
50
+ [1, 0],
51
+ ],
52
+ partC: [
53
+ [0, 0],
54
+ [0.1, -3],
55
+ [0.333, 7],
56
+ [0.6, -5],
57
+ [0.8, 3],
58
+ [1, 0],
59
+ ],
60
+ happy: [
61
+ [0, 0],
62
+ [0.15, 0],
63
+ [0.3, 1],
64
+ [0.85, 1],
65
+ [1, 0],
66
+ ],
67
+ holdGaze: [
68
+ [0, 0],
69
+ [0.15, 0.8],
70
+ [0.85, 0.8],
71
+ [1, 0],
72
+ ],
73
+ sparks: [
74
+ [0, 0],
75
+ [0.3, 0, 'linear'],
76
+ [0.9, 1],
77
+ [0.9001, 0],
78
+ ],
79
+ });
80
+ if (level !== 'module')
81
+ return base;
82
+ // Module: a somersault in the air (360° equals 0°, so it does not need to return).
83
+ const spin = track([
84
+ [0, 0],
85
+ [0.12, 0],
86
+ [0.52, 360],
87
+ ]);
88
+ return (t) => ({ ...base(t), centerRotate: spin(t) });
6
89
  }
7
- /** A single hop with squash-on-takeoff and squash-on-landing, no real physics integration needed since the whole arc is a closed-form curve of `t`. */
8
- export const bounce = {
9
- durationSeconds: 0.55,
10
- priority: 1,
11
- curve(t) {
12
- const { squash, stretch } = squashLaunchLand(t);
13
- const flight = clamp((t - 0.12) / 0.76, 0, 1);
14
- const y = -18 * Math.sin(Math.PI * flight);
15
- return {
16
- body: {
17
- y,
18
- scaleY: 1 - squash * 0.16 + (1 - squash) * (stretch - 1) * 0.1,
19
- scaleX: 1 + squash * 0.1,
20
- },
21
- };
22
- },
23
- };
24
- /** Eyes widen fast, body flinches back, both settle — a startle reaction. */
25
- export const fright = {
26
- durationSeconds: 0.5,
27
- priority: 3,
28
- curve(t) {
29
- const attack = clamp(t / 0.08, 0, 1);
30
- const release = 1 - clamp((t - 0.08) / 0.42, 0, 1);
31
- const shakeEnvelope = Math.max(0, 1 - t / 0.35);
32
- return {
33
- eyes: { scaleY: 1 + attack * release * 0.3 },
34
- body: { x: Math.sin(t * 55) * shakeEnvelope * 2.2, rotate: Math.sin(t * 40) * shakeEnvelope * 3 },
35
- };
36
- },
37
- };
38
- /** Two quick blinks in a row. */
39
- export const doubleBlink = {
40
- durationSeconds: 0.45,
41
- curve(t) {
42
- const cycle = (phase) => {
43
- const local = clamp((t - phase) / 0.12, 0, 1);
44
- return local < 1 ? Math.sin(Math.PI * local) : 0;
45
- };
46
- return { eyes: { shut: Math.max(cycle(0), cycle(0.2)) } };
47
- },
48
- };
49
- /** A small forward-back head nod, e.g. for acknowledging something. */
50
- export const nod = {
51
- durationSeconds: 0.6,
52
- curve(t) {
53
- const envelope = Math.sin(Math.PI * t);
54
- return { body: { rotate: Math.sin(t * Math.PI * 3) * envelope * 4 } };
55
- },
56
- };
57
- export const builtinReactions = { bounce, fright, doubleBlink, nod };
90
+ /* ---------- expression reactions ---------- */
91
+ const almostThere = fromTracks({
92
+ bodyRotate: [
93
+ [0, 0],
94
+ [0.2, -6],
95
+ [0.3, 5],
96
+ [0.4, -4],
97
+ [0.5, 3],
98
+ [0.6, 0],
99
+ ],
100
+ bodySx: [
101
+ [0, 0],
102
+ [0.08, 0.06],
103
+ [0.2, 0],
104
+ [0.75, 0.04],
105
+ [0.86, -0.02],
106
+ [1, 0],
107
+ ],
108
+ bodySy: [
109
+ [0, 0],
110
+ [0.08, -0.06],
111
+ [0.2, 0],
112
+ [0.75, -0.03],
113
+ [0.86, 0.04],
114
+ [1, 0],
115
+ ],
116
+ eyeY: [
117
+ [0, 0],
118
+ [0.1, 16],
119
+ [0.6, 16],
120
+ [0.78, -4],
121
+ [1, 0],
122
+ ],
123
+ lidTop: [
124
+ [0, 0],
125
+ [0.1, 0.3],
126
+ [0.6, 0.3],
127
+ [0.78, 0],
128
+ ],
129
+ lidAngle: [
130
+ [0, 0],
131
+ [0.1, -18],
132
+ [0.6, -18],
133
+ [0.78, 8],
134
+ [1, 0],
135
+ ],
136
+ partL: [
137
+ [0, 0],
138
+ [0.15, -18],
139
+ [0.6, -18],
140
+ [0.8, 6],
141
+ [1, 0],
142
+ ],
143
+ partR: [
144
+ [0, 0],
145
+ [0.15, 18],
146
+ [0.6, 18],
147
+ [0.8, -6],
148
+ [1, 0],
149
+ ],
150
+ partC: [
151
+ [0, 0],
152
+ [0.15, 14],
153
+ [0.6, 14],
154
+ [0.8, -4],
155
+ [1, 0],
156
+ ],
157
+ rootY: [
158
+ [0, 0],
159
+ [0.15, 10],
160
+ [0.6, 10],
161
+ [0.8, 0],
162
+ ],
163
+ holdGaze: [
164
+ [0, 0],
165
+ [0.1, 0.9],
166
+ [0.7, 0.9],
167
+ [1, 0],
168
+ ],
169
+ });
170
+ const fright = fromTracks({
171
+ rootY: [
172
+ [0, 0],
173
+ [0.12, -45, 'easeIn'],
174
+ [0.3, 0],
175
+ ],
176
+ bodyRotate: [
177
+ [0, 0],
178
+ [0.12, -5],
179
+ [0.5, -3],
180
+ [1, 0],
181
+ ],
182
+ bodySx: [
183
+ [0, 0],
184
+ [0.12, -0.08],
185
+ [0.3, 0.12],
186
+ [0.42, -0.03],
187
+ [0.55, 0],
188
+ ],
189
+ bodySy: [
190
+ [0, 0],
191
+ [0.12, 0.1],
192
+ [0.3, -0.14],
193
+ [0.42, 0.04],
194
+ [0.55, 0],
195
+ ],
196
+ // Eyes become tiny dots (• •), Pumpy's fright.
197
+ eyeSx: [
198
+ [0, 0],
199
+ [0.08, -0.45],
200
+ [0.7, -0.45],
201
+ [1, 0],
202
+ ],
203
+ eyeSy: [
204
+ [0, 0],
205
+ [0.08, -0.62],
206
+ [0.7, -0.62],
207
+ [1, 0],
208
+ ],
209
+ partL: [
210
+ [0, 0],
211
+ [0.12, 24],
212
+ [0.5, 10],
213
+ [1, 0],
214
+ ],
215
+ partR: [
216
+ [0, 0],
217
+ [0.12, -24],
218
+ [0.5, -10],
219
+ [1, 0],
220
+ ],
221
+ partC: [
222
+ [0, 0],
223
+ [0.12, -10],
224
+ [0.5, 4],
225
+ [1, 0],
226
+ ],
227
+ exclaim: [
228
+ [0, 0],
229
+ [0.08, 1],
230
+ [0.8, 1],
231
+ [1, 0],
232
+ ],
233
+ holdGaze: [
234
+ [0, 0],
235
+ [0.1, 1],
236
+ [0.7, 1],
237
+ [1, 0],
238
+ ],
239
+ });
240
+ const idea = fromTracks({
241
+ rootY: [
242
+ [0, 0],
243
+ [0.12, 0],
244
+ [0.24, -40, 'easeIn'],
245
+ [0.4, 0],
246
+ ],
247
+ bodySy: [
248
+ [0, 0],
249
+ [0.12, -0.06],
250
+ [0.24, 0.06],
251
+ [0.4, -0.04],
252
+ [0.5, 0],
253
+ ],
254
+ partC: [
255
+ [0, 0],
256
+ [0.2, -14],
257
+ [0.4, 6],
258
+ [0.6, -3],
259
+ [1, 0],
260
+ ],
261
+ eyeX: [
262
+ [0, 0],
263
+ [0.15, 22],
264
+ [0.85, 22],
265
+ [1, 0],
266
+ ],
267
+ eyeY: [
268
+ [0, 0],
269
+ [0.15, -22],
270
+ [0.85, -22],
271
+ [1, 0],
272
+ ],
273
+ eyeSy: [
274
+ [0, 0],
275
+ [0.15, 0.12],
276
+ [0.85, 0.12],
277
+ [1, 0],
278
+ ],
279
+ lamp: [
280
+ [0, 0],
281
+ [0.15, 1],
282
+ [0.85, 1],
283
+ [1, 0],
284
+ ],
285
+ holdGaze: [
286
+ [0, 0],
287
+ [0.1, 1],
288
+ [0.85, 1],
289
+ [1, 0],
290
+ ],
291
+ });
292
+ /** "Copied that, huh?": turns the face sideways and squints, suspicious. */
293
+ const copiedThat = fromTracks({
294
+ turn: [
295
+ [0, 0],
296
+ [0.15, -0.9],
297
+ [0.85, -0.9],
298
+ [1, 0],
299
+ ],
300
+ lidTop: [
301
+ [0, 0],
302
+ [0.2, 0.5],
303
+ [0.85, 0.5],
304
+ [1, 0],
305
+ ],
306
+ lidBottom: [
307
+ [0, 0],
308
+ [0.2, 0.15],
309
+ [0.85, 0.15],
310
+ [1, 0],
311
+ ],
312
+ lidAngle: [
313
+ [0, 0],
314
+ [0.2, 20],
315
+ [0.85, 20],
316
+ [1, 0],
317
+ ],
318
+ eyeX: [
319
+ [0, 0],
320
+ [0.15, 18],
321
+ [0.85, 18],
322
+ [1, 0],
323
+ ],
324
+ partL: [
325
+ [0, 0],
326
+ [0.2, -12],
327
+ [0.85, -12],
328
+ [1, 0],
329
+ ],
330
+ partR: [
331
+ [0, 0],
332
+ [0.2, 12],
333
+ [0.85, 12],
334
+ [1, 0],
335
+ ],
336
+ bodyRotate: [
337
+ [0, 0],
338
+ [0.2, -3],
339
+ [0.85, -3],
340
+ [1, 0],
341
+ ],
342
+ bodySy: [
343
+ [0, 0],
344
+ [0.2, 0.03],
345
+ [0.85, 0.03],
346
+ [1, 0],
347
+ ],
348
+ holdGaze: [
349
+ [0, 0],
350
+ [0.12, 1],
351
+ [0.88, 1],
352
+ [1, 0],
353
+ ],
354
+ });
355
+ const welcome = fromTracks({
356
+ rootY: [
357
+ [0, 430, 'easeOut'],
358
+ [0.25, -60, 'easeIn'],
359
+ [0.35, 0],
360
+ ],
361
+ opacity: [
362
+ [0, -1],
363
+ [0.15, 0],
364
+ ],
365
+ bodySx: [
366
+ [0, -0.1],
367
+ [0.25, -0.06],
368
+ [0.35, 0.14],
369
+ [0.45, -0.03],
370
+ [0.55, 0],
371
+ ],
372
+ bodySy: [
373
+ [0, 0.2],
374
+ [0.25, 0.1],
375
+ [0.35, -0.16],
376
+ [0.45, 0.04],
377
+ [0.55, 0],
378
+ ],
379
+ partR: [
380
+ [0, 0],
381
+ [0.55, 0],
382
+ [0.63, -36],
383
+ [0.71, -8],
384
+ [0.79, -36],
385
+ [0.87, -8],
386
+ [0.95, 0],
387
+ ],
388
+ partL: [
389
+ [0, 0],
390
+ [0.4, -8],
391
+ [0.6, 6],
392
+ [0.8, -2],
393
+ [1, 0],
394
+ ],
395
+ partC: [
396
+ [0, 0],
397
+ [0.3, 10],
398
+ [0.5, -5],
399
+ [0.7, 3],
400
+ [1, 0],
401
+ ],
402
+ happyRight: [
403
+ [0, 0],
404
+ [0.55, 0],
405
+ [0.6, 1],
406
+ [0.92, 1],
407
+ [1, 0],
408
+ ],
409
+ shadow: [
410
+ [0, -0.7],
411
+ [0.35, 0],
412
+ ],
413
+ });
414
+ const DIZZY_ENVELOPE = track([
415
+ [0, 0],
416
+ [0.15, 1],
417
+ [0.75, 1],
418
+ [1, 0],
419
+ ]);
420
+ /** Easter egg: eyes spinning in a circle and the body staggering. */
421
+ function dizzy(t) {
422
+ const e = DIZZY_ENVELOPE(t);
423
+ const a = t * Math.PI * 6;
424
+ return {
425
+ eyeX: Math.cos(a) * 26 * e,
426
+ eyeY: Math.sin(a) * 26 * e,
427
+ eyeSx: -0.3 * e,
428
+ eyeSy: -0.5 * e,
429
+ bodyRotate: Math.sin(t * Math.PI * 4) * 7 * e,
430
+ partL: Math.sin(t * Math.PI * 5) * 14 * e,
431
+ partR: Math.sin(t * Math.PI * 5 + 1) * 14 * e,
432
+ holdGaze: e,
433
+ };
434
+ }
435
+ const wake = fromTracks({
436
+ rootY: [
437
+ [0, 0],
438
+ [0.3, -60, 'easeIn'],
439
+ [0.6, 0],
440
+ ],
441
+ eyeSy: [
442
+ [0, 0],
443
+ [0.25, 0.2],
444
+ [1, 0],
445
+ ],
446
+ partL: [
447
+ [0, 0],
448
+ [0.3, 20],
449
+ [1, 0],
450
+ ],
451
+ partR: [
452
+ [0, 0],
453
+ [0.3, -20],
454
+ [1, 0],
455
+ ],
456
+ });
457
+ /* ---------- new reactions, Pumpy style ---------- */
458
+ /** Wink: one eye arcs happy, the body leans, a small hop. */
459
+ const wink = fromTracks({
460
+ happyRight: [
461
+ [0, 0],
462
+ [0.12, 1],
463
+ [0.7, 1],
464
+ [0.85, 0],
465
+ ],
466
+ lidBottom: [
467
+ [0, 0],
468
+ [0.12, 0.25],
469
+ [0.7, 0.25],
470
+ [0.85, 0],
471
+ ],
472
+ bodyRotate: [
473
+ [0, 0],
474
+ [0.15, 7],
475
+ [0.7, 7],
476
+ [1, 0],
477
+ ],
478
+ rootY: [
479
+ [0, 0],
480
+ [0.08, -26, 'easeIn'],
481
+ [0.2, 0],
482
+ ],
483
+ partR: [
484
+ [0, 0],
485
+ [0.15, -22],
486
+ [0.35, -6],
487
+ [0.55, -18],
488
+ [1, 0],
489
+ ],
490
+ turn: [
491
+ [0, 0],
492
+ [0.15, 0.35],
493
+ [0.7, 0.35],
494
+ [1, 0],
495
+ ],
496
+ holdGaze: [
497
+ [0, 0],
498
+ [0.1, 1],
499
+ [0.8, 1],
500
+ [1, 0],
501
+ ],
502
+ });
503
+ /** Cheerful: sways from side to side with arc eyes (column 2 of the video). */
504
+ function cheerful(t) {
505
+ const e = track([
506
+ [0, 0],
507
+ [0.12, 1],
508
+ [0.85, 1],
509
+ [1, 0],
510
+ ])(t);
511
+ const phase = t * Math.PI * 6;
512
+ const side = Math.sin(phase);
513
+ return {
514
+ happy: e,
515
+ bodyRotate: side * 9 * e,
516
+ rootY: -Math.abs(Math.cos(phase)) * 22 * e,
517
+ bodySx: Math.abs(side) * 0.04 * e,
518
+ bodySy: -Math.abs(side) * 0.05 * e,
519
+ partL: (10 + side * 8) * e,
520
+ partR: (-10 + side * 8) * e,
521
+ turn: side * 0.35 * e,
522
+ holdGaze: e,
523
+ };
524
+ }
525
+ /** Profile: looks around by turning the whole face sideways, until in profile. */
526
+ const profile = fromTracks({
527
+ turn: [
528
+ [0, 0],
529
+ [0.14, 1.55],
530
+ [0.42, 1.55],
531
+ [0.56, -1.55],
532
+ [0.84, -1.55],
533
+ [1, 0],
534
+ ],
535
+ eyeY: [
536
+ [0, 0],
537
+ [0.14, -8],
538
+ [0.84, -8],
539
+ [1, 0],
540
+ ],
541
+ bodyRotate: [
542
+ [0, 0],
543
+ [0.14, 3],
544
+ [0.42, 3],
545
+ [0.56, -3],
546
+ [0.84, -3],
547
+ [1, 0],
548
+ ],
549
+ holdGaze: [
550
+ [0, 0],
551
+ [0.08, 1],
552
+ [0.92, 1],
553
+ [1, 0],
554
+ ],
555
+ });
556
+ /** Flatten: lies on the floor like play dough, line eyes, and pops back (start of column 6). */
557
+ const flatten = fromTracks({
558
+ bodySy: [
559
+ [0, 0],
560
+ [0.18, -0.42, 'easeOut'],
561
+ [0.7, -0.42],
562
+ [0.82, 0.1],
563
+ [0.92, -0.03],
564
+ [1, 0],
565
+ ],
566
+ bodySx: [
567
+ [0, 0],
568
+ [0.18, 0.26, 'easeOut'],
569
+ [0.7, 0.26],
570
+ [0.82, -0.06],
571
+ [0.92, 0.02],
572
+ [1, 0],
573
+ ],
574
+ eyeSy: [
575
+ [0, 0],
576
+ [0.2, -0.88],
577
+ [0.7, -0.88],
578
+ [0.8, 0],
579
+ ],
580
+ partL: [
581
+ [0, 0],
582
+ [0.2, -26],
583
+ [0.7, -26],
584
+ [0.82, 12],
585
+ [1, 0],
586
+ ],
587
+ partR: [
588
+ [0, 0],
589
+ [0.2, 26],
590
+ [0.7, 26],
591
+ [0.82, -12],
592
+ [1, 0],
593
+ ],
594
+ zzz: [
595
+ [0, 0],
596
+ [0.3, 0],
597
+ [0.38, 1],
598
+ [0.66, 1],
599
+ [0.72, 0],
600
+ ],
601
+ holdGaze: [
602
+ [0, 0],
603
+ [0.15, 1],
604
+ [0.8, 1],
605
+ [1, 0],
606
+ ],
607
+ });
608
+ /** Confused: dot eyes, tilted head, a swaying "?". */
609
+ const confused = fromTracks({
610
+ eyeSx: [
611
+ [0, 0],
612
+ [0.12, -0.4],
613
+ [0.8, -0.4],
614
+ [1, 0],
615
+ ],
616
+ eyeSy: [
617
+ [0, 0],
618
+ [0.12, -0.55],
619
+ [0.8, -0.55],
620
+ [1, 0],
621
+ ],
622
+ bodyRotate: [
623
+ [0, 0],
624
+ [0.15, -10],
625
+ [0.45, -10],
626
+ [0.55, 8],
627
+ [0.8, 8],
628
+ [1, 0],
629
+ ],
630
+ turn: [
631
+ [0, 0],
632
+ [0.15, -0.3],
633
+ [0.45, -0.3],
634
+ [0.55, 0.3],
635
+ [0.8, 0.3],
636
+ [1, 0],
637
+ ],
638
+ partC: [
639
+ [0, 0],
640
+ [0.15, -12],
641
+ [0.45, -12],
642
+ [0.55, 12],
643
+ [0.8, 12],
644
+ [1, 0],
645
+ ],
646
+ question: [
647
+ [0, 0],
648
+ [0.12, 1],
649
+ [0.85, 1],
650
+ [1, 0],
651
+ ],
652
+ holdGaze: [
653
+ [0, 0],
654
+ [0.1, 1],
655
+ [0.85, 1],
656
+ [1, 0],
657
+ ],
658
+ });
659
+ /** Somersault: prepares, jumps high, does a full turn in the air, lands happy. */
660
+ const somersault = fromTracks({
661
+ rootY: [
662
+ [0, 0],
663
+ [0.16, 0, 'easeOut'],
664
+ [0.42, -250],
665
+ [0.5, -250, 'easeIn'],
666
+ [0.7, 0],
667
+ ],
668
+ bodySx: [
669
+ [0, 0],
670
+ [0.16, 0.18],
671
+ [0.24, -0.1],
672
+ [0.4, 0],
673
+ [0.7, 0.16],
674
+ [0.8, -0.04],
675
+ [0.9, 0],
676
+ ],
677
+ bodySy: [
678
+ [0, 0],
679
+ [0.16, -0.24],
680
+ [0.24, 0.16],
681
+ [0.4, 0],
682
+ [0.7, -0.2],
683
+ [0.8, 0.05],
684
+ [0.9, 0],
685
+ ],
686
+ centerRotate: [
687
+ [0, 0],
688
+ [0.2, 0],
689
+ [0.64, 360],
690
+ ],
691
+ lidTop: [
692
+ [0, 0],
693
+ [0.12, 0.5],
694
+ [0.18, 0],
695
+ ],
696
+ happy: [
697
+ [0, 0],
698
+ [0.7, 0],
699
+ [0.76, 1],
700
+ [0.95, 1],
701
+ [1, 0],
702
+ ],
703
+ partL: [
704
+ [0, 0],
705
+ [0.16, -16],
706
+ [0.3, 24],
707
+ [0.7, -14],
708
+ [0.85, 6],
709
+ [1, 0],
710
+ ],
711
+ partR: [
712
+ [0, 0],
713
+ [0.16, 16],
714
+ [0.3, -24],
715
+ [0.7, 14],
716
+ [0.85, -6],
717
+ [1, 0],
718
+ ],
719
+ holdGaze: [
720
+ [0, 0],
721
+ [0.1, 1],
722
+ [0.9, 1],
723
+ [1, 0],
724
+ ],
725
+ });
726
+ /** Ignite (Flame): is born from an ember, grows past the mark and throws out rays. */
727
+ const ignite = fromTracks({
728
+ scale: [
729
+ [0, -0.75],
730
+ [0.35, 0.22, 'easeOut'],
731
+ [0.5, -0.06],
732
+ [0.62, 0],
733
+ ],
734
+ bodySy: [
735
+ [0, -0.2],
736
+ [0.35, 0.12],
737
+ [0.5, -0.04],
738
+ [0.62, 0],
739
+ ],
740
+ partC: [
741
+ [0, -20],
742
+ [0.35, 16],
743
+ [0.5, -8],
744
+ [0.7, 0],
745
+ ],
746
+ rays: [
747
+ [0, 0],
748
+ [0.3, 0],
749
+ [0.38, 1],
750
+ [0.85, 1],
751
+ [1, 0],
752
+ ],
753
+ happy: [
754
+ [0, 0],
755
+ [0.38, 0],
756
+ [0.44, 1],
757
+ [0.85, 1],
758
+ [1, 0],
759
+ ],
760
+ shadow: [
761
+ [0, -0.8],
762
+ [0.35, 0],
763
+ ],
764
+ embers: [
765
+ [0, 0],
766
+ [0.3, 0],
767
+ [0.38, 1],
768
+ [0.8, 1],
769
+ [1, 0],
770
+ ],
771
+ core: [
772
+ [0, 0],
773
+ [0.3, 0],
774
+ [0.38, 0.8],
775
+ [0.65, 0],
776
+ ],
777
+ });
778
+ /* ---------- Flame only ---------- */
58
779
  /**
59
- * Plays one reaction at a time. A second request while one is already
60
- * playing doesn't cut it off: it waits as the single pending slot (a third
61
- * request only overwrites the pending one if it has equal or higher
62
- * priority), and starts when the current reaction ends — unless it's gone
63
- * stale (older than `maxQueueAgeSeconds`), in which case it's dropped
64
- * instead of surprising the user with a late reaction.
780
+ * Extinguish: the scare of losing the streak. Smoke, squeezed eyes, a
781
+ * shiver. The extinguished state itself is the `out` activity.
65
782
  */
66
- export class ReactionPlayer {
67
- current = null;
68
- pending = null;
69
- clock = 0;
70
- maxQueueAgeSeconds;
71
- reactions;
72
- constructor(options = {}) {
73
- this.maxQueueAgeSeconds = options.maxQueueAgeSeconds ?? 1.6;
74
- this.reactions = options.reactions ?? builtinReactions;
75
- }
76
- get isPlaying() {
77
- return this.current !== null;
78
- }
79
- get currentName() {
80
- return this.current?.name ?? null;
81
- }
82
- /** Requests `name` to play. Returns true if it started immediately, false if queued/dropped. */
83
- play(name) {
84
- const def = this.reactions[name];
85
- if (!def)
86
- return false;
87
- if (!this.current) {
88
- this.current = { name, def, t: 0 };
89
- return true;
90
- }
91
- const currentPriority = this.current.def.priority ?? 0;
92
- const pendingPriority = this.pending ? this.pending.def.priority ?? 0 : -Infinity;
93
- const requestedPriority = def.priority ?? 0;
94
- if (requestedPriority >= currentPriority && requestedPriority >= pendingPriority) {
95
- this.pending = { name, def, requestedAt: this.clock };
96
- }
97
- return false;
98
- }
99
- /** Advances the clock; returns the active reaction's pose delta, or `null` when nothing is playing. */
100
- update(dt) {
101
- this.clock += dt;
102
- if (this.current) {
103
- this.current.t += dt / this.current.def.durationSeconds;
104
- if (this.current.t >= 1) {
105
- this.current = null;
106
- }
107
- }
108
- if (!this.current && this.pending) {
109
- const age = this.clock - this.pending.requestedAt;
110
- const { name, def } = this.pending;
111
- this.pending = null;
112
- if (age <= this.maxQueueAgeSeconds) {
113
- this.current = { name, def, t: 0 };
114
- }
115
- }
116
- if (!this.current)
117
- return null;
118
- return this.current.def.curve(clamp(this.current.t, 0, 1));
119
- }
783
+ const extinguish = fromTracks({
784
+ smoke: [
785
+ [0, 0],
786
+ [0.1, 1],
787
+ [0.7, 1],
788
+ [1, 0],
789
+ ],
790
+ bodySy: [
791
+ [0, 0],
792
+ [0.08, 0.12],
793
+ [0.2, -0.16],
794
+ [0.32, 0.05],
795
+ [0.45, -0.02],
796
+ [0.6, 0],
797
+ ],
798
+ bodySx: [
799
+ [0, 0],
800
+ [0.08, -0.06],
801
+ [0.2, 0.12],
802
+ [0.32, -0.03],
803
+ [0.6, 0],
804
+ ],
805
+ partC: [
806
+ [0, 0],
807
+ [0.1, 12],
808
+ [0.18, -10],
809
+ [0.26, 7],
810
+ [0.34, -4],
811
+ [0.5, 0],
812
+ ],
813
+ closeLeft: [
814
+ [0, 0],
815
+ [0.08, 1],
816
+ [0.6, 1],
817
+ [0.8, 0],
818
+ ],
819
+ closeRight: [
820
+ [0, 0],
821
+ [0.08, 1],
822
+ [0.6, 1],
823
+ [0.8, 0],
824
+ ],
825
+ holdGaze: [
826
+ [0, 0],
827
+ [0.08, 1],
828
+ [0.8, 1],
829
+ [1, 0],
830
+ ],
831
+ });
832
+ /** Streak milestone: becomes a blaze, rises, lights the core, throws embers and sparks. */
833
+ const blaze = fromTracks({
834
+ rootY: [
835
+ [0, 0],
836
+ [0.12, 0, 'easeOut'],
837
+ [0.3, -120],
838
+ [0.45, -120, 'easeIn'],
839
+ [0.6, 0],
840
+ ],
841
+ bodySy: [
842
+ [0, 0],
843
+ [0.1, -0.18],
844
+ [0.25, 0.35],
845
+ [0.45, 0.3],
846
+ [0.6, -0.15],
847
+ [0.72, 0.06],
848
+ [0.85, 0],
849
+ ],
850
+ bodySx: [
851
+ [0, 0],
852
+ [0.1, 0.14],
853
+ [0.25, -0.12],
854
+ [0.45, -0.1],
855
+ [0.6, 0.16],
856
+ [0.72, -0.04],
857
+ [0.85, 0],
858
+ ],
859
+ partC: [
860
+ [0, 0],
861
+ [0.1, -14],
862
+ [0.25, 18],
863
+ [0.4, -12],
864
+ [0.55, 10],
865
+ [0.7, -5],
866
+ [0.85, 0],
867
+ ],
868
+ partL: [
869
+ [0, 0],
870
+ [0.1, -10],
871
+ [0.25, 24],
872
+ [0.6, -10],
873
+ [0.8, 0],
874
+ ],
875
+ partR: [
876
+ [0, 0],
877
+ [0.1, 10],
878
+ [0.25, -24],
879
+ [0.6, 10],
880
+ [0.8, 0],
881
+ ],
882
+ core: [
883
+ [0, 0],
884
+ [0.2, 0],
885
+ [0.3, 1],
886
+ [0.8, 1],
887
+ [1, 0],
888
+ ],
889
+ rays: [
890
+ [0, 0],
891
+ [0.25, 0],
892
+ [0.3, 1],
893
+ [0.85, 1],
894
+ [1, 0],
895
+ ],
896
+ embers: [
897
+ [0, 0],
898
+ [0.25, 0],
899
+ [0.3, 1],
900
+ [0.85, 1],
901
+ [1, 0],
902
+ ],
903
+ happy: [
904
+ [0, 0],
905
+ [0.2, 0],
906
+ [0.3, 1],
907
+ [0.85, 1],
908
+ [1, 0],
909
+ ],
910
+ sparks: [
911
+ [0, 0],
912
+ [0.28, 0, 'linear'],
913
+ [0.85, 1],
914
+ [0.8501, 0],
915
+ ],
916
+ holdGaze: [
917
+ [0, 0],
918
+ [0.15, 0.8],
919
+ [0.85, 0.8],
920
+ [1, 0],
921
+ ],
922
+ });
923
+ /** Gust of wind from the left: leans over, squints, holds and comes back swaying. */
924
+ const gust = fromTracks({
925
+ bodyRotate: [
926
+ [0, 0],
927
+ [0.1, 4],
928
+ [0.2, 14],
929
+ [0.5, 12],
930
+ [0.6, -6],
931
+ [0.7, 4],
932
+ [0.8, -2],
933
+ [0.9, 0],
934
+ ],
935
+ bodySx: [
936
+ [0, 0],
937
+ [0.2, 0.08],
938
+ [0.5, 0.06],
939
+ [0.6, -0.04],
940
+ [0.75, 0],
941
+ ],
942
+ bodySy: [
943
+ [0, 0],
944
+ [0.2, -0.12],
945
+ [0.5, -0.1],
946
+ [0.6, 0.06],
947
+ [0.75, 0],
948
+ ],
949
+ scale: [
950
+ [0, 0],
951
+ [0.2, -0.08],
952
+ [0.5, -0.06],
953
+ [0.65, 0.04],
954
+ [0.8, 0],
955
+ ],
956
+ partC: [
957
+ [0, 0],
958
+ [0.15, 20],
959
+ [0.25, 30],
960
+ [0.35, 24],
961
+ [0.5, 30],
962
+ [0.6, -14],
963
+ [0.72, 8],
964
+ [0.85, -3],
965
+ [1, 0],
966
+ ],
967
+ partL: [
968
+ [0, 0],
969
+ [0.15, 20],
970
+ [0.25, 26],
971
+ [0.5, 24],
972
+ [0.6, -12],
973
+ [0.75, 4],
974
+ [1, 0],
975
+ ],
976
+ partR: [
977
+ [0, 0],
978
+ [0.15, 20],
979
+ [0.25, 26],
980
+ [0.5, 24],
981
+ [0.6, -12],
982
+ [0.75, 4],
983
+ [1, 0],
984
+ ],
985
+ lidTop: [
986
+ [0, 0],
987
+ [0.12, 0.45],
988
+ [0.5, 0.45],
989
+ [0.62, 0],
990
+ ],
991
+ lidBottom: [
992
+ [0, 0],
993
+ [0.12, 0.3],
994
+ [0.5, 0.3],
995
+ [0.62, 0],
996
+ ],
997
+ eyeX: [
998
+ [0, 0],
999
+ [0.15, 18],
1000
+ [0.5, 18],
1001
+ [0.62, 0],
1002
+ ],
1003
+ turn: [
1004
+ [0, 0],
1005
+ [0.15, -0.3],
1006
+ [0.5, -0.3],
1007
+ [0.62, 0],
1008
+ ],
1009
+ holdGaze: [
1010
+ [0, 0],
1011
+ [0.1, 1],
1012
+ [0.6, 1],
1013
+ [0.8, 0],
1014
+ ],
1015
+ });
1016
+ /** Crackle: three little pops, each with a small hop and a happy blink, throwing embers. */
1017
+ const crackle = fromTracks({
1018
+ rootY: [
1019
+ [0, 0],
1020
+ [0.06, 0, 'easeOut'],
1021
+ [0.14, -50, 'easeIn'],
1022
+ [0.22, 0],
1023
+ [0.3, 0, 'easeOut'],
1024
+ [0.38, -70, 'easeIn'],
1025
+ [0.46, 0],
1026
+ [0.56, 0, 'easeOut'],
1027
+ [0.66, -40, 'easeIn'],
1028
+ [0.76, 0],
1029
+ ],
1030
+ bodySy: [
1031
+ [0, 0],
1032
+ [0.05, -0.1],
1033
+ [0.1, 0.08],
1034
+ [0.22, -0.08],
1035
+ [0.28, 0.06],
1036
+ [0.46, -0.1],
1037
+ [0.52, 0.05],
1038
+ [0.76, -0.06],
1039
+ [0.85, 0],
1040
+ ],
1041
+ bodySx: [
1042
+ [0, 0],
1043
+ [0.05, 0.06],
1044
+ [0.1, -0.04],
1045
+ [0.22, 0.05],
1046
+ [0.28, -0.03],
1047
+ [0.46, 0.06],
1048
+ [0.52, -0.02],
1049
+ [0.76, 0.04],
1050
+ [0.85, 0],
1051
+ ],
1052
+ partC: [
1053
+ [0, 0],
1054
+ [0.14, 10],
1055
+ [0.22, -8],
1056
+ [0.38, 12],
1057
+ [0.46, -10],
1058
+ [0.66, 8],
1059
+ [0.76, -6],
1060
+ [0.9, 0],
1061
+ ],
1062
+ embers: [
1063
+ [0, 0],
1064
+ [0.1, 1],
1065
+ [0.8, 1],
1066
+ [1, 0],
1067
+ ],
1068
+ happyLeft: [
1069
+ [0, 0],
1070
+ [0.1, 1],
1071
+ [0.24, 1],
1072
+ [0.3, 0],
1073
+ ],
1074
+ happyRight: [
1075
+ [0, 0],
1076
+ [0.3, 0],
1077
+ [0.36, 1],
1078
+ [0.5, 1],
1079
+ [0.56, 0],
1080
+ ],
1081
+ happy: [
1082
+ [0, 0],
1083
+ [0.56, 0],
1084
+ [0.64, 1],
1085
+ [0.9, 1],
1086
+ [1, 0],
1087
+ ],
1088
+ });
1089
+ /** Sneeze: "a... a..." (stretches, eyes closing, leans back) and "achoo!" with sparks. */
1090
+ const sneeze = fromTracks({
1091
+ bodySy: [
1092
+ [0, 0],
1093
+ [0.15, 0.08],
1094
+ [0.3, 0.12],
1095
+ [0.42, 0.2],
1096
+ [0.48, -0.26],
1097
+ [0.56, 0.08],
1098
+ [0.64, -0.04],
1099
+ [0.75, 0],
1100
+ ],
1101
+ bodySx: [
1102
+ [0, 0],
1103
+ [0.42, -0.08],
1104
+ [0.48, 0.2],
1105
+ [0.56, -0.05],
1106
+ [0.64, 0.02],
1107
+ [0.75, 0],
1108
+ ],
1109
+ bodyRotate: [
1110
+ [0, 0],
1111
+ [0.15, -3],
1112
+ [0.3, -5],
1113
+ [0.42, -9],
1114
+ [0.48, 16],
1115
+ [0.58, -6],
1116
+ [0.68, 3],
1117
+ [0.8, 0],
1118
+ ],
1119
+ scale: [
1120
+ [0, 0],
1121
+ [0.46, 0],
1122
+ [0.5, -0.12],
1123
+ [0.62, 0.03],
1124
+ [0.75, 0],
1125
+ ],
1126
+ partC: [
1127
+ [0, 0],
1128
+ [0.42, -12],
1129
+ [0.48, 26],
1130
+ [0.58, -12],
1131
+ [0.7, 6],
1132
+ [0.85, 0],
1133
+ ],
1134
+ closeLeft: [
1135
+ [0, 0],
1136
+ [0.15, 0.3],
1137
+ [0.3, 0.45],
1138
+ [0.42, 0.8],
1139
+ [0.46, 1],
1140
+ [0.6, 1],
1141
+ [0.7, 0],
1142
+ ],
1143
+ closeRight: [
1144
+ [0, 0],
1145
+ [0.15, 0.3],
1146
+ [0.3, 0.45],
1147
+ [0.42, 0.8],
1148
+ [0.46, 1],
1149
+ [0.6, 1],
1150
+ [0.7, 0],
1151
+ ],
1152
+ lidAngle: [
1153
+ [0, 0],
1154
+ [0.3, -14],
1155
+ [0.46, -14],
1156
+ [0.6, 0],
1157
+ ],
1158
+ eyeY: [
1159
+ [0, 0],
1160
+ [0.42, -14],
1161
+ [0.48, 10],
1162
+ [0.6, 0],
1163
+ ],
1164
+ sparks: [
1165
+ [0, 0],
1166
+ [0.46, 0, 'linear'],
1167
+ [0.95, 1],
1168
+ [0.9501, 0],
1169
+ ],
1170
+ embers: [
1171
+ [0, 0],
1172
+ [0.46, 0],
1173
+ [0.5, 1],
1174
+ [0.85, 0],
1175
+ ],
1176
+ holdGaze: [
1177
+ [0, 0],
1178
+ [0.1, 1],
1179
+ [0.75, 1],
1180
+ [0.9, 0],
1181
+ ],
1182
+ });
1183
+ /** Tier up: squashes, leaps spinning, grows in the air (the colour swaps here) and lands happy. */
1184
+ const tierUp = fromTracks({
1185
+ rootY: [
1186
+ [0, 0],
1187
+ [0.12, 0, 'easeOut'],
1188
+ [0.4, -180],
1189
+ [0.5, -180, 'easeIn'],
1190
+ [0.68, 0],
1191
+ ],
1192
+ centerRotate: [
1193
+ [0, 0],
1194
+ [0.14, 0],
1195
+ [0.5, 360],
1196
+ ],
1197
+ bodySy: [
1198
+ [0, 0],
1199
+ [0.1, -0.2],
1200
+ [0.2, 0.12],
1201
+ [0.4, 0],
1202
+ [0.68, -0.2],
1203
+ [0.78, 0.06],
1204
+ [0.9, 0],
1205
+ ],
1206
+ bodySx: [
1207
+ [0, 0],
1208
+ [0.1, 0.16],
1209
+ [0.2, -0.08],
1210
+ [0.4, 0],
1211
+ [0.68, 0.18],
1212
+ [0.78, -0.04],
1213
+ [0.9, 0],
1214
+ ],
1215
+ scale: [
1216
+ [0, 0],
1217
+ [0.1, -0.1],
1218
+ [0.3, -0.2],
1219
+ [0.48, 0.25],
1220
+ [0.62, 0.1],
1221
+ [0.72, -0.05],
1222
+ [0.85, 0],
1223
+ ],
1224
+ core: [
1225
+ [0, 0],
1226
+ [0.35, 0],
1227
+ [0.45, 1],
1228
+ [0.7, 1],
1229
+ [0.9, 0],
1230
+ ],
1231
+ sparks: [
1232
+ [0, 0],
1233
+ [0.45, 0, 'linear'],
1234
+ [0.95, 1],
1235
+ [0.9501, 0],
1236
+ ],
1237
+ happy: [
1238
+ [0, 0],
1239
+ [0.5, 0],
1240
+ [0.56, 1],
1241
+ [0.9, 1],
1242
+ [1, 0],
1243
+ ],
1244
+ rays: [
1245
+ [0, 0],
1246
+ [0.5, 0],
1247
+ [0.56, 1],
1248
+ [0.9, 1],
1249
+ [1, 0],
1250
+ ],
1251
+ holdGaze: [
1252
+ [0, 0],
1253
+ [0.1, 1],
1254
+ [0.9, 1],
1255
+ [1, 0],
1256
+ ],
1257
+ });
1258
+ /** Moment of the `tierUp` reaction at which the tier (the colour) swaps, from 0 to 1. */
1259
+ export const TIER_SWAP_T = 0.45;
1260
+ /* ---------- interactions (cursor and clicks) ---------- */
1261
+ /** Cursor arrived: widens the eyes toward it, stretches a little, parts standing up. */
1262
+ const peek = fromTracks({
1263
+ eyeSy: [
1264
+ [0, 0],
1265
+ [0.12, 0.16],
1266
+ [0.6, 0.12],
1267
+ [1, 0],
1268
+ ],
1269
+ eyeSx: [
1270
+ [0, 0],
1271
+ [0.12, 0.1],
1272
+ [0.6, 0.08],
1273
+ [1, 0],
1274
+ ],
1275
+ bodySy: [
1276
+ [0, 0],
1277
+ [0.1, -0.05],
1278
+ [0.24, 0.06],
1279
+ [0.4, -0.02],
1280
+ [0.55, 0],
1281
+ ],
1282
+ bodySx: [
1283
+ [0, 0],
1284
+ [0.1, 0.05],
1285
+ [0.24, -0.04],
1286
+ [0.4, 0.01],
1287
+ [0.55, 0],
1288
+ ],
1289
+ partL: [
1290
+ [0, 0],
1291
+ [0.15, 16],
1292
+ [0.7, 12],
1293
+ [1, 0],
1294
+ ],
1295
+ partR: [
1296
+ [0, 0],
1297
+ [0.15, -16],
1298
+ [0.7, -12],
1299
+ [1, 0],
1300
+ ],
1301
+ partC: [
1302
+ [0, 0],
1303
+ [0.12, 6],
1304
+ [0.3, -4],
1305
+ [0.5, 0],
1306
+ ],
1307
+ });
1308
+ /** Shy: shrinks, turns the face away, looks down smiling and peeks back. */
1309
+ const shy = fromTracks({
1310
+ scale: [
1311
+ [0, 0],
1312
+ [0.15, -0.07],
1313
+ [0.7, -0.06],
1314
+ [0.9, 0],
1315
+ ],
1316
+ bodyRotate: [
1317
+ [0, 0],
1318
+ [0.15, -7],
1319
+ [0.55, -6],
1320
+ [0.75, 2],
1321
+ [0.9, 0],
1322
+ ],
1323
+ turn: [
1324
+ [0, 0],
1325
+ [0.15, -0.55],
1326
+ [0.5, -0.55],
1327
+ [0.62, -0.15],
1328
+ [0.9, 0],
1329
+ ],
1330
+ eyeY: [
1331
+ [0, 0],
1332
+ [0.15, 16],
1333
+ [0.5, 16],
1334
+ [0.62, 4],
1335
+ [0.9, 0],
1336
+ ],
1337
+ lidBottom: [
1338
+ [0, 0],
1339
+ [0.15, 0.35],
1340
+ [0.75, 0.35],
1341
+ [0.95, 0],
1342
+ ],
1343
+ partL: [
1344
+ [0, 0],
1345
+ [0.15, -10],
1346
+ [0.7, -8],
1347
+ [0.9, 0],
1348
+ ],
1349
+ partR: [
1350
+ [0, 0],
1351
+ [0.15, 10],
1352
+ [0.7, 8],
1353
+ [0.9, 0],
1354
+ ],
1355
+ holdGaze: [
1356
+ [0, 0],
1357
+ [0.1, 1],
1358
+ [0.55, 1],
1359
+ [0.85, 0],
1360
+ ],
1361
+ });
1362
+ /** Two small hops, the second higher. */
1363
+ const doubleHop = fromTracks({
1364
+ rootY: [
1365
+ [0, 0],
1366
+ [0.08, 0, 'easeOut'],
1367
+ [0.2, -60, 'easeIn'],
1368
+ [0.34, 0],
1369
+ [0.4, 0, 'easeOut'],
1370
+ [0.56, -110, 'easeIn'],
1371
+ [0.74, 0],
1372
+ ],
1373
+ bodySy: [
1374
+ [0, 0],
1375
+ [0.06, -0.12],
1376
+ [0.14, 0.08],
1377
+ [0.34, -0.12],
1378
+ [0.42, 0.1],
1379
+ [0.74, -0.14],
1380
+ [0.84, 0.04],
1381
+ [0.95, 0],
1382
+ ],
1383
+ bodySx: [
1384
+ [0, 0],
1385
+ [0.06, 0.1],
1386
+ [0.14, -0.05],
1387
+ [0.34, 0.1],
1388
+ [0.42, -0.06],
1389
+ [0.74, 0.12],
1390
+ [0.84, -0.03],
1391
+ [0.95, 0],
1392
+ ],
1393
+ happy: [
1394
+ [0, 0],
1395
+ [0.4, 0],
1396
+ [0.48, 1],
1397
+ [0.85, 1],
1398
+ [1, 0],
1399
+ ],
1400
+ });
1401
+ /** Laugh: fast laughing shake, arc eyes, parts flapping. */
1402
+ function laugh(t) {
1403
+ const env = Math.sin(Math.min(1, t / 0.9) * Math.PI) ** 0.6;
1404
+ const k = Math.sin(t * 2 * Math.PI * 9);
1405
+ return {
1406
+ bodySy: 0.05 * k * env,
1407
+ bodySx: -0.035 * k * env,
1408
+ bodyRotate: 3 * Math.sin(t * 2 * Math.PI * 4.5) * env,
1409
+ rootY: -10 * Math.abs(k) * env,
1410
+ happy: Math.min(1, t * 10) * (t < 0.85 ? 1 : (1 - t) / 0.15),
1411
+ partL: 12 * k * env,
1412
+ partR: -12 * k * env,
1413
+ partC: 6 * k * env,
1414
+ holdGaze: 0.8 * env,
1415
+ };
1416
+ }
1417
+ /** Huff (three clicks): fills with air, angry face, and lets it all out shaking. */
1418
+ const huff = fromTracks({
1419
+ bodySx: [
1420
+ [0, 0],
1421
+ [0.3, 0.14, 'easeOut'],
1422
+ [0.55, 0.14],
1423
+ [0.62, -0.08],
1424
+ [0.7, 0.04],
1425
+ [0.8, -0.02],
1426
+ [0.9, 0],
1427
+ ],
1428
+ bodySy: [
1429
+ [0, 0],
1430
+ [0.3, 0.06, 'easeOut'],
1431
+ [0.55, 0.06],
1432
+ [0.62, -0.08],
1433
+ [0.7, 0.03],
1434
+ [0.85, 0],
1435
+ ],
1436
+ lidTop: [
1437
+ [0, 0],
1438
+ [0.15, 0.36],
1439
+ [0.75, 0.36],
1440
+ [0.95, 0],
1441
+ ],
1442
+ lidAngle: [
1443
+ [0, 0],
1444
+ [0.15, 26],
1445
+ [0.75, 26],
1446
+ [0.95, 0],
1447
+ ],
1448
+ partC: [
1449
+ [0, 0],
1450
+ [0.3, 10],
1451
+ [0.55, 10],
1452
+ [0.6, -16],
1453
+ [0.66, 12],
1454
+ [0.72, -8],
1455
+ [0.8, 4],
1456
+ [0.9, 0],
1457
+ ],
1458
+ partL: [
1459
+ [0, 0],
1460
+ [0.3, 18],
1461
+ [0.55, 18],
1462
+ [0.62, -8],
1463
+ [0.75, 0],
1464
+ ],
1465
+ partR: [
1466
+ [0, 0],
1467
+ [0.3, -18],
1468
+ [0.55, -18],
1469
+ [0.62, 8],
1470
+ [0.75, 0],
1471
+ ],
1472
+ exclaim: [
1473
+ [0, 0],
1474
+ [0.55, 0],
1475
+ [0.6, 1],
1476
+ [0.85, 1],
1477
+ [0.95, 0],
1478
+ ],
1479
+ holdGaze: [
1480
+ [0, 0],
1481
+ [0.1, 0.7],
1482
+ [0.85, 0.7],
1483
+ [1, 0],
1484
+ ],
1485
+ });
1486
+ /** Hide (eight clicks): flattens on the floor with eyes shut, peeks with one eye and gets up. */
1487
+ const hide = fromTracks({
1488
+ bodySy: [
1489
+ [0, 0],
1490
+ [0.12, -0.38, 'easeOut'],
1491
+ [0.62, -0.36],
1492
+ [0.78, 0.1],
1493
+ [0.88, -0.03],
1494
+ [1, 0],
1495
+ ],
1496
+ bodySx: [
1497
+ [0, 0],
1498
+ [0.12, 0.22, 'easeOut'],
1499
+ [0.62, 0.2],
1500
+ [0.78, -0.06],
1501
+ [0.88, 0.02],
1502
+ [1, 0],
1503
+ ],
1504
+ partL: [
1505
+ [0, 0],
1506
+ [0.12, -24],
1507
+ [0.62, -22],
1508
+ [0.8, 10],
1509
+ [1, 0],
1510
+ ],
1511
+ partR: [
1512
+ [0, 0],
1513
+ [0.12, 24],
1514
+ [0.62, 22],
1515
+ [0.8, -10],
1516
+ [1, 0],
1517
+ ],
1518
+ closeLeft: [
1519
+ [0, 0],
1520
+ [0.1, 1],
1521
+ [0.66, 1],
1522
+ [0.76, 0],
1523
+ ],
1524
+ closeRight: [
1525
+ [0, 0],
1526
+ [0.1, 1],
1527
+ [0.36, 1],
1528
+ [0.42, 0.15],
1529
+ [0.52, 0.15],
1530
+ [0.58, 1],
1531
+ [0.66, 1],
1532
+ [0.76, 0],
1533
+ ],
1534
+ eyeX: [
1535
+ [0.36, 0],
1536
+ [0.42, 26],
1537
+ [0.52, 26],
1538
+ [0.58, 0],
1539
+ ],
1540
+ eyeY: [
1541
+ [0, 0],
1542
+ [0.12, 18],
1543
+ [0.66, 18],
1544
+ [0.78, 0],
1545
+ ],
1546
+ lidTop: [
1547
+ [0.36, 0],
1548
+ [0.42, 0.25],
1549
+ [0.52, 0.25],
1550
+ [0.58, 0],
1551
+ ],
1552
+ partAmp: [
1553
+ [0, 0],
1554
+ [0.12, -0.9],
1555
+ [0.62, -0.9],
1556
+ [0.8, 0],
1557
+ ],
1558
+ holdGaze: [
1559
+ [0, 0],
1560
+ [0.1, 1],
1561
+ [0.8, 1],
1562
+ [1, 0],
1563
+ ],
1564
+ });
1565
+ /** Warm up (Flame, cursor over it): grows a little, core lights up, little embers, arc eyes. */
1566
+ const warmUp = fromTracks({
1567
+ scale: [
1568
+ [0, 0],
1569
+ [0.2, 0.1, 'easeOut'],
1570
+ [0.32, 0.04],
1571
+ [0.7, 0.06],
1572
+ [1, 0],
1573
+ ],
1574
+ bodySy: [
1575
+ [0, 0],
1576
+ [0.2, 0.08],
1577
+ [0.32, -0.02],
1578
+ [0.7, 0.03],
1579
+ [1, 0],
1580
+ ],
1581
+ core: [
1582
+ [0, 0],
1583
+ [0.2, 0.7],
1584
+ [0.75, 0.6],
1585
+ [1, 0],
1586
+ ],
1587
+ embers: [
1588
+ [0, 0],
1589
+ [0.2, 0.7],
1590
+ [0.75, 0.6],
1591
+ [1, 0],
1592
+ ],
1593
+ happy: [
1594
+ [0, 0],
1595
+ [0.18, 1],
1596
+ [0.8, 1],
1597
+ [1, 0],
1598
+ ],
1599
+ partC: [
1600
+ [0, 0],
1601
+ [0.2, -10],
1602
+ [0.35, 8],
1603
+ [0.5, -4],
1604
+ [0.65, 0],
1605
+ ],
1606
+ });
1607
+ /** Heat up (Flame, three clicks): boils with anger, grows, angry face, rays and "!". */
1608
+ function heatUp(t) {
1609
+ const env = track([
1610
+ [0, 0],
1611
+ [0.15, 1, 'easeOut'],
1612
+ [0.8, 1],
1613
+ [1, 0],
1614
+ ])(t);
1615
+ const boil = Math.sin(t * 2 * Math.PI * 7);
1616
+ return {
1617
+ scale: 0.16 * env,
1618
+ bodySy: (0.1 + 0.03 * boil) * env,
1619
+ bodySx: -0.03 * boil * env,
1620
+ lidTop: 0.36 * env,
1621
+ lidAngle: 28 * env,
1622
+ partC: 14 * boil * env,
1623
+ partL: -10 * boil * env,
1624
+ core: 0.8 * env,
1625
+ rays: env,
1626
+ exclaim: t > 0.2 && t < 0.85 ? 1 : 0,
1627
+ embers: env,
1628
+ holdGaze: 0.8 * env,
1629
+ };
1630
+ }
1631
+ /** Burst (Flame, eight clicks): swells, explodes into sparks, becomes a dizzy ember and relights. */
1632
+ const burst = fromTracks({
1633
+ scale: [
1634
+ [0, 0],
1635
+ [0.12, 0.3, 'easeIn'],
1636
+ [0.16, -0.5, 'easeOut'],
1637
+ [0.62, -0.5, 'easeOut'],
1638
+ [0.76, 0.14],
1639
+ [0.84, -0.04],
1640
+ [0.92, 0],
1641
+ ],
1642
+ bodySx: [
1643
+ [0, 0],
1644
+ [0.12, 0.12],
1645
+ [0.16, -0.1],
1646
+ [0.22, 0.06],
1647
+ [0.3, 0],
1648
+ ],
1649
+ gray: [
1650
+ [0, 0],
1651
+ [0.16, 0],
1652
+ [0.2, 0.7],
1653
+ [0.6, 0.7],
1654
+ [0.72, 0],
1655
+ ],
1656
+ smoke: [
1657
+ [0, 0],
1658
+ [0.18, 0],
1659
+ [0.22, 1],
1660
+ [0.55, 0.6],
1661
+ [0.7, 0],
1662
+ ],
1663
+ sparks: [
1664
+ [0, 0],
1665
+ [0.14, 0, 'linear'],
1666
+ [0.6, 1],
1667
+ [0.6001, 0],
1668
+ ],
1669
+ eyeSy: [
1670
+ [0, 0],
1671
+ [0.12, 0.2],
1672
+ [0.16, -0.7],
1673
+ [0.6, -0.7],
1674
+ [0.7, 0],
1675
+ ],
1676
+ eyeX: [
1677
+ [0.2, 0],
1678
+ [0.28, -12],
1679
+ [0.36, 12],
1680
+ [0.44, -12],
1681
+ [0.52, 12],
1682
+ [0.6, 0],
1683
+ ],
1684
+ rays: [
1685
+ [0, 0],
1686
+ [0.7, 0],
1687
+ [0.76, 1],
1688
+ [0.92, 1],
1689
+ [1, 0],
1690
+ ],
1691
+ happy: [
1692
+ [0, 0],
1693
+ [0.72, 0],
1694
+ [0.78, 1],
1695
+ [0.92, 1],
1696
+ [1, 0],
1697
+ ],
1698
+ embers: [
1699
+ [0, 0],
1700
+ [0.7, 0],
1701
+ [0.76, 1],
1702
+ [0.95, 0],
1703
+ ],
1704
+ holdGaze: [
1705
+ [0, 0],
1706
+ [0.1, 1],
1707
+ [0.9, 1],
1708
+ [1, 0],
1709
+ ],
1710
+ });
1711
+ export const REACTIONS = {
1712
+ success: { duration: 1.6, sample: success('lesson') },
1713
+ successExercise: { duration: 1.2, sample: success('exercise') },
1714
+ successModule: { duration: 2.4, sample: success('module') },
1715
+ almostThere: { duration: 1.6, sample: almostThere },
1716
+ fright: { duration: 0.9, sample: fright },
1717
+ idea: { duration: 1.6, sample: idea },
1718
+ copiedThat: { duration: 2.2, sample: copiedThat },
1719
+ welcome: { duration: 2.4, sample: welcome },
1720
+ dizzy: { duration: 1.6, sample: dizzy },
1721
+ wake: { duration: 0.6, sample: wake },
1722
+ wink: { duration: 1.2, sample: wink },
1723
+ cheerful: { duration: 2.4, sample: cheerful },
1724
+ profile: { duration: 2.8, sample: profile },
1725
+ flatten: { duration: 2.4, sample: flatten },
1726
+ confused: { duration: 2.0, sample: confused },
1727
+ somersault: { duration: 1.7, sample: somersault },
1728
+ morphLoading: TRANSFORMATIONS.morphLoading,
1729
+ morphCheck: TRANSFORMATIONS.morphCheck,
1730
+ morphCode: TRANSFORMATIONS.morphCode,
1731
+ energy: TRANSFORMATIONS.energy,
1732
+ ignite: { duration: 1.6, sample: ignite },
1733
+ extinguish: { duration: 1.8, sample: extinguish },
1734
+ blaze: { duration: 2.6, sample: blaze },
1735
+ gust: { duration: 2.4, sample: gust },
1736
+ crackle: { duration: 1.6, sample: crackle },
1737
+ sneeze: { duration: 2.0, sample: sneeze },
1738
+ tierUp: { duration: 2.4, sample: tierUp },
1739
+ peek: { duration: 1.0, sample: peek },
1740
+ shy: { duration: 1.8, sample: shy },
1741
+ doubleHop: { duration: 1.3, sample: doubleHop },
1742
+ laugh: { duration: 1.3, sample: laugh },
1743
+ huff: { duration: 1.8, sample: huff },
1744
+ hide: { duration: 3.2, sample: hide },
1745
+ warmUp: { duration: 1.8, sample: warmUp },
1746
+ heatUp: { duration: 1.8, sample: heatUp },
1747
+ burst: { duration: 3.4, sample: burst },
1748
+ };
1749
+ export const REACTION_NAMES = Object.keys(REACTIONS);
1750
+ /* ---------- activities (loops) ---------- */
1751
+ const THINK_LOOK_X = track([
1752
+ [0, 0],
1753
+ [0.15, -1],
1754
+ [0.45, -1],
1755
+ [0.58, 1],
1756
+ [0.85, 1],
1757
+ [1, 0],
1758
+ ]);
1759
+ const THINK_LOOK_Y = track([
1760
+ [0, 0],
1761
+ [0.15, -1],
1762
+ [0.85, -1],
1763
+ [1, 0],
1764
+ ]);
1765
+ function thinking(s) {
1766
+ // Looks up to the left, then to the right, and back; 3.6 s cycle.
1767
+ const u = (s % 3.6) / 3.6;
1768
+ const ox = THINK_LOOK_X(u);
1769
+ return {
1770
+ eyeX: ox * 22,
1771
+ eyeY: THINK_LOOK_Y(u) * 24,
1772
+ turn: ox * 0.25,
1773
+ lidTop: 0.15,
1774
+ lidAngle: -6 * ox,
1775
+ bodyRotate: -2 + Math.sin(s * 1.7) * 1.5,
1776
+ partC: 3 + Math.sin(s * 2.4) * 5,
1777
+ ellipsis: 1,
1778
+ holdGaze: 1,
1779
+ };
1780
+ }
1781
+ function loading(s) {
1782
+ const u = s % 1;
1783
+ const height = 4 * u * (1 - u); // parabola: 0 on the ground, 1 at the top
1784
+ const contact = clamp(1 - Math.min(u, 1 - u) / 0.12, 0, 1);
1785
+ return {
1786
+ rootY: -95 * height,
1787
+ bodySx: 0.08 * contact - 0.04 * height,
1788
+ bodySy: -0.1 * contact + 0.06 * height,
1789
+ eyeX: Math.sin(s * Math.PI) * 14,
1790
+ turn: Math.sin(s * Math.PI) * 0.2,
1791
+ partC: Math.sin(s * Math.PI * 2) * 7,
1792
+ partL: -height * 8,
1793
+ partR: height * 8,
1794
+ holdGaze: 1,
1795
+ };
1796
+ }
1797
+ function sleeping(s) {
1798
+ const r = Math.sin(s * 1.2);
1799
+ return {
1800
+ eyeSy: -0.9,
1801
+ lidTop: 0.3,
1802
+ eyeY: 10,
1803
+ bodySy: 0.03 * r,
1804
+ bodySx: -0.015 * r,
1805
+ partL: -12,
1806
+ partR: 12,
1807
+ partC: -8,
1808
+ rootY: 8,
1809
+ zzz: 1,
1810
+ holdGaze: 1,
1811
+ partAmp: -0.7,
1812
+ };
1813
+ }
1814
+ /** Flame at risk: flickers, loses colour in little jolts, worried look. */
1815
+ function flickering(s) {
1816
+ const tremor = Math.sin(s * 13) * Math.sin(s * 3.1);
1817
+ // Chokes: now and then it almost goes out.
1818
+ const choke = Math.max(0, Math.sin(s * 2.3)) ** 8;
1819
+ return {
1820
+ scale: -0.12 - 0.16 * choke,
1821
+ bodySy: -0.06 + 0.06 * tremor,
1822
+ bodySx: 0.03 - 0.03 * tremor,
1823
+ bodyRotate: 2.5 * Math.sin(s * 7.7),
1824
+ gray: 0.4 + 0.35 * choke,
1825
+ lidTop: 0.18,
1826
+ lidAngle: -14,
1827
+ eyeY: 6,
1828
+ eyeSy: -0.1 * choke,
1829
+ partC: 6 * Math.sin(s * 11) - 8 * choke,
1830
+ partL: 7 * Math.sin(s * 9 + 1),
1831
+ partR: -7 * Math.sin(s * 8 + 2),
1832
+ partAmp: 0.6,
1833
+ smoke: 0.4 * choke,
1834
+ };
1835
+ }
1836
+ /** Out: a small gray ember, sad eyes, a thread of smoke. */
1837
+ function out(s) {
1838
+ const r = Math.sin(s * 1.1);
1839
+ return {
1840
+ scale: -0.42,
1841
+ bodySy: -0.04 + 0.02 * r,
1842
+ gray: 1,
1843
+ lidTop: 0.5,
1844
+ lidAngle: -16,
1845
+ eyeY: 12,
1846
+ partC: -6,
1847
+ partL: -10,
1848
+ partR: 10,
1849
+ partAmp: -0.8,
1850
+ smoke: 0.35,
1851
+ holdGaze: 0.5,
1852
+ };
120
1853
  }
1854
+ export const ACTIVITIES = { thinking, loading, sleeping, flickering, out };
1855
+ export const ACTIVITY_NAMES = Object.keys(ACTIVITIES);