0、概述
数学理论与数学公式的展示总是一件很枯燥的事情,但3b1b的manim动画库在github上开源之后,让这一切变得非常简单。目前这个库已经分成两个版本一个由3b1b自身维护。但作者并没有承诺长期维护该库,所以由专门团队再次基础上研发了相应的社区版,并对该版本进行长期维护。本文的所有案例都基于社区版的官方案例。本文主要介绍该库的基本概念相关的案例,文章主要以代码为主,关键代码都有相关注释。
另外本文的运行环境维jupyter这与其他的ide环境运行代码稍微有些不同
1、类库引入已经相关测试
引入类库
from manim import *
1-1、shell命令格式
代码不能像传统python直接运行必须使用manim进行调用,命令格式如下
%manim -h
usage: manim file [flags] [scene [scene ...]] manim {cfg,init,plugins} [opts] Animation engine for explanatory math videos positional arguments: file Path to file holding the python code for the scene scene_names Name of the Scene class you want to see optional arguments: -h, --help show this help message and exit -o OUTPUT_FILE, --output_file OUTPUT_FILE Specify the name of the output file, if it should be different from the scene class name -p, --preview Automatically open the saved file once its done -f, --show_in_file_browser Show the output file in the File Browser --sound Play a success/failure sound --leave_progress_bars Leave progress bars displayed in terminal -a, --write_all Write all the scenes from a file -w, --write_to_movie Render the scene as a movie file (this is on by default) -s, --save_last_frame Save the last frame only (no movie file is generated) -g, --save_pngs Save each frame as a png -i, --save_as_gif Save the video as gif --disable_caching Disable caching (will generate partial-movie-files anyway) --flush_cache Remove all cached partial-movie-files --log_to_file Log termin