from manim import *
class DotTracedPath(Scene):
    """3. TracedPath 记录点每帧的位置并连成轨迹。
    必须 self.add(trace) 才会画出轨迹；传入的是「取点函数」dot.get_center，
    不要写成 dot.get_center()（那样只传一次坐标，轨迹不会更新）。
    """
    def construct(self):
        title = Text("3. TracedPath 绘制运动轨迹", font="STLiti", font_size=32).to_edge(UP)
        dot = Dot(RIGHT * 2.5, color=WHITE, radius=0.22)
        trace = TracedPath(dot.get_center, stroke_color=RED, stroke_width=3)
        center = Dot(ORIGIN, color=BLUE, radius=0.07)
        self.play(FadeIn(title), run_time=0.6)
        self.add(center, trace, dot)
        self.play(Rotating(dot, about_point=ORIGIN, angle=2 * PI), run_time=4.0)
        note = Text("传入函数名 dot.get_center，TracedPath 每帧取一次位置",
                    font="STLiti", font_size=22, color=YELLOW).to_edge(DOWN)
        self.play(FadeIn(note), run_time=0.6)
        self.wait(2.4)
