1.pycharm新建两个文件,一个manimCE.py并输入下列代码:
from manim import * class OpeningManim(Scene): def construct(self): config.tex_template=TexTemplateLibrary.ctex #设置中文显示 title = Tex(r"This is some \LaTeX") basel = MathTex(r"\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}") VGroup(title, basel).arrange(DOWN) self.play( Write(title), FadeIn(basel, shift=DOWN), ) self.wait() transform_title = Tex("这是个变换", font_size=72) transform_title.to_corner(UP + LEFT) self.play( Transform(title, transform_title), LaggedStart(*[FadeOut(obj, shift=DOWN) for obj in basel]), ) self.wait() grid = NumberPlane() grid_title = Tex("这是网格", font_size=72) grid_title.move_to(transform_title) self.add(grid, grid_title) # Make sure title is on top of grid self.play( FadeOut(title), FadeIn(grid_title, shift=UP), Create(grid, run_time=3, lag_ratio=0.1), ) self.wait() grid_transform_title = Tex( r"这是个非线性函数 \\ 应用于网格" ) grid_transform_title.move_to(grid_title, UL) grid.prepare_for_nonlinear_transform() self.play( grid.animate.apply_function( lambda p: p + np.array( [ np.sin(p[1]), np.sin(p[0]), 0, ] ) ), run_time=3, ) self.wait() self.play(Transform(grid_title, grid_transform_title)) self.wait()
2.另外建一个main.py并输入下列代码,调用刚才建好的类
OpeningManim标签:play,调用,title,self,transform,grid,pycharm,wait,manim From: https://www.cnblogs.com/yanglu115/p/17936471.html
代码如下:
1 import os 2 os.system('manim -p manimCE.py OpeningManim')