open-bot-avatar 0.2.1 → 0.3.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 (54) hide show
  1. package/README.md +25 -6
  2. package/dist/animator.d.ts +9 -4
  3. package/dist/animator.d.ts.map +1 -1
  4. package/dist/animator.js +32 -17
  5. package/dist/animator.js.map +1 -1
  6. package/dist/color.d.ts +4 -0
  7. package/dist/color.d.ts.map +1 -1
  8. package/dist/color.js +45 -0
  9. package/dist/color.js.map +1 -1
  10. package/dist/dom/mount.d.ts +8 -2
  11. package/dist/dom/mount.d.ts.map +1 -1
  12. package/dist/dom/mount.js +29 -8
  13. package/dist/dom/mount.js.map +1 -1
  14. package/dist/dom/paint.d.ts.map +1 -1
  15. package/dist/dom/paint.js +18 -5
  16. package/dist/dom/paint.js.map +1 -1
  17. package/dist/effects.d.ts +82 -0
  18. package/dist/effects.d.ts.map +1 -0
  19. package/dist/effects.js +352 -0
  20. package/dist/effects.js.map +1 -0
  21. package/dist/eyes.d.ts +29 -0
  22. package/dist/eyes.d.ts.map +1 -0
  23. package/dist/eyes.js +128 -0
  24. package/dist/eyes.js.map +1 -0
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/mood.d.ts +10 -5
  30. package/dist/mood.d.ts.map +1 -1
  31. package/dist/mood.js +3 -2
  32. package/dist/mood.js.map +1 -1
  33. package/dist/motion.d.ts +63 -10
  34. package/dist/motion.d.ts.map +1 -1
  35. package/dist/motion.js +239 -41
  36. package/dist/motion.js.map +1 -1
  37. package/dist/render.d.ts +68 -4
  38. package/dist/render.d.ts.map +1 -1
  39. package/dist/render.js +265 -34
  40. package/dist/render.js.map +1 -1
  41. package/dist/types.d.ts +35 -7
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/src/animator.ts +40 -20
  45. package/src/color.ts +48 -0
  46. package/src/dom/mount.ts +38 -11
  47. package/src/dom/paint.ts +17 -5
  48. package/src/effects.ts +405 -0
  49. package/src/eyes.ts +157 -0
  50. package/src/index.ts +3 -3
  51. package/src/mood.ts +13 -7
  52. package/src/motion.ts +270 -48
  53. package/src/render.ts +335 -42
  54. package/src/types.ts +42 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eyes.js","sourceRoot":"","sources":["../src/eyes.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAe1C,0BAA0B;AAC1B,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB,mHAAmH;AACnH,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAW,CAAC;AAE5D,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAU,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAEnF,8FAA8F;AAC9F,SAAS,QAAQ,CAAC,GAAY,EAAE,KAAa;IAC3C,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;IACrB,MAAM,EAAE,GAAa,CAAC,CAAC,CAAC,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACvC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG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ACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,CAAC,GAAG,CAAC;AACjB,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,OAAO,CAAC,IAAa,EAAE,CAAU;IAC/C,OAAO,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export type { AvatarDefinition, AvatarEyes, AvatarMotion, AvatarMotionBlend, RenderOptions, ValidationResult } from './types.ts';
1
+ export type { AvatarDefinition, AvatarEyes, AvatarMood, AvatarMotion, AvatarMotionBlend, AvatarState, RenderOptions, ValidationResult } from './types.ts';
2
2
  export { validateAvatar } from './validate.ts';
3
3
  export { avatarFrame, renderAvatarSvg, renderAvatarScene, sceneFrame, DEFAULT_COLOR, DEFAULT_DEPTH, DEFAULT_EYE_COLOR, } from './render.ts';
4
4
  export type { AvatarFrame, EyeMark, FramePath, FrameShape, Matrix, SceneFrame } from './render.ts';
5
- export { BASE_PITCH, BASE_YAW, blendPoses, computePose } from './motion.ts';
6
- export type { Pose, PoseInput } from './motion.ts';
5
+ export { BASE_PITCH, BASE_YAW, DONE_CYCLE_S, DONE_TURN_S, MOODS, STATES, blendPoses, computePose, isMood, isState, resolveLook } from './motion.ts';
6
+ export type { EyeLook, Pose, PoseInput } from './motion.ts';
7
7
  export { MOOD_MS, moodProgress, settleMood } from './mood.ts';
8
8
  export type { MoodState } from './mood.ts';
9
9
  export { REST, followGaze, followStep, pointerGaze } from './follow.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjI,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC1J,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACpJ,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { validateAvatar } from './validate.js';
