from manim import *
import numpy as np
def head(cn, en):
    t = Text(cn, font="STLiti", font_size=27).to_edge(UP)
    s = Text(en, font="Consolas", font_size=20, color=YELLOW).next_to(t, DOWN, buff=0.10)
    return VGroup(t, s)
def foot(cn):
    return Text(cn, font="STLiti", font_size=20, color=YELLOW).to_edge(DOWN)
class GroupAnimDemo(Scene):
    def construct(self):
        self.add(head("高级特效：多个动画的编排", "AnimationGroup / LaggedStart"))
        shapes = VGroup(*[Square(side_length=1.0, color=c).set_fill(c, opacity=0.4)
                          for c in (RED, GREEN, BLUE, YELLOW)])
        shapes.arrange(RIGHT, buff=0.7)
        self.play(LaggedStart(*[FadeIn(s, shift=UP * 0.6) for s in shapes],
                              lag_ratio=0.28), run_time=2.6)
        self.play(AnimationGroup(*[Rotate(s, angle=PI) for s in shapes],
                                 lag_ratio=0.2), run_time=2.4)
        self.play(FadeIn(foot("lag_ratio 决定相邻动画的启动间隔")), run_time=0.4)
        self.wait(1.2)
