Tutorial: Your First Animation

This tutorial walks through building animations step by step, starting from the very basics.

The Coordinate System

VectorMation uses an SVG canvas of 1920 x 1080 pixels. The origin (ORIGIN) is at the centre of the canvas: (960, 540).

  • X increases to the right

  • Y increases downward (standard SVG convention)

  • One abstract unit (UNIT) equals 135 pixels

Direction constants like UP, DOWN, LEFT, RIGHT are available for convenience. Note that UP = (0, -1) because Y points down.

Hello Shapes

Every VectorMation script starts by creating a canvas:

from vectormation.objects import *

canvas = VectorMathAnim()
canvas.set_background()

Create some shapes, add entrance animations, and display them:

Example: basic shapes

Create a circle, rectangle, and text. Fade them in one at a time, then shift them all upward together.

"""Basic shapes intro: circle, rectangle, text with animations."""
from vectormation.objects import *

v = VectorMathAnim()
v.set_background()

# Create three shapes
circle = Circle(r=80, cx=400, cy=540, fill='#58C4DD', fill_opacity=0.8)
rect = Rectangle(160, 160, x=880, y=460, fill='#E74C3C', fill_opacity=0.8)
text = Text('Hello!', x=1440, y=540, font_size=64, fill='WHITE')

# Fade them in one at a time
circle.fadein(start=0, end=1)
rect.fadein(start=0.5, end=1.5)
text.fadein(start=1, end=2)

# Move them together
circle.shift(dy=-150, start=2.5, end=3.5)
rect.shift(dy=-150, start=2.5, end=3.5)
text.shift(dy=-150, start=2.5, end=3.5)

v.add(circle, rect, text)

v.show(end=4)

The Timing Model

Animations are scheduled with start= and end= parameters. Every animation method accepts these two values (in seconds):

dot.fadein(start=0, end=1)        # fade in during t=0..1
dot.shift(dx=300, start=1, end=2) # slide right during t=1..2
dot.shift(dy=-200, start=2, end=3) # slide up during t=2..3

Animations at different times happen sequentially; animations at the same time happen simultaneously.

Example: timing model

Sequential shift calls with consecutive start/end values create a step-by-step path.

"""Timing model demo: sequential start/end animations."""
from vectormation.objects import *

v = VectorMathAnim()
v.set_background()

dot = Dot(cx=300, cy=540, r=20, fill='#58C4DD')
dot.fadein(start=0, end=0.5)

# Sequential animations using start= and end=
dot.shift(dx=300, start=0.5, end=1.5)   # move right
dot.shift(dy=-200, start=1.5, end=2.5)  # move up
dot.shift(dx=300, start=2.5, end=3.5)   # move right again
dot.shift(dy=200, start=3.5, end=4.5)   # move down

# Add time markers as text
for i, t in enumerate([0.5, 1.5, 2.5, 3.5, 4.5]):
    label = Text(f't={t}', x=300 + i * 150, y=900, font_size=24, fill='#666666')
    label.fadein(start=t - 0.2, end=t + 0.2)
    v.add(label)

v.add(dot)

v.show(end=5)

Building a Spiral

Now let’s build something more interesting. Create a dot at the centre and make it move rightward:

point = Dot(cx=960, cy=540)
point.c.set(0, 5, lambda t: (t * 80 + 960, 540))

Add rotation around the canvas centre – combined with the linear motion this creates a spiral:

point.c.rotate_around(0, 5, (960, 540), 360 * 4)

A Trace follows a coordinate over time, drawing a polyline trail:

trace = Trace(point.c)

Register objects and open the browser viewer:

canvas.add(trace, point)
canvas.show(end=6)

Example: spiral animation

A dot spirals outward for 4 revolutions while leaving a trace trail.

"""Tutorial spiral example with rendered output."""
from vectormation.objects import *

v = VectorMathAnim()
v.set_background()

point = Dot(cx=960, cy=540)
trace = Trace(point.c, stroke_width=4)
point.c.set(start=0, end=5, func_inner=lambda t: (t * 80 + 960, 540))
point.c.rotate_around(0, 5, pivot_point=(960, 540), degrees=360 * 4)

v.add(trace, point)

v.show(end=5)

Next Steps