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 a second demo: a ring of cards orbiting a floating bird
Eder Rosabc63693e0048
diff --git a/README.md b/README.mdindex e81fe28..4568cd6 100644--- a/README.md+++ b/README.md@@ -41,22 +41,33 @@ Then, in Claude Code, ask it to animate something ("make this plant sway", "brinEvery moving thing reads a clock. A loop clock gives idle life; a one-shot clock tells a small story when a scene appears. Parts are layers that rotate around their real pivots, trailing parts lag behind, and repeated things never move in sync. Amplitudes stay small, the curves are strong and nothing bounces. Characters get live eyes: pupils glide and lids blink over plain eye whites. Everything stops on a good frame when the user asks for reduced motion, and nothing runs off screen.-## The demo+## The demos-`demo/DemoScene.swift` draws the scene above with `templates/swiftui/`:+Both are drawn with `templates/swiftui/`, on one clock each, in seamless 8-second loops.++**Room** (`demo/DemoScene.swift`, at the top of this page):- a creature that breathes, with ears that follow through and live eyes that look, blink and smile;- snow in the window, with seeded variety;- steam that rises and fades;- a candle flickering on two waves;- a plant swaying around its base, with leaves that lag behind.-Every period divides 8 s, so the loop is seamless. To render it again on macOS 14+:+**Orbit** (`demo/OrbitScene.swift`):++++- a ring of cards orbiting in depth: the fronts in front of the bird, the backs behind it, edge-on at the sides;+- the bird floats and tilts, its wings flutter, and its feet and tufts follow through;+- sparkles that appear and disappear once per loop, at seeded times.++[MP4 version](demo/orbit.mp4).++To render them again on macOS 14+:```bashswiftc -parse-as-library -target arm64-apple-macos14 \- templates/swiftui/Motion.swift templates/swiftui/LiveFace.swift \- demo/DemoScene.swift demo/render.swift -o /tmp/render-demo-/tmp/render-demo /tmp/frames+ templates/swiftui/Motion.swift templates/swiftui/LiveFace.swift demo/*.swift -o /tmp/render-demo+/tmp/render-demo room /tmp/frames # or: orbitffmpeg -framerate 30 -i /tmp/frames/%04d.png -c:v libx264 -pix_fmt yuv420p -crf 20 demo/demo.mp4```diff --git a/demo/Color+Hex.swift b/demo/Color+Hex.swiftnew file mode 100644index 0000000..e12176c--- /dev/null+++ b/demo/Color+Hex.swift@@ -0,0 +1,12 @@+// Color+Hex.swift: colours from hex for the demo scenes.+import SwiftUI++extension Color {+ init(hex: UInt32) {+ self.init(+ red: Double((hex >> 16) & 0xFF) / 255,+ green: Double((hex >> 8) & 0xFF) / 255,+ blue: Double(hex & 0xFF) / 255+ )+ }+}diff --git a/demo/DemoScene.swift b/demo/DemoScene.swiftindex 3033b9b..8c2c4b1 100644--- a/demo/DemoScene.swift+++ b/demo/DemoScene.swift@@ -227,13 +227,3 @@ struct DemoScene: View {return p}}--extension Color {- init(hex: UInt32) {- self.init(- red: Double((hex >> 16) & 0xFF) / 255,- green: Double((hex >> 8) & 0xFF) / 255,- blue: Double(hex & 0xFF) / 255- )- }-}diff --git a/demo/OrbitScene.swift b/demo/OrbitScene.swiftnew file mode 100644index 0000000..5b8e52d--- /dev/null+++ b/demo/OrbitScene.swift@@ -0,0 +1,163 @@+// OrbitScene.swift: a round bird, eyes closed in bliss, floating while a ring of cards+// orbits around it in depth, with sparkles twinkling. One clock, an 8-second loop.+import SwiftUI++struct OrbitScene: View {+ let t: Double+ static let size = CGSize(width: 720, height: 720)+ static let loopMs = 8000.0++ private enum Ink {+ static let bg = Color(hex: 0x15191F)+ static let body = Color(hex: 0x4FB6E8)+ static let bodyShade = Color(hex: 0x3A9BD0)+ static let belly = Color(hex: 0x9ADCF7)+ static let face = Color(hex: 0x7FCDF2)+ static let line = Color(hex: 0x1D5E86)+ static let beak = Color(hex: 0xFFB13B)+ static let beakShade = Color(hex: 0xE8892A)+ static let feet = Color(hex: 0xE8892A)+ static let cardFront = Color(hex: 0xE6CCFF)+ static let cardBack = Color(hex: 0xB57BFF)+ static let cardEdge = Color(hex: 0xCDA6FF)+ static let star = Color(hex: 0xB57BFF)+ static let sparkle = Color(hex: 0x86C95F)+ }++ // MARK: - Tokens++ /// The ring: centre, radii, screen tilt, card size, cards and one turn per loop.+ private let ring = (cx: 360.0, cy: 384.0, rx: 252.0, ry: 66.0, tilt: -12.0, cardW: 74.0, cardH: 96.0, count: 8, turnMs: 4000.0)++ var body: some View {+ Canvas { ctx, _ in+ ctx.fill(Path(CGRect(origin: .zero, size: Self.size)), with: .color(Ink.bg))+ drawSparkles(ctx)+ let cards = cardStates()+ for c in cards where c.depth < 0 { drawCard(ctx, c) }+ drawBird(ctx)+ for c in cards where c.depth >= 0 { drawCard(ctx, c) }+ }+ .frame(width: Self.size.width, height: Self.size.height)+ }++ // MARK: - Cards in orbit++ private struct CardState { var x: Double; var y: Double; var depth: Double; var facing: Double; var scale: Double }++ /// Each card's place on the ring now. `depth` > 0 is in front; `facing` is how much of the+ /// face we see (1 square on, 0 edge-on at the sides). Sorted back to front.+ private func cardStates() -> [CardState] {+ let tiltR = ring.tilt * .pi / 180+ var out: [CardState] = []+ for i in 0..<ring.count {+ let theta = 2 * .pi * (Double(i) / Double(ring.count) + loop(t, period: ring.turnMs))+ let lx = ring.rx * cos(theta)+ let ly = ring.ry * sin(theta)+ let x = ring.cx + lx * cos(tiltR) - ly * sin(tiltR)+ let y = ring.cy + lx * sin(tiltR) + ly * cos(tiltR)+ out.append(CardState(x: x, y: y, depth: sin(theta), facing: abs(sin(theta)), scale: 1 + 0.08 * sin(theta)))+ }+ return out.sorted { $0.depth < $1.depth }+ }++ private func drawCard(_ ctx: GraphicsContext, _ c: CardState) {+ var g = ctx+ g.translateBy(x: c.x, y: c.y)+ g.rotate(by: .degrees(ring.tilt))+ g.scaleBy(x: c.scale * max(0.07, c.facing), y: c.scale)+ let rect = CGRect(x: -ring.cardW / 2, y: -ring.cardH / 2, width: ring.cardW, height: ring.cardH)+ let shape = Path(roundedRect: rect, cornerRadius: 14)+ if c.depth >= 0 {+ g.fill(shape, with: .color(Ink.cardFront))+ if c.facing > 0.25 { g.fill(fourPointStar(r: 17), with: .color(Ink.star)) }+ } else {+ g.fill(shape, with: .color(c.facing < 0.2 ? Ink.cardEdge : Ink.cardBack))+ }+ }++ // MARK: - The bird: floats, tilts a little, wings flutter, feet lag behind++ private func drawBird(_ ctx: GraphicsContext) {+ let bob = 5 * wave(t, period: 4000)+ let tilt = 3 * wave(t, period: 8000, phase: 0.1)+ var bird = ctx+ bird.translateBy(x: 360, y: 330 + bob)+ bird.rotate(by: .degrees(tilt))++ // Feet: hang from the hips and swing a touch after the body (follow-through).+ for (i, x) in [-16.0, 16.0].enumerated() {+ var leg = bird+ leg.translateBy(x: x, y: 108)+ leg.rotate(by: .degrees(7 * wave(t, period: 4000, phase: -0.12 - 0.05 * Double(i))))+ leg.fill(Path(roundedRect: CGRect(x: -9, y: -6, width: 18, height: 42), cornerRadius: 9), with: .color(Ink.feet))+ leg.fill(Path(roundedRect: CGRect(x: -9, y: 22, width: 26, height: 16), cornerRadius: 8), with: .color(Ink.feet))+ }+ // Wings: open wide, fluttering around the shoulders.+ for side in [-1.0, 1.0] {+ var wing = bird+ wing.translateBy(x: side * 88, y: 10)+ wing.rotate(by: .degrees(side * (-18 + 6 * wave(t, period: 2000, phase: side > 0 ? 0 : 0.08))))+ wing.fill(Path(ellipseIn: CGRect(x: side > 0 ? -10 : -86, y: -26, width: 96, height: 52)), with: .color(Ink.bodyShade))+ }+ // Body, head tufts, belly, face.+ bird.fill(Path(roundedRect: CGRect(x: -110, y: -110, width: 220, height: 225), cornerRadius: 104), with: .color(Ink.body))+ for side in [-1.0, 1.0] {+ var tuft = bird+ tuft.translateBy(x: side * 58, y: -96)+ tuft.rotate(by: .degrees(side * 22 + 3 * wave(t, period: 4000, phase: -0.1)))+ tuft.fill(Path(ellipseIn: CGRect(x: -20, y: -26, width: 40, height: 40)), with: .color(Ink.body))+ }+ bird.fill(Path(ellipseIn: CGRect(x: -66, y: 18, width: 132, height: 88)), with: .color(Ink.belly))+ bird.fill(Path(roundedRect: CGRect(x: -92, y: -64, width: 184, height: 86), cornerRadius: 43), with: .color(Ink.face))+ // Eyes closed in bliss: two calm arcs.+ for side in [-1.0, 1.0] {+ var arc = Path()+ arc.move(to: CGPoint(x: side * 44 - 24, y: -26))+ arc.addQuadCurve(to: CGPoint(x: side * 44 + 24, y: -26), control: CGPoint(x: side * 44, y: 2))+ bird.stroke(arc, with: .color(Ink.line), style: StrokeStyle(lineWidth: 7, lineCap: .round))+ }+ // Beak.+ bird.fill(Path(roundedRect: CGRect(x: -17, y: -12, width: 34, height: 26), cornerRadius: 12), with: .color(Ink.beakShade))+ bird.fill(Path(roundedRect: CGRect(x: -17, y: -16, width: 34, height: 20), cornerRadius: 10), with: .color(Ink.beak))+ }++ // MARK: - Sparkles: each appears and disappears once per loop, at its own seeded time++ private func drawSparkles(_ ctx: GraphicsContext) {+ let spots: [(x: Double, y: Double, r: Double, dots: Bool)] = [+ (190, 170, 12, true), (560, 160, 14, true), (130, 560, 20, false),+ (600, 600, 22, false), (210, 650, 12, false), (520, 250, 9, false), (95, 300, 9, false),+ ]+ for (i, s) in spots.enumerated() {+ let start = seeded(i, salt: 7) * Self.loopMs+ let p = loop(t - start, period: Self.loopMs) / (1600 / Self.loopMs)+ guard p < 1 else { continue }+ let k = bell(p)+ var g = ctx+ g.translateBy(x: s.x, y: s.y)+ g.scaleBy(x: k, y: k)+ if s.dots {+ for a in 0..<4 {+ let ang = Double(a) * .pi / 2+ let d = s.r+ g.fill(Path(ellipseIn: CGRect(x: cos(ang) * d - 3, y: sin(ang) * d - 3, width: 6, height: 6)), with: .color(Ink.sparkle))+ }+ } else {+ g.fill(fourPointStar(r: s.r), with: .color(Ink.sparkle))+ }+ }+ }++ /// A soft four-point star centred on (0, 0).+ private func fourPointStar(r: CGFloat) -> Path {+ var p = Path()+ let w = r * 0.32+ p.move(to: CGPoint(x: 0, y: -r))+ p.addQuadCurve(to: CGPoint(x: r, y: 0), control: CGPoint(x: w, y: -w))+ p.addQuadCurve(to: CGPoint(x: 0, y: r), control: CGPoint(x: w, y: w))+ p.addQuadCurve(to: CGPoint(x: -r, y: 0), control: CGPoint(x: -w, y: w))+ p.addQuadCurve(to: CGPoint(x: 0, y: -r), control: CGPoint(x: -w, y: -w))+ return p+ }+}diff --git a/demo/orbit.gif b/demo/orbit.gifnew file mode 100644index 0000000..61bf2c1Binary files /dev/null and b/demo/orbit.gif differdiff --git a/demo/orbit.mp4 b/demo/orbit.mp4new file mode 100644index 0000000..4a25ec3Binary files /dev/null and b/demo/orbit.mp4 differdiff --git a/demo/render.swift b/demo/render.swiftindex 4eafaee..6e1cc1f 100644--- a/demo/render.swift+++ b/demo/render.swift@@ -1,10 +1,9 @@-// render.swift: renders the demo scene to PNG frames (macOS 14+).+// render.swift: renders a demo scene to PNG frames (macOS 14+).//// swiftc -parse-as-library -target arm64-apple-macos14 \-// templates/swiftui/Motion.swift templates/swiftui/LiveFace.swift \-// demo/DemoScene.swift demo/render.swift -o /tmp/render-demo-// /tmp/render-demo /tmp/frames-// ffmpeg -framerate 30 -i /tmp/frames/%04d.png -c:v libx264 -pix_fmt yuv420p -crf 18 demo/demo.mp4+// templates/swiftui/Motion.swift templates/swiftui/LiveFace.swift demo/*.swift -o /tmp/render-demo+// /tmp/render-demo room /tmp/frames # or: orbit+// ffmpeg -framerate 30 -i /tmp/frames/%04d.png -c:v libx264 -pix_fmt yuv420p -crf 20 demo/demo.mp4import Foundationimport ImageIOimport SwiftUI@@ -14,13 +13,17 @@ import UniformTypeIdentifiersstruct RenderDemo {@MainActorstatic func main() throws {- let out = URL(fileURLWithPath: CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "frames")+ let args = CommandLine.arguments+ let scene = args.count > 1 ? args[1] : "room"+ let out = URL(fileURLWithPath: args.count > 2 ? args[2] : "frames")try FileManager.default.createDirectory(at: out, withIntermediateDirectories: true)let fps = 30.0- let frames = Int(DemoScene.loopMs / 1000 * fps)+ let loopMs = scene == "orbit" ? OrbitScene.loopMs : DemoScene.loopMs+ let frames = Int(loopMs / 1000 * fps)for f in 0..<frames {let t = Double(f) / fps * 1000- let renderer = ImageRenderer(content: DemoScene(t: t))+ let content: AnyView = scene == "orbit" ? AnyView(OrbitScene(t: t)) : AnyView(DemoScene(t: t))+ let renderer = ImageRenderer(content: content)renderer.scale = 2guard let image = renderer.cgImage else { throw CocoaError(.fileWriteUnknown) }let url = out.appendingPathComponent(String(format: "%04d.png", f))@@ -30,6 +33,6 @@ struct RenderDemo {CGImageDestinationAddImage(dest, image, nil)CGImageDestinationFinalize(dest)}- print("rendered \(frames) frames to \(out.path)")+ print("rendered \(frames) frames of \(scene) to \(out.path)")}}