from manim import *
class ArrowRatio(Scene):
    """3.1 三个参数如何改变「箭头 : 直线」的视觉比例。
    每列演示一个参数，从上到下依次增大取值，便于横向对照。
    """
    def construct(self):
        title = Text("箭头与直线的比例", font="STLiti", font_size=36).to_edge(UP)
        self.play(Write(title), run_time=0.8)
        # ① buff：箭头两端到 start / end 的留白，越大箭头越短
        col1 = VGroup(*[
            Arrow(2 * LEFT, 2 * RIGHT, buff=b)
            for b in (0, 0.25, 0.5, 0.75)
        ]).arrange(DOWN, buff=0.42)
        # ② 线宽与箭头长度之比：越大，线条相对越粗
        col2 = VGroup(*[
            Arrow(2 * LEFT, 2 * RIGHT, max_stroke_width_to_length_ratio=r)
            for r in (1, 3, 5, 8)
        ]).arrange(DOWN, buff=0.42)
        # ③ 箭头长度与线长之比：越大，箭头相对越大
        col3 = VGroup(*[
            Arrow(2 * LEFT, 2 * RIGHT, max_tip_length_to_length_ratio=r)
            for r in (0.05, 0.12, 0.25, 0.40)
        ]).arrange(DOWN, buff=0.42)
        cols = VGroup(col1, col2, col3).arrange(RIGHT, buff=1.1)
        cols.scale(0.62).shift(DOWN * 0.35)
        labels = VGroup(
            Text("buff", font="STLiti", font_size=26),
            Text("线宽 / 箭头", font="STLiti", font_size=26),
            Text("箭头 / 线长", font="STLiti", font_size=26),
        )
        for lab, col in zip(labels, cols):
            lab.next_to(col, UP, buff=0.35)
        self.play(LaggedStart(*[FadeIn(c) for c in cols], lag_ratio=0.35),
                  run_time=2.4)
        self.play(FadeIn(labels), run_time=0.6)
        self.wait(2.0)
