2021/9/16MANIM笔记

安装教程太多我就不多说了

安装多让大家安装manimgl

image-20210916200140316

manimgl或者manim render都可以。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Usage: python -m manim render [OPTIONS] FILE [SCENE_NAMES]...

Render SCENE(S) from the input FILE.

FILE is the file path of the script.

SCENES is an optional list of scenes in the file.

Global options:
-c, --config_file TEXT Specify the configuration file to use for
render settings.
--custom_folders Use the folders defined in the
[custom_folders] section of the config file
to define the output folder structure.
--disable_caching Disable the use of the cache (still
generates cache files).
--flush_cache Remove cached partial movie files.
--tex_template TEXT Specify a custom TeX template file.
-v, --verbosity [DEBUG|INFO|WARNING|ERROR|CRITICAL]
Verbosity of CLI output. Changes ffmpeg log
level unless 5+.
--notify_outdated_version / --silent
Display warnings for outdated installation.
--enable_gui Enable GUI interaction.
--gui_location TEXT Starting location for the GUI.
--fullscreen Expand the window to its maximum possible
size.

Output options:
-o, --output_file TEXT Specify the filename(s) of the rendered
scene(s).
-0, --zero_pad INTEGER RANGE Zero padding for PNG file names. [0<=x<=9]
--write_to_movie Write to a file.
--media_dir PATH Path to store rendered videos and latex.
--log_dir PATH Path to store render logs.
--log_to_file Log terminal output to file.

Render Options:
-n, --from_animation_number TEXT
Start rendering from n_0 until n_1. If n_1
is left unspecified, renders all scenes
after n_0.
-a, --write_all Render all scenes in the input file.
--format [png|gif|mp4|webm|mov]
-s, --save_last_frame
-q, --quality [l|m|h|p|k] Render quality at the follow resolution
framerates, respectively: 854x480 30FPS,
1280x720 30FPS, 1920x1080 60FPS, 2560x1440
60FPS, 3840x2160 60FPS
-r, --resolution TEXT Resolution in (W,H) for when 16:9 aspect
ratio isn't possible.
--fps, --frame_rate FLOAT Render at this frame rate.
--renderer [cairo|opengl|webgl]
Select a renderer for your Scene.
--use_opengl_renderer Render scenes using OpenGL (Deprecated).
--use_webgl_renderer Render scenes using the WebGL frontend
(Deprecated).
--webgl_renderer_path PATH The path to the WebGL frontend.
-g, --save_pngs Save each frame as png (Deprecated).
-i, --save_as_gif Save as a gif (Deprecated).
-s, --save_last_frame Save last frame as png (Deprecated).
-t, --transparent Render scenes with alpha channel.
--use_projection_fill_shaders Use shaders for OpenGLVMobject fill which
are compatible with transformation matrices.
--use_projection_stroke_shaders
Use shaders for OpenGLVMobject stroke which
are compatible with transformation matrices.

Ease of access options:
--progress_bar [display|leave|none]
Display progress bars and/or keep them
displayed.
-p, --preview Preview the Scene's animation. OpenGL does a
live preview in a popup window. Cairo opens
the rendered video file in the system
default media player.
-f, --show_in_file_browser Show the output file in the file browser.
--jupyter Using jupyter notebook magic.

Other options:
--help Show this message and exit.

Made with <3 by Manim Community developers.

上面是新版manim render的用法,老款用的是

1
python -m manim加命令。

现在要用manim render.

image-20210916202903307

可以用-p后面不加命令,自动保存为mp4格式,我加上了transparent(透明的),播放时可能会有透明背景,并且文件格式为.mov,不过需要特定的播放器。image-20210916210126544

加-n 数字,表示从第几个图像开始保存显示。

1
2
3
4
5
6
7
8
9
10
11
12
class WriteText(Scene):
def construct(self):
text = Text('A Text')
text.to_edge(UP)
text.move_to(0 * UP + 0.1 * RIGHT)
circle = Circle(radius=3, color=GREEN);
self.play(Write(text))
self.wait(5)
self.remove(text)
self.wait(1);
self.play(Create(circle));
self.play(FadeOut(circle));

学习了一些方法。比如画圆,平移move_to等,明天继续。

我们运行动画后发现对Text文字部分只运行了最后一句,也就是move_to

并没有运行to_edge说明play只运行一个object的最后状态。

我们要找一个能够运行对一个object的所有方法。

move_to的区别在于,next_to表示的是边界的距离,而不是中心距离

例如:

1
text1.next_to(text2, LEFT, buff=2)

旋转

1
rotate(PI / 4)

用作对象的方法。

1
someObject.flip(DIRECTION)#按照矢量方向旋转180度。

再看看同时播放多种动作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class ChangeColorAndSizeAnimation(Scene):
def construct(self):
text = Text("Text")
text.scale(2)
text.shift(LEFT*2)
self.play(Write(text))
self.wait()
self.play(
text.shift, RIGHT*2,
text.scale, 2,
text.set_color, RED,
run_time=2#这个run_time要作为最后一个参数

)
self.wait()