ChangeSpeed#
Qualified name: manim.animation.speedmodifier.ChangeSpeed
- class ChangeSpeed(mobject=None, *args, use_override=True, **kwargs)[source]#
Bases:
Animation
Modifies the speed of passed animation.
AnimationGroup
with differentlag_ratio
can also be used which combines multiple animations into one. Therun_time
of the passed animation is changed to modify the speed.- Parameters:
anim (Animation | _AnimationBuilder) – Animation of which the speed is to be modified.
speedinfo (dict[float, float]) – Contains nodes (percentage of
run_time
) and its corresponding speed factor.rate_func (Callable[[float], float] | None) – Overrides
rate_func
of passed animation, applied before changing speed.affects_speed_updaters (bool) –
Examples
Example: SpeedModifierExample ¶
from manim import * class SpeedModifierExample(Scene): def construct(self): a = Dot().shift(LEFT * 4) b = Dot().shift(RIGHT * 4) self.add(a, b) self.play( ChangeSpeed( AnimationGroup( a.animate(run_time=1).shift(RIGHT * 8), b.animate(run_time=1).shift(LEFT * 8), ), speedinfo={0.3: 1, 0.4: 0.1, 0.6: 0.1, 1: 1}, rate_func=linear, ) )
class SpeedModifierExample(Scene): def construct(self): a = Dot().shift(LEFT * 4) b = Dot().shift(RIGHT * 4) self.add(a, b) self.play( ChangeSpeed( AnimationGroup( a.animate(run_time=1).shift(RIGHT * 8), b.animate(run_time=1).shift(LEFT * 8), ), speedinfo={0.3: 1, 0.4: 0.1, 0.6: 0.1, 1: 1}, rate_func=linear, ) )
Example: SpeedModifierUpdaterExample ¶
from manim import * class SpeedModifierUpdaterExample(Scene): def construct(self): a = Dot().shift(LEFT * 4) self.add(a) ChangeSpeed.add_updater(a, lambda x, dt: x.shift(RIGHT * 4 * dt)) self.play( ChangeSpeed( Wait(2), speedinfo={0.4: 1, 0.5: 0.2, 0.8: 0.2, 1: 1}, affects_speed_updaters=True, ) )
class SpeedModifierUpdaterExample(Scene): def construct(self): a = Dot().shift(LEFT * 4) self.add(a) ChangeSpeed.add_updater(a, lambda x, dt: x.shift(RIGHT * 4 * dt)) self.play( ChangeSpeed( Wait(2), speedinfo={0.4: 1, 0.5: 0.2, 0.8: 0.2, 1: 1}, affects_speed_updaters=True, ) )
Example: SpeedModifierUpdaterExample2 ¶
from manim import * class SpeedModifierUpdaterExample2(Scene): def construct(self): a = Dot().shift(LEFT * 4) self.add(a) ChangeSpeed.add_updater(a, lambda x, dt: x.shift(RIGHT * 4 * dt)) self.wait() self.play( ChangeSpeed( Wait(), speedinfo={1: 0}, affects_speed_updaters=True, ) )
class SpeedModifierUpdaterExample2(Scene): def construct(self): a = Dot().shift(LEFT * 4) self.add(a) ChangeSpeed.add_updater(a, lambda x, dt: x.shift(RIGHT * 4 * dt)) self.wait() self.play( ChangeSpeed( Wait(), speedinfo={1: 0}, affects_speed_updaters=True, ) )
Methods
This static method can be used to apply speed change to updaters.
Begin the animation.
Clean up the
Scene
after finishing the animation.Finish the animation.
The time taken by the animation under the assumption that the
run_time
is 1.Set the animation progress.
setup
Updates things like starting_mobject, and (for Transforms) target_mobject.
Attributes
dt
is_changing_dt
- _setup_scene(scene)[source]#
Setup up the
Scene
before starting the animation.This includes to
add()
the Animation’sMobject
if the animation is an introducer.- Parameters:
scene – The scene the animation should be cleaned up from.
- Return type:
None
- classmethod add_updater(mobject, update_function, index=None, call_updater=False)[source]#
This static method can be used to apply speed change to updaters.
This updater will follow speed and rate function of any
ChangeSpeed
animation that is playing withaffects_speed_updaters=True
. By default, updater functions added via the usualMobject.add_updater()
method do not respect the change of animation speed.- Parameters:
mobject (Mobject) – The mobject to which the updater should be attached.
update_function (Union[Callable[[Mobject], None], Callable[[Mobject, float], None]]) – The function that is called whenever a new frame is rendered.
index (int | None) – The position in the list of the mobject’s updaters at which the function should be inserted.
call_updater (bool) – If
True
, calls the update function when attaching it to the mobject.
See also
- 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_scaled_total_time()[source]#
The time taken by the animation under the assumption that the
run_time
is 1.- Return type:
float