from manim import *
class ArcPolygonConfig(Scene):
    """2.3 arc_config 逐条设置每条边：list 长度必须等于顶点数（源码里有 assert）。
    顺序对应 UR→UL（上）、UL→DL（左）、DL→DR（下）、DR→UR（右）；
    dict 直接透传给 ArcBetweenPoints，所以 color / stroke_width 也能逐条设置。
    """
    def construct(self):
        kw = dict(font="STLiti")
        title = Text("2.3 分别设置每个弧 arc_config", 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)
        verts = [UR, UL, DL, DR]
        arc_config = [
            {"angle": 30 * DEGREES, "color": RED, "stroke_width": 6},
            {"angle": 90 * DEGREES, "color": YELLOW, "stroke_width": 6},
            {"radius": 2, "color": GREEN, "stroke_width": 6},
            {"radius": 5, "color": PURPLE, "stroke_width": 6},
        ]
        poly = ArcPolygon(*verts, arc_config=arc_config,
                          fill_color=TEAL, fill_opacity=0.28).scale(1.2).shift(DOWN * 0.25)
        caps = VGroup(
            Text("angle = 30 度", font_size=26, color=RED, **kw).next_to(poly, UP, buff=0.35),
            Text("angle = 90 度", font_size=26, color=YELLOW, **kw).next_to(poly, LEFT, buff=0.35),
            Text("radius = 2", font_size=26, color=GREEN, **kw).next_to(poly, DOWN, buff=0.35),
            Text("radius = 5", font_size=26, color=PURPLE, **kw).next_to(poly, RIGHT, buff=0.35),
        )
        note = Text("arc_config 是 list[dict]，元素个数必须和顶点数相同",
                    font_size=24, color=GREY_B, **kw).to_edge(DOWN, buff=0.3)
        self.play(FadeIn(title), FadeIn(rule), run_time=0.7)
        self.play(FadeIn(poly), run_time=1.2)
        self.play(LaggedStart(*[FadeIn(c) for c in caps], lag_ratio=0.2, run_time=1.0))
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.2)
