본문 바로가기

Programming/Manim Lectures

[06-2] Animation by Object's Method

반응형

We can animate the methods of the Mobject as it is.

self.play(mob.to_edge, RIGHT)
Most of the animation methods we saw earlier were by animation classes.

In this animation class, it creates an animation by making the image of a different shape for each frame for the target object. Therefore, because the method of Mobject changes the shape of an object for each frame, it is the same principle to play this method to create an animation class.

Note that the method name should be written without parentheses, and the parameter for the method should be written after the comma.

 

For exampel, if we make an animation from left to right by creating a circle,

        self.play(circle.to_edge, LEFT)
        self.play(circle.to_edge, RIGHT)

 

The animation where the color is painted inside the circle,

        self.play(circle.set_fill, RED, 1)
        self.play(circle.set_color_by_gradient, YELLOW)

 

Note that when you need to specify a dictionary type value as a method parameter, you must enter the complete dictionary type.

        self.play(circle.set_fill, RED, {"opacity":1})        

 

If you want to animate back to the original state, you can save the original state with mob.save_state() and animate the mob.restore method.

    circle.save_state()

    self.play(circle.to_edge, RIGHT)
    self.play(circle.restore)

 

The disadvantage of animation by methods compared to animation by classes is that method type animations cannot be grouped.

 

Classes are grouped by AnimationGroup and can be executed while adjusting the execution interval through lag_ratio, but the method type animation must be manually adjusted by the each 'play' method.

 

 

The example below is an animation that uses a method to move a circle and change its color in different directions on the screen.

        circle = Circle()
        circle.save_state()

        self.play(circle.to_edge, LEFT)
        self.play(circle.to_edge, RIGHT)
        self.play(circle.restore)
        self.play(circle.to_edge, UP)
        self.play(circle.to_edge, DOWN)
        self.play(circle.restore)

        self.play(circle.set_fill, RED, {"opacity": 0.5})
        self.play(circle.set_color_by_gradient, YELLOW)

        self.play(circle.to_corner, UL)
        self.play(circle.to_corner, DR)
        self.play(circle.restore)

        self.wait()

 


Next: [06-3] Animation by Object Updating

 

[06-3] Animation by Object Updating

One of the best features of Manim animation is to control and animate the changes of objects in each scene. It's all about applying this technique to keep the object's color changing, move its posit..

infograph.tistory.com

Go To: [99] Table of Contents

 

 

반응형