Play differet animations at the same time and with different speeds in manim

28 Views Asked by At

I know that in manim I am allowed to play two or more different animations simultaneously together, using

self.play(anim1, anim2, ... )

However, I am looking for some method/approach to play different animation simultaneously together but with a different speed for each.

Here is an exampe: Two dots should be scaled bigger and smaller multiple times (periodically). The below approach doesn't work. (Please excuse the unprofessional python algorithm applied. It's just a dummy example.)

from manim import *

class TwoDots(Scene):
    def construct(self):
        point1 = Dot(point=[-3, 0, 0], radius= 0.5)
        point2 = Dot(point=[3, 0, 0], radius= 0.5)

        # Define the target scales
        target_scales = [1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5, 1.5, 0.5,  
        1.5, 0.5]

        animations = VGroup()

        # Perform the scaling animation
        for scale in target_scales:
            # Creating transformations for point1 and point2
            transform_point1 = Transform(point1, point1.copy().scale(scale), run_time=1)
            transform_point2 = Transform(point2, point2.copy().scale(scale),                  
            run_time=2)

            # Adding the visual transformations to the VGroup
            animations.add(transform_point1, transform_point2)

        
        self.play(animations)

1

There are 1 best solutions below

0
CodingWithMagga On

Running animations with different run_time can be done like this:

self.play(point1.animate(run_time=1).scale(0.5), point2.animate(run_time=2).scale(0.5))

If you want to have a periodically updating animation like in the example, I would suggest using UpdateFromFunc. The approach above doesn't work in this case, because using multiple animate calls in one self.play(...) call does not work.