Basic Animations¶
In Algan you build animations by creating Mob s
and then changing them. By default, changes
you make to a mob are animated over a one second period. More complex
animation behaviour will be covered in the later Combining Animations tutorial.
Changing Animatable Attributes¶
Every Mob has these animatable attributes:
Attribute |
Shape |
Meaning |
|---|---|---|
3 floats |
Where the Mob sits in 3-D space. New Mobs start at |
|
9 floats |
Orientation and scale, as three basis vectors. Change it with
|
|
The Mob’s main color. |
||
float |
How strongly the mob glows. |
|
float |
How see-through the mob is. |
These attributes are special: assigning to one performs a 1-second animation that interpolates from the old value to the new value.
Example: BasicChangingAttributes ¶
from algan import *
circle = Circle().spawn()
circle.location = circle.location + UP * 2
circle.color = GREEN
circle.location = circle.location + DOWN + RIGHT * 2
circle.glow = 0.5
circle.opacity = 0.0
Scene.wait()
Scene.save_video()
Important
Reading an animatable attribute gives you a copy. circle.location
hands back a copy of the value on the timeline, so editing that copy in place
(e.g. circle.location[0] = 1 ) changes nothing and records nothing. The
write goes into the copy and is thrown away silently.
Assignment is what Algan records, so both circle.location = circle.location
+ UP and circle.location += UP work.
A note on colors¶
An Algan Color carries five components: red, green, blue, glow and
opacity, in that order. So glow and opacity can be set either on the Mob or baked
into the color you assign:
Example: BasicColorComponents ¶
from algan import *
circle = Circle().spawn()
circle.color = BLUE # leaves glow and opacity alone
circle.opacity = 0.5 # ... or set them separately
circle.color = GREEN.set_glow(0.5) # ... or together, in one animation
Scene.wait()
Scene.save_video()
Algan ships the full Manim color palette: RED, BLUE_E, TEAL_A, GOLD and so
on, plus WHITE, BLACK and TRANSPARENT.
Note
The two spellings compose, but they do not read each other back. A glow
or an opacity baked into a color lands in that color’s own channel, so
circle.glow still reports 0.0 after circle.color =
GREEN.set_glow(0.5) – read circle.color[..., 3] for the glow the
color carries, and [..., 4] for its opacity. What is rendered is
correct either way, and setting one does not undo the other: assigning
circle.opacity after a color with its own opacity leaves the color’s
channel where it was.
See also
Images and Textures – painting a gradient or an image across a shape instead of one flat color.
Backgrounds and Post-Processing – what
glowactually does, and the bloom pass that makes it visible.
Mob Methods¶
Mob s also have a bunch of common operations built in to them as methods.
Most of the time, these are what you will use.
Example: BasicMobMethods ¶
from algan import *
pentagon = RegularPolygon(5).spawn()
pentagon.move(RIGHT * 2)
pentagon.rotate(360, OUT)
pentagon.rotate(360, UP)
pentagon.rotate(360, OUT, about=ORIGIN)
pentagon.scale(2)
pentagon = pentagon.become(Circle(add_to_scene=False))
pentagon.wait(2)
Scene.save_video()
The methods used above:
move()translates the Mob by a vector:pentagon.move(RIGHT)slides it one unit right. To move to an absolute point instead, usemove_to().rotate()turns the Mob about an axis through its own centre. Passingaboutturns it about that point instead, which sweeps the Mob around in an arc:pentagon.rotate(180, OUT, about=ORIGIN)swings it half way around the origin.become()morphs the Mob into a different Mob. It returns the resulting Mob, so assign it back:pentagon = pentagon.become(Circle(add_to_scene=False)). Build the target withadd_to_scene=False: it is only there to say what shape to become, and is never itself drawn on screen. Without that flag Algan registers it as a Mob you meant to show, and warns that you never spawned it.scale()grows or shrinks the Mob:pentagon.scale(2)doubles its size.wait()holds the Mob still:pentagon.wait(2)leaves two seconds of nothing happening.Scene.wait(2)also does the same thing.
The Mob reference lists every method.
See also
Positioning and Layout – every placement and sizing method, and when to reach for which.
Built-in Animations – ready-made animations for drawing attention, moving along a path and transforming a diagram.
Custom Animations – writing an animation of your own with
animated_function(), for anything the built-ins do not cover.