procedural-bot-animations 0.0.0-stage → 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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -2
  3. package/dist/animation.d.ts +90 -0
  4. package/dist/animation.js +396 -0
  5. package/dist/brain.d.ts +198 -0
  6. package/dist/brain.js +581 -0
  7. package/dist/character.d.ts +123 -0
  8. package/dist/character.js +916 -0
  9. package/dist/characters/berry.d.ts +2 -0
  10. package/dist/characters/berry.js +38 -0
  11. package/dist/characters/flame.d.ts +2 -0
  12. package/dist/characters/flame.js +46 -0
  13. package/dist/delta.d.ts +16 -0
  14. package/dist/delta.js +146 -0
  15. package/dist/examples.d.ts +4 -0
  16. package/dist/examples.js +208 -0
  17. package/dist/focus.d.ts +46 -0
  18. package/dist/focus.js +284 -0
  19. package/dist/gaze.d.ts +48 -0
  20. package/dist/gaze.js +133 -0
  21. package/dist/index.d.ts +21 -0
  22. package/dist/index.js +21 -0
  23. package/dist/interactions.d.ts +30 -0
  24. package/dist/interactions.js +100 -0
  25. package/dist/library.d.ts +18 -0
  26. package/dist/library.js +14 -0
  27. package/dist/moods.d.ts +80 -0
  28. package/dist/moods.js +51 -0
  29. package/dist/motion.d.ts +93 -0
  30. package/dist/motion.js +167 -0
  31. package/dist/mount.d.ts +90 -0
  32. package/dist/mount.js +707 -0
  33. package/dist/parts.d.ts +36 -0
  34. package/dist/parts.js +131 -0
  35. package/dist/reactions.d.ts +184 -0
  36. package/dist/reactions.js +1855 -0
  37. package/dist/rig.d.ts +119 -0
  38. package/dist/rig.js +59 -0
  39. package/dist/scroll-traveler.d.ts +41 -0
  40. package/dist/scroll-traveler.js +43 -0
  41. package/dist/state-machine.d.ts +49 -0
  42. package/dist/state-machine.js +68 -0
  43. package/dist/ticker.d.ts +10 -0
  44. package/dist/ticker.js +42 -0
  45. package/dist/transformations.d.ts +21 -0
  46. package/dist/transformations.js +306 -0
  47. package/package.json +51 -4
