from manim import *
class CutoutBasic(Scene):
    """2.1 通用示例：在一个大正方形里挖出四个不同形状的孔。
    Cutout(main_shape, *mobjects, **kwargs) 本身就是一个 VMobject，
    必须 self.add / self.play 才会上屏，只构造不接住返回值就是黑片。
    另外原文的 `Square()scale(2)` 少了点号，是语法错误，应写 Square().scale(2)。
    """
    def construct(self):
        kw = dict(font="STLiti")
        title = Text("2.1 通用示例：一个主体挖四个孔", font_size=36, color=RED, **kw).to_edge(UP, buff=0.3)
        rule = Line(LEFT * 6.6, RIGHT * 6.6, color=BLUE_B, stroke_width=3).next_to(title, DOWN, buff=0.18)
        main = Square(side_length=4.4)
        sub1 = RegularPolygon(6).scale(0.6).move_to(UP * 1.05 + LEFT * 1.15)
        sub2 = Square(side_length=1.2).move_to(UP * 1.05 + RIGHT * 1.15)
        sub3 = RegularPolygon(5).scale(0.6).move_to(DOWN * 1.05 + LEFT * 1.15)
        sub4 = Triangle().scale(0.62).move_to(DOWN * 1.05 + RIGHT * 1.15)
        cut = Cutout(main, sub1, sub2, sub3, sub4, fill_opacity=1,
                     color=BLUE, stroke_color=YELLOW, stroke_width=4)
        note = Text("四个孔洞：六边形 / 正方形 / 五边形 / 三角形，黄色描边",
                    font_size=24, color=GREY_B, **kw).to_edge(DOWN, buff=0.35)
        self.play(FadeIn(title), FadeIn(rule), run_time=0.7)
        self.play(FadeIn(cut), run_time=1.6)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(3.0)
