Search code examples
animationmanim

Is it possible to play two animations with different rate functions simultaneously?


Suppose that I wanted to rotate a line in a linear fashion and summon a text mobject with the GrowFromCenter animation at the same time. The thing is, text growing in a linear fashion looks awkward to my taste and I want it to grow smoothly. Is there a way I can play two animations, one with smooth and the other with linear rate functions simultaneously?

Below is only a simplified code to describe the situation.

class test(Scene):
    def construct(self):
        phi = ValueTracker(0)
        line = Line(ORIGIN,(2,0,0))
        sample_text = TextMobject("Text")
        sample_text.shift(LEFT*2)
        line.add_updater(lambda d: d.set_angle(phi.get_value()))
        self.add(line)
        self.play(
            GrowFromCenter(sample_text),
            phi.increment_value,PI/2,
            rate_func = linear
        )

Solution

  • class test(Scene):
        def construct(self):
            phi = ValueTracker(0)
            line = Line(ORIGIN,(2,0,0))
            sample_text = TextMobject("Text")
            sample_text.shift(LEFT*2)
            line.add_updater(lambda d: d.set_angle(phi.get_value()))
            self.add(line)
            self.play(
                GrowFromCenter(sample_text,rate_func = linear),
                phi.increment_value,PI/2,{"rate_func":smooth}
            )