from manim import *
class FadePiecesDemo(Scene):
    def construct(self):
        title = Text("FadeTransformPieces：按子图逐个变换", font="STLiti", font_size=28).to_edge(UP)
        self.play(FadeIn(title), run_time=0.6)
        squares = VGroup(*[Square(side_length=0.9, color=BLUE, stroke_width=6) for _ in range(4)])
        squares.arrange_in_grid(rows=2, cols=2, buff=0.5)
        targets = VGroup(Circle(radius=0.45, color=YELLOW, stroke_width=6),
                         Triangle(color=GREEN, stroke_width=6).scale(0.7),
                         Star(color=RED, stroke_width=6).scale(0.6),
                         Square(side_length=0.8, color=PURPLE, stroke_width=6))
        targets.arrange_in_grid(rows=2, cols=2, buff=0.6)
        self.play(FadeIn(squares), run_time=0.8)
        self.play(FadeTransformPieces(squares, targets), run_time=2.2)
        note = Text("子图一一对应地淡入淡出，而不是整体融合", font="STLiti", font_size=21, color=YELLOW).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.4)
        self.wait(2.0)
