Skip to content

Build your first Anim composition

This tutorial builds a small vector scene with moving shapes, Bézier easing, repeated motion, and group transparency. You will validate the source, inspect its timing, and export frames and video.


Prerequisites

Install the Anim preview CLI, then verify it:

sh
anim --version

1. Understanding the Anim Philosophy

Anim is a purely functional, statically typed animation language. Unlike traditional animation systems that rely on mutable state update loops or keyframe mutation, Anim operates on Signals:

Signal<T> = f(Time) -> T

Every animated attribute (position, size, opacity, or a color switch) is a pure function of time. Given the same source and exact time (t), the canonical CPU path is designed to compute the same frame without depending on playback history.


2. Step 1: Composing a Little Scene

Create a file named hello_anim.anim in your working directory.

Start by composing basic primitives — rectangles, ellipses, and triangles — into a little owl perched on a branch. Even this first example has a bit of life: a firefly blinks beside the owl, so the result already feels like a scene rather than a diagram:

Live canvasStep 1: A Little Owl at Night
400 × 30060 fps
Animated preview for Step 1: A Little Owl at Night.
Loading renderer…
0.00s · 1 / 1

Notice that dimensional values require explicit units:

  • Lengths: px (e.g. 800px, 16px)
  • Time: s or ms (e.g. 2s, 500ms)
  • Frame Rate: fps (e.g. 60fps)
  • Colors: #rrggbb or #rrggbbaa

3. Step 2: Adding Motion with Signals

Next, create continuous signals using tween and a custom Bézier easing curve. A paper airplane glides into the sky and back out over three seconds, with a gentle bob so it feels like it is really flying:

Live canvasStep 2: A Gliding Paper Airplane
400 × 30060 fps
Animated preview for Step 2: A Gliding Paper Airplane.
Loading renderer…
0.00s · 1 / 1

Here, enter and leave are joined into one glide signal. The expression 300px + glide automatically promotes the static base position into signal arithmetic, while the Bézier curve gives the airplane its smooth swoop.


4. Step 3: Sequencing and Repeating Animation

Anim provides sequence and repeat to structure timelines without keyframe mutation. Here they power the calm, four-second breathing rhythm of a friendly star buddy:

Live canvasStep 3: A Breathing Star Buddy
400 × 30060 fps
Animated preview for Step 3: A Breathing Star Buddy.
Loading renderer…
0.00s · 1 / 1

5. Step 4: Layering and Visual Effects

Use stack to composite elements in painter's order (first child rendered at back, last child on top), then add group transparency with opacity to make a sparkling pile of treasure fade up inside an open chest:

Live canvasStep 4: A Treasure Chest Reveal
400 × 30060 fps
Animated preview for Step 4: A Treasure Chest Reveal.
Loading renderer…
0.00s · 1 / 1

6. Step 5: Exporting the Main Composition

Every executable .anim document must export exactly one binding named main of type composition:

anim
export let main = composition(
  width: 800px,
  height: 600px,
  duration: 4s,
  fps: 60fps,
  scene: scene_content
);

The composition binds together render target dimensions, continuous timeline duration, canonical frame rate, and the root scene tree.


7. Step 6: Validating and Inspecting Your Source

At each step, replace the contents of hello_anim.anim with the complete source shown in that step. After Step 4, use the CLI to check it for syntax, type, or unit errors:

sh
anim check hello_anim.anim

If successful, anim check exits cleanly with code 0. Next, inspect the composition parameters and timing metadata:

sh
anim inspect hello_anim.anim --json

Output:

json
{
  "schema_version": 1,
  "compositions": [
    {
      "name": "main",
      "width": 600,
      "height": 400,
      "duration": {
        "numerator": 3,
        "denominator": 1,
        "unit": "seconds"
      },
      "frame_rate": {
        "numerator": 60,
        "denominator": 1,
        "unit": "frames_per_second"
      },
      "frame_count": 180
    }
  ]
}

8. Step 7: Rendering Frames and Videos

Rendering a Single Frame

To render frame 60 (at 1.0 second) as a PNG image:

sh
anim render hello_anim.anim --frame 60 -o frame_60.png

Rendering a Sequence of Frames

To render frames 0 through 120 as a numbered sequence:

Create the destination directory, then render the complete half-open frame range:

sh
mkdir -p frames
anim render hello_anim.anim --range 0..180 -o frames/frame_%04d.png

Rendering Video Output

To render the entire three-second animation as an MP4 or WebM video:

Video export requires a local FFmpeg installation:

sh
anim render hello_anim.anim --range 0..180 -o output.mp4 --video raster --background "#000000"

Summary

Congratulations! You have completed the Anim tutorial. You learned how to:

  1. Compose expressive scene geometry with explicit units (px, #hex, s, fps).
  2. Build smooth continuous signals with tween and cubic_bezier.
  3. Construct complex timelines with sequence and repeat.
  4. Composite scenes with stack, translate, scale, and opacity.
  5. Export main: composition.
  6. Use anim check, anim inspect, and anim render CLI commands.

Proceed to the How-to Guides for specialized workflows such as Lottie JSON import and 2D Mesh Deformation physics!

Anim 0.1 preview · Documentation and examples are MIT licensed · Runtime binaries are proprietary