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
Add SwiftUI: LiveFace.swift template and a SwiftUI section
Eder Rosae183f2dc826f
diff --git a/MOTION.md b/MOTION.mdindex d215231..cc5a124 100644--- a/MOTION.md+++ b/MOTION.md@@ -26,6 +26,7 @@- **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.+- **In SwiftUI:** `UnitCurve.bezier` with the same points, or `.timingCurve(...)`, and never a spring with bounce.### The live face1. Draw the eyes as plain whites, with no pupils.@@ -84,7 +85,8 @@> 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"*+- **Platform:** *React Native, SwiftUI, web*+- **Live face module:** *path, or "copy `templates/liveFace.tsx` (React Native) or `templates/LiveFace.swift` (SwiftUI) 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*diff --git a/README.md b/README.mdindex 7d5ae68..4f4a71e 100644--- a/README.md+++ b/README.md@@ -2,7 +2,7 @@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.+It comes with ready-made templates for React Native (`react-native-svg` + `react-native-reanimated`) and SwiftUI (`TimelineView` + `Canvas`, iOS 17+ / macOS 14+), and the method works the same on the web.## What's inside@@ -10,7 +10,8 @@ It's written for React Native (`react-native-svg` + `react-native-reanimated`),|---|---|| `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. |+| `templates/liveFace.tsx` | React Native: a ready-to-copy live face (`LiveEye`, `LiveMouth`, keyframe `track`, `Choreo`, `useChoreoClock`). You give it the eye geometry and colours; nothing else is assumed. |+| `templates/LiveFace.swift` | SwiftUI: the same live face (`drawLiveEye`, `drawLiveMouth`, `track`, `Choreo`, `ChoreoClock`), drawn into a `Canvas` and driven by a `TimelineView`. |## Install@@ -28,7 +29,7 @@ Then, in Claude Code, ask to animate an illustration, or type `/rossark-motion-s1. 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.+3. If you don't have a live-face module yet, copy `templates/liveFace.tsx` (React Native) or `templates/LiveFace.swift` (SwiftUI) into the project, and set the eye geometry to match your character.## The idea in one paragraphdiff --git a/SKILL.md b/SKILL.mdindex e658792..1f576b8 100644--- a/SKILL.md+++ b/SKILL.md@@ -1,6 +1,6 @@---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.+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. Ready-made templates for React Native (react-native-svg + Reanimated) and SwiftUI (TimelineView + Canvas); the method also works on the web.---# rossark-motion-skill: living illustrations@@ -41,7 +41,11 @@ 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`.+Ready-made modules live in this skill's `templates/` folder. Copy the one for your platform into the project, or use the project's own version if the notes name one:+- **React Native:** `templates/liveFace.tsx` exports `LiveEye`, `LiveMouth`, `track`, `Choreo`, `Keys` and `useChoreoClock`.+- **SwiftUI:** `templates/LiveFace.swift` exports `drawLiveEye`, `drawLiveMouth`, `track`, `Choreo`, `Key` and `ChoreoClock`. See the SwiftUI section below.++The steps, and the React Native example: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.@@ -112,6 +116,43 @@ The recipe for one loop of 6 to 9 seconds: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.+## SwiftUI++The same method, with SwiftUI's tools (iOS 17+, macOS 14+; template in `templates/LiveFace.swift`).++| Piece | React Native | SwiftUI |+|---|---|---|+| The clock | `useChoreoClock` (Reanimated `withRepeat`) | `ChoreoClock { t in ... }` (`TimelineView(.animation)`) |+| Drawing | `react-native-svg` groups | `Canvas`: `drawLiveEye` and `drawLiveMouth` into a `GraphicsContext` already in the head's coordinates |+| Curves | `Easing.bezierFn` | `UnitCurve.bezier` inside `track`; `Animation.travel(_:)` and `.open(_:)` for one-off animations |+| Reduced motion | `useReducedMotion()` | `@Environment(\.accessibilityReduceMotion)` (built into `ChoreoClock`) |+| Off screen | `live = false` | `ChoreoClock(period:, paused:)`, driven by `onAppear`/`onDisappear` and `scenePhase` |++```swift+ChoreoClock(period: choreo.period, paused: !visible) { t in+ ZStack {+ CharacterArt() // eyes drawn as plain whites, no pupils+ Canvas { ctx, _ in+ var head = ctx // the head's own coordinates+ head.translateBy(x: headX, y: headY)+ head.scaleBy(x: s, y: s)+ drawLiveEye(head, side: -1, eye: eyeL, ink: ink, choreo: choreo, t: t)+ drawLiveEye(head, side: 1, eye: eyeR, ink: ink, choreo: choreo, t: t)+ // then whatever covers the lids (nose, fringe)+ }+ .allowsHitTesting(false)+ }+}+```++- **Breathing and head tilt:** compute them from the same `t` and apply them as render-only modifiers, which never change layout:+ - breathing: `.offset(y: -track(t, breath))`;+ - head tilt: `.rotationEffect(.degrees(track(t, tilt)), anchor: neckAnchor)`, on the head layer.+- **Layers:** split the character into back-hair, body, head and front views (or images) in a `ZStack`. Tilt only the head and back hair.+- **No springs with bounce.** Avoid `.bouncy` and `.spring` with bounce. Use `.timingCurve(...)` (the `travel` and `open` helpers), or drive everything from the clock.+- **Cost:** a `TimelineView(.animation)` redraws every frame while it runs. Pause it off screen and in the background, and keep one per character or scene, not one per eye.+- **Images instead of vector art:** live eyes still work. Draw the eyes as plain whites in the artwork and lay the `Canvas` over the image, with the head's transform matching the image's coordinates.+## On the webThe 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.swift b/templates/LiveFace.swiftnew file mode 100644index 0000000..1b18e85--- /dev/null+++ b/templates/LiveFace.swift@@ -0,0 +1,265 @@+// LiveFace.swift: a living face for SwiftUI characters (iOS 17+, macOS 14+).+//+// 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 (`ChoreoClock`) drives every channel through keyframe tracks.+//+// Usage (see SKILL.md, "SwiftUI"):+// ChoreoClock(period: blink.period) { t in+// ZStack {+// CharacterArt() // eyes drawn as plain whites, no pupils+// Canvas { ctx, _ in+// var head = ctx // the head's own coordinates+// head.translateBy(x: 120, y: 90)+// head.scaleBy(x: 0.8, y: 0.8)+// drawLiveEye(head, side: -1, eye: eyeL, ink: ink, choreo: blink, t: t)+// drawLiveEye(head, side: 1, eye: eyeR, ink: ink, choreo: blink, t: t)+// // then whatever covers the lids (nose, fringe)+// }+// }+// }+import SwiftUI++// MARK: - Curves++/// Things that travel (gaze, head, lid closing): a strong ease-in-out.+private let easeInOut = UnitCurve.bezier(+ startControlPoint: UnitPoint(x: 0.77, y: 0),+ endControlPoint: UnitPoint(x: 0.175, y: 1)+)+/// Things that open (mouth, lid reopening): a strong ease-out.+private let easeOut = UnitCurve.bezier(+ startControlPoint: UnitPoint(x: 0.23, y: 1),+ endControlPoint: UnitPoint(x: 0.32, y: 1)+)++/// The same curves for SwiftUI animations elsewhere in the scene (never a bouncy spring).+public extension Animation {+ static func travel(_ duration: Double) -> Animation { .timingCurve(0.77, 0, 0.175, 1, duration: duration) }+ static func open(_ duration: Double) -> Animation { .timingCurve(0.23, 1, 0.32, 1, duration: duration) }+}++// MARK: - Keyframe tracks++/// A keyframe: time (ms), value, and whether the segment ARRIVING here eases out (default: ease-in-out).+public struct Key: Sendable {+ public let ms: Double+ public let value: Double+ public let easeOut: Bool+ public init(_ ms: Double, _ value: Double, out easeOut: Bool = false) {+ self.ms = ms+ self.value = value+ self.easeOut = easeOut+ }+}++public typealias Keys = [Key]++/// The value of a track at time `t` (ms).+public func track(_ t: Double, _ keys: Keys) -> Double {+ guard let first = keys.first else { return 0 }+ if t <= first.ms { return first.value }+ for i in 1..<keys.count {+ let k1 = keys[i]+ if t <= k1.ms {+ let k0 = keys[i - 1]+ let span = k1.ms - k0.ms+ let p = span > 0 ? (t - k0.ms) / span : 1+ let e = (k1.easeOut ? easeOut : easeInOut).value(at: p)+ return k0.value + (k1.value - k0.value) * e+ }+ }+ return keys[keys.count - 1].value+}++/// 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, a happy squint. `mouth`: open-mouth depth. `tilt`: head angle in degrees.+public struct Choreo: Sendable {+ public var period: Double+ public var lookX: Keys+ public var lookY: Keys+ public var lid: Keys+ public var lidRight: Keys?+ public var cheek: Keys?+ public var mouth: Keys?+ public var tilt: Keys?+ public init(+ period: Double, lookX: Keys, lookY: Keys, lid: Keys,+ lidRight: Keys? = nil, cheek: Keys? = nil, mouth: Keys? = nil, tilt: Keys? = nil+ ) {+ self.period = period+ self.lookX = lookX+ self.lookY = lookY+ self.lid = lid+ self.lidRight = lidRight+ self.cheek = cheek+ self.mouth = mouth+ self.tilt = tilt+ }+}++// MARK: - The clock++/// A looping clock from 0 to `period` ms. Frozen at 0 with Reduce Motion, or when `paused`+/// (off screen, app in the background). Frame 0 must be a good drawing on its own.+public struct ChoreoClock<Content: View>: View {+ let period: Double+ var paused: Bool+ let content: (Double) -> Content+ @Environment(\.accessibilityReduceMotion) private var reduceMotion+ @State private var start = Date()++ public init(period: Double, paused: Bool = false, @ViewBuilder content: @escaping (Double) -> Content) {+ self.period = period+ self.paused = paused+ self.content = content+ }++ public var body: some View {+ let still = paused || reduceMotion+ TimelineView(.animation(minimumInterval: nil, paused: still)) { context in+ let t = still ? 0 : (context.date.timeIntervalSince(start) * 1000).truncatingRemainder(dividingBy: period)+ content(t)+ }+ }+}++// MARK: - Geometry and colours++/// A rounded pill (stadium) centred on (cx, cy).+public func pill(cx: CGFloat, cy: CGFloat, w: CGFloat, h: CGFloat) -> Path {+ Path(roundedRect: CGRect(x: cx - w / 2, y: cy - h / 2, width: w, height: h), cornerRadius: min(w, h) / 2)+}++/// Where one eye sits, in the head's own coordinates.+public struct EyeGeometry: Sendable {+ public var cx: CGFloat, cy: CGFloat+ /// Size of the eye white (a pill).+ public var w: CGFloat, h: CGFloat+ /// Pupil size, and its top edge measured from the top of the eye white.+ public var pupilW: CGFloat, pupilH: CGFloat, pupilTop: CGFloat+ /// Radius of the highlight dot. 0 for none.+ public var shine: CGFloat+ public init(cx: CGFloat, cy: CGFloat, w: CGFloat, h: CGFloat, pupilW: CGFloat, pupilH: CGFloat, pupilTop: CGFloat, shine: CGFloat) {+ self.cx = cx; self.cy = cy; self.w = w; self.h = h+ self.pupilW = pupilW; self.pupilH = pupilH; self.pupilTop = pupilTop; self.shine = shine+ }+}++public struct FaceInk: Sendable {+ public var white: Color, pupil: Color+ /// The skin colour: eyelid and cheek are skin sliding over the white.+ public var skin: Color+ /// Lines: lash edge, closed eye, happy-squint arc.+ public var line: Color+ public var lineWidth: CGFloat+ public init(white: Color, pupil: Color, skin: Color, line: Color, lineWidth: CGFloat = 5) {+ self.white = white; self.pupil = pupil; self.skin = skin; self.line = line; self.lineWidth = lineWidth+ }+}++// MARK: - The live eye++/// Draws one living eye into `context`, which must already be in the head's coordinates.+/// The 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 edge leaks+/// around a closed eye and reads as glasses. `side`: -1 the eye on the viewer's left, 1 the right.+public func drawLiveEye(+ _ context: GraphicsContext, side: CGFloat, eye: EyeGeometry, ink: FaceInk, choreo: Choreo, t: Double+) {+ let cx = eye.cx, cy = eye.cy, w = eye.w, h = eye.h+ let lid = CGFloat(track(t, side > 0 ? (choreo.lidRight ?? choreo.lid) : choreo.lid))+ let lx = CGFloat(track(t, choreo.lookX))+ let ly = CGFloat(track(t, choreo.lookY))+ let top = cy - h / 2 + eye.pupilTop + ly+ let lidH = h + 4++ // The pupil and its shine, inside the white.+ context.drawLayer { c in+ c.clip(to: pill(cx: cx, cy: cy, w: w, h: h))+ let pupil = CGRect(x: cx + lx - eye.pupilW / 2, y: top, width: eye.pupilW, height: eye.pupilH)+ c.fill(Path(roundedRect: pupil, cornerRadius: eye.pupilW / 2), with: .color(ink.pupil))+ if eye.shine > 0 {+ let s = CGPoint(x: cx + lx - eye.pupilW * 0.22, y: top + eye.shine + 1.6)+ c.fill(Path(ellipseIn: CGRect(x: s.x - eye.shine, y: s.y - eye.shine, width: eye.shine * 2, height: eye.shine * 2)),+ with: .color(ink.white))+ }+ }++ // The skin that slides over it: the lid from the top, the cheek from the bottom.+ context.drawLayer { c in+ c.clip(to: pill(cx: cx, cy: cy, w: w + 2, h: h + 2))+ c.fill(Path(CGRect(x: cx - w / 2 - 2, y: cy - h / 2 - 2, width: w + 4, height: lid * lidH)), with: .color(ink.skin))+ // The lid's edge: shows as soon as it starts down, hides when the closed line takes over.+ let lashOn = min(1, lid / 0.06) * min(1, max(0, (0.95 - lid) / 0.08))+ if lashOn > 0 {+ let y = cy - h / 2 - 2 + lid * lidH+ var lash = Path()+ lash.move(to: CGPoint(x: cx - w / 2 - 2, y: y))+ lash.addLine(to: CGPoint(x: cx + w / 2 + 2, y: y))+ c.stroke(lash, with: .color(ink.line.opacity(lashOn)), lineWidth: ink.lineWidth * 0.6)+ }+ if let cheekKeys = choreo.cheek {+ let k = CGFloat(track(t, cheekKeys))+ c.fill(Path(CGRect(x: cx - w / 2 - 2, y: cy + h / 2 + 2 - k * lidH, width: w + 4, height: k * lidH)),+ with: .color(ink.skin))+ }+ }++ // The closed eye: a line with the outer tip dropping, once the lid is nearly down.+ let closedOn = min(1, max(0, (lid - 0.88) / 0.12))+ if closedOn > 0 {+ var closed = Path()+ closed.move(to: CGPoint(x: cx - side * w * 0.37, y: cy))+ closed.addLine(to: CGPoint(x: cx + side * w * 0.13, y: cy))+ closed.addQuadCurve(to: CGPoint(x: cx + side * w * 0.37, y: cy + h * 0.17),+ control: CGPoint(x: cx + side * w * 0.33, y: cy))+ context.stroke(closed, with: .color(ink.line.opacity(closedOn)),+ style: StrokeStyle(lineWidth: ink.lineWidth, lineCap: .round, lineJoin: .round))+ }++ // The happy squint: an upward arc once the cheek is nearly up.+ if let cheekKeys = choreo.cheek {+ let happyOn = min(1, max(0, (CGFloat(track(t, cheekKeys)) - 0.86) / 0.14))+ if happyOn > 0 {+ var arc = Path()+ arc.move(to: CGPoint(x: cx - w * 0.4, y: cy - h * 0.1))+ arc.addQuadCurve(to: CGPoint(x: cx + w * 0.4, y: cy - h * 0.1), control: CGPoint(x: cx, y: cy - h * 0.7))+ context.stroke(arc, with: .color(ink.line.opacity(happyOn)),+ style: StrokeStyle(lineWidth: ink.lineWidth, lineCap: .round))+ }+ }+}++// MARK: - The live mouth++/// Draws 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.+public func drawLiveMouth(+ _ context: GraphicsContext, x0: CGFloat, x1: CGFloat, top: CGFloat, tilt: CGFloat = 0,+ mouth: Color, tongue: Color, teeth: Color? = nil, choreo: Choreo, t: Double, restDepth: CGFloat = 11+) {+ let d = choreo.mouth.map { CGFloat(track(t, $0)) } ?? restDepth+ let mid = (x0 + x1) / 2+ var dark = Path()+ dark.move(to: CGPoint(x: x0, y: top))+ dark.addLine(to: CGPoint(x: x1, y: top - tilt))+ dark.addQuadCurve(to: CGPoint(x: mid, y: top + d), control: CGPoint(x: x1 + 2, y: top + d))+ dark.addQuadCurve(to: CGPoint(x: x0, y: top), control: CGPoint(x: x0 - 2, y: top + d))+ dark.closeSubpath()+ context.fill(dark, with: .color(mouth))+ let r = min(d * 0.36, (x1 - x0) * 0.22)+ let ty = top + d - r - 1.5+ context.fill(Path(ellipseIn: CGRect(x: mid + 1 - r, y: ty - r, width: r * 2, height: r * 2)), with: .color(tongue))+ if let teeth {+ var tooth = Path()+ tooth.move(to: CGPoint(x: x0 + 1, y: top))+ tooth.addLine(to: CGPoint(x: x1 - 1, y: top - tilt))+ tooth.addLine(to: CGPoint(x: x1 - 1.5, y: top - tilt + 5))+ tooth.addLine(to: CGPoint(x: x0 + 1.5, y: top + 5))+ tooth.closeSubpath()+ context.fill(tooth, with: .color(teeth))+ }+}