from manim import *
import numpy as np
def head(cn, en):
    t = Text(cn, font="STLiti", font_size=27).to_edge(UP)
    s = Text(en, font="Consolas", font_size=20, color=YELLOW).next_to(t, DOWN, buff=0.10)
    return VGroup(t, s)
def foot(cn):
    return Text(cn, font="STLiti", font_size=20, color=YELLOW).to_edge(DOWN)
class MoveAlongPathDemo(Scene):
    def construct(self):
        self.add(head("高级特效：沿任意路径运动", "MoveAlongPath"))
        path = ParametricFunction(lambda t: np.array([3 * np.cos(t), 1.4 * np.sin(t), 0]),
                                  t_range=[0, TAU, 0.02], color=GREY_B).set_stroke(width=3)
        dot = Dot(color=YELLOW, radius=0.16).move_to(path.get_start())
        self.add(path, dot)
        self.play(MoveAlongPath(dot, path, rate_func=linear), run_time=4.0)
        self.play(FadeIn(foot("把 VMobject 作为路径传入，点会沿曲线逐帧移动")), run_time=0.4)
        self.wait(1.6)
