AnimationContext¶
Qualified name: algan.animation\_timeline.animation\_contexts.AnimationContext
- class AnimationContext(runtime=None, runtime_per_part=None, equalize_runtimes=None, lag_ratio=None, priority_level=None, easing=None, composed_easing=None, combine_easing=False, record_funcs=None, record_attr_modifications=None, prev_context=None, spawn_at_end=None, new_animation=False, finished=False, new_mobs=None, child_contexts=None, kwargs=None, animation_manager=None)[source]¶
Bases:
objectBase class for the
withblocks that control animation timing.A context decides when the animations recorded inside it happen: together, one after another, overlapping, or not at all. Use the subclasses rather than this class directly:
Sync,Seq,Lag,Off,Audio,Speech.Contexts nest, and a nested context inherits every parameter left as
Nonefrom its parent, overriding only what it sets. On exit, a context with aruntimeretroactively rescales all the timestamps recorded inside it, which is how you give a whole block a fixed runtime without timing its parts.- Parameters:
runtime (float | None) – Total runtime of this context, in seconds; the animations inside are rescaled to fit. Must be finite and zero or more. Defaults to
None, meaning the runtime follows from the animations themselves.runtime_per_part (float | None) – Runtime of each individual animation inside, in seconds. Must be finite and zero or more. Defaults to
None, meaning inherit from the parent context (1.0at the top level).runtimeoverrides this.equalize_runtimes (bool | None) – Whether to stretch every animation inside to the runtime of the longest one. Defaults to
None(inherited; effectively False).lag_ratio (float | None) – Fraction of one animation’s runtime to wait before starting the next:
0plays them together,1strictly in sequence, in between overlaps them. Defaults toNone, meaning inherit from the parent.priority_level (float | None) – Priority of this context. A context can only be overridden by one of equal or higher priority, which is what lets
Offresist an enclosingruntime. Defaults toNone, meaning inherit (0at the top level).easing (collections.abc.Callable[[], float] | None) – Easing function mapping progress in
[0, 1]to adjusted progress, e.g.easings.identity. Replaces the parent’s. Defaults toNone, meaning inherit (easings.smoothat the top level).composed_easing (collections.abc.Callable[[], float] | None) – Easing function to compose with the parent’s rather than replace it. Defaults to
None. SeeComposedEasing.combine_easing (bool) – Whether component rate functions are combined into the context’s own. Defaults to False.
record_funcs (bool | None) – Whether animated functions inside are recorded on the Scene timeline. Defaults to
None, meaning inherit (True at the top level;Offsets it False).record_attr_modifications (bool | None) – Whether attribute changes inside are recorded on the Scene timeline. Defaults to
None, meaning inherit (True at the top level).prev_context (algan.animation_timeline.animation_contexts.AnimationContext | None) – The context this one was created inside. Defaults to
None; it is filled in on entry.spawn_at_end (bool | None) – Whether Mobs created inside are held back and spawned together when the block ends. Defaults to
None, meaning inherit (False at the top level).animation_manager (Any) – The
AnimationManagerto record against. Defaults toNone, meaning the active Scene’s – pass one explicitly when authoring a Scene that is not currently active.new_animation (bool | None)
finished (bool)
new_mobs (list | None)
child_contexts (list | None)
kwargs (Any)
- Raises:
.AlganConfigurationError – If
runtimeorruntime_per_partis not finite and non-negative, or a parameter is spelled the way Manim or an older Algan spelled it (duration,run_time,rate_func)..ContextReuseError – If the same context object is entered by a second
withblock.
Methods
Register a nested context, so this one's rescaling reaches it.
Register work to run once this block has finished, at its end time.
Record that a Mob was created in this context.
Get the time an animation started now would finish, in seconds.
Get the current authoring time, in seconds, after any rescaling.
Get this context and every context nested inside it, flattened.
Get the time this context ends, in seconds, after any rescaling.
Get this context's timespan object.
Advance the cursor after recording one animation.
Run spawn hooks for this context and every enclosing one.
Hook for behaviour to add whenever a Mob spawns in this context.
Run despawn hooks for this context and every enclosing one.
Hook for behaviour to add whenever a Mob despawns in this context.
Run construction hooks for this context and every enclosing one.
Hook for behaviour to add whenever a Mob is constructed in this context.
Move the authoring cursor backwards, so what follows is recorded earlier.
Hold still, leaving a pause before the next animation.
Attributes
animation_managerchild_contextscombine_easingcomposed_easingWhere the authoring cursor sits within this context, in seconds.
easingThe furthest time anything recorded in this context reaches, in seconds.
equalize_runtimesfinishedkwargslag_rationew_animationnew_mobsprev_contextpriority_levelrecord_attr_modificationsrecord_funcsruntimeruntime_per_partspawn_at_end- add_child_context(c)[source]¶
Register a nested context, so this one’s rescaling reaches it.
Called when a context is entered inside this one.
- Parameters:
c – The child
AnimationContext.
- add_exit_callback(callback)[source]¶
Register work to run once this block has finished, at its end time.
The callback runs after everything inside the block has been recorded and rescaled, with the authoring cursor placed at this context’s end, so anything the callback records lands after the whole block. Callbacks run in reverse registration order, so nested set-up unwinds the way it was applied.
This exists for changes that have to outlive the statement that asked for them:
wave_color()refines a Mob’s sampling so its color wave renders smoothly, and can only drop that resolution again once nothing further will be recorded alongside the wave.- Parameters:
callback – Zero-argument callable.
- add_mob(mob)[source]¶
Record that a Mob was created in this context.
Bubbles up to enclosing contexts too, which is how
SlideShowknows what to clear at the end.- Parameters:
mob – The Mob that was created.
- Returns:
This context, so calls can be chained.
- Return type:
- property current_time¶
Where the authoring cursor sits within this context, in seconds.
The time the next animation recorded in this context will start at.
- property end_time¶
The furthest time anything recorded in this context reaches, in seconds.
- get_current_end_time()[source]¶
Get the time an animation started now would finish, in seconds.
- Returns:
The current time plus one animation’s runtime.
- Return type:
float
- get_current_time()[source]¶
Get the current authoring time, in seconds, after any rescaling.
- Returns:
The time the next recorded animation starts at.
- Return type:
float
- get_descendants(include_self=True)[source]¶
Get this context and every context nested inside it, flattened.
- Parameters:
include_self (bool) – Whether this context is the first element. Defaults to True.
- Returns:
This context (unless excluded) followed by all nested contexts.
- Return type:
list[
AnimationContext]
- get_end_time()[source]¶
Get the time this context ends, in seconds, after any rescaling.
- Returns:
End time on the Scene timeline.
- Return type:
float
- get_timespan()[source]¶
Get this context’s timespan object.
- Returns:
The span holding this context’s start, cursor and end times.
- Return type:
- increment_times()[source]¶
Advance the cursor after recording one animation.
How much it moves is what distinguishes the contexts:
lag_ratioof one animation’s runtime, soSync(0) leaves the cursor put andSeq(1) moves it past the whole animation. Called by theanimated_functionmachinery; you do not call it yourself.
- on_create(animatable)[source]¶
Run spawn hooks for this context and every enclosing one.
- Parameters:
animatable – The Mob being spawned.
- on_create_extra(animatable)[source]¶
Hook for behaviour to add whenever a Mob spawns in this context.
Does nothing by default.
SlideShowoverrides it to pause after each spawn; override it in your own context subclass for similar effects.- Parameters:
animatable – The Mob being spawned.
- Returns:
This context.
- Return type:
- on_destroy(animatable)[source]¶
Run despawn hooks for this context and every enclosing one.
- Parameters:
animatable – The Mob being despawned.
- on_destroy_extra(animatable)[source]¶
Hook for behaviour to add whenever a Mob despawns in this context.
Does nothing by default.
- Parameters:
animatable – The Mob being despawned.
- Returns:
This context.
- Return type:
- on_init(animatable)[source]¶
Run construction hooks for this context and every enclosing one.
- Parameters:
animatable – The Mob being constructed.
- on_init_extra(animatable)[source]¶
Hook for behaviour to add whenever a Mob is constructed in this context.
Does nothing by default;
OnInitoverrides it to run a function of your choosing.- Parameters:
animatable – The Mob being constructed.
- Returns:
This context.
- Return type:
- rewind(num_frames)[source]¶
Move the authoring cursor backwards, so what follows is recorded earlier.
Animation
Not animated: this moves the cursor, not any Mob. Animation recorded after this call overlaps what was recorded before it.
- Parameters:
num_frames (float) – How far back to move the cursor, in the context’s own time units.
- wait(t=None)[source]¶
Hold still, leaving a pause before the next animation.
Animation
Recorded on the timeline: it consumes video time and nothing else. As with any animation in this context, the cursor advances by
lag_ratioof the wait, so a wait inside aSyncextends the block without pushing later animations back.- Parameters:
t (float | None) – How long to wait, in seconds. Must be zero or more. Defaults to
None, meaning one animation’s runtime (runtime_per_part, 1 second by default).- Raises:
.AlganConfigurationError – If
tis not a finite, non-negative number.