quote,
Manim is an engine for precise programatic animations, designed for creating explanatory math videos.
clone仓库
1 | git clone https://github.com/3b1b/manim.git |
运行demo
1 | cd manim |
编写一个
在manim目录下新建python文件
demo.py,代码如下1
2
3
4
5
6
7
8
9
10
11
12
13
14from manimlib.imports import *
class SquareToCircle(Scene):
def construct(self):
circle = Circle()
circle.set_fill(BLUE, opacity=0.5)
circle.set_stroke(BLUE_A, width=4)
square = Square()
self.play(ShowCreation(square))
self.play(ReplacementTransform(square, circle))
self.wait()
exit()运行程序,执行
manim demo.py SquareToCircle,就会展示如下动画- 执行
manim demo.py SquareToCircle -wm可以在videos目录下生成视屏文件
- 执行
代码解析
定义场景类:
- 需要继承自场景类
Scene - override函数:
construct
1
2class SquareToCircle(Scene):
def construct(self):- 需要继承自场景类
场景元素添加并设置:
1
2
3
4circle = Circle()
circle.set_fill(BLUE, opacity=0.5)
circle.set_stroke(BLUE_A, width=4)
square = Square()动画定义及播放:
1
2self.play(ShowCreation(square))
self.play(ReplacementTransform(square, circle))以上。