让一个点沿着圆走一圈,比手写 updater 简单得多。示例先画出圆,再用 MoveAlongPath(dot, circle) 让点贴着圆周运动,接着用 Rotating 绕指定点转,最后停住。

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from manim import *
class PointMovingOnShapes(Scene):
def construct(self):
circle = Circle(radius=1, color=BLUE)
dot = Dot()
dot2 = dot.copy().shift(RIGHT)
self.play(*[FadeIn(_o) for _o in [dot]], run_time=1.0)
line = Line([3, 0, 0], [5, 0, 0])
self.play(*[FadeIn(_o) for _o in [line]], run_time=1.0)
self.play(GrowFromCenter(circle))
self.play(Transform(dot, dot2))
self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
self.play(Rotating(dot, about_point=[2, 0, 0]), run_time=1.5)
self.wait()

演示视频

下载 Python 脚本

要点

  • MoveAlongPath(mob, path) 让对象沿路径的描边移动,路径本身不必显示
  • rate_func=linear 才是匀速;默认 smooth 会两头慢、中间快
  • Rotating(mob, about_point=...) 是持续旋转动画,和 Rotate 的一次性旋转不同

代码来源:Manim Community 官方 Example Gallery 示例 PointMovingOnShapes(MIT),已在 Manim CE 0.20.1 实跑验证并生成上方视频。