Animation#
Qualified name: manim.animation.animation.Animation
- class Animation(mobject=None, *args, use_override=True, **kwargs)[source]#
Bases:
object
An animation.
Animations have a fixed time span.
- Parameters
mobject – The mobject to be animated. This is not required for all types of animations.
lag_ratio –
Defines the delay after which the animation is applied to submobjects. This lag is relative to the duration of the animation.
This does not influence the total runtime of the animation. Instead the runtime of individual animations is adjusted so that the complete animation has the defined run time.
run_time – The duration of the animation in seconds.
rate_func –
The function defining the animation progress based on the relative runtime (see
rate_functions
) .For example
rate_func(0.5)
is the proportion of the animation that is done after half of the animations run time.
- reverse_rate_function
Reverses the rate function of the animation. Setting
reverse_rate_function
does not have any effect onremover
orintroducer
. These need to be set explicitly if an introducer-animation should be turned into a remover one and vice versa.- name
The name of the animation. This gets displayed while rendering the animation. Defaults to <class-name>(<Mobject-name>).
- remover
Whether the given mobject should be removed from the scene after this animation.
- suspend_mobject_updating
Whether updaters of the mobject should be suspended during the animation.
Note
In the current implementation of this class, the specified rate function is applied within
Animation.interpolate_mobject()
call as part of the call toAnimation.interpolate_submobject()
. For subclasses ofAnimation
that are implemented by overridinginterpolate_mobject()
, the rate function has to be applied manually (e.g., by passingself.rate_func(alpha)
instead of justalpha
).Examples
Example: LagRatios ¶
from manim import * class LagRatios(Scene): def construct(self): ratios = [0, 0.1, 0.5, 1, 2] # demonstrated lag_ratios # Create dot groups group = VGroup(*[Dot() for _ in range(4)]).arrange_submobjects() groups = VGroup(*[group.copy() for _ in ratios]).arrange_submobjects(buff=1) self.add(groups) # Label groups self.add(Text("lag_ratio = ", font_size=36).next_to(groups, UP, buff=1.5)) for group, ratio in zip(groups, ratios): self.add(Text(str(ratio), font_size=36).next_to(group, UP)) #Animate groups with different lag_ratios self.play(AnimationGroup(*[ group.animate(lag_ratio=ratio, run_time=1.5).shift(DOWN * 2) for group, ratio in zip(groups, ratios) ])) # lag_ratio also works recursively on nested submobjects: self.play(groups.animate(run_time=1, lag_ratio=0.1).shift(UP * 2))
Methods
Begin the animation.
Clean up the
Scene
after finishing the animation.Create a copy of the animation.
create_starting_mobject
Finish the animation.
get_all_families_zipped
Get all mobjects involved in the animation.
Get all mobjects to be updated during the animation.
Get the rate function of the animation.
Get the run time of the animation.
Get the animation progress of any submobjects subanimation.
Set the animation progress.
Interpolates the mobject of the
Animation
based on alpha value.interpolate_submobject
Test if the animation is an introducer.
Test if the animation is a remover.
Set the name of the animation.
Set the rate function of the animation.
Set the run time of the animation.
Updates things like starting_mobject, and (for Transforms) target_mobject.
- begin()[source]#
Begin the animation.
This method is called right as an animation is being played. As much initialization as possible, especially any mobject copying, should live in this method.
- Return type
None
- clean_up_from_scene(scene)[source]#
Clean up the
Scene
after finishing the animation.This includes to
remove()
the Animation’sMobject
if the animation is a remover.- Parameters
scene (Scene) – The scene the animation should be cleaned up from.
- Return type
None
- finish()[source]#
Finish the animation.
This method gets called when the animation is over.
- Return type
None
- get_all_mobjects()[source]#
Get all mobjects involved in the animation.
Ordering must match the ordering of arguments to interpolate_submobject
- Returns
The sequence of mobjects.
- Return type
Sequence[Mobject]
- get_all_mobjects_to_update()[source]#
Get all mobjects to be updated during the animation.
- Returns
The list of mobjects to be updated during the animation.
- Return type
List[Mobject]
- get_rate_func()[source]#
Get the rate function of the animation.
- Returns
The rate function of the animation.
- Return type
Callable[[float], float]
- get_run_time()[source]#
Get the run time of the animation.
- Returns
The time the animation takes in seconds.
- Return type
float
- get_sub_alpha(alpha, index, num_submobjects)[source]#
Get the animation progress of any submobjects subanimation.
- Parameters
alpha (float) – The overall animation progress
index (int) – The index of the subanimation.
num_submobjects (int) – The total count of subanimations.
- Returns
The progress of the subanimation.
- Return type
float
- interpolate(alpha)[source]#
Set the animation progress.
This method gets called for every frame during an animation.
- Parameters
alpha (float) – The relative time to set the animation to, 0 meaning the start, 1 meaning the end.
- Return type
None
- interpolate_mobject(alpha)[source]#
Interpolates the mobject of the
Animation
based on alpha value.- Parameters
alpha (float) – A float between 0 and 1 expressing the ratio to which the animation is completed. For example, alpha-values of 0, 0.5, and 1 correspond to the animation being completed 0%, 50%, and 100%, respectively.
- Return type
None
- is_introducer()[source]#
Test if the animation is an introducer.
- Returns
True
if the animation is an introducer,False
otherwise.- Return type
bool
- is_remover()[source]#
Test if the animation is a remover.
- Returns
True
if the animation is a remover,False
otherwise.- Return type
bool
- set_name(name)[source]#
Set the name of the animation.
- Parameters
name (str) – The new name of the animation.
- Returns
self
- Return type
- set_rate_func(rate_func)[source]#
Set the rate function of the animation.
- Parameters
rate_func (Callable[[float], float]) – The new function defining the animation progress based on the relative runtime (see
rate_functions
).- Returns
self
- Return type