Skip to content

Turn any SVG into a professional 60 fps animation. A Claude Code skill that brings anything drawn to life: live faces, full-body acting and whole scenes, in React Native and SwiftUI.

Swift

rossark-motion-skill: living illustrations for SVG characters

Eder Rosaaa3a353f73b9
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f4b80ff
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 rossark0
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/MOTION.md b/MOTION.md
new file mode 100644
index 0000000..d215231
--- /dev/null
+++ b/MOTION.md
@@ -0,0 +1,101 @@
+# MOTION.md: living illustrations in this project
+
+> Copy this file next to the project's illustrations (for example `src/art/MOTION.md`) and fill in **Part 2** as you learn the project. Part 1 is the method and stays as it is. The `rossark-motion-skill` reads this file first, and Part 2 overrides the skill's defaults.
+
+---
+
+## Part 1. The method
+
+**The goal:** characters that feel alive and calm. Nothing teleports, nothing bounces, nothing shouts.
+
+### Rules
+1. **Never swap drawings mid-motion.** Pupils slide, lids lower and rise, mouths open and close, heads rotate.
+2. **No bounce.** Timed motion with strong curves, never springy overshoot.
+3. **Small amplitudes.**
+ - breathing: 1 to 2 units;
+ - head tilt: 3 to 6°;
+ - gaze: a few units inside the eye.
+4. **Opacity only to appear or disappear**, never to dim a part halfway.
+5. **The art keeps its layout.** Motion happens inside the drawing (translate and rotate on groups), never by resizing or moving the view.
+6. **Reduced motion means still.** Frame 0 of every clock must be a good drawing.
+7. **One main action per scene, plus two or three idle loops.** Side characters and mascots stay quiet.
+8. **Unique SVG ids** (clip paths are global to the screen).
+
+### Curves
+- **Things that travel** (gaze, head, lid closing): ease-in-out `bezier(0.77, 0, 0.175, 1)`.
+- **Things that open** (mouth, lid reopening, a prop appearing): ease-out `bezier(0.23, 1, 0.32, 1)`.
+- **Endless loops** (rain, conveyor, rotation): linear.
+- **Declare easings at the top of the module:** worklets capture them when they are created.
+
+### The live face
+1. Draw the eyes as plain whites, with no pupils.
+2. On top, in the head's coordinates, draw:
+ - the live eyes: the pupil slides, clipped to the white, and the lid and cheek are skin clipped to a shape 2 units larger than the white;
+ - then whatever covers the lids (nose, fringe);
+ - then the live mouth.
+3. **One clock per character** (0 to `period` ms, looping). Every channel is a keyframe track `[ms, value, 'out'?]` read from it:
+ - `lookX` and `lookY`: where the pupil looks;
+ - `lid`, 0 open to 1 closed (`lidRight` for one eye only);
+ - `cheek`, 0 to 1, for a happy squint;
+ - `mouth`, the depth of the open mouth;
+ - `tilt`, the head angle in degrees.
+4. **A loop of 6 to 9 s:**
+ - a resting gaze, plus one or two glances that glide in about 500 ms and hold for at least 1 s;
+ - a blink every 3 to 4 s: close in ~90 ms, hold up to 60 ms, reopen in ~150 ms with ease-out;
+ - the last key equals the first.
+
+| Feeling | Gaze | Lid | Extra |
+|---|---|---|---|
+| tired | down or at a screen | rests at 0.3 to 0.4 | slow blinks |
+| sad | down and away | rests at 0.1 | slow blinks, one slow look up |
+| happy | at the viewer or a friend | 0 | `cheek` up once per loop |
+| talking | at the listener | 0 | `mouth` in syllables |
+| focused | on the task | 0.1 | rare blinks |
+
+### Body, head, scene
+- **Breathing:** the character's layer rises 1 to 2 units over 3 to 5 s, ease-in-out. Characters on the same screen breathe out of phase.
+- **Head tilt:** layers for back hair, body, head and front, with the head and back hair rotating around the neck pivot. Don't tilt if a hand touches the face.
+- **Cropped by an edge:** draw a few units below the crop, so the cut never shows when the character rises.
+- **Props:**
+ - steam rises and fades in and out (`sin(π·p)`);
+ - rain and drift are linear loops, each with its own phase;
+ - a clock's colon blinks and its hand steps;
+ - a phone buzzes in short ±3° bursts, then pauses.
+- **A scene that tells an action** plays a one-shot clock when it appears, with windows for each beat. After that, only the idle loops run.
+
+### Performance
+- One clock per character or scene; everything else is a worklet reading it.
+- Freeze clocks off screen, when hidden and with reduced motion. A loop running behind opacity 0 still costs.
+- A repeating animation restarts from its current value: reset to 0 before starting, and cancel on cleanup.
+- Prefer one SVG per layer over many animated views.
+
+### Workflow
+1. Read Part 2 and the header comments of the illustration file.
+2. List what could live, pick one main action and two or three idle loops.
+3. Put every number in a token object at the top of the file.
+4. Check frame 0 and that every loop closes without a jump.
+5. Run the project's checks.
+6. Hand off: what moves, and what hasn't been seen on a real device.
+
+---
+
+## Part 2. This project
+
+> Fill these in. Delete the hints in *italics* as you go.
+
+### Where the code is
+- **Live face module:** *path, or "copy `templates/liveFace.tsx` from the skill"*
+- **Character / kit / poses:** *paths, and the character's coordinate system (where the head centre is, units)*
+- **Existing animated scenes to copy from:** *paths*
+
+### The owner's rules
+*Quote them in their own words, with the date. They override Part 1.*
+- …
+
+### Rig limits
+*Which poses or characters can't do what (no separate head layer, eyes baked into the drawing, a hand on the face).*
+- …
+
+### How changes are checked
+*Device or simulator, who tests, the type, lint and test commands, known pre-existing errors.*
+- …
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7d5ae68
--- /dev/null
+++ b/README.md
@@ -0,0 +1,39 @@
+# rossark-motion-skill
+
+A Claude Code skill for bringing character illustrations to life: eyes whose pupils glide and lids blink, breathing, head tilts, and small scene props (steam, rain, a ticking clock, a buzzing phone). Calm, believable motion that never teleports and never bounces.
+
+It's written for React Native (`react-native-svg` + `react-native-reanimated`), and the method works the same on the web.
+
+## What's inside
+
+| File | What it is |
+|---|---|
+| `SKILL.md` | The skill: rules, curves, the live face, choreography recipes, body/head/scene motion, performance pitfalls and a workflow. |
+| `MOTION.md` | A notes file to copy into your project. Part 1 is the method in short form; Part 2 is where your project's specifics go (where the code is, the owner's rules, rig limits, how changes are checked). The skill reads it first. |
+| `templates/liveFace.tsx` | A ready-to-copy live face: `LiveEye`, `LiveMouth`, keyframe `track`, `Choreo` and `useChoreoClock`. You give it the eye geometry and colours; nothing else is assumed. |
+
+## Install
+
+For all your projects:
+
+```bash
+git clone https://github.com/rossark0/rossark-motion-skill ~/.claude/skills/rossark-motion-skill
+```
+
+For one project only, clone it into that project's `.claude/skills/rossark-motion-skill` instead.
+
+Then, in Claude Code, ask to animate an illustration, or type `/rossark-motion-skill`.
+
+## First time in a project
+
+1. Copy `MOTION.md` next to your illustrations (for example `src/art/MOTION.md`).
+2. Fill in Part 2 as you go: the files, your rules (in your own words), what your rig can't do, and how you test.
+3. If you don't have a live-face module yet, copy `templates/liveFace.tsx` into the project and set the eye geometry to match your character.
+
+## The idea in one paragraph
+
+Draw the character once, with plain eye whites. On top, in the head's coordinates, live eyes slide their pupils and lower their lids, and the cheeks push up for a happy squint. One looping clock per character feeds keyframe tracks (gaze, lid, cheek, mouth, tilt), eased with strong curves. The body breathes a unit or two, the head tilts a few degrees around the neck, and props loop quietly. Everything stops on a good-looking frame 0 when the user asks for reduced motion, and nothing runs off screen.
+
+## License
+
+MIT. See `LICENSE`.
diff --git a/SKILL.md b/SKILL.md
new file mode 100644
index 0000000..e658792
--- /dev/null
+++ b/SKILL.md
@@ -0,0 +1,117 @@
+---
+name: rossark-motion-skill
+description: Bring character illustrations to life (mascots, people, scenes drawn in SVG) with calm, believable idle motion. Eyes whose pupils glide and lids blink, breathing, head tilts, and small scene props like steam, rain, a ticking clock or a buzzing phone. Use it whenever someone asks to animate an illustration, make a character "feel alive", add blinking or breathing, or build a scene's motion. Written for React Native (react-native-svg + Reanimated); the method also works on the web.
+---
+
+# rossark-motion-skill: living illustrations
+
+A method for making drawn characters feel alive without making them busy. It came from a production app's onboarding and paywall art, where the brief was "the character has to feel ALIVE" and "NO TELEPORTING in the animation".
+
+## 0. Read the project's notes first
+
+Before touching anything, look for the project's own motion notes: a `MOTION.md` next to the illustrations (search the repo for `MOTION.md`), the project's `CLAUDE.md`, and any saved memory about animation. **Project rules override the defaults below.** They usually name the existing live-face module, the character kit, poses that can't be animated a certain way, and things the owner has banned.
+
+If the project has none, copy `MOTION.md` from this skill's folder next to the illustrations. Its Part 1 is this method in short form; fill in Part 2 (where the code is, the owner's rules, rig limits, how changes are checked) as you learn the project, and keep it up to date after each round.
+
+## 1. Rules
+
+- **Never swap drawings mid-motion.** Pupils slide, lids lower and rise, mouths open and close, heads rotate. Snapping from one expression to another is "teleporting", and it is what makes animation look cheap.
+- **No bounce.** Use timed motion with strong curves (below), not springy overshoot. Characters breathe; they don't wobble.
+- **Small amplitudes.**
+ - breathing: 1 to 2 drawing units;
+ - head tilt: 3 to 6 degrees;
+ - gaze: a few units inside the eye.
+ This is life, not a dance.
+- **Opacity only for appearing and disappearing** (steam, raindrops, a notification). Never use it to dim a part halfway.
+- **Never animate the view's size or position on the page.** The art keeps its layout; motion happens inside the drawing (translate and rotate on groups). The size goes in as a transform matrix, not as a view scale.
+- **Reduced motion means still.** Every clock frozen at 0, and frame 0 must be a good-looking drawing on its own.
+- **One main action per scene, plus two or three idle loops.** Mascots and side characters stay quiet unless the scene is about them.
+- **Unique ids.** SVG `clipPath` ids are global to the screen.
+
+## 2. Curves
+
+```ts
+// At the TOP of the module: a worklet captures what it references when it's created,
+// and easings declared further down are undefined inside it.
+const EASE_IN_OUT = Easing.bezierFn(0.77, 0, 0.175, 1); // things that travel: gaze, head, lid closing
+const EASE_OUT = Easing.bezierFn(0.23, 1, 0.32, 1); // things that open: mouth, lid reopening, a prop appearing
+```
+
+Continuous loops (rain, conveyor, rotating sun) are linear.
+
+## 3. The live face
+
+A ready-made module is in `templates/liveFace.tsx` (in this skill's folder). Copy it into the project, or use the project's own version if the notes name one. It exports `LiveEye`, `LiveMouth`, `track`, `Choreo`, `Keys` and `useChoreoClock`.
+
+1. **The static eyes.** Draw the character with plain eye whites and no pupils (if the character comes from a kit, use its "no pupils" option).
+2. **The live layer.** Inside the same transform as the head, draw two `LiveEye` on top, then anything that must cover the lids (nose, hair, glasses), then `LiveMouth` if the mouth talks or laughs.
+3. **The clock.** Run one clock per character, and derive every channel from it:
+
+```tsx
+const clock = useChoreoClock(CHOREO.period, live); // live = on screen && !reducedMotion
+<G transform={`translate(${headX} ${headY}) scale(${s})`}>
+ <LiveEye side={-1} eye={EYE_L} ink={INK} choreo={CHOREO} clock={clock} id="introEyeL" />
+ <LiveEye side={1} eye={EYE_R} ink={INK} choreo={CHOREO} clock={clock} id="introEyeR" />
+ {/* nose / hair fringe here, above the lids */}
+</G>
+```
+
+### The choreography
+
+A `Choreo` holds keyframe tracks `[ms, value, 'out'?]`. Each segment eases in and out, or eases out when marked `'out'`.
+
+| Track | What it moves |
+|---|---|
+| `lookX` / `lookY` | pupil offset |
+| `lid` (and `lidRight`) | upper eyelid, from 0 (open) to 1 (closed) |
+| `cheek` | happy squint, from 0 to 1 |
+| `mouth` | depth of the open mouth |
+| `tilt` | head rotation, in degrees, which you apply to the head layer |
+
+The recipe for one loop of 6 to 9 seconds:
+- **Gaze:** a resting gaze, plus one or two glances at something in the scene. Glide there in about 500 ms and hold for at least 1 s.
+- **Blinks:** one every 3 to 4 s. Close in about 90 ms with ease-in-out, hold 0 to 60 ms, and reopen in about 150 ms with `'out'`. Now and then, a double blink.
+- **The loop closes:** the last key equals the first, so the loop never jumps.
+
+| Feeling | Gaze | Lid | Extra |
+|---|---|---|---|
+| tired | down or at a screen | rests at 0.3 to 0.4 | slow blinks, one heavy blink |
+| sad | down and away | rests at 0.1 | slow blinks, one slow look up |
+| happy | at the viewer and at a friend | 0 | `cheek` up once per loop |
+| talking | at the listener | 0 | `mouth` in syllables (8 to 14, around 180 ms each) |
+| focused | fixed on the task | 0.1 | rare blinks, small saccades |
+| sleepless | wide, at the ceiling, then the clock | 0 | a slow, tired close near the end |
+
+## 4. Body, head and scene
+
+- **Breathing:** the whole body rises 1 to 2 units and comes back over 3 to 5 s, with ease-in-out, on a loop (`translateY` on the character's layer). Characters on the same screen should be out of phase.
+- **Head tilt:** split the character into layers: back hair, body, head (with the live face) and front (hands, held props). Rotate the head and back-hair layers around the neck pivot with the `tilt` track. If a hand touches the face, don't tilt; it would come apart.
+- **Cropped characters** (cut by a card edge): when they bob, draw a few units below the crop line, or the cut edge shows at the top of the motion. Things in front (a desk, a table) go on a layer above.
+- **Scene props:**
+ - **steam:** a wisp rises about 10 units while its opacity follows `sin(π·p)`, so it fades in and out;
+ - **rain and drift:** linear loops, each item with its own phase;
+ - **ticking clock:** the colon blinks every 0.5 s and a hand steps once a second, with ease-out;
+ - **buzzing phone:** short bursts of ±3 degrees (4 cycles in about 0.45 s), then a pause, with vibration ticks that show only during the burst.
+- **A scene that tells an action** (press, buzz, a message arrives): run a one-shot clock that plays once when the scene appears, with windows `seg(t, a, b)` for each beat. After that, only the idle loops run.
+
+## 5. Performance and pitfalls
+
+- One clock per character or scene; everything else is a worklet reading it.
+- Put `live` in the dependencies of every `useAnimatedProps`, and freeze clocks for anything off screen or hidden. A layer at opacity 0 with a running loop still costs.
+- `withRepeat` restarts from the current value: set it to 0 before starting again, and cancel in the effect cleanup.
+- Clip the skin (lid, cheek) to a shape 2 units larger than the eye white. Clipped to the exact white, the anti-aliased edge leaks around a closed eye and looks like glasses.
+- Prefer one SVG per layer over many animated views. Canvas engines (Skia) are heavier: don't multiply them.
+
+## 6. Workflow
+
+1. Read the project notes (section 0) and the header comments of the illustration file; decisions recorded there are law.
+2. List what could live: the face, the body, the head, the props and the mascot.
+3. Pick ONE main action and two or three idle loops. Less is more.
+4. Put every number in a token object at the top of the file, so "slower" or "smaller" is a one-line change.
+5. Check frame 0 (reduced motion) and that every loop closes without a jump.
+6. Run the project's type check, lint and tests.
+7. Hand off in plain words: what moves on each screen, and what has not been seen on a real device yet.
+
+## On the web
+
+The same model works: one clock (`requestAnimationFrame`, or a Motion value) feeding keyframe tracks into SVG attributes. Animate only `transform` and `opacity`, and respect `prefers-reduced-motion`.
diff --git a/templates/liveFace.tsx b/templates/liveFace.tsx
new file mode 100644
index 0000000..91cc5c3
--- /dev/null
+++ b/templates/liveFace.tsx
@@ -0,0 +1,256 @@
+// liveFace.tsx: a living face for SVG characters (react-native-svg + react-native-reanimated 3/4).
+//
+// Nothing ever swaps drawings: the pupil SLIDES, the eyelid LOWERS and RISES, the
+// cheek pushes up for a happy squint, the mouth OPENS and CLOSES. One clock per
+// character drives every channel through keyframe tracks.
+//
+// Usage (see SKILL.md, "The live face"):
+// 1. Draw your character's eyes as plain whites, with no pupils.
+// 2. Inside the same <G> transform as the head, draw two <LiveEye> on top,
+// then anything that must cover the eyelids (nose, hair, glasses).
+// 3. One `useChoreoClock(choreo.period, live)` per character.
+import React, { useEffect } from 'react';
+import Animated, {
+ Easing,
+ cancelAnimation,
+ useAnimatedProps,
+ useSharedValue,
+ withRepeat,
+ withTiming,
+ type SharedValue,
+} from 'react-native-reanimated';
+import { Circle, ClipPath, Defs, G, Line, Path, Rect } from 'react-native-svg';
+
+// ⚠️ Keep these at the TOP of the module. A worklet captures what it uses when
+// it is created; easings declared further down are undefined inside it.
+const EASE_IN_OUT = Easing.bezierFn(0.77, 0, 0.175, 1); // things that travel: gaze, head, lid closing
+const EASE_OUT = Easing.bezierFn(0.23, 1, 0.32, 1); // things that open: mouth, lid reopening
+
+const ARect = Animated.createAnimatedComponent(Rect);
+const APath = Animated.createAnimatedComponent(Path);
+const ACircle = Animated.createAnimatedComponent(Circle);
+const ALine = Animated.createAnimatedComponent(Line);
+
+/** A keyframe: time (ms), value, and the curve of the segment ARRIVING here ('out', or ease-in-out by default). */
+export type Key = readonly [number, number, 'out'?];
+export type Keys = readonly Key[];
+
+/** The value of a track at time `t`. */
+export function track(t: number, keys: Keys): number {
+ 'worklet';
+ if (t <= keys[0][0]) return keys[0][1];
+ for (let i = 1; i < keys.length; i++) {
+ const k1 = keys[i];
+ if (t <= k1[0]) {
+ const k0 = keys[i - 1];
+ const span = k1[0] - k0[0];
+ const p = span > 0 ? (t - k0[0]) / span : 1;
+ const e = k1[2] === 'out' ? EASE_OUT(p) : EASE_IN_OUT(p);
+ return k0[1] + (k1[1] - k0[1]) * e;
+ }
+ }
+ return keys[keys.length - 1][1];
+}
+
+/**
+ * One character's choreography. `lookX`/`lookY`: pupil offset in eye units.
+ * `lid`: upper eyelid, 0 open to 1 closed (`lidRight` for a one-eyed blink or wink).
+ * `cheek`: 0 to 1, the cheek rising into a happy squint. `mouth`: open-mouth depth.
+ * `tilt`: head rotation in degrees (applied by you, on the head layer).
+ */
+export type Choreo = {
+ period: number;
+ lookX: Keys;
+ lookY: Keys;
+ lid: Keys;
+ lidRight?: Keys;
+ cheek?: Keys;
+ mouth?: Keys;
+ tilt?: Keys;
+};
+
+/** A looping clock from 0 to `period` ms. Frozen at 0 when `live` is false (reduced motion, off screen). */
+export function useChoreoClock(period: number, live: boolean): SharedValue<number> {
+ const clock = useSharedValue(0);
+ useEffect(() => {
+ cancelAnimation(clock);
+ // withRepeat restarts from the CURRENT value: always reset first.
+ clock.value = 0;
+ if (!live) return;
+ clock.value = withRepeat(withTiming(period, { duration: period, easing: Easing.linear }), -1);
+ return () => cancelAnimation(clock);
+ }, [live, period, clock]);
+ return clock;
+}
+
+/** A rounded pill (stadium) path centred on (cx, cy). */
+export function pill(cx: number, cy: number, w: number, h: number): string {
+ const r = Math.min(w, h) / 2;
+ const x = cx - w / 2;
+ const y = cy - h / 2;
+ return `M${x + r} ${y}H${x + w - r}A${r} ${r} 0 0 1 ${x + w} ${y + r}V${y + h - r}A${r} ${r} 0 0 1 ${x + w - r} ${y + h}H${x + r}A${r} ${r} 0 0 1 ${x} ${y + h - r}V${y + r}A${r} ${r} 0 0 1 ${x + r} ${y}Z`;
+}
+
+/** Where one eye sits, in the head's own coordinates. */
+export type EyeGeometry = {
+ /** Centre of the eye white. */
+ cx: number;
+ cy: number;
+ /** Size of the eye white (a pill). */
+ w: number;
+ h: number;
+ /** Pupil size, and its top edge measured from the top of the eye white. */
+ pupilW: number;
+ pupilH: number;
+ pupilTop: number;
+ /** Radius of the highlight dot. 0 for none. */
+ shine: number;
+};
+
+export type FaceInk = {
+ white: string;
+ pupil: string;
+ /** The skin colour: eyelid and cheek are skin sliding over the white. */
+ skin: string;
+ /** Lines: lash edge, closed eye, happy-squint arc. */
+ line: string;
+ lineWidth?: number;
+};
+
+/**
+ * A living eye. Pupil and shine slide, clipped to the white. The lid and cheek
+ * are skin clipped to a pill 2 units LARGER than the white: clipped to the exact
+ * white, the anti-aliased white edge leaks around a closed eye and reads as
+ * glasses. The closed-eye line appears only when the lid is nearly down.
+ */
+export function LiveEye({
+ side,
+ eye,
+ ink,
+ choreo,
+ clock,
+ id,
+}: {
+ /** -1 the eye on the viewer's left, 1 the right (mirrors the closed-eye line). */
+ side: -1 | 1;
+ eye: EyeGeometry;
+ ink: FaceInk;
+ choreo: Choreo;
+ clock: SharedValue<number>;
+ /** UNIQUE on screen: SVG clip ids are global. */
+ id: string;
+}) {
+ const { cx, cy, w, h, pupilW: pw, pupilH: ph } = eye;
+ const lidKeys = side === 1 && choreo.lidRight ? choreo.lidRight : choreo.lid;
+ const top = cy - h / 2 + eye.pupilTop;
+ const lidH = h + 4;
+ const lw = ink.lineWidth ?? 5;
+
+ const pupil = useAnimatedProps(() => ({
+ x: cx + track(clock.value, choreo.lookX) - pw / 2,
+ y: top + track(clock.value, choreo.lookY),
+ }));
+ const shine = useAnimatedProps(() => ({
+ cx: cx + track(clock.value, choreo.lookX) - pw * 0.22,
+ cy: top + track(clock.value, choreo.lookY) + eye.shine + 1.6,
+ }));
+ const lid = useAnimatedProps(() => ({ height: track(clock.value, lidKeys) * lidH }));
+ // The lid's edge: shows as soon as it starts down, hides when the closed line takes over.
+ const lash = useAnimatedProps(() => {
+ const l = track(clock.value, lidKeys);
+ const y = cy - h / 2 - 2 + l * lidH;
+ const on = Math.min(1, l / 0.06) * Math.min(1, Math.max(0, (0.95 - l) / 0.08));
+ return { y1: y, y2: y, strokeOpacity: on };
+ });
+ const closedD = `M${cx - side * w * 0.37} ${cy}H${cx + side * w * 0.13}Q${cx + side * w * 0.33} ${cy} ${cx + side * w * 0.37} ${cy + h * 0.17}`;
+ const closed = useAnimatedProps(() => {
+ const l = track(clock.value, lidKeys);
+ return { strokeOpacity: Math.min(1, Math.max(0, (l - 0.88) / 0.12)) };
+ });
+ const cheek = useAnimatedProps(() => {
+ const c = choreo.cheek ? track(clock.value, choreo.cheek) : 0;
+ return { y: cy + h / 2 + 2 - c * lidH, height: c * lidH };
+ });
+ const happyD = `M${cx - w * 0.4} ${cy - h * 0.1}Q${cx} ${cy - h * 0.7} ${cx + w * 0.4} ${cy - h * 0.1}`;
+ const happy = useAnimatedProps(() => {
+ const c = choreo.cheek ? track(clock.value, choreo.cheek) : 0;
+ return { strokeOpacity: Math.min(1, Math.max(0, (c - 0.86) / 0.14)) };
+ });
+
+ return (
+ <G>
+ <Defs>
+ <ClipPath id={id}>
+ <Path d={pill(cx, cy, w, h)} />
+ </ClipPath>
+ <ClipPath id={`${id}Skin`}>
+ <Path d={pill(cx, cy, w + 2, h + 2)} />
+ </ClipPath>
+ </Defs>
+ <G clipPath={`url(#${id})`}>
+ <ARect animatedProps={pupil} width={pw} height={ph} rx={pw / 2} fill={ink.pupil} />
+ {eye.shine > 0 ? <ACircle animatedProps={shine} r={eye.shine} fill={ink.white} /> : null}
+ </G>
+ <G clipPath={`url(#${id}Skin)`}>
+ <ARect animatedProps={lid} x={cx - w / 2 - 2} y={cy - h / 2 - 2} width={w + 4} fill={ink.skin} />
+ <ALine animatedProps={lash} x1={cx - w / 2 - 2} x2={cx + w / 2 + 2} stroke={ink.line} strokeWidth={lw * 0.6} />
+ {choreo.cheek ? <ARect animatedProps={cheek} x={cx - w / 2 - 2} width={w + 4} fill={ink.skin} /> : null}
+ </G>
+ <APath animatedProps={closed} d={closedD} stroke={ink.line} strokeWidth={lw} strokeLinecap="round" strokeLinejoin="round" fill="none" />
+ {choreo.cheek ? (
+ <APath animatedProps={happy} d={happyD} stroke={ink.line} strokeWidth={lw} strokeLinecap="round" fill="none" />
+ ) : null}
+ </G>
+ );
+}
+
+/**
+ * A living open mouth: the dark inside deepens and shallows, the tongue follows.
+ * `x0`/`x1` are the corners, `top` the upper lip line, `tilt` how much higher the
+ * right corner sits. It never fully closes: with the teeth on top it reads as talking.
+ */
+export function LiveMouth({
+ x0,
+ x1,
+ top,
+ tilt = 0,
+ ink,
+ choreo,
+ clock,
+ restDepth = 11,
+}: {
+ x0: number;
+ x1: number;
+ top: number;
+ tilt?: number;
+ ink: { mouth: string; tongue: string; teeth?: string };
+ choreo: Choreo;
+ clock: SharedValue<number>;
+ /** Depth used when the choreography has no `mouth` track. */
+ restDepth?: number;
+}) {
+ const mid = (x0 + x1) / 2;
+ const dark = useAnimatedProps(() => {
+ const d = choreo.mouth ? track(clock.value, choreo.mouth) : restDepth;
+ return {
+ d: `M${x0} ${top}L${x1} ${top - tilt}Q${x1 + 2} ${top + d} ${mid} ${top + d}Q${x0 - 2} ${top + d} ${x0} ${top}Z`,
+ };
+ });
+ const tongue = useAnimatedProps(() => {
+ const d = choreo.mouth ? track(clock.value, choreo.mouth) : restDepth;
+ const r = Math.min(d * 0.36, (x1 - x0) * 0.22);
+ return { cy: top + d - r - 1.5, r };
+ });
+ return (
+ <G>
+ <APath animatedProps={dark} fill={ink.mouth} />
+ <ACircle animatedProps={tongue} cx={mid + 1} fill={ink.tongue} />
+ {ink.teeth ? (
+ <Path
+ d={`M${x0 + 1} ${top}L${x1 - 1} ${top - tilt}L${x1 - 1.5} ${top - tilt + 5}L${x0 + 1.5} ${top + 5}Z`}
+ fill={ink.teeth}
+ />
+ ) : null}
+ </G>
+ );
+}