2
2
  export { avatarFrame, renderAvatarSvg, renderAvatarScene, sceneFrame, DEFAULT_COLOR, DEFAULT_DEPTH, DEFAULT_EYE_COLOR, } from './render.js';
3
- export { BASE_PITCH, BASE_YAW, blendPoses, computePose } from './motion.js';
3
+ export { BASE_PITCH, BASE_YAW, DONE_CYCLE_S, DONE_TURN_S, MOODS, STATES, blendPoses, computePose, isMood, isState, resolveLook } from './motion.js';
4
4
  export { MOOD_MS, moodProgress, settleMood } from './mood.js';
5
5
  export { REST, followGaze, followStep, pointerGaze } from './follow.js';
6
6
  export { createAnimator } from './animator.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEpJ,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
package/dist/mood.d.ts CHANGED
@@ -1,16 +1,21 @@
1
1
  /**
2
- * Mood changes (idle, thinking, happy) as pure functions a frame loop steps:
3
- * the pose eases from the mood on screen into the new one (see blendPoses in
2
+ * Changes of state and mood as pure functions a frame loop steps: the pose
3
+ * eases from what is on screen into the new state and mood (see blendPoses in
4
4
  * motion.ts), and a change during a change continues from where it is.
5
5
  */
6
- import type { AvatarMotion, AvatarMotionBlend } from './types.ts';
6
+ import type { AvatarMood, AvatarMotion, AvatarMotionBlend, AvatarState } from './types.ts';
7
7
  /** Length of a mood change, ms. */
8
8
  export declare const MOOD_MS = 420;
9
9
  /** Eased progress of a mood change from elapsed time (smoothstep, clamped). */
10
10
  export declare function moodProgress(elapsedMs: number): number;
11
- /** A mood on screen, possibly still easing in over what came before. */
11
+ /** A state and mood on screen, possibly still easing in over what came before. */
12
12
  export interface MoodState {
13
- motion: AvatarMotion;
13
+ state?: AvatarState;
14
+ mood?: AvatarMood;
15
+ /** @deprecated Use `state` and `mood`. */
16
+ motion?: AvatarMotion;
17
+ /** Seconds the state had been showing when the next change began. */
18
+ age?: number;
14
19
  blend?: AvatarMotionBlend;
15
20
  }
