@kodax-ai/botui 0.1.1 → 0.1.3
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.
- package/README.md +140 -113
- package/core/identity.js +46 -0
- package/{themes/solids → core}/motion.js +114 -114
- package/core/registry.js +26 -18
- package/docs/usage.md +202 -0
- package/element.js +5 -0
- package/index.d.ts +2 -0
- package/index.js +11 -5
- package/package.json +38 -2
- package/themes/caret/README.md +43 -0
- package/themes/caret/avatar.js +10 -0
- package/themes/caret/engine.js +143 -0
- package/themes/caret/index.d.ts +24 -0
- package/themes/caret/index.js +35 -0
- package/themes/critter/README.md +43 -0
- package/themes/critter/avatar.js +12 -0
- package/themes/critter/engine.js +113 -0
- package/themes/critter/index.d.ts +28 -0
- package/themes/critter/index.js +35 -0
- package/themes/doodle/README.md +43 -0
- package/themes/doodle/avatar.js +10 -0
- package/themes/doodle/engine.js +149 -0
- package/themes/doodle/index.d.ts +24 -0
- package/themes/doodle/index.js +36 -0
- package/themes/dots/README.md +42 -0
- package/themes/dots/avatar.js +15 -0
- package/themes/dots/engine.js +179 -0
- package/themes/dots/index.d.ts +24 -0
- package/themes/dots/index.js +35 -0
- package/themes/kaomoji/README.md +42 -0
- package/themes/kaomoji/avatar.js +10 -0
- package/themes/kaomoji/engine.js +110 -0
- package/themes/kaomoji/index.d.ts +24 -0
- package/themes/kaomoji/index.js +35 -0
- package/themes/liquid/README.md +47 -0
- package/themes/liquid/avatar.js +10 -0
- package/themes/liquid/engine.js +161 -0
- package/themes/liquid/index.d.ts +24 -0
- package/themes/liquid/index.js +35 -0
- package/themes/matrix/README.md +48 -0
- package/themes/matrix/avatar.js +227 -0
- package/themes/matrix/engine.js +479 -0
- package/themes/matrix/index.d.ts +47 -0
- package/themes/matrix/index.js +34 -0
- package/themes/orb/README.md +44 -0
- package/themes/orb/avatar.js +10 -0
- package/themes/orb/engine.js +130 -0
- package/themes/orb/index.d.ts +24 -0
- package/themes/orb/index.js +36 -0
- package/themes/solids/README.md +2 -2
- package/themes/solids/avatar.js +561 -579
- package/themes/solids/face.js +52 -56
- package/themes/solids/index.js +34 -28
package/themes/solids/avatar.js
CHANGED
|
@@ -1,579 +1,561 @@
|
|
|
1
|
-
// The solids theme: a shaded 3D solid with eyes on its surface, drawn as SVG.
|
|
2
|
-
//
|
|
3
|
-
// One instance owns one <span> with one <svg>. Nothing here reads the wall
|
|
4
|
-
// clock: `step(dt)` advances an avatar by exactly dt seconds, so motion can be
|
|
5
|
-
// driven by hand for tests and film strips.
|
|
6
|
-
|
|
7
|
-
import {TAU, ease, clamp, smooth, bump, hash, random, pointer, world, join, leave, joined, prefersDark} from '../../core/core.js';
|
|
8
|
-
import {STATES, resolveState} from '../../core/states.js';
|
|
9
|
-
import {solid, SHAPES} from './geometry.js';
|
|
10
|
-
import {
|
|
11
|
-
import {REST, POSES, GESTURES, FIDGETS} from '
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* @param {
|
|
78
|
-
* @param {
|
|
79
|
-
* @param {
|
|
80
|
-
* @param {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
119
|
-
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
this.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
this.
|
|
143
|
-
this.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.
|
|
182
|
-
|
|
183
|
-
return this;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
this.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
host.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
this.press =
|
|
307
|
-
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
this.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (this.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
this.vel
|
|
349
|
-
this.
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
this.
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (this.
|
|
401
|
-
this.
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
this.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
this.
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this.
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
geo.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
})
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const def =
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
for (let i = 0; i < 4; i++) { const x = r1(50 + 1.42 * UNIT + i * 4.6), tall = 1.5 + 8 * Math.abs(Math.sin(t * 7 + i * 1.3) * Math.cos(t * 2.3 + i)); d += `M${x},${r1(cy - tall)}L${x},${r1(cy + tall)}`; }
|
|
563
|
-
this.barsNode.removeAttribute('display'); this.barsNode.setAttribute('d', d); this.barsNode.setAttribute('stroke', accent); this.barsNode.setAttribute('stroke-width', (2.6 * aura.bars).toFixed(2));
|
|
564
|
-
}
|
|
565
|
-
for (const q of this.particles) {
|
|
566
|
-
const u = q.age / q.life, x = r1(50 + q.x * UNIT), y = r1(CY + q.y * UNIT), node = q.node;
|
|
567
|
-
if (q.type === 'ring') {
|
|
568
|
-
node.removeAttribute('transform'); node.setAttribute('rx', r1(8 + 30 * u)); node.setAttribute('ry', r1((8 + 30 * u) * 0.22));
|
|
569
|
-
node.setAttribute('stroke', accent); node.setAttribute('stroke-width', (1.8 * (1 - u)).toFixed(2)); node.setAttribute('opacity', (1 - u).toFixed(2));
|
|
570
|
-
} else if (q.stroked) {
|
|
571
|
-
node.setAttribute('stroke', accent); node.setAttribute('opacity', bump(u).toFixed(2));
|
|
572
|
-
node.setAttribute('transform', `translate(${x} ${y}) rotate(${q.turn}) scale(${(q.size * (1 - q.grow * 0.4 + q.grow * u)).toFixed(2)})`);
|
|
573
|
-
} else {
|
|
574
|
-
node.setAttribute('fill', q.paint || (q.bright ? bright : accent));
|
|
575
|
-
node.setAttribute('transform', `translate(${x} ${y}) rotate(${r1(q.turn + q.spin * q.age)}) scale(${(q.size * Math.sqrt(bump(u))).toFixed(2)})`);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
1
|
+
// The solids theme: a shaded 3D solid with eyes on its surface, drawn as SVG.
|
|
2
|
+
//
|
|
3
|
+
// One instance owns one <span> with one <svg>. Nothing here reads the wall
|
|
4
|
+
// clock: `step(dt)` advances an avatar by exactly dt seconds, so motion can be
|
|
5
|
+
// driven by hand for tests and film strips.
|
|
6
|
+
|
|
7
|
+
import {TAU, ease, clamp, smooth, bump, hash, random, pointer, world, join, leave, joined, prefersDark} from '../../core/core.js';
|
|
8
|
+
import {STATES, resolveState} from '../../core/states.js';
|
|
9
|
+
import {solid, SHAPES} from './geometry.js';
|
|
10
|
+
import {EXPRESSIONS, eyeShape} from './face.js';
|
|
11
|
+
import {REST, POSES, GESTURES, FIDGETS} from '../../core/motion.js';
|
|
12
|
+
import {COLORS, HUES, EYE_STYLES, bornLook, pick, WATERMARK, WATERMARK_FROM, CREDIT} from '../../core/identity.js';
|
|
13
|
+
import {SYMBOLS} from './symbols.js';
|
|
14
|
+
|
|
15
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
16
|
+
const LIGHT = [-0.42, -0.82, 0.39];
|
|
17
|
+
const CY = 50, UNIT = 23, PERSPECTIVE = 0.07, GROUND = 90, RING = 42;
|
|
18
|
+
const STAR = 'M0,-1L.26,-.26L1,0L.26,.26L0,1L-.26,.26L-1,0L-.26,-.26Z';
|
|
19
|
+
const HEART = 'M0,1C-1.3,0 -1.1,-1 -.5,-1C-.2,-1 0,-.8 0,-.6C0,-.8 .2,-1 .5,-1C1.1,-1 1.3,0 0,1Z';
|
|
20
|
+
|
|
21
|
+
export {COLORS, BIRTH_COLORS, HUES, WATERMARK, WATERMARK_FROM, CREDIT} from '../../core/identity.js';
|
|
22
|
+
|
|
23
|
+
// Glyphs shown beside the head. `d` is stroked, `dot` is a filled circle [x, y, r].
|
|
24
|
+
const MARKS = {
|
|
25
|
+
ask: {d: 'M-4,-6Q-4,-11 0,-11Q4.5,-11 4.5,-6.5Q4.5,-3.5 0,-2L0,1', dot: [0, 6.5, 2]},
|
|
26
|
+
bang: {d: 'M0,-11L0,0', dot: [0, 6.5, 2.1]},
|
|
27
|
+
dots: {d: 'M-7,0L-7,0M0,0L0,0M7,0L7,0', wide: true},
|
|
28
|
+
check: {d: 'M-7,0L-2,5L7,-6'},
|
|
29
|
+
up: {d: 'M0,8L0,-9M-6,-3L0,-9L6,-3'},
|
|
30
|
+
code: {d: 'M-4,-6L-10,0L-4,6M4,-6L10,0L4,6'},
|
|
31
|
+
search: {d: 'M-8,-2a6,6 0 1,0 12,0a6,6 0 1,0 -12,0M3,3L9,9'},
|
|
32
|
+
cursor: {d: 'M-5,-9L-5,7L-1,3L2,9L5,7.5L2,2L7,2Z', fill: true},
|
|
33
|
+
pen: {d: 'M-7,8L-6,3L4,-8L8,-4L-2,7ZM-9,10L8,10'},
|
|
34
|
+
anger: {d: 'M-6,-2Q-2,-2 -2,-6M6,-2Q2,-2 2,-6M-6,2Q-2,2 -2,6M6,2Q2,2 2,6', paint: 'oklch(0.62 0.22 25)'},
|
|
35
|
+
sweat: {d: 'M0,-8Q6,2 0,6Q-6,2 0,-8Z', paint: 'oklch(0.78 0.1 230)'},
|
|
36
|
+
badge: {d: '', dot: [0, 0, 5.5], paint: 'oklch(0.64 0.22 25)'},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const known = name => SHAPES.some(s => s.name === name);
|
|
40
|
+
const r1 = v => Math.round(v * 10) / 10;
|
|
41
|
+
function el(name, attrs, parent) {
|
|
42
|
+
const node = document.createElementNS(NS, name);
|
|
43
|
+
for (const key in attrs) node.setAttribute(key, attrs[key]);
|
|
44
|
+
if (parent) parent.append(node);
|
|
45
|
+
return node;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The look a Bot ID maps to: one solid, one colour, one eye style. `pool` can
|
|
50
|
+
* limit the choice: {shapes, colors, eyes}, each a list of names.
|
|
51
|
+
*/
|
|
52
|
+
export function identityFrom(identity, pool) {
|
|
53
|
+
const shapes = pick(pool?.shapes, known, SHAPES.map(s => s.name));
|
|
54
|
+
return {shape: shapes[hash(identity) % shapes.length], ...bornLook(identity, pool)};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class SolidAvatar {
|
|
58
|
+
/**
|
|
59
|
+
* @param {object} options
|
|
60
|
+
* @param {string} [options.identity] Bot ID. Picks shape, colour and eyes unless given.
|
|
61
|
+
* @param {{shapes?: string[], colors?: string[], eyes?: string[]}} [options.pool] Limits what an identity can be born as.
|
|
62
|
+
* @param {number} [options.size=36] Width and height in CSS pixels.
|
|
63
|
+
* @param {string} [options.shape] A name from SHAPES.
|
|
64
|
+
* @param {string} [options.color] A name from COLORS.
|
|
65
|
+
* @param {number} [options.hue] An OKLCH hue, 0..360, instead of a named colour.
|
|
66
|
+
* @param {string} [options.eyes] A name from EYE_STYLES.
|
|
67
|
+
* @param {string} [options.eyeColor] Any CSS colour for the eyes.
|
|
68
|
+
* @param {string} [options.state='idle'] A name from STATES.
|
|
69
|
+
* @param {number} [options.progress] 0..1, shown by the `progress` state. Without it the ring loops.
|
|
70
|
+
* @param {'light'|'dark'|'auto'} [options.scheme='light'] The background it sits on; 'auto' follows the system.
|
|
71
|
+
* @param {'around'|'morph'} [options.signals='around'] How signal states show: effects around the body, or the body turning into a symbol.
|
|
72
|
+
* @param {boolean} [options.emphasized=false] Mark this one as the active Bot: slightly larger, with a halo on the ground.
|
|
73
|
+
* @param {boolean} [options.interactive=true] React to hover, press, click and drag.
|
|
74
|
+
* @param {boolean} [options.track=true] Follow the pointer with head and eyes.
|
|
75
|
+
* @param {boolean} [options.static=false] Show only the resting pose. Reduced-motion users always get this.
|
|
76
|
+
* @param {boolean} [options.playing=true] False pauses the animation.
|
|
77
|
+
* @param {number} [options.maxFrameRate=60]
|
|
78
|
+
* @param {boolean} [options.autoplay=true] Animate on the shared frame loop. With false, call step() yourself.
|
|
79
|
+
* @param {string} [options.label] Accessible name. Without it the avatar is decorative.
|
|
80
|
+
* @param {boolean} [options.watermark=true] Show the KodaX-AI mark (drawn from 48 px up). The licence allows turning it off only for Community Use or under a Customer Agreement; see LICENSE.
|
|
81
|
+
*/
|
|
82
|
+
constructor(options = {}) {
|
|
83
|
+
this.identity = options.identity ?? 'bot';
|
|
84
|
+
this.pool = options.pool ?? null;
|
|
85
|
+
const born = identityFrom(this.identity, this.pool);
|
|
86
|
+
this.size = options.size ?? 36; this.shape = known(options.shape) ? options.shape : born.shape;
|
|
87
|
+
this.eyes = EYE_STYLES[options.eyes] ? options.eyes : born.eyes; this.eyeColor = options.eyeColor ?? null;
|
|
88
|
+
this.scheme = options.scheme ?? 'light'; this.signals = options.signals ?? 'around'; this.emphasized = !!options.emphasized;
|
|
89
|
+
this.paint(options.color, options.hue, born.color);
|
|
90
|
+
this.state = resolveState(options.state) || 'idle'; this.progress = options.progress ?? null;
|
|
91
|
+
this.watermark = options.watermark ?? true;
|
|
92
|
+
this.track = options.track ?? true; this.static = !!options.static; this.playing = options.playing ?? true; this.maxFrameRate = options.maxFrameRate ?? 60;
|
|
93
|
+
this.visible = true; this.settled = false;
|
|
94
|
+
this.rng = random(hash(this.identity)); this.t = this.rng() * 10; this.since = 0; this.dt = 0; this.beat = 0;
|
|
95
|
+
this.p = {yaw: 0.3, pitch: -0.26, roll: 0, sy: 1, lift: 0, scale: 1, sat: 1, open: 1, blush: 0};
|
|
96
|
+
this.vel = {sy: 0, lift: 0, scale: 0, roll: 0};
|
|
97
|
+
this.omega = 0; this.spun = 0; this.dizzy = 0; this.tug = 0; this.phase = 0;
|
|
98
|
+
this.aim = {x: 0, y: 0}; this.gazeAt = {x: 0, y: 0}; this.focus = null; this.fixed = null; this.stray = {x: 0, y: 0}; this.strayIn = 0;
|
|
99
|
+
this.shown = 'neutral'; this.override = null;
|
|
100
|
+
this.blinkIn = 1 + this.rng() * 3; this.blinkFor = 0; this.fidgetIn = 4 + this.rng() * 6;
|
|
101
|
+
this.gestures = []; this.particles = []; this.swap = null;
|
|
102
|
+
this.aura = {orbit: 0, mark: 0, stars: 0, ring: 0, bars: 0, morph: 0, emph: 0}; this.markName = 'ask'; this.ringKind = 'spin';
|
|
103
|
+
this.hover = false; this.press = false; this.dragging = false; this.rectAge = 99; this.center = {x: 0, y: 0};
|
|
104
|
+
|
|
105
|
+
this.el = document.createElement('span');
|
|
106
|
+
this.el.className = 'botui-avatar botui-solid'; this.el.botAvatar = this; this.el.dataset.state = this.state;
|
|
107
|
+
this.el.style.cssText = 'display:inline-block;line-height:0;vertical-align:middle;user-select:none;-webkit-user-select:none';
|
|
108
|
+
this.name(options.label);
|
|
109
|
+
this.svg = el('svg', {viewBox: '0 0 100 100', width: this.size, height: this.size, overflow: 'visible'}, this.el);
|
|
110
|
+
el('metadata', {}, this.svg).textContent = CREDIT;
|
|
111
|
+
this.shadow = el('ellipse', {cx: 50, cy: GROUND, ry: 3.6}, this.svg);
|
|
112
|
+
this.back = el('g', {}, this.svg);
|
|
113
|
+
this.haloNode = el('ellipse', {cx: 50, cy: GROUND, fill: 'none', display: 'none'}, this.back);
|
|
114
|
+
this.ringNode = el('circle', {cx: 50, r: RING, fill: 'none', 'stroke-linecap': 'round', display: 'none'}, this.back);
|
|
115
|
+
this.body = el('g', {'stroke-linejoin': 'round', 'stroke-width': 2.4}, this.svg);
|
|
116
|
+
this.blushNodes = [-1, 1].map(() => el('path', {fill: 'none', 'stroke-linecap': 'round', stroke: 'oklch(0.74 0.17 15)', display: 'none'}, this.svg));
|
|
117
|
+
this.eyeNodes = [-1, 1].map(() => el('path', {'stroke-linecap': 'round', 'stroke-linejoin': 'round'}, this.svg));
|
|
118
|
+
this.symbolNode = el('g', {display: 'none'}, this.svg);
|
|
119
|
+
el('path', {fill: 'none', 'stroke-linecap': 'round', 'stroke-linejoin': 'round'}, this.symbolNode);
|
|
120
|
+
this.front = el('g', {}, this.svg);
|
|
121
|
+
this.barsNode = el('path', {fill: 'none', 'stroke-linecap': 'round', display: 'none'}, this.front);
|
|
122
|
+
this.markNode = el('text', {x: 99, y: 98, 'text-anchor': 'end', 'font-family': "system-ui, 'Segoe UI', sans-serif", 'font-weight': 600, fill: '#8b8b8b', 'fill-opacity': 0.75, 'pointer-events': 'none', display: 'none'}, this.svg);
|
|
123
|
+
this.markNode.textContent = WATERMARK;
|
|
124
|
+
this.facePaths = []; this.used = 0;
|
|
125
|
+
this.build();
|
|
126
|
+
if (options.interactive ?? true) this.listen();
|
|
127
|
+
this.settle();
|
|
128
|
+
this.auto = options.autoplay ?? true;
|
|
129
|
+
if (this.auto) join(this);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ---- public API ----
|
|
133
|
+
/** Change any of: label, size, shape, color, hue, eyes, eyeColor, scheme, signals, emphasized, state, progress, track, static, playing, maxFrameRate, identity. */
|
|
134
|
+
update(options) {
|
|
135
|
+
let born = null;
|
|
136
|
+
if (options.identity !== undefined && options.identity !== this.identity) { this.identity = options.identity; born = identityFrom(this.identity, this.pool); this.eyes = born.eyes; this.paint(born.color); }
|
|
137
|
+
if (options.color !== undefined || options.hue !== undefined) this.paint(options.color, options.hue, this.color);
|
|
138
|
+
if (options.eyes !== undefined && EYE_STYLES[options.eyes]) this.eyes = options.eyes;
|
|
139
|
+
for (const key of ['eyeColor', 'track', 'progress', 'playing', 'maxFrameRate', 'signals', 'emphasized', 'watermark']) if (options[key] !== undefined) { this[key] = options[key]; this.settled = false; }
|
|
140
|
+
if (options.scheme !== undefined) { this.scheme = options.scheme; this.retone(); }
|
|
141
|
+
if (options.label !== undefined) this.name(options.label);
|
|
142
|
+
if (options.static !== undefined) { this.static = !!options.static; this.settled = false; }
|
|
143
|
+
if (options.size !== undefined) { this.size = Number(options.size); this.svg.setAttribute('width', this.size); this.svg.setAttribute('height', this.size); }
|
|
144
|
+
const shape = known(options.shape) ? options.shape : born?.shape;
|
|
145
|
+
// A new shape arrives with a quick turn: it shrinks, swaps and pops back.
|
|
146
|
+
if (shape && shape !== (this.swap?.to || this.shape)) { if (joined(this) && !this.static) this.swap = {to: shape, age: 0}; else this.shape = shape; }
|
|
147
|
+
this.build();
|
|
148
|
+
if (options.state !== undefined) this.setState(options.state);
|
|
149
|
+
if (!joined(this)) this.render();
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
setState(name) {
|
|
153
|
+
const state = resolveState(name);
|
|
154
|
+
if (!state || state === this.state) return this;
|
|
155
|
+
this.state = state; this.since = 0; this.el.dataset.state = state; this.vel.scale += 1.2; this.settled = false;
|
|
156
|
+
if (!this.morphing) POSES[state]?.enter?.(this);
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
/** Play a one-shot gesture from GESTURES. */
|
|
160
|
+
play(name) {
|
|
161
|
+
const def = GESTURES[name];
|
|
162
|
+
if (!def) return this;
|
|
163
|
+
this.gestures = this.gestures.filter(g => g.def !== def);
|
|
164
|
+
this.gestures.push({def, age: 0}); def.start?.(this);
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
/** Show an expression from EXPRESSIONS for `ms` milliseconds, over whatever the state shows. */
|
|
168
|
+
express(name, ms = 1500) { this.override = name && EXPRESSIONS[name] ? {name, left: ms / 1000} : null; return this; }
|
|
169
|
+
/** Watch a client-space point; lookAt(null) hands control back to the pointer. */
|
|
170
|
+
lookAt(x, y) { this.focus = x == null ? null : {x, y}; return this; }
|
|
171
|
+
/** Hold a direction, each axis -1..1; look(null) releases it. */
|
|
172
|
+
look(direction) { this.fixed = direction ? {x: clamp(direction.x ?? 0, -1, 1), y: clamp(direction.y ?? 0, -1, 1)} : null; return this; }
|
|
173
|
+
blink() { this.blinkFor = 0.13; return this; }
|
|
174
|
+
/** A small acknowledging bob, e.g. on each keystroke. */
|
|
175
|
+
nudge() { this.vel.sy -= 1.4; return this; }
|
|
176
|
+
/**
|
|
177
|
+
* React to a touch. `poke('spin', {turns})`, `poke('bounce')`, `poke('nod')` or
|
|
178
|
+
* any gesture name; with no action it picks a reaction itself.
|
|
179
|
+
*/
|
|
180
|
+
poke(action, {turns = 1} = {}) {
|
|
181
|
+
this.pulse();
|
|
182
|
+
if (action === 'spin') { this.omega += 3 * TAU * turns; this.hop(170); return this; }
|
|
183
|
+
if (action) return this.play(action);
|
|
184
|
+
if (this.state === 'blocked' || this.state === 'sleeping' || this.state === 'powering-down') { this.hop(40); return this; }
|
|
185
|
+
const r = this.rng();
|
|
186
|
+
if (r < 0.4) { this.omega += r < 0.2 ? 19 : -19; this.hop(170); this.express('happy', 800); }
|
|
187
|
+
else this.play(r < 0.6 ? 'jump' : r < 0.75 ? 'wobble' : r < 0.9 ? 'flip' : 'roll');
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
/** Advance by dt seconds and redraw. Long steps are simulated in slices so the springs stay stable at any frame rate. */
|
|
191
|
+
step(dt) {
|
|
192
|
+
const slices = Math.max(1, Math.ceil(dt / 0.017 - 1e-6));
|
|
193
|
+
for (let i = 1; i <= slices; i++) this.advance(dt / slices, i === slices);
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
/** Start the current state again from its resting pose. */
|
|
197
|
+
restart() { this.since = 0; this.settle(); this.settled = false; return this; }
|
|
198
|
+
/** Leave the frame loop, e.g. while detached from the page; resume() joins it again. */
|
|
199
|
+
suspend() { leave(this); return this; }
|
|
200
|
+
resume() { if (this.auto) join(this); return this; }
|
|
201
|
+
/** The current frame as standalone SVG markup, for a favicon, an export or server-rendered HTML. */
|
|
202
|
+
toSVG() {
|
|
203
|
+
const copy = this.svg.cloneNode(true);
|
|
204
|
+
copy.setAttribute('xmlns', NS);
|
|
205
|
+
for (const node of copy.querySelectorAll('[display="none"]')) node.remove();
|
|
206
|
+
return copy.outerHTML;
|
|
207
|
+
}
|
|
208
|
+
dispose() { leave(this); this.el.botAvatar = null; this.el.remove(); }
|
|
209
|
+
// Names used by RSIBot's existing component.
|
|
210
|
+
gaze(point) { return point ? this.lookAt(point.x, point.y) : this.lookAt(null); }
|
|
211
|
+
setExpression(name, {duration = 1200} = {}) { return this.express(name, duration); }
|
|
212
|
+
|
|
213
|
+
// ---- building blocks used by states and gestures ----
|
|
214
|
+
hop(strength) { this.vel.lift -= strength; }
|
|
215
|
+
squash(strength) { this.vel.sy -= strength; }
|
|
216
|
+
every(period) { return Math.floor(this.since / period) !== Math.floor((this.since - this.dt) / period); }
|
|
217
|
+
pulse() { this.spawn({type: 'ring', life: 0.6, node: el('ellipse', {cx: 50, cy: GROUND, fill: 'none'}, this.back)}); }
|
|
218
|
+
emit(type) {
|
|
219
|
+
const rng = this.rng, dot = () => el('circle', {r: 1}, this.front), line = d => el('path', {d, fill: 'none', 'stroke-width': 0.62, 'stroke-linecap': 'round', 'stroke-linejoin': 'round'}, this.front);
|
|
220
|
+
if (type === 'z') this.spawn({life: 2.2, x: 0.9, y: -1.0, vx: 0.32, vy: -0.42, size: 2.2, turn: -12, grow: 1, stroked: true, node: line('M-1,-1H1L-1,1H1')});
|
|
221
|
+
else if (type === 'note') this.spawn({life: 1.8, x: 0.7 + rng() * 0.5, y: -0.9, vx: 0.3 * (rng() - 0.3), vy: -0.6, size: 4.6, turn: rng() * 24 - 12, grow: 0.3, stroked: true, node: line('M-.8,1.4L-.8,-1.6L1.2,-1.1L1.2,.9M-1.3,1.5L-.8,1.4M.7,1L1.2,.9')});
|
|
222
|
+
else if (type === 'heart') this.spawn({life: 1.4, x: (rng() - 0.5) * 1.6, y: -0.9, vx: (rng() - 0.5) * 0.5, vy: -0.9, size: 2.6 + rng() * 1.6, paint: 'oklch(0.7 0.19 10)', node: el('path', {d: HEART}, this.front)});
|
|
223
|
+
else if (type === 'tear') this.spawn({life: 0.9, x: (rng() < 0.5 ? -0.42 : 0.42), y: 0.25, vy: 0.3, g: 5, size: 1.5, paint: 'oklch(0.8 0.1 230)', node: dot()});
|
|
224
|
+
else if (type === 'dust') this.spawn({life: 0.5, x: -0.5 - rng() * 0.3, y: 1.7, vx: -1.6 - rng(), vy: -0.5, size: 3 + rng() * 1.6, paint: 'oklch(0.8 0.01 260)', node: dot()});
|
|
225
|
+
else if (type === 'out') this.spawn({life: 0.7, x: (rng() - 0.5) * 0.6, y: -0.7, vx: 1.6 + rng() * 1.2, vy: -2 - rng() * 1.4, size: 2.4 + rng() * 1.2, node: dot()});
|
|
226
|
+
else if (type === 'up') this.spawn({life: 0.9, x: (rng() - 0.5) * 2.2, y: 0.8, vy: -2.4, size: 2.2 + rng() * 1.2, node: dot()});
|
|
227
|
+
else if (type === 'in') { const a = rng() * TAU, life = 0.6; this.spawn({life, x: 2.3 * Math.cos(a), y: 2.3 * Math.sin(a), vx: -2.3 * Math.cos(a) / life, vy: -2.3 * Math.sin(a) / life, size: 3.2 + rng() * 1.6, node: dot()}); }
|
|
228
|
+
}
|
|
229
|
+
burst(type, count) {
|
|
230
|
+
const rng = this.rng;
|
|
231
|
+
for (let i = 0; i < count; i++) {
|
|
232
|
+
const a = (i + rng()) / count * TAU;
|
|
233
|
+
if (type === 'spark') this.spawn({life: 0.55 + rng() * 0.4, x: Math.cos(a), y: Math.sin(a) * 0.9 - 0.1, vx: Math.cos(a) * (1.3 + rng()), vy: Math.sin(a) * (1.3 + rng()), drag: 2, size: 4 + rng() * 4, turn: rng() * 90, spin: 90, bright: true, node: el('path', {d: STAR}, this.front)});
|
|
234
|
+
else this.spawn({life: 1 + rng() * 0.5, x: (rng() - 0.5) * 0.8, y: -0.9, vx: (rng() - 0.5) * 4.6, vy: -2.4 - rng() * 2.4, g: 9, size: 2.4 + rng() * 1.6, turn: rng() * 360, spin: 520, paint: `oklch(0.78 0.17 ${HUES[Math.floor(rng() * HUES.length)]})`, node: el('rect', {x: -1, y: -0.6, width: 2, height: 1.2, rx: 0.3}, this.front)});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
spawn(particle) {
|
|
238
|
+
if (this.particles.length >= 40) { particle.node.remove(); return; }
|
|
239
|
+
particle.node.setAttribute('transform', 'scale(0)');
|
|
240
|
+
this.particles.push({age: 0, x: 0, y: 0, vx: 0, vy: 0, size: 1, turn: 0, spin: 0, ...particle});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ---- internals ----
|
|
244
|
+
name(label) {
|
|
245
|
+
if (label) { this.el.setAttribute('role', 'img'); this.el.setAttribute('aria-label', label); this.el.removeAttribute('aria-hidden'); }
|
|
246
|
+
else { this.el.removeAttribute('role'); this.el.removeAttribute('aria-label'); this.el.setAttribute('aria-hidden', 'true'); }
|
|
247
|
+
}
|
|
248
|
+
paint(color, hue, fallback) {
|
|
249
|
+
const given = hue != null && hue !== '' && Number.isFinite(Number(hue)), named = COLORS[color] ? color : given ? null : fallback;
|
|
250
|
+
if (!named && !given) return; // neither a known colour nor a usable hue: keep what it has
|
|
251
|
+
this.color = named ?? null;
|
|
252
|
+
this.spec = named ? COLORS[named] : {hue: Number(hue)};
|
|
253
|
+
this.retone();
|
|
254
|
+
}
|
|
255
|
+
retone() {
|
|
256
|
+
const spec = this.spec;
|
|
257
|
+
this.dark = this.scheme === 'dark' || (this.scheme === 'auto' && prefersDark());
|
|
258
|
+
this.tone = {chroma: 0.15, base: 0.6, span: 0.26, eye: null, ...spec, ...(this.dark ? spec.dark ?? {base: (spec.base ?? 0.6) + 0.05} : null)};
|
|
259
|
+
this.hue = this.tone.hue; this.settled = false;
|
|
260
|
+
}
|
|
261
|
+
get morphing() { return this.signals === 'morph' && !!SYMBOLS[this.state]; }
|
|
262
|
+
build() {
|
|
263
|
+
// The mark keeps a readable pixel size, so it takes more of a small avatar; below 48 px it would not be legible at all.
|
|
264
|
+
const marked = this.watermark !== false && this.size >= WATERMARK_FROM;
|
|
265
|
+
if (marked) { this.markNode.setAttribute('font-size', (clamp(this.size * 0.075, 5.5, 10) * 100 / this.size).toFixed(2)); this.markNode.removeAttribute('display'); }
|
|
266
|
+
else this.markNode.setAttribute('display', 'none');
|
|
267
|
+
const geo = solid(this.shape, this.size <= 40 ? 12 : this.size <= 110 ? 18 : 28);
|
|
268
|
+
if (geo !== this.geo) {
|
|
269
|
+
this.geo = geo; this.points = new Float32Array(geo.verts.length * 3);
|
|
270
|
+
while (this.facePaths.length < geo.faces.length) this.facePaths.push(el('path', {display: 'none'}, this.body));
|
|
271
|
+
for (let i = geo.faces.length; i < this.facePaths.length; i++) this.facePaths[i].setAttribute('display', 'none');
|
|
272
|
+
this.used = Math.min(this.used, geo.faces.length);
|
|
273
|
+
}
|
|
274
|
+
this.el.dataset.shape = this.shape;
|
|
275
|
+
// How far it may turn before the far eye slips round the side. Narrow and
|
|
276
|
+
// strongly curved solids get less.
|
|
277
|
+
const gap = EYE_STYLES[this.eyes].gap * geo.k, n = geo.nrm(gap, 0.02 * geo.k);
|
|
278
|
+
this.turnLimit = clamp(1.2 - Math.atan2(Math.abs(n[0]), -n[2]), 0.3, 1.2);
|
|
279
|
+
this.shadow.setAttribute('fill', this.dark ? 'oklch(0 0 0)' : `oklch(0.25 0.06 ${this.hue})`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
listen() {
|
|
283
|
+
const host = this.el;
|
|
284
|
+
host.style.cursor = 'grab'; host.style.touchAction = 'pan-y';
|
|
285
|
+
host.addEventListener('pointerenter', () => { this.hover = true; });
|
|
286
|
+
host.addEventListener('pointerleave', () => { this.hover = false; });
|
|
287
|
+
host.addEventListener('pointerdown', e => {
|
|
288
|
+
this.press = true; this.dragging = false; this.drag = {x: e.clientX, y: e.clientY, travel: 0, at: performance.now(), speed: 0};
|
|
289
|
+
host.setPointerCapture?.(e.pointerId);
|
|
290
|
+
});
|
|
291
|
+
host.addEventListener('pointermove', e => {
|
|
292
|
+
if (!this.press) return;
|
|
293
|
+
const d = this.drag, dx = e.clientX - d.x, dy = e.clientY - d.y, now = performance.now(), dt = Math.max(0.004, (now - d.at) / 1000);
|
|
294
|
+
d.x = e.clientX; d.y = e.clientY; d.at = now; d.travel += Math.abs(dx) + Math.abs(dy);
|
|
295
|
+
if (d.travel < 5) return;
|
|
296
|
+
// Dragging across the avatar's own width turns it half a revolution.
|
|
297
|
+
this.dragging = true; host.style.cursor = 'grabbing';
|
|
298
|
+
const turn = dx / this.size * Math.PI;
|
|
299
|
+
this.p.yaw += turn; this.spun += Math.abs(turn); d.speed = d.speed * 0.5 + turn / dt * 0.5;
|
|
300
|
+
this.tug = clamp(this.tug - dy / this.size * 1.4, -0.7, 0.7);
|
|
301
|
+
});
|
|
302
|
+
host.addEventListener('pointerup', () => {
|
|
303
|
+
if (!this.press) return;
|
|
304
|
+
if (this.dragging) this.omega = clamp(this.drag.speed, -34, 34);
|
|
305
|
+
else { this.poke(); host.dispatchEvent(new CustomEvent('bot-poke', {bubbles: true, detail: {avatar: this}})); }
|
|
306
|
+
this.press = false; this.dragging = false; host.style.cursor = 'grab';
|
|
307
|
+
});
|
|
308
|
+
host.addEventListener('pointercancel', () => { this.press = false; this.dragging = false; host.style.cursor = 'grab'; });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Where to look, as a vector that saturates with distance.
|
|
312
|
+
attend(dt) {
|
|
313
|
+
let x = 0, y = 0;
|
|
314
|
+
const target = this.focus || world.attention || (this.track && performance.now() - pointer.at < 6000 ? pointer : null);
|
|
315
|
+
if (this.fixed) { x = this.fixed.x; y = this.fixed.y; }
|
|
316
|
+
else if (target) {
|
|
317
|
+
if ((this.rectAge += dt) > 0.4) { const r = this.el.getBoundingClientRect(); this.center = {x: r.left + r.width / 2, y: r.top + r.height / 2}; this.rectAge = 0; }
|
|
318
|
+
const dx = target.x - this.center.x, dy = target.y - this.center.y, d = Math.hypot(dx, dy) + 60 + this.size;
|
|
319
|
+
x = dx / d; y = dy / d;
|
|
320
|
+
} else {
|
|
321
|
+
// Nobody to look at: glance around, and come back to the viewer now and then.
|
|
322
|
+
if ((this.strayIn -= dt) < 0) { this.strayIn = 1.2 + this.rng() * 2.6; this.stray = this.rng() < 0.35 ? {x: 0, y: 0} : {x: (this.rng() - 0.5) * 0.7, y: (this.rng() - 0.5) * 0.35}; }
|
|
323
|
+
x = this.stray.x; y = this.stray.y;
|
|
324
|
+
}
|
|
325
|
+
this.aim.x = ease(this.aim.x, x, dt, 7); this.aim.y = ease(this.aim.y, y, dt, 7);
|
|
326
|
+
return this.aim;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
spring(key, target, stiff, damp, dt) {
|
|
330
|
+
this.vel[key] += (stiff * (target - this.p[key]) - damp * this.vel[key]) * dt;
|
|
331
|
+
this.p[key] += this.vel[key] * dt;
|
|
332
|
+
}
|
|
333
|
+
wanted(look) {
|
|
334
|
+
// As a symbol the body only floats; the symbol does the talking.
|
|
335
|
+
const want = this.morphing ? {...REST, lift: 1.5 * Math.sin(this.t * 2), still: true} : {...REST, ...(POSES[this.state] || POSES.idle).pose(this, this.t, look)};
|
|
336
|
+
if (this.emphasized) want.scale *= 1.1;
|
|
337
|
+
// Turns short of a profile are eased back so both eyes stay in view; real turn-arounds pass through.
|
|
338
|
+
const limit = this.turnLimit, knee = 0.6 * limit, turn = Math.abs(want.yaw);
|
|
339
|
+
if (turn > knee && turn < 1.6) want.yaw = Math.sign(want.yaw) * (knee + (limit - knee) * Math.tanh((turn - knee) / (limit - knee)));
|
|
340
|
+
return want;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Jump straight to the resting pose of the current state and draw it. */
|
|
344
|
+
settle() {
|
|
345
|
+
const p = this.p; this.dt = 0;
|
|
346
|
+
const want = this.wanted({x: 0, y: 0});
|
|
347
|
+
Object.assign(p, {yaw: want.yaw, pitch: want.pitch, roll: want.roll, sy: want.sy, lift: want.lift, scale: want.scale, sat: want.sat, blush: want.blush, open: 1});
|
|
348
|
+
this.vel = {sy: 0, lift: 0, scale: 0, roll: 0}; this.omega = 0; this.dizzy = 0; this.tug = 0; this.gestures = []; this.swap = null;
|
|
349
|
+
this.gazeAt = {x: want.gx, y: want.gy}; this.shown = want.expr;
|
|
350
|
+
if (want.mark) this.markName = want.mark; if (want.ring) this.ringKind = want.ring;
|
|
351
|
+
this.aura = {orbit: +(want.orbit > 0), mark: +!!want.mark, stars: 0, ring: +!!want.ring, bars: +want.bars, morph: +this.morphing, emph: +this.emphasized};
|
|
352
|
+
for (const q of this.particles) q.node.remove();
|
|
353
|
+
this.particles = [];
|
|
354
|
+
this.render(); this.settled = true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
advance(dt, draw = true) {
|
|
358
|
+
const p = this.p; this.dt = dt; this.t += dt; this.since += dt; this.settled = false;
|
|
359
|
+
const want = this.wanted(this.attend(dt));
|
|
360
|
+
|
|
361
|
+
if (this.state === 'idle' && !this.hover && !this.press && (this.fidgetIn -= dt) < 0) { this.fidgetIn = 5 + this.rng() * 7; this.play(FIDGETS[Math.floor(this.rng() * FIDGETS.length)]); }
|
|
362
|
+
if (this.hover) want.scale *= 1.08;
|
|
363
|
+
if (this.press && !this.dragging) { want.sy = Math.min(want.sy, 0.55); want.lift += 10; }
|
|
364
|
+
|
|
365
|
+
const g = {yaw: 0, pitch: 0, roll: 0, sy: 0, lift: 0, scale: 0, gx: 0, gy: 0};
|
|
366
|
+
let acted = null;
|
|
367
|
+
this.gestures = this.gestures.filter(item => {
|
|
368
|
+
item.age += dt;
|
|
369
|
+
if (item.age >= item.def.dur) { item.def.end?.(this); return false; }
|
|
370
|
+
item.def.move(item.age / item.def.dur, g); acted = item.def.expr || acted;
|
|
371
|
+
return true;
|
|
372
|
+
});
|
|
373
|
+
if (this.swap) {
|
|
374
|
+
const s = this.swap, u = (s.age += dt) / 0.36;
|
|
375
|
+
if (u >= 0.5 && s.to) { this.shape = s.to; s.to = null; this.build(); }
|
|
376
|
+
g.scale -= 0.5 * bump(u); g.yaw += TAU * smooth(Math.min(1, u));
|
|
377
|
+
if (u >= 1) this.swap = null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Spin too much and it gets dizzy.
|
|
381
|
+
this.spun = Math.max(0, this.spun + Math.abs(this.omega) * dt - 2.5 * dt);
|
|
382
|
+
if (this.spun > 15 && this.dizzy <= 0) { this.dizzy = 2.8; this.spun = 0; }
|
|
383
|
+
this.dizzy = Math.max(0, this.dizzy - dt);
|
|
384
|
+
if (this.dizzy > 0) g.roll += 0.16 * Math.sin(this.t * 9) * Math.min(1, this.dizzy);
|
|
385
|
+
|
|
386
|
+
this.omega = ease(this.omega, 0, dt, 3);
|
|
387
|
+
if (!this.dragging) { p.yaw = ease(p.yaw, want.yaw + Math.round((p.yaw - want.yaw) / TAU) * TAU, dt, want.rate) + this.omega * dt; this.tug = ease(this.tug, 0, dt, 4); }
|
|
388
|
+
p.pitch = ease(p.pitch, want.pitch + this.tug, dt, want.rate);
|
|
389
|
+
this.spring('sy', want.sy, want.stiff, Math.sqrt(want.stiff), dt);
|
|
390
|
+
this.spring('lift', want.lift, 180, 12, dt);
|
|
391
|
+
this.spring('scale', want.scale, 220, 18, dt);
|
|
392
|
+
this.spring('roll', want.roll, 120, 12, dt);
|
|
393
|
+
p.sat = ease(p.sat, want.sat, dt, 5); p.blush = ease(p.blush, want.blush, dt, 6);
|
|
394
|
+
this.gazeAt.x = ease(this.gazeAt.x, want.gx + g.gx, dt, 10); this.gazeAt.y = ease(this.gazeAt.y, want.gy + g.gy, dt, 10);
|
|
395
|
+
|
|
396
|
+
// Expressions change behind a blink.
|
|
397
|
+
if (this.override && (this.override.left -= dt) <= 0) this.override = null;
|
|
398
|
+
const expr = this.override?.name || (this.dizzy > 0 && 'dizzy') || acted || (this.press && !this.dragging && 'squint') || (this.hover && want.expr === 'neutral' ? 'wide' : want.expr);
|
|
399
|
+
if (expr !== this.shown && p.open < 0.2) this.shown = expr;
|
|
400
|
+
if ((this.blinkIn -= dt) < 0) { this.blinkFor = want.still ? 0 : 0.13; this.blinkIn = this.rng() < 0.2 ? 0.3 : 2 + this.rng() * 3.5; }
|
|
401
|
+
this.blinkFor = Math.max(0, this.blinkFor - dt);
|
|
402
|
+
p.open = ease(p.open, expr !== this.shown || this.blinkFor > 0 ? 0 : 1, dt, 32);
|
|
403
|
+
|
|
404
|
+
if (want.mark) this.markName = want.mark; if (want.ring) this.ringKind = want.ring;
|
|
405
|
+
this.phase += dt * 2.6 * (want.orbit || 1);
|
|
406
|
+
const goal = {orbit: +(want.orbit > 0), mark: +!!want.mark, stars: +(this.dizzy > 0), ring: +!!want.ring, bars: +want.bars, morph: +this.morphing, emph: +this.emphasized};
|
|
407
|
+
for (const key in goal) this.aura[key] = ease(this.aura[key], goal[key], dt, 7);
|
|
408
|
+
this.particles = this.particles.filter(q => {
|
|
409
|
+
q.age += dt;
|
|
410
|
+
if (q.age >= q.life) { q.node.remove(); return false; }
|
|
411
|
+
if (q.g) q.vy += q.g * dt;
|
|
412
|
+
if (q.drag) { q.vx *= 1 - q.drag * dt; q.vy *= 1 - q.drag * dt; }
|
|
413
|
+
q.x += q.vx * dt; q.y += q.vy * dt;
|
|
414
|
+
return true;
|
|
415
|
+
});
|
|
416
|
+
if (draw) this.render(g);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
render(g = {yaw: 0, pitch: 0, roll: 0, sy: 0, lift: 0, scale: 0}) {
|
|
420
|
+
if (this.scheme === 'auto' && prefersDark() !== this.dark) { this.retone(); this.build(); }
|
|
421
|
+
const p = this.p, geo = this.geo, P = this.points, tone = this.tone, hue = tone.hue, morph = smooth(clamp(this.aura.morph, 0, 1)), gone = morph > 0.9;
|
|
422
|
+
const sy = clamp(p.sy + g.sy, 0.3, 1.7), sx = 1 + (1 - sy) * 0.3, lift = p.lift + g.lift, S = UNIT * Math.max(0.1, p.scale * (1 + g.scale)) * (1 - morph);
|
|
423
|
+
if (gone !== this.gone) { this.gone = gone; if (gone) this.body.setAttribute('display', 'none'); else this.body.removeAttribute('display'); }
|
|
424
|
+
const ca = Math.cos(p.yaw + g.yaw), sa = Math.sin(p.yaw + g.yaw), cb = Math.cos(p.pitch + g.pitch), sb = Math.sin(p.pitch + g.pitch), cr = Math.cos(p.roll + g.roll), sr = Math.sin(p.roll + g.roll);
|
|
425
|
+
// Yaw, then pitch, then roll.
|
|
426
|
+
const turn = (x, y, z) => { const x1 = x * ca + z * sa, z1 = -x * sa + z * ca, y2 = y * cb - z1 * sb; return [x1 * cr - y2 * sr, x1 * sr + y2 * cr, y * sb + z1 * cb]; };
|
|
427
|
+
const place = v => { const q = turn(v[0] * sx, v[1] * sy + 1 - sy, v[2] * sx), w = S * (1 - q[2] * PERSPECTIVE); return [50 + q[0] * w, CY + lift + q[1] * w, q[2]]; };
|
|
428
|
+
|
|
429
|
+
geo.verts.forEach((v, i) => { const q = place(v); P[i * 3] = q[0]; P[i * 3 + 1] = q[1]; P[i * 3 + 2] = q[2]; });
|
|
430
|
+
|
|
431
|
+
// Faces that point at the viewer, far ones first.
|
|
432
|
+
const seen = [], chroma = (tone.chroma * p.sat).toFixed(3);
|
|
433
|
+
geo.faces.forEach(face => {
|
|
434
|
+
const n = turn(face.n[0], face.n[1], face.n[2]);
|
|
435
|
+
if (n[2] > 0.02) return;
|
|
436
|
+
let depth = 0; for (const m of face.idx) depth += P[m * 3 + 2];
|
|
437
|
+
seen.push({face, order: face.layer * 1000 - depth / face.idx.length, lit: n[0] * LIGHT[0] + n[1] * LIGHT[1] + n[2] * LIGHT[2]});
|
|
438
|
+
});
|
|
439
|
+
seen.sort((a, b) => a.order - b.order);
|
|
440
|
+
seen.forEach(({face, lit}, i) => {
|
|
441
|
+
let d = '';
|
|
442
|
+
for (const m of face.idx) d += (d ? 'L' : 'M') + r1(P[m * 3]) + ',' + r1(P[m * 3 + 1]);
|
|
443
|
+
const shade = `oklch(${(tone.base + tone.span * clamp(lit, -1, 1)).toFixed(3)} ${chroma} ${hue})`, node = this.facePaths[i];
|
|
444
|
+
node.setAttribute('d', d + 'Z'); node.setAttribute('fill', shade); node.setAttribute('stroke', shade);
|
|
445
|
+
if (i >= this.used) node.removeAttribute('display');
|
|
446
|
+
});
|
|
447
|
+
for (let i = seen.length; i < this.used; i++) this.facePaths[i].setAttribute('display', 'none');
|
|
448
|
+
this.used = seen.length;
|
|
449
|
+
|
|
450
|
+
// Eyes, drawn on the surface so they turn with the solid. Small avatars get slightly larger eyes.
|
|
451
|
+
const style = EYE_STYLES[this.eyes], k = this.size <= 28 ? Math.max(geo.k * 1.18, 0.74) : this.size <= 40 ? Math.max(geo.k * 1.08, 0.68) : geo.k, minWidth = 110 / this.size;
|
|
452
|
+
const ink = this.eyeColor || tone.eye || `oklch(0.975 0.03 ${hue})`;
|
|
453
|
+
this.eyeNodes.forEach((node, i) => {
|
|
454
|
+
const side = i ? 1 : -1, ex = side * style.gap + this.gazeAt.x, ey = 0.02 + this.gazeAt.y, blush = this.blushNodes[i];
|
|
455
|
+
const n = geo.nrm(ex * k, ey * k), toward = -turn(n[0], n[1], n[2])[2];
|
|
456
|
+
if (toward < 0.12 || gone) { node.setAttribute('display', 'none'); blush.setAttribute('display', 'none'); return; }
|
|
457
|
+
const shape = eyeShape(this.shown, side, style, p.open), fade = clamp(toward * 1.5, 0.45, 1);
|
|
458
|
+
let d = '';
|
|
459
|
+
for (const line of shape.lines) {
|
|
460
|
+
line.forEach(([x, y], j) => { const q = place(geo.at((ex + x) * k, (ey + y) * k)); d += (j ? 'L' : 'M') + r1(q[0]) + ',' + r1(q[1]); });
|
|
461
|
+
if (shape.fill) d += 'Z';
|
|
462
|
+
}
|
|
463
|
+
node.setAttribute('d', d); node.removeAttribute('display'); node.setAttribute('stroke', ink);
|
|
464
|
+
node.setAttribute('fill', shape.fill ? ink : 'none');
|
|
465
|
+
node.setAttribute('stroke-width', Math.max(shape.fill ? 0 : minWidth, shape.w * S * k * fade).toFixed(2));
|
|
466
|
+
node.setAttribute('opacity', (0.55 + 0.45 * p.sat).toFixed(2));
|
|
467
|
+
if (p.blush < 0.03) { blush.setAttribute('display', 'none'); return; }
|
|
468
|
+
const bx = ex + side * 0.2, by = ey + 0.3, a = place(geo.at((bx - 0.07) * k, by * k)), b = place(geo.at((bx + 0.07) * k, by * k));
|
|
469
|
+
blush.setAttribute('d', `M${r1(a[0])},${r1(a[1])}L${r1(b[0])},${r1(b[1])}`); blush.removeAttribute('display');
|
|
470
|
+
blush.setAttribute('stroke-width', (0.17 * S * k * fade).toFixed(2)); blush.setAttribute('opacity', (0.75 * p.blush * p.sat).toFixed(2));
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const rise = Math.max(0, -lift);
|
|
474
|
+
this.shadow.setAttribute('rx', Math.max(13 * morph, geo.foot * S * sx * (1 - Math.min(0.5, rise * 0.02))).toFixed(1));
|
|
475
|
+
this.shadow.setAttribute('opacity', ((this.dark ? 0.45 : 0.16) * (1 - Math.min(0.6, rise * 0.03))).toFixed(3));
|
|
476
|
+
this.effects(lift, morph);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Things around the body: circling dots, dizzy stars, a glyph, a ring, sound bars, particles.
|
|
480
|
+
effects(lift, morph = 0) {
|
|
481
|
+
const hue = this.hue, t = this.t, aura = this.aura, cy = CY + lift;
|
|
482
|
+
const accent = `oklch(0.72 ${Math.min(0.16, this.tone.chroma + 0.02)} ${hue})`, bright = `oklch(0.86 0.14 ${hue + 50})`;
|
|
483
|
+
const circling = (key, count, make) => {
|
|
484
|
+
const nodes = (this[key + 'Nodes'] = this[key + 'Nodes'] || []);
|
|
485
|
+
if (aura[key] < 0.02) { for (const node of nodes) node.setAttribute('display', 'none'); return null; }
|
|
486
|
+
while (nodes.length < count) nodes.push(make());
|
|
487
|
+
return nodes;
|
|
488
|
+
};
|
|
489
|
+
circling('orbit', 3, () => el('circle', {}, this.back))?.forEach((node, i) => {
|
|
490
|
+
const a = this.phase + i * TAU / 3, z = Math.sin(a), layer = z < 0 ? this.front : this.back;
|
|
491
|
+
if (node.parentNode !== layer) layer.append(node);
|
|
492
|
+
node.removeAttribute('display'); node.setAttribute('fill', accent);
|
|
493
|
+
node.setAttribute('cx', r1(50 + 1.75 * UNIT * Math.cos(a))); node.setAttribute('cy', r1(cy + UNIT * (-0.1 + 0.45 * z)));
|
|
494
|
+
node.setAttribute('r', Math.max(0, (3.6 - 0.9 * z) * aura.orbit).toFixed(2));
|
|
495
|
+
});
|
|
496
|
+
circling('stars', 3, () => el('path', {d: STAR}, this.front))?.forEach((node, i) => {
|
|
497
|
+
const a = t * 4 + i * TAU / 3, z = Math.sin(a), layer = z < 0 ? this.front : this.back;
|
|
498
|
+
if (node.parentNode !== layer) layer.append(node);
|
|
499
|
+
node.removeAttribute('display'); node.setAttribute('fill', bright);
|
|
500
|
+
node.setAttribute('transform', `translate(${r1(50 + 0.95 * UNIT * Math.cos(a))} ${r1(cy + UNIT * (-1.45 + 0.2 * z))}) scale(${((3.2 - 0.6 * z) * aura.stars).toFixed(2)})`);
|
|
501
|
+
});
|
|
502
|
+
const mark = circling('mark', 1, () => { const group = el('g', {'stroke-linecap': 'round', 'stroke-linejoin': 'round'}, this.front); el('path', {}, group); el('circle', {stroke: 'none'}, group); return group; });
|
|
503
|
+
if (mark) {
|
|
504
|
+
const def = MARKS[this.markName] || MARKS.ask, [group] = mark, path = group.firstChild, dot = group.lastChild, paint = def.paint || accent;
|
|
505
|
+
if (group.botMark !== this.markName) {
|
|
506
|
+
group.botMark = this.markName; path.setAttribute('d', def.d); path.setAttribute('stroke-width', def.wide ? 4.2 : def.fill ? 1.4 : 3.2);
|
|
507
|
+
if (def.dot) { dot.setAttribute('cx', def.dot[0]); dot.setAttribute('cy', def.dot[1]); dot.setAttribute('r', def.dot[2]); dot.removeAttribute('display'); } else dot.setAttribute('display', 'none');
|
|
508
|
+
}
|
|
509
|
+
path.setAttribute('stroke', paint); path.setAttribute('fill', def.fill ? paint : 'none'); dot.setAttribute('fill', paint);
|
|
510
|
+
group.removeAttribute('display');
|
|
511
|
+
group.setAttribute('transform', `translate(${r1(50 + 1.35 * UNIT)} ${r1(cy - 1.25 * UNIT + 1.5 * Math.sin(t * 3))}) rotate(${def.dot && def.d ? 12 : 0}) scale(${((this.size <= 28 ? 1.7 : 1.35) * aura.mark).toFixed(2)})`);
|
|
512
|
+
}
|
|
513
|
+
if (aura.emph < 0.02) this.haloNode.setAttribute('display', 'none');
|
|
514
|
+
else {
|
|
515
|
+
const rx = 31 + 1.5 * Math.sin(t * 3);
|
|
516
|
+
this.haloNode.removeAttribute('display'); this.haloNode.setAttribute('rx', r1(rx)); this.haloNode.setAttribute('ry', r1(rx * 0.24));
|
|
517
|
+
this.haloNode.setAttribute('stroke', accent); this.haloNode.setAttribute('stroke-width', (2.4 * aura.emph).toFixed(2));
|
|
518
|
+
}
|
|
519
|
+
if (morph < 0.02) this.symbolNode.setAttribute('display', 'none');
|
|
520
|
+
else {
|
|
521
|
+
if (SYMBOLS[this.state]) this.symbolName = this.state;
|
|
522
|
+
const def = (SYMBOLS[this.symbolName] || SYMBOLS.loading)(t, this.progress), tone = this.tone, node = this.symbolNode, path = node.firstChild, dots = def.dots || [];
|
|
523
|
+
const paint = `oklch(${tone.base} ${tone.chroma} ${hue})`;
|
|
524
|
+
node.removeAttribute('display'); node.setAttribute('opacity', (def.fade ?? 1).toFixed(2));
|
|
525
|
+
node.setAttribute('transform', `translate(50 ${r1(cy)}) rotate(${r1((1 - morph) * -50)}) scale(${(morph * (def.scale ?? 1) * 1.15).toFixed(3)})`);
|
|
526
|
+
path.setAttribute('d', def.d || ''); path.setAttribute('stroke', paint); path.setAttribute('stroke-width', def.w || 0);
|
|
527
|
+
while (node.childNodes.length - 1 < dots.length) el('circle', {}, node);
|
|
528
|
+
for (let i = 1; i < node.childNodes.length; i++) {
|
|
529
|
+
const dot = dots[i - 1], c = node.childNodes[i];
|
|
530
|
+
if (!dot) { c.setAttribute('display', 'none'); continue; }
|
|
531
|
+
c.removeAttribute('display'); c.setAttribute('fill', paint); c.setAttribute('cx', r1(dot[0])); c.setAttribute('cy', r1(dot[1])); c.setAttribute('r', Math.max(0, dot[2]).toFixed(2));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (aura.ring < 0.02) this.ringNode.setAttribute('display', 'none');
|
|
535
|
+
else {
|
|
536
|
+
const around = TAU * RING, steady = this.ringKind === 'progress', part = steady ? clamp(this.progress ?? (this.since * 0.22) % 1, 0, 1) : 0.22;
|
|
537
|
+
this.ringNode.removeAttribute('display'); this.ringNode.setAttribute('cy', r1(cy)); this.ringNode.setAttribute('stroke', accent);
|
|
538
|
+
this.ringNode.setAttribute('stroke-width', (4 * aura.ring).toFixed(2)); this.ringNode.setAttribute('stroke-dasharray', `${r1(Math.max(0.01, part) * around)} ${r1(around)}`);
|
|
539
|
+
this.ringNode.setAttribute('transform', `rotate(${r1(steady ? -90 : t * 320)} 50 ${r1(cy)})`);
|
|
540
|
+
}
|
|
541
|
+
if (aura.bars < 0.02) this.barsNode.setAttribute('display', 'none');
|
|
542
|
+
else {
|
|
543
|
+
let d = '';
|
|
544
|
+
for (let i = 0; i < 4; i++) { const x = r1(50 + 1.42 * UNIT + i * 4.6), tall = 1.5 + 8 * Math.abs(Math.sin(t * 7 + i * 1.3) * Math.cos(t * 2.3 + i)); d += `M${x},${r1(cy - tall)}L${x},${r1(cy + tall)}`; }
|
|
545
|
+
this.barsNode.removeAttribute('display'); this.barsNode.setAttribute('d', d); this.barsNode.setAttribute('stroke', accent); this.barsNode.setAttribute('stroke-width', (2.6 * aura.bars).toFixed(2));
|
|
546
|
+
}
|
|
547
|
+
for (const q of this.particles) {
|
|
548
|
+
const u = q.age / q.life, x = r1(50 + q.x * UNIT), y = r1(CY + q.y * UNIT), node = q.node;
|
|
549
|
+
if (q.type === 'ring') {
|
|
550
|
+
node.removeAttribute('transform'); node.setAttribute('rx', r1(8 + 30 * u)); node.setAttribute('ry', r1((8 + 30 * u) * 0.22));
|
|
551
|
+
node.setAttribute('stroke', accent); node.setAttribute('stroke-width', (1.8 * (1 - u)).toFixed(2)); node.setAttribute('opacity', (1 - u).toFixed(2));
|
|
552
|
+
} else if (q.stroked) {
|
|
553
|
+
node.setAttribute('stroke', accent); node.setAttribute('opacity', bump(u).toFixed(2));
|
|
554
|
+
node.setAttribute('transform', `translate(${x} ${y}) rotate(${q.turn}) scale(${(q.size * (1 - q.grow * 0.4 + q.grow * u)).toFixed(2)})`);
|
|
555
|
+
} else {
|
|
556
|
+
node.setAttribute('fill', q.paint || (q.bright ? bright : accent));
|
|
557
|
+
node.setAttribute('transform', `translate(${x} ${y}) rotate(${r1(q.turn + q.spin * q.age)}) scale(${(q.size * Math.sqrt(bump(u))).toFixed(2)})`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|