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 different lag_ratio can also be used which combines multiple animations into one. The run_time of the passed animation is changed to modify the speed.

Parameters
  • anim – Animation of which the speed is to be modified.

  • speedinfo – Contains nodes (percentage of run_time) and its corresponding speed factor.

  • rate_func – Overrides rate_func of passed animation, applied before changing speed.

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,
            )
        )

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,
            )
        )

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,
            )
        )

Methods

add_updater

This static method can be used to apply speed change to updaters.

begin

Begin the animation.

clean_up_from_scene

Clean up the Scene after finishing the animation.

finish

Finish the animation.

get_scaled_total_time

The time taken by the animation under the assumption that the run_time is 1.

interpolate

Set the animation progress.

setup

update_mobjects

Updates things like starting_mobject, and (for Transforms) target_mobject.

Attributes

dt

is_changing_dt

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 with affects_speed_updaters=True. By default, updater functions added via the usual Mobject.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 (Updater) – 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.

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’s Mobject 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

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

update_mobjects(dt)[source]#

Updates things like starting_mobject, and (for Transforms) target_mobject. Note, since typically (always?) self.mobject will have its updating suspended during the animation, this will do nothing to self.mobject.

Parameters

dt (float) –

Return type

None