@@ -0,0 +1,306 @@
1
+ import { track } from './motion.js';
2
+ import { CHECK, CODE, DOT_R, DOT_SCALE, RING } from './rig.js';
3
+ /*
4
+ * Seamless transformations, in Pumpy's style. Three phases:
5
+ *
6
+ * 1. Entry: anticipates (squashes and stretches), the silhouette becomes a
7
+ * perfect circle around the anchor, the parts retract inwards, the eyes
8
+ * close and vanish, and the circle shrinks to the exact radius of the
9
+ * bubble (`DOT_R`).
10
+ * 2. Object: at the swap frame, the body vanishes and the bubble appears at the
11
+ * same center, with the same radius and the same colour, so nothing changes
12
+ * on screen. From there the bubble becomes dots, disc, ring, check or </>
13
+ * purely through continuous geometry: the dots are born under it, the ring
14
+ * is a disc that opens a hole, the check and the </> are strokes with the
15
+ * width of the bubble that grow out of it.
16
+ * 3. Exit: the same path in reverse. The object goes back to being the bubble,
17
+ * swaps for the circle and the circle grows, overshoots and goes back to
18
+ * being a strawberry.
19
+ *
20
+ * Everything in seconds in here; the brain receives progress from 0 to 1.
21
+ */
22
+ function fromCues(cues) {
23
+ const fns = Object.entries(cues).map(([k, c]) => [k, track(c)]);
24
+ return (s) => {
25
+ const d = {};
26
+ for (const [k, f] of fns)
27
+ d[k] = f(s);
28
+ return d;
29
+ };
30
+ }
31
+ /** Scale (delta) of the round body at the size of the bubble. */
32
+ const DOT_DELTA = DOT_SCALE - 1;
33
+ const ENTRY = 0.66;
34
+ const entry = fromCues({
35
+ bodySx: [
36
+ [0, 0],
37
+ [0.1, 0.1],
38
+ [0.22, -0.04],
39
+ [0.34, 0],
40
+ ],
41
+ bodySy: [
42
+ [0, 0],
43
+ [0.1, -0.1],
44
+ [0.22, 0.06],
45
+ [0.34, 0],
46
+ ],
47
+ round: [
48
+ [0.06, 0],
49
+ [0.4, 1],
50
+ ],
51
+ retract: [
52
+ [0.04, 0, 'easeIn'],
53
+ [0.3, 1],
54
+ ],
55
+ eyeSy: [
56
+ [0.08, 0],
57
+ [0.2, -0.9],
58
+ ],
59
+ eyesVanish: [
60
+ [0.18, 0],
61
+ [0.34, 1],
62
+ ],
63
+ scale: [
64
+ [0, 0],
65
+ [0.1, -0.04],
66
+ [0.36, -0.08],
67
+ [ENTRY, DOT_DELTA],
68
+ ],
69
+ });
70
+ const EXIT = 0.95;
71
+ function leave(options) {
72
+ const extra = options.hop ?? 0.1;
73
+ const f = fromCues({
74
+ // Grows from rest (the bubble was still at the swap frame).
75
+ scale: [
76
+ [0, DOT_DELTA],
77
+ [0.34, extra],
78
+ [0.48, -0.04],
79
+ [0.6, 0.01],
80
+ [0.7, 0],
81
+ ],
82
+ round: [
83
+ [0.16, 1],
84
+ [0.5, 0],
85
+ ],
86
+ retract: [
87
+ [0.26, 1, 'easeOut'],
88
+ [0.46, -0.18],
89
+ [0.62, 0.05],
90
+ [0.72, 0],
91
+ ],
92
+ eyesVanish: [
93
+ [0.16, 1],
94
+ [0.32, 0],
95
+ ],
96
+ eyeSy: [
97
+ [0.26, -0.9],
98
+ [0.42, 0.1],
99
+ [0.5, 0],
100
+ ],
101
+ bodySx: [
102
+ [0.3, 0],
103
+ [0.4, 0.06],
104
+ [0.52, -0.03],
105
+ [0.64, 0.01],
106
+ [0.7, 0],
107
+ ],
108
+ bodySy: [
109
+ [0.3, 0],
110
+ [0.4, -0.06],
111
+ [0.52, 0.03],
112
+ [0.64, -0.01],
113
+ [0.7, 0],
114
+ ],
115
+ happy: options.happy
116
+ ? [
117
+ [0.3, 0],
118
+ [0.4, 1],
119
+ [0.8, 1],
120
+ [0.95, 0],
121
+ ]
122
+ : [[0, 0]],
123
+ sparks: options.sparks
124
+ ? [
125
+ [0.05, 0, 'linear'],
126
+ [0.75, 1],
127
+ [0.7501, 0],
128
+ ]
129
+ : [[0, 0]],
130
+ });
131
+ return f;
132
+ }
133
+ /** Bubble pulse right after the swap: adds life without moving the center. */
134
+ const BUBBLE_PULSE = [
135
+ [0, DOT_R],
136
+ [0.08, DOT_R + 6],
137
+ [0.2, DOT_R],
138
+ ];
139
+ /**
140
+ * Builds a transformation: entry, `middle` seconds of object and exit. The object
141
+ * returns only its own fields; the rest (hidden body, bubble at the right radius)
142
+ * comes from here, and the bubble radius must return to `DOT_R` at the end of the middle.
143
+ */
144
+ function makeTransformation(middle, obj, options = {}) {
145
+ const exitSampler = leave(options);
146
+ const duration = ENTRY + middle + EXIT;
147
+ const morph = track([
148
+ [0, 0],
149
+ [0.1, 1],
150
+ [duration - 0.25, 1],
151
+ [duration, 0],
152
+ ]);
153
+ const hold = track([
154
+ [0, 0],
155
+ [0.08, 1],
156
+ [duration - 0.35, 1],
157
+ [duration, 0],
158
+ ]);
159
+ // Before returning, the bubble "inhales" (shrinks a little and returns to the exact radius, still).
160
+ const inhale = track([
161
+ [middle - 0.3, DOT_R],
162
+ [middle - 0.15, DOT_R - 6],
163
+ [middle - 0.02, DOT_R],
164
+ ]);
165
+ const sample = (t) => {
166
+ const s = t * duration;
167
+ let d;
168
+ if (s < ENTRY)
169
+ d = entry(s);
170
+ else if (s < ENTRY + middle) {
171
+ const objT = s - ENTRY;
172
+ d = {
173
+ scale: DOT_DELTA,
174
+ round: 1,
175
+ retract: 1,
176
+ eyeSy: -0.9,
177
+ eyesVanish: 1,
178
+ swap: 1,
179
+ bubbleR: DOT_R,
180
+ ...obj(objT),
181
+ };
182
+ if (objT > middle - 0.3)
183
+ d.bubbleR = inhale(objT);
184
+ }
185
+ else
186
+ d = exitSampler(s - ENTRY - middle);
187
+ return { ...d, morph: morph(s), holdGaze: hold(s) };
188
+ };
189
+ return { duration, sample };
190
+ }
191
+ /* ---------- becomes loading: dots → disc → spinning ring → disc → bubble ---------- */
192
+ const loading = fromCues({
193
+ bubbleR: [
194
+ ...BUBBLE_PULSE,
195
+ [1.15, DOT_R, 'easeOut'],
196
+ [1.45, RING.R],
197
+ [2.75, RING.R],
198
+ [3.05, DOT_R],
199
+ ],
200
+ dotsDist: [
201
+ [0.15, 0, 'easeOut'],
202
+ [0.45, 90],
203
+ [0.9, 90],
204
+ [1.15, 0],
205
+ ],
206
+ dotsBounce: [
207
+ [0.2, 0],
208
+ [0.45, 1],
209
+ [0.85, 1],
210
+ [1.05, 0],
211
+ ],
212
+ bubbleHole: [
213
+ [1.45, 0],
214
+ [1.7, RING.hole],
215
+ [2.45, RING.hole],
216
+ [2.7, 0],
217
+ ],
218
+ bubbleArc: [
219
+ [1.7, 0],
220
+ [1.95, 0.72],
221
+ [2.2, 0.72],
222
+ [2.42, 0],
223
+ ],
224
+ });
225
+ function loadingSpin(s) {
226
+ // Starts spinning when it becomes a disc (invisible until the ring opens) and accelerates.
227
+ const x = Math.max(0, s - 1.45);
228
+ return x < 0.4 ? 450 * x * x : 72 + 360 * (x - 0.4);
229
+ }
230
+ /* ---------- becomes check: the bubble walks to the start of the check and draws it ---------- */
231
+ const check = fromCues({
232
+ bubbleR: BUBBLE_PULSE,
233
+ bubbleX: [
234
+ [0.15, 0, 'easeOut'],
235
+ [0.42, CHECK.start.x],
236
+ [1.75, CHECK.start.x],
237
+ [2.0, 0],
238
+ ],
239
+ bubbleY: [
240
+ [0.15, 0, 'easeOut'],
241
+ [0.42, CHECK.start.y],
242
+ [1.75, CHECK.start.y],
243
+ [2.0, 0],
244
+ ],
245
+ checkDraw: [
246
+ [0.42, 0, 'easeOut'],
247
+ [0.8, 1],
248
+ [1.45, 1, 'easeIn'],
249
+ [1.75, 0],
250
+ ],
251
+ objScale: [
252
+ [0.8, 0],
253
+ [0.9, 0.1],
254
+ [1.04, -0.03],
255
+ [1.14, 0],
256
+ ],
257
+ });
258
+ /* ---------- becomes </>: three dots and a stroke leaving each one ---------- */
259
+ const code = fromCues({
260
+ bubbleR: [
261
+ ...BUBBLE_PULSE,
262
+ [0.3, DOT_R],
263
+ [0.55, CODE.radius],
264
+ [1.75, CODE.radius],
265
+ [2.0, DOT_R],
266
+ ],
267
+ dotsDist: [
268
+ [0.25, 0, 'easeOut'],
269
+ [0.55, CODE.dist],
270
+ [1.7, CODE.dist, 'easeIn'],
271
+ [1.95, 0],
272
+ ],
273
+ codeDraw: [
274
+ [0.55, 0, 'easeOut'],
275
+ [0.9, 1],
276
+ [1.35, 1, 'easeIn'],
277
+ [1.65, 0],
278
+ ],
279
+ objScale: [
280
+ [0.9, 0],
281
+ [1.0, 0.08],
282
+ [1.12, -0.02],
283
+ [1.22, 0],
284
+ ],
285
+ });
286
+ /* ---------- energy: eight dots come out from under the bubble and orbit ---------- */
287
+ const energy = fromCues({
288
+ bubbleR: [...BUBBLE_PULSE, [0.3, DOT_R], [0.55, 28], [1.55, 28], [1.8, 48], [1.95, DOT_R]],
289
+ orbitOpen: [
290
+ [0.25, 0, 'easeOut'],
291
+ [0.65, 1],
292
+ [1.3, 1, 'easeIn'],
293
+ [1.65, 0],
294
+ ],
295
+ });
296
+ export const TRANSFORMATIONS = {
297
+ morphLoading: makeTransformation(3.4, (s) => ({ ...loading(s), objRotate: loadingSpin(s) })),
298
+ morphCheck: makeTransformation(2.35, check, { happy: true }),
299
+ morphCode: makeTransformation(2.35, code),
300
+ energy: makeTransformation(2.3, (s) => ({ ...energy(s), objRotate: 260 * s + 160 * s * s }), {
301
+ hop: 0.2,
302
+ sparks: true,
303
+ }),
304
+ };
305
+ /** Reactions that cannot be interrupted: in the middle of them the body does not even exist. */
306
+ export const EXCLUSIVE = new Set(Object.keys(TRANSFORMATIONS));
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "procedural-bot-animations",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "A procedural animation engine for 2D SVG mascots: lively eyes (saccades, pursuit, blinks, eyelids), blended moods, reactions and activities, sprung and bending parts. Characters and animations are plain JSON. Includes a state machine and a scroll traveler.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "site": "npm run build && rm -rf site/dist site/docs && cp -r dist site/dist && mkdir -p site/docs && cp docs/character-format.md docs/animation-format.md site/docs/",
26
+ "check": "npm run typecheck && npm run test && npm run build"
27
+ },
28
+ "keywords": [
29
+ "avatar",
30
+ "bot",
31
+ "mascot",
32
+ "procedural-animation",
33
+ "state-machine",
34
+ "open-bot-avatar",
35
+ "svg",
36
+ "character-animation",
37
+ "eyes"
38
+ ],
39
+ "license": "MIT",
40
+ "author": "Jp-mainieri",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/Jp-mainieri/procedural-bot-animations.git"
44
+ },
45
+ "homepage": "https://github.com/Jp-mainieri/procedural-bot-animations",
46
+ "devDependencies": {
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^3.2.4"
49
+ },
50
+ "engines": {
51
+ "node": ">=18"
52
+ }
53
+ }