所有 Manim 动画都从一个继承 Scene 的类开始,动画写在 construct() 里。这段代码先写出标题与副标题,再把标题变成一个圆,用最短的路径走完「创建对象 → 播放动画 → 变形」三步。

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
from manim import *
class QuickstartOverview(Scene):
def construct(self):
title = Text("Manim", font_size=96, color=BLUE)
subtitle = Text("Mathematical Animation Engine", font_size=30)
VGroup(title, subtitle).arrange(DOWN, buff=0.4)
self.play(Write(title), FadeIn(subtitle, shift=UP))
self.wait(0.5)
circle = Circle(radius=1.2, color=YELLOW)
self.play(Transform(title, circle))
self.wait(1)
self.wait(2.10)

演示视频

下载 Python 脚本

要点

  • 类名随意,但必须继承 Scene,并实现 construct(self)
  • self.play() 一次可接收多个动画,它们会同时播放
  • Transform(a, b) 之后画面上留下的是 a,只是形状变成了 b

代码来源:Manim Community 官方教程 Tutorials / Quickstart,示例代码按 Manim CE 0.20.1 编写并实跑验证。