본문 바로가기

Programming/Manim Lectures

[06-1-H] Animation : Grouping

반응형

Animations can be grouped and handled.

 

When grouped, whether to run each animation together or one by one is determined by lag_ratio.

 

lag_ratio = 0 : Run together (simultaneously)
lag_ratio = 1: The previous animation is finished and the next animation is executed
0 < lag_ratio < 1: Wait amount of the ratio, then run the next animation

The most basic class is AnimationGroup class, Succession is lag_ratio=1, and LaggedStart is set with lag_ratio so that the next animation is executed at some interval.

 

Class Parameters Explanation
AnimationGroup *animations, **kwargs A class that allows animations to be grouped and run together or in sequence
Succession *animations, **kwargs Run animations that change one object one after another in sequence.
In other words, after the previous conversion is over, the next animation starts.
LaggedStart *animations, **kwargs Delayed animations are delayed by lag_ratio value and executed sequentially.
The default value of lag_ratio is 0.05
LaggedStartMap AnimationClass, mobject, **kwargs A class that enables AnimationClass to be executed in turn with sub-objects constituting mobject at intervals of lag_ratio.

 

 


AnimationGroup class

 object > Animation > AnimationGroup
manimlib.animation.composition.AnimationGroup(self, *animations, **kwargs)

A class that allows animations to be grouped and run together or in sequence

 

    CONFIG = {
        # If None, this defaults to the sum of all
        # internal animations
        "run_time": None,

        "rate_func": linear,

        # If 0, all animations are played at once.
        # If 1, all are played successively.
        # If >0 and <1, they start at lagged times
        # from one and other.
        "lag_ratio": 0,

        "group": None,
    }
Parameters: *animations
    Animation classes

Parameters: **kwargs
   CONFIG values of AnimationGroup

    Frequently used variables are, 
    - lag_ratio: A value that determines whether to run the given animations at the same time, 
                 or how often to run them sequentially. 
                 
                 0: Simultaneous execution 
                 1: Run the next animation after the previous animation ends
                 0~1: After the previous animation is executed in proporton, 
                      the next animation is executed
    

 

Below is an example of running 3 animations with lag_ratio in 0, 0.1 and 1 respectively.

 

class AnimationGroupTest(Scene):
    def construct(self):        
        self.animation_group()

    def animation_group(self):
        self.t1 = TextMobject("Hello").shift(UP*2).to_edge(LEFT, buff=1)
        self.t2 = TextMobject("Wordld").shift(UP*2).to_edge(RIGHT, buff=1)

        self.shape1 = Circle().to_edge(LEFT, buff=1)
        self.shape2 = Square().to_edge(RIGHT, buff=1)

        self.arrow1 = Arrow().shift(DOWN*2).to_edge(LEFT, buff=1)
        self.arrow2 = Arrow().shift(DOWN*2).to_edge(RIGHT, buff=1)

        self.do_animation("1. lag_ratio=0", 0)
        self.do_animation("2. lag_ratio=0.5", 0.5)
        self.do_animation("3. lag_ratio=1", 1)

    def do_animation(self, name, ratio):
        text = Text(name, stroke_width=0, color=YELLOW, size=0.4).to_corner(UL, buff=0.5)

        self.add(text, self.t1, self.shape1, self.arrow1)
        self.wait(2)

        self.play(
            AnimationGroup(
                TransformFromCopy(self.t1, self.t2, run_time=2),
                TransformFromCopy(self.shape1, self.shape2, run_time=2),
                TransformFromCopy(self.arrow1, self.arrow2, run_time=2),
                lag_ratio=ratio,
            )
        )

        self.wait(0.5)
        self.remove(text, self.t1, self.shape1, self.arrow1)

 


Succession class

object > Animation > AnimationGroup > Succession
manimlib.animation.composition.Succession(self, *animations, **kwargs)

Run animations that change one object one after another in sequence. 
In other words, after the previous conversion is over, the next animation starts.

 

    CONFIG = {
        "lag_ratio": 1,
    }
Parameters: *animations
    Animation classes

Parameters: **kwargs
   CONFIG values of Succession and AnimationGroup

 

It is used to make animations run sequentially. 

However, it is different AnimationGroup with lag_ration=1

 

Succession is not simply set to lag_ratio=1 in AnimationGroup, but is used to animate the transition of one object to another sequentially.

 

In other words, when there are animations A1, A2, and A3, this animation should be used by setting lag_ratio=1 in AnimationGroup to make the animations performed sequentially (A1 perfomed and after finishing A1 then A2 starts), and Succession does not produce the same effect. 

 

