from manim import *
class RightAngleDemo(Scene):
    """3.4 RightAngle 依据两条互相垂直的线生成直角标记，Elbow 可独立摆放。
    length / width 控制大小，quadrant 控制所在象限，angle 控制 Elbow 朝向。
    """
    def construct(self):
        title = Text("直角标记 RightAngle / Elbow", font="STLiti", font_size=32).to_edge(UP)
        self.play(Write(title), run_time=0.8)
        def cross():
            return VGroup(Line(LEFT, RIGHT, color=GREY_B),
                          Line(DOWN, UP, color=GREY_B))
        ra_specs = [
            (dict(length=0.2), "length 0.2"),
            (dict(length=0.4), "length 0.4"),
            (dict(quadrant=(1, -1)), "quadrant (1,-1)"),
            (dict(quadrant=(-1, -1)), "quadrant (-1,-1)"),
        ]
        el_specs = [
            (dict(width=0.5), "width 0.5"),
            (dict(width=1.0), "width 1.0"),
            (dict(width=1.0, angle=PI / 2), "angle PI/2"),
            (dict(width=1.0, angle=5 * PI / 4), "angle 5PI/4"),
        ]
        cells = VGroup()
        for kw, name in ra_specs:
            c = cross()
            mark = RightAngle(c[0], c[1], color=YELLOW, **kw)
            cap = Text(name, font="STLiti", font_size=20).next_to(c, DOWN, buff=0.3)
            cells.add(VGroup(c, mark, cap))
        for kw, name in el_specs:
            mark = Elbow(color=BLUE, **kw)
            cap = Text(name, font="STLiti", font_size=20).next_to(mark, DOWN, buff=0.3)
            cells.add(VGroup(mark, cap))
        cells.arrange_in_grid(rows=2, cols=4, buff=(1.1, 0.9)).scale(0.72)
        self.play(LaggedStart(*[FadeIn(x) for x in cells], lag_ratio=0.18),
                  run_time=2.6)
        self.wait(2.6)
