본문 바로가기

Programming/Manim Lectures

[06-1-F] Animation : Transformation series (2/3)

반응형

CyclicReplace class

object > Animation > Transform > CyclicReplace
manimlib.animation.transform.CyclicReplace(self, *mobjects, **kwargs)

Move the given mobjects one by one.
The first one changes to the second, the second to the third, the last one to the first, and so on, as if on a circular cycle.

 

self.play(CyclicReplace(tri, square, circle), run_time=3)
    CONFIG = {
        "path_arc": 90 * DEGREES,
    }
Parameters: *mobject
    Target objects to be animated.

Parameters: **kwargs
    CONFIG values of CyclicReplace and Transform/Animation

    Frequently used variables are, 
    - run_time=1.0: Animation running time
    - rate_func=smooth: Velocity change function when the animation is running

When three objects are arranged side by side, such as triangle, square, and circle, and the CyclicReplace animation is applied, the effect of moving the objects one space to the rigth can be seen.

 

    def cyclic(self):
        tri = Triangle().to_edge(LEFT, buff=0.5)
        square = Square()
        circle = Circle().to_edge(RIGHT, buff=0.5)
        group = VGroup(tri, square, circle)

        self.add(group)
        self.wait()
        self.play(CyclicReplace(tri, square, circle), run_time=4)
        self.wait()

 

 

 


ScaleInPlace class

object > Animation > Transform > ApplyMethod > ScaleInPlace
manimlib.animation.transform.ScaleInPlace(self, mobject, scale_factor, **kwargs)

An animation effect that changes the mobject to a size equal to the scale_factor scale.

 

self.play(ScaleInPlace(square, 1.5))
Parameters: mobject
    Object to be animated

Parameters: scale_factor
    Scale factor. 
    It is enlarged/reduced by the manification of this value.

Parameters: **kwargs
    CONFIG value of Transform/Animation

    Frequently used variables are, 
    - run_time=1.0: Animation running time
    - rate_func=smooth: Velocity change function when the animation is running

 

It is an animation whose size changes by scale_factor. If scale_factor is greater than 1, it is enlarged, and if it is less than 1, it is reduced.

 

     def scale(self):
        tri = Triangle().to_edge(LEFT, buff=1)
        square = Square()
        circle = Circle().to_edge(RIGHT, buff=1)
        group = VGroup(tri, square, circle)

        self.add(group)
        self.wait()
        self.play(ScaleInPlace(group, 0.3), run_time=3) # 0.3
        self.play(ScaleInPlace(group, 5), run_time=3)  # 1.5 = 0.3 * 5
        self.play(ScaleInPlace(group, 1/1.5), run_time=3) # 1 = 1.5 * 1/1.5
        self.wait()       

 


FadeToColor class

object > Animation > Transform > ApplyMethod > FadeToColor
manimlib.animation.transform.FadeToColor(self, mobject, color, **kwargs)

An animation effect that changes the color of mobject to a given color value.

 

self.play(FadeToColor(square, YELLOW))

Parameters: mobject
    Object to be animated

Parameters: color
    Color value to be changed

Parameters: **kwargs
    CONFIG value of Transform/Animation

    Frequently used variables are, 
    - run_time=1.0: Animation running time
    - rate_func=smooth: Velocity change function when the animation is running

 

It is an animation that chage the color of mobject to a given color value. Below is a sample code to change colors gradually with FadeToColor animation.

 

    def fade_to_color(self):
        tri = Triangle(fill_opacity=1).to_edge(LEFT, buff=1)
        square = Square(fill_opacity=1)
        circle = Circle(fill_opacity=1).to_edge(RIGHT, buff=1)
        group = VGroup(tri, square, circle)

        self.add(group)
        self.wait()
        self.play(FadeToColor(group, RED))
        self.play(FadeToColor(group, GREEN))
        self.play(FadeToColor(group, BLUE))
        self.play(FadeToColor(group, YELLOW))
        self.play(FadeToColor(group, PINK))
        self.wait()

 

 


Restore class

object > Animation > Transform > ApplyMethod > Restore
manimlib.animation.transform.Restore(self, mobject, **kwargs)

Animation that returns mobject to the state it was in when mobject.save_state() was called.

 

The mobject saves the current state as mobject.saved_starte by the save_state() method, and returns to the saved_state by the restore() method.  Restore class shows the animation of the restore() method being executed.

 

Note that in order to use this animation, the mobject.save_state() method must be called at least once prior to run this animation. 

square.save_state()
...
self.play(Restore(square))
Parameters: mobject
    Object to be animated. 
    The mobject.save_state() method must be called at least once.

Parameters: **kwargs
   CONFIG values of Transform and Animation

   Frequently used variables are, 
    - run_time=1.0: Animation running time
    - rate_func=smooth: Velocity change function when the animation is running

The mobject.save_state() and mobject.restore() methods are used when you want to return an object to its initial state after several objects are animated and their position or color/shape is changed. The Restore class is an animation that shows mobject.restore() in action.

 

As an example, let's create an animation that has a circle, and after this circle is blown away, it turns into a triangle, square, pentagon, ... octagon, and then returns to the circle.

 

    def restore(self):
        circle = Circle(fill_opacity=1, radius=0.3).to_edge(LEFT, buff=2)
        circle.save_state()
        self.add(circle)
        self.wait()

        for n, y in zip(np.arange(3,9), np.linspace(3,-3,6)):
            obj = RegularPolygon(n, color=RED).move_to(np.array([5,y,0]))
            self.play(ReplacementTransform(circle, obj))

        self.play(Restore(circle))

        self.wait()  

 


MoveToTarget class

object > Animation > Transform > MoveToTarget

manimlib.animation.transform.MoveToTarget(self, mobject, **kwargs)

Animation moving mobject to mobject.target.

 

The mobject.target is created by mobject.generate_target() method.

 

target = arrow.generate_target()
target.shift(RIGHT*2)
...
self.play(MoveToTarget(arrow))
Parameters: mobject
     Object to be animated

Parameters: **kwargs
   CONFIG values of Transform/Animation

   Frequently used variables are, 
   - run_time=1.0: Animation running time
   - rate_func=smooth: Velocity change function when the animation is running

Animation used to create a clone of an object, transform the clone object, and move/transform the original object to the clone object. When creating a clone object, you can use mobject.copy() method, but it is convenient to make clone object using mobject.generate_target() method and use it by MoveToTarget animation.

 

The example below shows an animation as if an arrow is flying towards the target, making a clone of it through generate_target, moving it around the target on the right side of the screen, and using MoveToTarget.

 

     def move_to_target(self):
        arrow = Arrow(LEFT, RIGHT, stroke_width=7, color=RED).to_edge(LEFT, buff=0.5)
        circle = Circle(stroke_color=WHITE, fill_opacity=1, color=BLUE).to_edge(RIGHT, buff=1)

        self.add(circle, arrow)

        target = arrow.generate_target()
        target.move_to(circle.get_center(), aligned_edge=RIGHT).set_length(target.get_length()-0.5)

        self.play(Rotate(circle,70 * DEGREES, axis=UP))
        self.play(MoveToTarget(arrow), rate_func=running_start, run_time=2)
        self.wait()

 

 

 


Next: [06-1-G] Animation : Transformation series (3/3)

 

[06-1-G] Animation : Transformation series (3/3)

It is the transformation animations that are performed by some method or function. Class Parameters Explanation ApplyMethod mobject, *args, **kwargs Animation effect where a method of mobject is per..

infograph.tistory.com

Go To: [99] Table of Contents

반응형