一开始按照这个教程做,但是他的教程是对于debian用户的。
malhotra5/Manim-Tutorial
Clone Manim
git clone https://github.com/3b1b/manim
manjaro 安装ffmpeg, sox, cairo, latex:
sudo pacman -S ffmpeg sox cairo
sudo pacman -S texlive-core texlive-humanities texlive-latexextra texlive-publishers texlive-fontsextra texlive-science texlive-langchinese
sudo pacman -S scipy
(对latex不是很熟悉所以就把textlive-most相关的全装了)
我还把requirements.txt里面的部分版本号给去掉了, 避免出现版本不匹配的错误.
测试
安装完成之后可以在项目目录执行
python3 -m manim example_scenes.py SquareToCircle -pl
来测试是否安装成功。
测试通过之后也可以通过这份代码来测试latex是否安装成功。
from manimlib.imports import *
class Equations(Scene):
def construct(self):
#Making equations
first_eq = TextMobject("$$J(\\theta) = -\\frac{1}{m} [\\sum_{i=1}^{m} y^{(i)} \\log{h_{\\theta}(x^{(i)})} + (1-y^{(i)}) \\log{(1-h_{\\theta}(x^{(i)}))}] $$")
second_eq = ["$J(\\theta_{0}, \\theta_{1})$", "=", "$\\frac{1}{2m}$", "$\\sum\\limits_{i=1}^m$", "(", "$h_{\\theta}(x^{(i)})$", "-", "$y^{(i)}$", "$)^2$"]
second_mob = TextMobject(*second_eq)
for i,item in enumerate(second_mob):
if(i != 0):
item.next_to(second_mob[i-1],RIGHT)
eq2 = VGroup(*second_mob)
des1 = TextMobject("With manim, you can write complex equations like this...")
des2 = TextMobject("Or this...")
des3 = TextMobject("And it looks nice!!")
#Coloring equations
second_mob.set_color_by_gradient("#33ccff","#ff00ff")
#Positioning equations
des1.shift(2*UP)
des2.shift(2*UP)
#Animating equations
self.play(Write(des1))
self.play(Write(first_eq))
self.play(ReplacementTransform(des1, des2), Transform(first_eq, eq2))
self.wait(1)
for i, item in enumerate(eq2):
if (i<2):
eq2[i].set_color(color=PURPLE)
else:
eq2[i].set_color(color="#00FFFF")
self.add(eq2)
self.wait(1)
self.play(FadeOutAndShiftDown(eq2), FadeOutAndShiftDown(first_eq), Transform(des2, des3))
self.wait(2)
执行
python3 -m manim pythonFile.py className -pl