from manim import *
class ArcPolygonFromArcsDemo(Scene):
    """2.4 用四段首尾相接的圆弧拼出闭合弧形多边形。
    关键：ArcBetweenPoints 的 start / end 是必需的位置参数，
    必须写成 ArcBetweenPoints(A, B, angle=..., color=...)；
    只给 angle 和 color 会直接 TypeError（旧版教程里的写法已失效）。
    """
    def construct(self):
        kw = dict(font="STLiti")
        title = Text("2.4 通过圆弧构造多边形", 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)
        A, B, C, D = UR, UL, DL, DR
        arc1 = ArcBetweenPoints(A, B, angle=PI / 6, color=BLUE, stroke_width=6)
        arc2 = ArcBetweenPoints(B, C, angle=PI / 3, color=GREEN, stroke_width=6)
        arc3 = ArcBetweenPoints(C, D, angle=PI / 2, color=YELLOW, stroke_width=6)
        arc4 = ArcBetweenPoints(D, A, angle=2 * PI / 3, color=RED, stroke_width=6)
        poly = ArcPolygonFromArcs(arc1, arc2, arc3, arc4).scale(1.2).shift(DOWN * 0.25)
        caps = VGroup(
            Text("30 度", font_size=26, color=BLUE, **kw).next_to(poly, UP, buff=0.4),
            Text("60 度", font_size=26, color=GREEN, **kw).next_to(poly, LEFT, buff=0.4),
            Text("90 度", font_size=26, color=YELLOW, **kw).next_to(poly, DOWN, buff=0.4),
            Text("120 度", font_size=26, color=RED, **kw).next_to(poly, RIGHT, buff=0.4),
        )
        note = Text("四段弧首尾相接即为闭合多边形，ArcPolygonFromArcs 负责拼合",
                    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.5)
        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)