16
21
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mood.d.ts","sourceRoot":"","sources":["../src/mood.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE,mCAAmC;AACnC,eAAO,MAAM,OAAO,MAAM,CAAC;AAO3B,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,wEAAwE;AACxE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,SAAI,EAAE,KAAK,SAAI,GAAG,SAAS,CAM5E"}
1
+ {"version":3,"file":"mood.d.ts","sourceRoot":"","sources":["../src/mood.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3F,mCAAmC;AACnC,eAAO,MAAM,OAAO,MAAM,CAAC;AAO3B,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,kFAAkF;AAClF,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,SAAI,EAAE,KAAK,SAAI,GAAG,SAAS,CAO5E"}
package/dist/mood.js CHANGED
@@ -18,9 +18,10 @@ export function settleMood(state, share = 1, depth = 0) {
18
18
  const b = state.blend;
19
19
  if (!b)
20
20
  return state;
21
+ const { blend: _, ...settled } = state;
21
22
  const rest = share * (1 - b.t);
22
23
  if (rest < 0.02 || depth >= 3)
23
- return { motion: state.motion };
24
- return { motion: state.motion, blend: { from: typeof b.from === 'string' ? b.from : settleMood(b.from, rest, depth + 1), t: b.t } };
24
+ return settled;
25
+ return { ...settled, blend: { from: typeof b.from === 'string' ? b.from : settleMood(b.from, rest, depth + 1), t: b.t } };
25
26
  }
26
27
  //# sourceMappingURL=mood.js.map
package/dist/mood.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mood.js","sourceRoot":"","sources":["../src/mood.ts"],"names":[],"mappings":"AAOA,mCAAmC;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAE3B,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE;IAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,+EAA+E;AAC/E,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,OAAO,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC;AACrC,CAAC;AAQD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAgB,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC;IAC/D,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;IACtB,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrB,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IAC/D,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAA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IAC9C,OAAO,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC5H,CAAC"}
package/dist/motion.d.ts CHANGED
@@ -1,9 +1,19 @@
1
1
  /**
2
- * Deterministic pose model. A pose is a pure function of (seed, time, motion,
3
- * gaze, reducedMotion): no wall clock, no Math.random, so any frame can be
4
- * reproduced exactly (tests, SSR, scrubbing).
2
+ * Deterministic pose model. A pose is a pure function of (seed, time, state,
3
+ * mood, gaze, reducedMotion): no wall clock, no Math.random, so any frame can
4
+ * be reproduced exactly (tests, SSR, scrubbing).
5
5
  */
6
- import type { AvatarMotion, AvatarMotionBlend } from './types.ts';
6
+ import type { AvatarMood, AvatarMotion, AvatarMotionBlend, AvatarState } from './types.ts';
7
+ /**
8
+ * How the eyes are drawn, as numbers that blend: any two looks mix into a shape in between, so
9
+ * the eyes morph from one to the other (see eyes.ts).
10
+ */
11
+ export interface EyeLook {
12
+ /** 0 = the plain pill, 1 = the happy arc. */
13
+ arc: number;
14
+ /** 0 = the plain pill, 1 = the flat slit of a waiting bot. Never more than `1 - arc`. */
15
+ slit: number;
16
+ }
7
17
  export interface Pose {
8
18
  /** View rotation in radians: yaw turns about the vertical axis, pitch about the horizontal. */
9
19
  yaw: number;
@@ -23,8 +33,37 @@ export interface Pose {
23
33
  /** Extra lid narrowing per eye, 0..1. */
24
34
  squintL: number;
25
35
  squintR: number;
26
- eyeShape: 'pill' | 'happy';
36
+ eyes: EyeLook;
37
+ /** Presence of the ribbons that circle the body: 0..1 draws them out and back in. */
38
+ ribbons: number;
39
+ /** Which layout the ribbons take: 0 a working turn's one hoop, 1 a celebration's cage of three. */
40
+ cage: number;
41
+ /**
42
+ * How far the body's turn has carried the ribbons round, radians, signed and not wrapped: each
43
+ * ribbon goes its own share of it, so a whole turn more does not put them back where they were.
44
+ */
45
+ sweep: number;
46
+ /** How far the body has given way to a mark, 0..1 each: the exclamation mark and the three dots. */
47
+ bang: number;
48
+ dots: number;
27
49
  }
50
+ /** Every state and mood, in the order hosts list them. */
51
+ export declare const STATES: readonly AvatarState[];
52
+ export declare const MOODS: readonly AvatarMood[];
53
+ export declare function isState(value: unknown): value is AvatarState;
54
+ export declare function isMood(value: unknown): value is AvatarMood;
55
+ /**
56
+ * The state and mood to show. `motion` is the single option that came before them: `thinking`
57
+ * is a state, `happy` a mood. An explicit `state` or `mood` wins over it.
58
+ */
59
+ export declare function resolveLook(given: {
60
+ state?: unknown;
61
+ mood?: unknown;
62
+ motion?: unknown;
63
+ }): {
64
+ state: AvatarState;
65
+ mood: AvatarMood;
66
+ };
28
67
  /** Resting view: turned a little and seen a little from above, so the volume reads without dominating. */
29
68
  export declare const BASE_YAW = -0.3;
30
69
  export declare const BASE_PITCH = 0.2;
@@ -46,7 +85,12 @@ export declare function wanderAt(seed: number, t: number): [number, number];
46
85
  export interface PoseInput {
47
86
  seed: number;
48
87
  time: number;
49
- motion: AvatarMotion;
88
+ state?: AvatarState;
89
+ mood?: AvatarMood;
90
+ /** @deprecated Use `state` and `mood`; they win when given. */
91
+ motion?: AvatarMotion;
92
+ /** Seconds since `state` began: `done` celebrates from then on. Without it the state is at rest. */
93
+ stateAge?: number;
50
94
  /** Look target, -1..1 per axis (x right, y down); `weight` 0..1 fades it in over the idle pose (default 1). */
51
95
  gaze?: {
52
96
  x: number;
@@ -59,14 +103,23 @@ export interface PoseInput {
59
103
  yaw: number;
60
104
  pitch: number;
61
105
  };
62
- /** Easing in `motion` from the mood shown before (see blendPoses). */
106
+ /** Easing in from what was shown before (see blendPoses). */
63
107
  blend?: AvatarMotionBlend;
64
108
  }
65
109
  /**
66
- * Pose part way from `a` to `b`, both taken at the same moment so either
67
- * side's motion keeps running. A change of eye shape swaps halfway, inside a
68
- * blink: pills close toward the swap and open after it.
110
+ * Pose part way from `a` to `b`, both taken at the same moment so either side's motion keeps
111
+ * running. Everything is a number, the eyes' look included, so eyes morph from one shape to the
112
+ * next and a body gives way to a mark (and back) part by part.
69
113
  */
70
114
  export declare function blendPoses(a: Pose, b: Pose, t: number): Pose;
71
115
  export declare function computePose(input: PoseInput): Pose;
116
+ /**
117
+ * Done celebrates in cycles, timed as PR #14 measured the Grok Bot demo: the ribbons go round
118
+ * DONE_SWEEPS times while the body turns DONE_SWEEPS / 3 times (see celebration), then they draw
119
+ * back in and the bot rests. DONE_TURN_S covers the turn and the drawing in. A cycle lasts
120
+ * DONE_CYCLE_S or up to a seventh longer, differently for each avatar, so several done bots on a
121
+ * page drift apart instead of turning together.
122
+ */
123
+ export declare const DONE_TURN_S = 3.87;
124
+ export declare const DONE_CYCLE_S = 6.2;
72
125
  //# sourceMappingURL=motion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../src/motion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE,MAAM,WAAW,IAAI;IACnB,+FAA+F;IAC/F,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IA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,+GAA+G;IAC/G,IAAI,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,aAAa,EAAE,OAAO,CAAC;IACvB,0FAA0F;IAC1F,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,6DAA6D;IAC7D,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAe5D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAUlD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,OAAO,CAAC;AAChC,eAAO,MAAM,YAAY,MAAM,CAAC"}
package/dist/motion.js CHANGED
@@ -1,3 +1,22 @@
1
+ /** Every state and mood, in the order hosts list them. */
2
+ export const STATES = ['idle', 'thinking', 'working', 'waiting', 'blocked', 'done'];
3
+ export const MOODS = ['neutral', 'happy'];
4
+ export function isState(value) {
5
+ return STATES.includes(value);
6
+ }
7
+ export function isMood(value) {
8
+ return MOODS.includes(value);
9
+ }
10
+ /**
11
+ * The state and mood to show. `motion` is the single option that came before them: `thinking`
12
+ * is a state, `happy` a mood. An explicit `state` or `mood` wins over it.
13
+ */
14
+ export function resolveLook(given) {
15
+ return {
16
+ state: isState(given.state) ? given.state : given.motion === 'thinking' ? 'thinking' : 'idle',
17
+ mood: isMood(given.mood) ? given.mood : given.motion === 'happy' ? 'happy' : 'neutral',
18
+ };
19
+ }
1
20
  /** Resting view: turned a little and seen a little from above, so the volume reads without dominating. */
2
21
  export const BASE_YAW = -0.3;
3
22
  export const BASE_PITCH = 0.2;
@@ -28,6 +47,7 @@ export function noise(seed, n) {
28
47
  }
29
48
  const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
30
49
  const smooth = (u) => { const x = clamp(u, 0, 1); return x * x * (3 - 2 * x); };
50
+ const mix = (a, b, k) => a + (b - a) * k;
31
51
  /** Blink closure 0..1: one blink per ~4.2 s slot at a seeded offset, sometimes a double blink. */
32
52
  export function blinkAt(seed, t) {
33
53
  const SLOT = 4.2, DUR = 0.19;
@@ -57,37 +77,124 @@ export function wanderAt(seed, t) {
57
77
  const e = smooth((t - s * SLOT) / 0.16);
58
78
  return [a[0] + (b[0] - a[0]) * e, a[1] + (b[1] - a[1]) * e];
59
79
  }
80
+ /** Working: the eyes dart from one thing to the next, mostly down at the work. */
81
+ function dartAt(seed, t) {
82
+ const SLOT = 0.62;
83
+ const s = Math.floor(t / SLOT);
84
+ const target = (k) => [(noise(seed, 2001 + k * 3) * 2 - 1) * 0.8, 0.1 + noise(seed, 2002 + k * 3) * 0.5];
85
+ const a = target(s - 1), b = target(s);
86
+ const e = smooth((t - s * SLOT) / 0.12);
87
+ return [mix(a[0], b[0], e), mix(a[1], b[1], e)];
88
+ }
60
89
  /**
61
- * Pose part way from `a` to `b`, both taken at the same moment so either
62
- * side's motion keeps running. A change of eye shape swaps halfway, inside a
63
- * blink: pills close toward the swap and open after it.
90
+ * Pose part way from `a` to `b`, both taken at the same moment so either side's motion keeps
91
+ * running. Everything is a number, the eyes' look included, so eyes morph from one shape to the
92
+ * next and a body gives way to a mark (and back) part by part.
64
93
  */
65
94
  export function blendPoses(a, b, t) {
66
95
  const k = clamp(t, 0, 1);
67
- const mix = (x, y) => x + (y - x) * k;
68
- const pose = {
69
- yaw: mix(a.yaw, b.yaw), pitch: mix(a.pitch, b.pitch), roll: mix(a.roll, b.roll), lift: mix(a.lift, b.lift),
70
- sx: mix(a.sx, b.sx), sy: mix(a.sy, b.sy), gazeX: mix(a.gazeX, b.gazeX), gazeY: mix(a.gazeY, b.gazeY),
71
- blink: mix(a.blink, b.blink), squintL: mix(a.squintL, b.squintL), squintR: mix(a.squintR, b.squintR),
72
- eyeShape: b.eyeShape,
96
+ const m = (x, y) => mix(x, y, k);
97
+ // The ribbons stay where the side that shows them has carried them: mixing a celebration's many
98
+ // turns with a pose that has none would wind them back round while they fade.
99
+ const sweep = a.ribbons > 0 && b.ribbons > 0 ? m(a.sweep, b.sweep) : a.ribbons > 0 ? a.sweep : b.sweep;
100
+ // Likewise their layout: a celebration fading out keeps its cage.
101
+ const cage = a.ribbons > 0 && b.ribbons > 0 ? m(a.cage, b.cage) : a.ribbons > 0 ? a.cage : b.cage;
102
+ return {
103
+ yaw: m(a.yaw, b.yaw), pitch: m(a.pitch, b.pitch), roll: m(a.roll, b.roll), lift: m(a.lift, b.lift),
104
+ sx: m(a.sx, b.sx), sy: m(a.sy, b.sy), gazeX: m(a.gazeX, b.gazeX), gazeY: m(a.gazeY, b.gazeY),
105
+ blink: m(a.blink, b.blink), squintL: m(a.squintL, b.squintL), squintR: m(a.squintR, b.squintR),
106
+ eyes: { arc: m(a.eyes.arc, b.eyes.arc), slit: m(a.eyes.slit, b.eyes.slit) },
107
+ ribbons: m(a.ribbons, b.ribbons), cage, sweep, bang: m(a.bang, b.bang), dots: m(a.dots, b.dots),
73
108
  };
74
- if (a.eyeShape !== b.eyeShape) {
75
- pose.eyeShape = k < 0.5 ? a.eyeShape : b.eyeShape;
76
- pose.blink = Math.max(pose.blink, 1 - Math.abs(2 * k - 1));
77
- }
78
- return pose;
79
109
  }
80
110
  export function computePose(input) {
81
- const pose = moodPose(input);
111
+ const pose = statePose(input);
82
112
  const blend = input.blend;
83
113
  if (!blend || !(blend.t < 1))
84
114
  return pose;
85
115
  const from = typeof blend.from === 'string' ? { motion: blend.from } : blend.from;
86
- return blendPoses(computePose({ ...input, motion: from.motion, blend: from.blend }), pose, Number.isFinite(blend.t) ? blend.t : 1);
116
+ // A change of mood alone keeps the state's clock running on both sides, so a turn under way
117
+ // stays one turn; a state that was left is held at the age it had.
118
+ const stateAge = resolveLook(from).state === resolveLook(input).state ? input.stateAge : from.age;
119
+ const before = computePose({ ...input, state: from.state, mood: from.mood, motion: from.motion, stateAge, blend: from.blend });
120
+ return blendPoses(before, pose, Number.isFinite(blend.t) ? blend.t : 1);
121
+ }
122
+ /**
123
+ * Done celebrates in cycles, timed as PR #14 measured the Grok Bot demo: the ribbons go round
124
+ * DONE_SWEEPS times while the body turns DONE_SWEEPS / 3 times (see celebration), then they draw
125
+ * back in and the bot rests. DONE_TURN_S covers the turn and the drawing in. A cycle lasts
126
+ * DONE_CYCLE_S or up to a seventh longer, differently for each avatar, so several done bots on a
127
+ * page drift apart instead of turning together.
128
+ */
129
+ export const DONE_TURN_S = 3.87;
130
+ export const DONE_CYCLE_S = 6.2;
131
+ const DONE_SWEEPS = 9;
132
+ /**
133
+ * How long the ribbons take to draw back in, seconds: they start once the turn has slowed below
134
+ * about 0.9 rad/s, 3.37 s in, and are gone at DONE_TURN_S.
135
+ */
136
+ const DONE_DRAW_IN_S = 0.5;
137
+ /**
138
+ * A working bot gets on with it and every so often throws itself into the work: a band of
139
+ * ribbons sweeps once round it, easing in like a spring settling, then draws back in. The first comes WORK_FIRST_S
140
+ * (plus up to WORK_FIRST_JITTER_S) after the state begins, then one every WORK_GAP_S, each up to
141
+ * WORK_JITTER_S late, so several working bots do not turn together. A turn takes WORK_TURN_S.
142
+ */
143
+ const WORK_FIRST_S = 1.2;
144
+ const WORK_FIRST_JITTER_S = 1.2;
145
+ const WORK_GAP_S = 7.5;
146
+ const WORK_JITTER_S = 1.5;
147
+ const WORK_TURN_S = 1.5;
148
+ /** How quickly a working turn eases in to its full circle, per second: a critically damped spring's rate. */
149
+ const WORK_EASE = 6.2;
150
+ /**
151
+ * Where a working bot is in its turns `age` seconds into the state: how far into the current
152
+ * turn (seconds), or null between turns.
153
+ */
154
+ function workTurn(seed, age) {
155
+ const first = WORK_FIRST_S + WORK_FIRST_JITTER_S * noise(seed, 41);
156
+ if (age < first)
157
+ return null;
158
+ const n = Math.floor((age - first) / WORK_GAP_S);
159
+ // A turn may start up to WORK_JITTER_S late, so the one before may still be running.
160
+ for (const k of [n, n - 1]) {
161
+ if (k < 0)
162
+ continue;
163
+ const start = first + k * WORK_GAP_S + (k ? WORK_JITTER_S * noise(seed, 60 + k) : 0);
164
+ if (age >= start && age < start + WORK_TURN_S)
165
+ return age - start;
166
+ }
167
+ return null;
168
+ }
169
+ /** An angle as the nearest way round to it, -π..π, so a blend never unwinds whole turns. */
170
+ const near = (angle) => angle - TAU * Math.round(angle / TAU);
171
+ /**
172
+ * How far a celebration's ribbons have gone round `t` seconds in, radians, on PR #14's curve: half
173
+ * a radian of wind-up the other way over 0.24 s, a speed-up to a steady run, then from 2.54 s a
174
+ * slow-down that lands, at 3.79 s, on DONE_SWEEPS whole turns.
175
+ */
176
+ const CELEBRATION_END_S = 3.79;
177
+ const CELEBRATION_SPEED = (DONE_SWEEPS * TAU + 0.5) / 2.4625;
178
+ function celebration(t) {
179
+ const v = CELEBRATION_SPEED;
180
+ if (t <= 0)
181
+ return 0;
182
+ if (t < 0.24)
183
+ return -0.25 * (1 - Math.cos((Math.PI * t) / 0.24));
184
+ if (t < 0.54)
185
+ return -0.5 + (v * (t - 0.24) ** 2) / 0.6;
186
+ if (t < 2.54)
187
+ return -0.5 + v * (t - 0.39);
188
+ if (t < CELEBRATION_END_S)
189
+ return -0.5 + v * 2.15 + (1.25 * v * (1 - (1 - (t - 2.54) / 1.25) ** 4)) / 4;
190
+ return DONE_SWEEPS * TAU;
87
191
  }
88
- function moodPose({ seed, time, motion, gaze, reducedMotion, view }) {
192
+ function statePose(input) {
193
+ const { seed, time, gaze, reducedMotion, view } = input;
194
+ const { state, mood } = resolveLook(input);
89
195
  // Per-avatar phase offset so several avatars on a page do not move in lockstep.
90
196
  const t = reducedMotion ? 0 : time + noise(seed, 7) * 10;
197
+ const live = reducedMotion ? 0 : 1;
91
198
  const wave = (period, phase = 0) => (reducedMotion ? 0 : Math.sin((TAU * t) / period + phase));
92
199
  const given = gaze && Number.isFinite(gaze.x) && Number.isFinite(gaze.y)
93
200
  ? [clamp(gaze.x, -1, 1), clamp(gaze.y, -1, 1)]
@@ -97,56 +204,147 @@ function moodPose({ seed, time, motion, gaze, reducedMotion, view }) {
97
204
  const sway = 1 - 0.7 * weight;
98
205
  const pose = {
99
206
  yaw: BASE_YAW, pitch: BASE_PITCH, roll: 0, lift: 0, sx: 1, sy: 1,
100
- gazeX: 0, gazeY: 0, blink: 0, squintL: 0, squintR: 0, eyeShape: 'pill',
207
+ gazeX: 0, gazeY: 0, blink: 0, squintL: 0, squintR: 0,
208
+ eyes: { arc: mood === 'happy' ? 1 : 0, slit: 0 }, ribbons: 0, cage: 0, sweep: 0, bang: 0, dots: 0,
209
+ };
210
+ /** The calm pose of a bot with nothing to do: it breathes, sways, blinks and looks around. */
211
+ const rest = (pace) => {
212
+ pose.yaw += 0.07 * sway * wave(6.1 * pace);
213
+ pose.pitch += 0.04 * sway * wave(4.7 * pace, 1);
214
+ pose.roll = 1.6 * wave(5.3 * pace, 2);
215
+ pose.lift = reducedMotion ? 0 : -0.45 * (1 - Math.cos((TAU * t) / (3.4 * pace)));
216
+ const breath = wave(3.4 * pace, -Math.PI / 2);
217
+ pose.sy = 1 + 0.012 * breath;
218
+ pose.sx = 1 - 0.008 * breath;
219
+ if (!reducedMotion) {
220
+ pose.blink = blinkAt(seed, t);
221
+ [pose.gazeX, pose.gazeY] = wanderAt(seed, t);
222
+ }
101
223
  };
102
- if (motion === 'happy') {
224
+ if (state === 'idle' && mood === 'happy') {
225
+ // With nothing to do, a happy bot hops.
103
226
  const period = 0.92;
104
227
  const p = reducedMotion ? 0.5 : ((t % period) + period) % period / period;
105
228
  const air = 4 * p * (1 - p);
106
229
  const land = reducedMotion ? 0 : clamp(1 - Math.min(p, 1 - p) / 0.12, 0, 1);
107
230
  pose.lift = reducedMotion ? 0 : -3.2 * air;
108
- pose.sy = 1 - 0.09 * land + 0.03 * air * (reducedMotion ? 0 : 1);
109
- pose.sx = 1 + 0.07 * land - 0.015 * air * (reducedMotion ? 0 : 1);
231
+ pose.sy = 1 - 0.09 * land + 0.03 * air * live;
232
+ pose.sx = 1 + 0.07 * land - 0.015 * air * live;
110
233
  pose.roll = 4.5 * wave(period * 2);
111
234
  pose.yaw += 0.1 * wave(period * 2, 0.6);
112
- pose.eyeShape = 'happy';
113
235
  }
114
- else if (motion === 'thinking') {
236
+ else if (state === 'thinking') {
237
+ // Looks up and away while it gives way to the three dots.
115
238
  pose.yaw += 0.12 + 0.05 * sway * wave(7.3);
116
239
  pose.pitch += 0.08;
117
240
  pose.roll = -5 + 1.4 * wave(4.1);
118
- pose.lift = -0.5 * (1 - Math.cos((TAU * t) / 5.2)) * (reducedMotion ? 0 : 1);
241
+ pose.lift = -0.5 * (1 - Math.cos((TAU * t) / 5.2)) * live;
119
242
  pose.gazeX = 0.55 + 0.3 * wave(5.6);
120
243
  pose.gazeY = -0.8;
121
244
  pose.squintL = 0.22;
122
245
  pose.squintR = 0.32 + 0.1 * wave(3.1);
123
246
  if (!reducedMotion)
124
247
  pose.blink = blinkAt(seed, t * 0.7);
248
+ pose.dots = 1;
125
249
  }
126
- else {
127
- pose.yaw += 0.07 * sway * wave(6.1);
128
- pose.pitch += 0.04 * sway * wave(4.7, 1);
129
- pose.roll = 1.6 * wave(5.3, 2);
130
- pose.lift = reducedMotion ? 0 : -0.45 * (1 - Math.cos((TAU * t) / 3.4));
131
- const breath = wave(3.4, -Math.PI / 2);
132
- pose.sy = 1 + 0.012 * breath;
133
- pose.sx = 1 - 0.008 * breath;
134
- if (!reducedMotion) {
135
- pose.blink = blinkAt(seed, t);
136
- [pose.gazeX, pose.gazeY] = wanderAt(seed, t);
250
+ else if (state === 'working') {
251
+ // Bent over the work and busy: a quick steady bob and eyes darting across it, and every so
252
+ // often a turn with a band of ribbons sweeping round it.
253
+ const beat = wave(0.7);
254
+ pose.yaw += 0.08 * sway * wave(2.3, 0.4);
255
+ pose.pitch -= 0.05;
256
+ pose.roll = 3 + 0.6 * beat;
257
+ pose.lift = -0.3 * (0.5 + 0.5 * beat) * live;
258
+ pose.sy = 0.99 - 0.008 * beat;
259
+ pose.sx = 1.005 + 0.005 * beat;
260
+ pose.squintL = 0.25;
261
+ pose.squintR = 0.25;
262
+ if (reducedMotion) {
263
+ pose.gazeX = 0.15;
264
+ pose.gazeY = 0.3;
265
+ }
266
+ else {
267
+ [pose.gazeX, pose.gazeY] = dartAt(seed, t);
268
+ pose.blink = blinkAt(seed, t * 1.3);
269
+ }
270
+ // Counted from when the state began; without an age, from the clock.
271
+ const age = Number.isFinite(input.stateAge) ? Math.max(0, input.stateAge) : Math.max(0, time);
272
+ const into = reducedMotion ? null : workTurn(seed, age);
273
+ if (into !== null) {
274
+ // A full circle that eases in like a spring settling. The band rides it round, out at the
275
+ // start and back in at the end; the body keeps facing the work, leaning into the sweep, and
276
+ // the eyes follow the band across.
277
+ const e = WORK_EASE * into;
278
+ const turn = TAU * (1 - (1 + e) * Math.exp(-e));
279
+ const swell = Math.sin(turn / 2);
280
+ pose.ribbons = clamp(into / 0.16, 0, 1) * clamp((WORK_TURN_S - into) / 0.5, 0, 1);
281
+ pose.sweep = turn;
282
+ pose.yaw += 0.22 * swell;
283
+ pose.roll += 3 * swell;
284
+ pose.lift -= 1.2 * swell;
285
+ pose.gazeX = clamp(pose.gazeX * (1 - swell) - 0.85 * Math.sin(turn), -1, 1);
286
+ pose.gazeY = pose.gazeY * (1 - swell) - 0.3 * swell;
287
+ }
288
+ }
289
+ else if (state === 'waiting') {
290
+ // Leans to one side, eyes flattened to slits, glancing off at whatever it is waiting on.
291
+ // Now and then it sighs. A happy bot keeps its arcs.
292
+ const p = reducedMotion ? 0 : ((t % 6.5) + 6.5) % 6.5 / 6.5;
293
+ // One breath in and out over the first third of the cycle.
294
+ const sigh = Math.sin(TAU * clamp(p / 0.33, 0, 1));
295
+ pose.yaw += 0.04 * sway * wave(7.4);
296
+ pose.pitch += 0.02 + 0.03 * sigh;
297
+ pose.roll = 7 + 1.2 * wave(6.4, 2);
298
+ pose.lift = -0.3 * (1 - Math.cos((TAU * t) / 6.5)) * live;
299
+ pose.sy = 1 + 0.025 * sigh;
300
+ pose.sx = 1 - 0.012 * sigh;
301
+ pose.gazeX = 0.5 + 0.15 * wave(8.2);
302
+ pose.gazeY = 0.1;
303
+ pose.eyes.slit = 1 - pose.eyes.arc;
304
+ if (!reducedMotion)
305
+ pose.blink = blinkAt(seed, t * 0.6);
306
+ }
307
+ else if (state === 'blocked') {
308
+ // Stops still while it gives way to the exclamation mark.
309
+ pose.sy = 1.02;
310
+ pose.sx = 0.99;
311
+ pose.bang = 1;
312
+ }
313
+ else if (state === 'done') {
314
+ // Celebrates: a few turns with ribbons flying round it, then a rest, content and a little
315
+ // slower than idle, and after a while again, the other way round.
316
+ rest(1.25);
317
+ // Counted from when the state began. Without an age it is at rest.
318
+ const age = !reducedMotion && Number.isFinite(input.stateAge) ? Math.max(0, input.stateAge) : DONE_TURN_S;
319
+ const length = DONE_CYCLE_S * (1 + 0.15 * noise(seed, 31));
320
+ const cycle = Math.floor(age / length), since = age - cycle * length;
321
+ if (since < DONE_TURN_S) {
322
+ const swell = Math.sin((Math.PI * since) / DONE_TURN_S);
323
+ const way = cycle % 2 ? -1 : 1;
324
+ const sweep = celebration(since) * way;
325
+ // The body turns a third as often as the ribbons go round.
326
+ pose.yaw += near(sweep / 3);
327
+ pose.lift -= 2.2 * swell;
328
+ pose.sy += 0.04 * swell;
329
+ // All the ribbons out at full strength while the turn is quick, drawn back in as it settles.
330
+ pose.ribbons = clamp(since / 0.1, 0, 1) * clamp((DONE_TURN_S - since) / DONE_DRAW_IN_S, 0, 1);
331
+ pose.cage = 1;
332
+ // The ribbons only set off once the turn goes forward: the wind-up does not carry them.
333
+ pose.sweep = way * Math.max(0, celebration(since));
137
334
  }
138
335
  }
336
+ else {
337
+ rest(1);
338
+ }
139
339
  if (given && weight > 0) {
140
340
  // A look target wins over idle wander. The body turns to face it: the resting
141
341
  // three-quarter turn gives way (so a target on either side turns the front that
142
342
  // way) and the eyes add a modest share on top. Reduced motion keeps the body
143
- // still, so the eyes alone use their full (still small) range.
144
- const mix = (a, b) => a + (b - a) * weight;
343
+ // still, so the eyes alone use their full (still small) range. Happy arcs stay put.
145
344
  const share = reducedMotion ? 1 : LOOK_EYES;
146
- if (pose.eyeShape === 'pill') {
147
- pose.gazeX = mix(pose.gazeX, given[0] * share);
148
- pose.gazeY = mix(pose.gazeY, given[1] * share);
149
- }
345
+ const follow = weight * (1 - pose.eyes.arc);
346
+ pose.gazeX = mix(pose.gazeX, given[0] * share, follow);
347
+ pose.gazeY = mix(pose.gazeY, given[1] * share, follow);
150
348
  if (!reducedMotion) {
151
349
  // Positive yaw turns the front to the right, positive pitch tips it up.
152
350
  pose.yaw += weight * (given[0] * LOOK_YAW - BASE_YAW);