pip install manim_express以上步骤将安装 manim_express 和 manimlib. 然后就可以在任何代码位置导入使用这个动画库了.
-
渲染一个动画: 3b1b:SquareToCircle
from manimlib import * from manim_express import GlEagerScene scene = GlEagerScene() circle = Circle() circle.set_fill(BLUE, opacity=0.5) circle.set_stroke(BLUE_E, width=4) square = Square() scene.play(ShowCreation(square)) scene.play(ReplacementTransform(square, circle)) scene.hold_on()
与渲染画面交互:
- 按住
d键 或 鼠标左键 然后移动鼠标可以改变三维空间中相机的旋转视角. - 按住
s键 或 鼠标右键 然后移动鼠标可以平移相机. - 按住
z键 或 ctrl键 同时滚动鼠标滚轮以缩放画面. - 通过
r重制相机视角. - 离开/退出当前动画:
qortab - 暂停动画:
spaceorctrloralt - 前一段动画:
LEFT - 后一段动画:
RIGHT - 重新播放当前动画:
DOWN
- 按住
-
manim_expressvsMatplotlib:
使用Eager mode:from manimlib import * from manim_express import GlEagerScene CONFIG.use_online_tex = True # If you don't have installed latex locally. theta = np.linspace(0, 2*np.pi, 200) x = np.cos(theta) y = np.sin(theta) scene = GlEagerScene() scene.plot(x, y, color=GREEN, width=2, scale_ratio=1) scene.hold_on()
使用面向对象的方式:
from manimlib import * from manim_express import GlEagerScene import numpy as np class ScatterExample(GlEagerScene): def clip_1(self): n_features = 2 X = np.random.normal(0, 20, (2000, n_features)) theta = np.linspace(0, np.pi*2, 150) r = 50 x, y = r*np.cos(theta), r*np.sin(theta) self.scatter2d(X[:, 0], X[:, 1], size=.03, color=YELLOW, ratio=0.618) self.scatter2d(x, y, size=.03, color=BLUE) ScatterExample().render()

