Search code examples
pythonmanim

In Manim, how can I rotate a Mobject and scale it at the same time?


I'm using Manim Community v0.17.2, and I am trying to animate a text growing from its center and rotating 90 degrees at the same time.

txt_1 = Text("Hello World!", font_size=76).rotate(PI/2)
self.play(
            Rotate(txt_1, -PI/2),
            GrowFromCenter(txt_1)
        )

I expected the text to start vertically and very small (with a scale of 0 to be precise), and then it would rotate 90 degrees to get in a horizontal position and scale until it had a font size of 76. Instead, the only animation that is being played is GrowFromCenter. I have tried using alternatives like Succession with a lag ratio of 0, but I get the same problem. I have also tried using Transform and animate.rotate, but the rotation is not done well because instead of rotating the object as a whole, it moves each point of the Mobject to it's destination, creating a weird effect. So it looks like I have no other choice but to use Rotate in some way.

Thanks for your help!


Solution

  • You can use the built-in animation SpinInFromNothing. See docs.

    class SpinGrowText(Scene):
        def construct(self):
            txt_1 = Text("Hello World!", font_size=76)
            self.play(SpinInFromNothing(txt_1, angle=-90*DEGREES, rate_func = linear, run_time = 2))
            self.wait(2)