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,36 @@
1
+ import { type Spring } from "./motion.js";
2
+ import type { Appendage, Point } from "./rig.js";
3
+ export type Axis = {
4
+ pivot: Point;
5
+ dir: Point;
6
+ L: number;
7
+ };
8
+ /** Axis from the base to the tip of a rig appendage. */
9
+ export declare function axisOf(a: Pick<Appendage, "pivot" | "tip">): Axis;
10
+ /**
11
+ * One step of the tip spring. `dBaseVel` is the change in the base's angular
12
+ * velocity this frame (degrees/s); `dBodyVy`, the change in the body's
13
+ * vertical velocity (px/s, negative = accelerated upward); `side` says where
14
+ * the appendage points (−1 left, 0 up, 1 right).
15
+ */
16
+ export declare function stepTip(p: Spring, dBaseVel: number, dBodyVy: number, side: -1 | 0 | 1, dt: number): void;
17
+ export type PathCommand = {
18
+ c: string;
19
+ pts: number[];
20
+ };
21
+ /** Reads an absolute path with M, L, C and Z (the rig's format). */
22
+ export declare function parsePath(d: string): PathCommand[];
23
+ /**
24
+ * Curves the path around the axis pivot: a point at a distance `t·L` from the
25
+ * base (measured along the axis) rotates `bend·t²` degrees. The base, which is
26
+ * hidden inside the body, does not move.
27
+ */
28
+ export declare function bendPath(cmds: readonly PathCommand[], axis: Axis, bend: number): string;
29
+ /**
30
+ * A circle with the same commands as the path (M, n × C, Z), with the end
31
+ * points at the same angles around `c`. Interpolating point by point between
32
+ * the two takes the silhouette to the circle without twisting.
33
+ */
34
+ export declare function circleLike(cmds: readonly PathCommand[], c: Point, R: number): PathCommand[];
35
+ /** Path between `a` and `b` (same commands), at `t` from 0 to 1. */
36
+ export declare function mixPath(a: readonly PathCommand[], b: readonly PathCommand[], t: number): string;
package/dist/parts.js ADDED
@@ -0,0 +1,131 @@
1
+ import { clamp, substep } from "./motion.js";
2
+ /** Axis from the base to the tip of a rig appendage. */
3
+ export function axisOf(a) {
4
+ const dx = a.tip.x - a.pivot.x;
5
+ const dy = a.tip.y - a.pivot.y;
6
+ const L = Math.hypot(dx, dy);
7
+ return { pivot: a.pivot, dir: { x: dx / L, y: dy / L }, L };
8
+ }
9
+ /* ---------- tip physics ---------- */
10
+ const K_TIP = 190;
11
+ const C_TIP = 8;
12
+ /** How much the tip lags behind when the base rotates (dimensionless). */
13
+ const ROTATION_LAG = 0.55;
14
+ /** Degrees/s of impulse on the tip per px/s of change in the body's vertical velocity. */
15
+ const VERTICAL_LAG = 0.14;
16
+ const MAX_BEND = 38;
17
+ /**
18
+ * One step of the tip spring. `dBaseVel` is the change in the base's angular
19
+ * velocity this frame (degrees/s); `dBodyVy`, the change in the body's
20
+ * vertical velocity (px/s, negative = accelerated upward); `side` says where
21
+ * the appendage points (−1 left, 0 up, 1 right).
22
+ */
23
+ export function stepTip(p, dBaseVel, dBodyVy, side, dt) {
24
+ // Inertia: the tip "stays" where it was, so it rotates opposite to the base.
25
+ p.v -= dBaseVel * ROTATION_LAG;
26
+ // Body accelerated upward: the side tips stay down (and vice versa).
27
+ // On the left, positive raises; on the right, negative raises. The middle
28
+ // one points up and does not feel vertical acceleration as torque.
29
+ p.v += dBodyVy * VERTICAL_LAG * -side;
30
+ substep(dt, (h) => {
31
+ p.v += (-K_TIP * p.a - C_TIP * p.v) * h;
32
+ p.a = clamp(p.a + p.v * h, -MAX_BEND, MAX_BEND);
33
+ });
34
+ }
35
+ /** Reads an absolute path with M, L, C and Z (the rig's format). */
36
+ export function parsePath(d) {
37
+ const out = [];
38
+ const re = /([MLCZ])([^MLCZ]*)/gi;
39
+ let m;
40
+ while ((m = re.exec(d))) {
41
+ const nums = m[2].match(/-?\d*\.?\d+/g)?.map(Number) ?? [];
42
+ out.push({ c: m[1].toUpperCase(), pts: nums });
43
+ }
44
+ return out;
45
+ }
46
+ const fmt = (v) => (Math.round(v * 10) / 10).toString();
47
+ /**
48
+ * Curves the path around the axis pivot: a point at a distance `t·L` from the
49
+ * base (measured along the axis) rotates `bend·t²` degrees. The base, which is
50
+ * hidden inside the body, does not move.
51
+ */
52
+ export function bendPath(cmds, axis, bend) {
53
+ const { pivot, dir, L } = axis;
54
+ const rad = (bend * Math.PI) / 180;
55
+ return cmds
56
+ .map(({ c, pts }) => {
57
+ const out = [];
58
+ for (let i = 0; i < pts.length; i += 2) {
59
+ const x = pts[i] - pivot.x;
60
+ const y = pts[i + 1] - pivot.y;
61
+ const t = clamp((x * dir.x + y * dir.y) / L, 0, 1.2);
62
+ const a = rad * t * t;
63
+ const cos = Math.cos(a);
64
+ const sin = Math.sin(a);
65
+ out.push(`${fmt(pivot.x + x * cos - y * sin)},${fmt(pivot.y + x * sin + y * cos)}`);
66
+ }
67
+ return out.length ? `${c}${out.join(" ")}` : c;
68
+ })
69
+ .join(" ");
70
+ }
71
+ /* ---------- round body (transformations) ---------- */
72
+ /**
73
+ * A circle with the same commands as the path (M, n × C, Z), with the end
74
+ * points at the same angles around `c`. Interpolating point by point between
75
+ * the two takes the silhouette to the circle without twisting.
76
+ */
77
+ export function circleLike(cmds, c, R) {
78
+ const ends = [];
79
+ for (const { pts } of cmds)
80
+ if (pts.length >= 2)
81
+ ends.push({ x: pts[pts.length - 2], y: pts[pts.length - 1] });
82
+ // Angles of the end points, unwrapped so they always run the same way round.
83
+ const angs = ends.map((p) => Math.atan2(p.y - c.y, p.x - c.x));
84
+ const direction = Math.sign(ends.reduce((acc, p, i) => {
85
+ const q = ends[(i + 1) % ends.length];
86
+ return acc + (p.x - c.x) * (q.y - c.y) - (p.y - c.y) * (q.x - c.x);
87
+ }, 0));
88
+ for (let i = 1; i < angs.length; i++) {
89
+ while (direction * (angs[i] - angs[i - 1]) < 0)
90
+ angs[i] += direction * 2 * Math.PI;
91
+ }
92
+ const point = (a) => [c.x + R * Math.cos(a), c.y + R * Math.sin(a)];
93
+ let j = 0;
94
+ return cmds.map(({ c: k }) => {
95
+ if (k === "M")
96
+ return { c: k, pts: point(angs[j++]) };
97
+ if (k === "C") {
98
+ const a0 = angs[j - 1];
99
+ const a1 = angs[j++];
100
+ const kappa = (4 / 3) * Math.tan((a1 - a0) / 4) * R;
101
+ const [x0, y0] = point(a0);
102
+ const [x1, y1] = point(a1);
103
+ return {
104
+ c: k,
105
+ pts: [
106
+ x0 - kappa * Math.sin(a0),
107
+ y0 + kappa * Math.cos(a0),
108
+ x1 + kappa * Math.sin(a1),
109
+ y1 - kappa * Math.cos(a1),
110
+ x1,
111
+ y1,
112
+ ],
113
+ };
114
+ }
115
+ if (k === "L")
116
+ return { c: k, pts: point(angs[j++]) };
117
+ return { c: k, pts: [] };
118
+ });
119
+ }
120
+ /** Path between `a` and `b` (same commands), at `t` from 0 to 1. */
121
+ export function mixPath(a, b, t) {
122
+ return a
123
+ .map(({ c, pts }, i) => {
124
+ const q = b[i].pts;
125
+ const nums = [];
126
+ for (let k = 0; k < pts.length; k += 2)
127
+ nums.push(`${fmt(pts[k] + (q[k] - pts[k]) * t)},${fmt(pts[k + 1] + (q[k + 1] - pts[k + 1]) * t)}`);
128
+ return nums.length ? `${c}${nums.join(" ")}` : c;
129
+ })
130
+ .join(" ");
131
+ }
@@ -0,0 +1,184 @@
1
+ import type { PartialDelta } from './delta.js';
2
+ export type SuccessLevel = 'exercise' | 'lesson' | 'module';
3
+ /** Easter egg: eyes spinning in a circle and the body staggering. */
4
+ declare function dizzy(t: number): PartialDelta;
5
+ /** Cheerful: sways from side to side with arc eyes (column 2 of the video). */
6
+ declare function cheerful(t: number): PartialDelta;
7
+ /** Moment of the `tierUp` reaction at which the tier (the colour) swaps, from 0 to 1. */
8
+ export declare const TIER_SWAP_T = 0.45;
9
+ /** Laugh: fast laughing shake, arc eyes, parts flapping. */
10
+ declare function laugh(t: number): PartialDelta;
11
+ /** Heat up (Flame, three clicks): boils with anger, grows, angry face, rays and "!". */
12
+ declare function heatUp(t: number): PartialDelta;
13
+ /** A reaction: its duration in seconds and a sampler of progress t (0 to 1). */
14
+ export type ReactionDef = {
15
+ duration: number;
16
+ sample: (t: number) => PartialDelta;
17
+ };
18
+ export declare const REACTIONS: {
19
+ success: {
20
+ duration: number;
21
+ sample: (t: number) => PartialDelta;
22
+ };
23
+ successExercise: {
24
+ duration: number;
25
+ sample: (t: number) => PartialDelta;
26
+ };
27
+ successModule: {
28
+ duration: number;
29
+ sample: (t: number) => PartialDelta;
30
+ };
31
+ almostThere: {
32
+ duration: number;
33
+ sample: (t: number) => PartialDelta;
34
+ };
35
+ fright: {
36
+ duration: number;
37
+ sample: (t: number) => PartialDelta;
38
+ };
39
+ idea: {
40
+ duration: number;
41
+ sample: (t: number) => PartialDelta;
42
+ };
43
+ copiedThat: {
44
+ duration: number;
45
+ sample: (t: number) => PartialDelta;
46
+ };
47
+ welcome: {
48
+ duration: number;
49
+ sample: (t: number) => PartialDelta;
50
+ };
51
+ dizzy: {
52
+ duration: number;
53
+ sample: typeof dizzy;
54
+ };
55
+ wake: {
56
+ duration: number;
57
+ sample: (t: number) => PartialDelta;
58
+ };
59
+ wink: {
60
+ duration: number;
61
+ sample: (t: number) => PartialDelta;
62
+ };
63
+ cheerful: {
64
+ duration: number;
65
+ sample: typeof cheerful;
66
+ };
67
+ profile: {
68
+ duration: number;
69
+ sample: (t: number) => PartialDelta;
70
+ };
71
+ flatten: {
72
+ duration: number;
73
+ sample: (t: number) => PartialDelta;
74
+ };
75
+ confused: {
76
+ duration: number;
77
+ sample: (t: number) => PartialDelta;
78
+ };
79
+ somersault: {
80
+ duration: number;
81
+ sample: (t: number) => PartialDelta;
82
+ };
83
+ morphLoading: {
84
+ duration: number;
85
+ sample: (t: number) => PartialDelta;
86
+ };
87
+ morphCheck: {
88
+ duration: number;
89
+ sample: (t: number) => PartialDelta;
90
+ };
91
+ morphCode: {
92
+ duration: number;
93
+ sample: (t: number) => PartialDelta;
94
+ };
95
+ energy: {
96
+ duration: number;
97
+ sample: (t: number) => PartialDelta;
98
+ };
99
+ ignite: {
100
+ duration: number;
101
+ sample: (t: number) => PartialDelta;
102
+ };
103
+ extinguish: {
104
+ duration: number;
105
+ sample: (t: number) => PartialDelta;
106
+ };
107
+ blaze: {
108
+ duration: number;
109
+ sample: (t: number) => PartialDelta;
110
+ };
111
+ gust: {
112
+ duration: number;
113
+ sample: (t: number) => PartialDelta;
114
+ };
115
+ crackle: {
116
+ duration: number;
117
+ sample: (t: number) => PartialDelta;
118
+ };
119
+ sneeze: {
120
+ duration: number;
121
+ sample: (t: number) => PartialDelta;
122
+ };
123
+ tierUp: {
124
+ duration: number;
125
+ sample: (t: number) => PartialDelta;
126
+ };
127
+ peek: {
128
+ duration: number;
129
+ sample: (t: number) => PartialDelta;
130
+ };
131
+ shy: {
132
+ duration: number;
133
+ sample: (t: number) => PartialDelta;
134
+ };
135
+ doubleHop: {
136
+ duration: number;
137
+ sample: (t: number) => PartialDelta;
138
+ };
139
+ laugh: {
140
+ duration: number;
141
+ sample: typeof laugh;
142
+ };
143
+ huff: {
144
+ duration: number;
145
+ sample: (t: number) => PartialDelta;
146
+ };
147
+ hide: {
148
+ duration: number;
149
+ sample: (t: number) => PartialDelta;
150
+ };
151
+ warmUp: {
152
+ duration: number;
153
+ sample: (t: number) => PartialDelta;
154
+ };
155
+ heatUp: {
156
+ duration: number;
157
+ sample: typeof heatUp;
158
+ };
159
+ burst: {
160
+ duration: number;
161
+ sample: (t: number) => PartialDelta;
162
+ };
163
+ };
164
+ export type ReactionName = keyof typeof REACTIONS;
165
+ export declare const REACTION_NAMES: ReactionName[];
166
+ declare function thinking(s: number): PartialDelta;
167
+ declare function loading(s: number): PartialDelta;
168
+ declare function sleeping(s: number): PartialDelta;
169
+ /** Flame at risk: flickers, loses colour in little jolts, worried look. */
170
+ declare function flickering(s: number): PartialDelta;
171
+ /** Out: a small gray ember, sad eyes, a thread of smoke. */
172
+ declare function out(s: number): PartialDelta;
173
+ /** An activity: a loop sampled by time in seconds. */
174
+ export type ActivityDef = (s: number) => PartialDelta;
175
+ export declare const ACTIVITIES: {
176
+ thinking: typeof thinking;
177
+ loading: typeof loading;
178
+ sleeping: typeof sleeping;
179
+ flickering: typeof flickering;
180
+ out: typeof out;
181
+ };
182
+ export type Activity = keyof typeof ACTIVITIES;
183
+ export declare const ACTIVITY_NAMES: Activity[];
184
+ export {};