On the other hand, Succession can be used to sequentially animate A, B, and C objects, when A changes to B and B changes to C. In other words, it is convenient to think of it as an effect of animating while following the changes of the starting object.

 

    def succession(self):
        text = Text("Succession", stroke_width=0, color=YELLOW, size=0.4).to_corner(UL, buff=0.5)

        t1 = TextMobject("Hello").shift(UP * 2).to_edge(LEFT, buff=1)
        t2 = TextMobject("Wordld").shift(UP * 2).to_edge(RIGHT, buff=1)

        shape1 = Circle().to_edge(LEFT, buff=1)
        shape2 = Square().to_edge(RIGHT, buff=1)

        arrow1 = Arrow().shift(DOWN * 2).to_edge(LEFT, buff=1)
        arrow2 = Arrow().shift(DOWN * 2).to_edge(RIGHT, buff=1)

        self.add(text, t1, shape1, arrow1)
        self.wait(2)

        self.play(
            Succession(
                Transform(t1,t2),
                Transform(shape1, shape2),
                Transform(arrow1, arrow2),
            )
        )

LaggedStart class

object > Animation > AnimationGroup > LaggedStart
manimlib.animation.composition.LaggedStart(self, *animations, **kwargs)

Delayed animations are delayed by lag_ratio value and executed sequentially. 
The default value of lag_ratio is 0.05

 

    CONFIG = {
        "lag_ratio": DEFAULT_LAGGED_START_LAG_RATIO,
    }

 

Parameters: *animations
    Animation classes

Parameters: **kwargs
   CONFIG values of LaggedStart and AnimationGroup

   Frequently used variables are, 
   lag_ratio=DEFAULT_LAGGED_START_LAG_RATIO=0.05: 
       When the total execution time is 1, 
       the next animation is executed after the ratio of 0.05. 
       
       If lag_ratio is 0.3, 30% is executed and then the animation will be executed.

 

This is used when the previous animation starts and after a while the next animation starts.

The intervale is adjusted by lag_ratio value.

 

The example below use lag_ration = 0.3

    def lagged_start(self):
        text = Text("LaggedStart", stroke_width=0, color=YELLOW, size=0.4).to_corner(UL, buff=0.5)

        t1 = TextMobject("Hello").shift(UP * 2).to_edge(LEFT, buff=1)
        t2 = TextMobject("Wordld").shift(UP * 2).to_edge(RIGHT, buff=1)

        shape1 = Circle().to_edge(LEFT, buff=1)
        shape2 = Square().to_edge(RIGHT, buff=1)

        arrow1 = Arrow().shift(DOWN * 2).to_edge(LEFT, buff=1)
        arrow2 = Arrow().shift(DOWN * 2).to_edge(RIGHT, buff=1)

        self.add(text, t1, shape1, arrow1)
        self.wait(2)

        self.play(
            LaggedStart(
                Transform(t1, t2),
                Transform(shape1, shape2),
                Transform(arrow1, arrow2),
                lag_ratio=0.3,
            )
        )

LaggedStartMap class

object > Animation > AnimationGroup > LaggedStart > LaggedStartMap
manimlib.animation.composition.LaggedStartMap(self, AnimationClass, mobject, arg_creator=None, **kwargs)

A class that enables Animation class to be executed in turn with sub-objects of mobject at intervals of lag_ratio.

 

    CONFIG = {
        "run_time": 2,
    }

 

Parameters: AnimationClass
    Animation class to be applied to Mobject instance

Parameters: mobject
    Mobject instance consisting of sub-objects

Parameters: arg_creator=None
    Function t assign parameters to sub-objects

Parameters: **kwargs
   CONFIG values of LaggedStartMap and LaggedStart/AnimationGroup

    Frequently used variables are, 
   lag_ratio=DEFAULT_LAGGED_START_LAG_RATIO=0.05: 
       When the total execution time is 1, 
       the next animation is executed after the ratio of 0.05. 
       
       If lag_ratio is 0.3, 30% is executed and then the animation will be executed.

Suppose that you have an animation with multiple lines of text, the first line starts to appear, then the second line starts, then again, and then the third line starts.

 

You can group these multiple lines of text into one VGroup and animate it with LaggedStartMap.

At this time, lag_ratio determines how much time interval will start after the previous animation starts.

 

If your animation class requires parameters, you can create a function that specifies the parameters.

 

For example, if you want to specify the LEFT parameter in FadeInFrom class,

 

LaggedStartMap(FadeInFrom, text, lambda m: (m, LEFT))

 

Below is sample code to use LaggedStartMap class.

    def lagged_start_map(self):
        text = VGroup(
            TextMobject("Monday"),
            TextMobject("Tuesday"),
            TextMobject("Wednesday"),
            TextMobject("Thursday"),
            TextMobject("Friday"),
        ).arrange(DOWN)

        self.play(
            LaggedStartMap(FadeInFrom, text, lambda m: (m, LEFT), lag_ratio=0.2),
            run_time=10,
        )
        self.wait()

Next: [06-1-I] Animation : Special Effect

 

[06-1-I] Animation : Special Effect

Broadcast class object > Animation > AnimationGroup > LaggedStart > Broadcast manimlib.animation.specialized.Broadcast(self, focal_point, **kwargs) At one point, concentric circles spread out in all..

infograph.tistory.com

Go To: [99] Table of Contents

반응형