from manim import *
class DotAlongPath(Scene):
    """2. MoveAlongPath 让点沿任意 VMobject 路径运动。
    点必须先上屏（self.add），路径用 FadeIn/Create 显示；
    run_time 决定走完整个路径所需的时间。
    """
    def construct(self):
        title = Text("2. MoveAlongPath 沿路径移动", font="STLiti", font_size=32).to_edge(UP)
        path = Line(ORIGIN, RIGHT * 2 + UP * 1, color=BLUE, stroke_width=4)
        path.shift(LEFT * 1.5 + DOWN * 0.4)
        dot = Dot(path.get_start(), color=GREEN, radius=0.22)
        caps = VGroup(
            Text("起点 (0, 0)", font="STLiti", font_size=20, color=GREY),
            Text("终点 (2, 1)", font="STLiti", font_size=20, color=GREY),
        )
        caps[0].next_to(path.get_start(), DOWN, buff=0.35)
        caps[1].next_to(path.get_end(), UP, buff=0.35)
        self.play(FadeIn(title), run_time=0.6)
        self.play(Create(path), FadeIn(caps), run_time=1.0)
        self.add(dot)
        self.play(MoveAlongPath(dot, path), run_time=3.0)
        note = Text("路径可以是任意 VMobject：Line、Arc、自定义曲线都行",
                    font="STLiti", font_size=22, color=YELLOW).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.6)
