from manim import *
class ArcPolygonRadius(Scene):
    """2.2 radius 统一设置每条边所在圆的半径：半径越大，边越平直。
    注意 ArcPolygon 源码是 if radius: ... else: angle，同时给两个参数时 angle 会被忽略。
    """
    def construct(self):
        kw = dict(font="STLiti")
        title = Text("2.2 统一设置半径 radius", 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]
        specs = [(10, BLUE, "radius = 10"), (2, GREEN, "radius = 2"),
                 (1, YELLOW, "radius = 1")]
        group = VGroup()
        for rad, color, label in specs:
            poly = ArcPolygon(*verts, radius=rad, color=color, stroke_width=5,
                              fill_color=color, fill_opacity=0.22).scale(0.85)
            cap = Text(label, font_size=26, color=color, **kw)
            group.add(VGroup(poly, cap).arrange(DOWN, buff=0.42))
        group.arrange(RIGHT, buff=1.35).shift(DOWN * 0.45)
        note = Text("radius 越大边越平直；同时传 angle 与 radius 时 angle 无效",
                    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(LaggedStart(*[FadeIn(g) for g in group], lag_ratio=0.3, run_time=1.5))
        self.play(FadeIn(note), run_time=0.6)
        self.wait(3.0)
