Appearance
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 --version1. 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
Notice that dimensional values require explicit units:
- Lengths:
px(e.g.800px,16px) - Time:
sorms(e.g.2s,500ms) - Frame Rate:
fps(e.g.60fps) - Colors:
#rrggbbor#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
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
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
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.animIf successful, anim check exits cleanly with code 0. Next, inspect the composition parameters and timing metadata:
sh
anim inspect hello_anim.anim --jsonOutput:
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.pngRendering 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.pngRendering 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:
- Compose expressive scene geometry with explicit units (
px,#hex,s,fps). - Build smooth continuous signals with
tweenandcubic_bezier. - Construct complex timelines with
sequenceandrepeat. - Composite scenes with
stack,translate,scale, andopacity. - Export
main: composition. - Use
anim check,anim inspect, andanim renderCLI commands.
Proceed to the How-to Guides for specialized workflows such as Lottie JSON import and 2D Mesh Deformation physics!