Composition

AnimationGroup

class manimlib.animation.composition.AnimationGroup(*animations, **kwargs)

包含一系列动画,默认lag_ratio为0,但不是序列(即不能通过下标访问动画)

AnimationGroupExample
class AnimationGroupExample(Scene):
    def construct(self):
        mobjects = VGroup(
            Circle(),
            Circle(fill_opacity=1),
            TextMobject("Text").scale(2)
        )
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT,buff=2)

        self.wait()
        anims = AnimationGroup(
            *[GrowFromCenter(mob) for mob in mobjects]
        )
        self.play(anims)
        self.wait()

Succession

class manimlib.animation.composition.Succession(*animations, **kwargs)

将传入的动画一个一个执行

SuccessionExample
class SuccessionExample(Scene):
    def construct(self):
        mobjects = VGroup(
            Circle(),
            Circle(fill_opacity=1),
            TextMobject("Text").scale(2)
        )
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT,buff=2)

        self.add(mobjects)
        self.wait()
        anims = Succession(
            *[ApplyMethod(mob.shift, DOWN) for mob in mobjects]
        )
        self.play(anims)
        self.wait()

LaggedStart

class manimlib.animation.composition.LaggedStart(*animations, **kwargs)

和AnimationGroup相同,lag_ratio为0.05(即上一个动画运行到5%的时候运行下一个动画)

LaggedStartExample
class LaggedStartExample(Scene):
    def construct(self):
        mobjects = VGroup(
            Circle(),
            Circle(fill_opacity=1),
            TextMobject("Text").scale(2)
        )
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT,buff=2)

        self.add(mobjects)
        self.wait()
        anims = LaggedStart(
            *[ApplyMethod(mob.shift, DOWN) for mob in mobjects]
        )
        self.play(anims)
        self.wait()

LaggedStartMap

class manimlib.animation.composition.LaggedStartMap(AnimationClass, mobject, arg_creator=None, **kwargs)

对所有mobject根据AnimationClass创建动画并传入LaggedStart中

LaggedStartMapExample
class LaggedStartMapExample(Scene):
    def construct(self):
        mobjects = VGroup(
            Circle(),
            Circle(fill_opacity=1),
            TextMobject("Text").scale(2)
        )
        mobjects.scale(1.5)
        mobjects.arrange_submobjects(RIGHT,buff=2)

        self.add(mobjects)
        self.wait()
        anims = LaggedStartMap(
            FadeOut, mobjects
        )
        self.play(anims)
        self.wait()