Skip to content

Animate developer documentation

Move your first shape

Create an Empty Canvas project and open main.py. With Video2D and Neutral selected in Packages, replace the file with this example and choose Save & Run. Press play. A blue rectangle fades in, moves 240 pixels to the right, and holds at its destination.

A blue rectangle fades in, slides right, and stops

from manifest import FadeIn, Move, Position, Rectangle, Video2d, color_schemes

palette = color_schemes['neutral.colors']

def build(seq, frame):
    box = Rectangle(frame, Position(60, 100), Position(100, 60),
                    fill=palette['accent'])
    reveal = FadeIn(box, time=0.5)
    seq.show(0.25)
    seq.show(reveal)
    seq.show(Move(box, Position(240, 0), time=1))
    seq.show(0.5)

def make_video():
    return Video2d(build, resolution=(640, 360), fps=30,
                   background_color=palette['background'])

frame is the root container. At the root, coordinates are pixels, with x increasing to the right and y increasing downward. seq.show(...) advances the timeline. Numeric durations are seconds. Constructing FadeIn sets the starting opacity to zero, so create it before the first hold.

Copy the example into your project's main.py to try it, then change the distance, duration, or color and choose Save & Run again.

Read and animate properties

To change In the builder Result
Position Move(box, (80, 0), time=1) Adds 80 parent units to x.
Destination MoveTo(box, (80, 100), time=1) Ends at (80, 100) in the parent’s coordinates.
Opacity Fade(box, end=0.3, time=0.5) Ends at 30% opacity. FadeOut takes it to zero.
Shape size ExpandSize(box, (40, 0), time=0.5) Adds 40 units to the rectangle’s width.
Shape paint box.props.fill = (80, 160, 240) Changes the fill immediately at the current builder position.

Import the animation you need from manifest, then pass it to seq.show. For a direct change, assign the whole property value. These three expressions do different jobs:

from manifest import SetProperty

local = box.props.position()             # authored coordinates
resolved = box.props.position.resolve()  # coordinates after inheritance
seq.show(SetProperty(box.props.opacity, 0.5))

Compare timing

The following clips show two squares from the same scene. Each row of code runs inside build(seq, frame). Import Sequence, Bundle, Pause, Delay, FadeIn, FadeOut, and Move from manifest.

Bundle starts its children together. The blue square fades in while moving. Opacity reaches one after 0.35 seconds, while movement continues until 1.1 seconds. Passing both animations to one seq.show(a, b) also runs them together.

seq.show(Bundle(FadeIn(blue, time=0.35), Move(blue, (400, 0), time=1.1)))

The blue square fades in as it moves right

Sequence runs its children in order. The dark square moves first, waits at the right edge, then fades out. The movement, wait, and fade take 1.65 seconds in total.

seq.show(Sequence(
    Move(dark, (400, 0), time=1.1),
    Delay(0.2, FadeOut(dark, time=0.35)),
))

The dark square moves to the right before fading

Pause holds a sequence. Delay postpones one animation. In the previous example, Delay(0.2, FadeOut(...)) starts the fade 0.2 seconds after the move ends. Inside a bundle, a delayed child can wait while another child moves. Use seq.show(Pause(0.25)), or simply seq.show(0.25), to hold the whole sequence for a quarter second.

The dark square holds its final position before disappearing

For motion along a curve, try the ball trajectory example. For a gesture you can reuse, see Creating animations.

Choose an entity

Top row shows a rectangle, circle, ellipse, and triangular path. Bottom row shows a line and arrow.

Entity Geometry
Rectangle, Ellipse Supply the top-left position and a (width, height) pair.
Circle Supply the center and a radius.
Line, Arrow Supply the start and a displacement from that start.
Path Supply path commands, or use Path.from_svg_path(..., d='M0 0 L80 0 L40 70 Z').
Group Parent several entities to move, scale, or fade them together.

Place shapes and characters in cells

A Grid gives children a coordinate system. In this example, cell (2, 3) starts at pixel (140, 80). The rectangle covers one 20-by-10-pixel cell.

from manifest import Grid, Rectangle

grid = Grid(frame, cell_size=(20, 10), position=(100, 50))
tile = Rectangle(grid, (2, 3), (1, 1), fill=(60, 100, 190))

A TextGrid derives its cell size from a font. insert returns the visible Character entities. Spaces advance the cursor, and newlines start another row. A character can move or fade independently of its grid.

from manifest import Font, Move, TextGrid

text = TextGrid(frame, 28, font=Font('JetBrains Mono'), show_line_numbers=True)
text.props.position = (100, 80)
text.insert('for value in values:\n    total += value')
seq.show(Move(text.line(1), (1, 0), time=0.5))  # move the second row one cell

Select JetBrains Mono Regular in the project’s fonts for this example. The image shows a numbered text grid above seven directly positioned characters.

A two-line numbered text grid above individually positioned blue letters spelling Animate

If the preview differs

  • The previous animation is still visible. Check the compile message after Save & Run. A failed build keeps your saved edits and the last successful preview.
  • A font or import is missing. Check the selected font face, package version, and asset path in project.json. The site describes the current release. A project agent reads the API for its pinned environment.
  • An object moves too far. Check its parent. A displacement of one unit means one pixel under the root and one cell under a grid. See Property inheritance.

Continue with Creating components or look up a signature in the Python API reference. For standalone use, install the bundled Python package codeanimate, run from the directory containing project.json, and set CODEANIMATE_PACKAGE_PATH to the directories containing the selected packages. The authoring cheatsheet and core concepts cover the same builder outside the editor.

Build versions

Runtime API 1 · DOM schema 1.