目录
一、安装brew
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"
$ cd
$ vim .zshrc
export PATH=/opt/homebrew/bin:$PATH
export PATH=/opt/homebrew/sbin:$PATH
$ source .zshrc
$ brew -v
Homebrew 3.4.1-52-gf0f1eb6-dirty
Homebrew/homebrew-core (git revision ffaaa05a956; last commit 2022-03-12)
Homebrew/homebrew-cask (git revision 0a97b50172; last commit 2022-03-13)
二、安装依赖
$ brew install py3cairo ffmpeg
$ brew install cmake automake pango scipy
$ pip3 install manim
$ brew install wget
$ wget http://www.zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ sudo make install
$ tar -zxvf expat-*.*.*.tar.gz
$ cd expat-*.*.*
$ ./buildconf.sh
$ ./configure
$ make
$ sudo make install
三、运行测试
$ manim
Manim Community v0.15.1
Usage: manim [OPTIONS] COMMAND [ARGS]...
Animation engine for explanatory math videos
Options:
--version Show version and exit.
--help Show this message and exit.
from manim import *
class SquareToCircle(Scene):
def construct(self):
circle = Circle()
circle.set_fill(PINK, opacity=0.5)
square = Square()
square.rotate(PI / 4)
self.play(Create(square))
self.play(Transform(square, circle))
self.play(FadeOut(square))
class AnimatedSquareToCircle(Scene):
def construct(self):
circle = Circle()
square = Square()
self.play(Create(square))
self.play(square.animate.rotate(PI / 4))
self.play(
ReplacementTransform(square, circle)
)
self.play(
circle.animate.set_fill(PINK, opacity=0.5)
)
class DifferentRotations(Scene):
def construct(self):
left_square = Square(color=BLUE, fill_opacity=0.7).shift(2 * LEFT)
right_square = Square(color=GREEN, fill_opacity=0.7).shift(2 * RIGHT)
self.play(
left_square.animate.rotate(PI), Rotate(right_square, angle=PI), run_time=2
)
self.wait()
class Count(Animation):
def __init__(self, number: DecimalNumber, start: float, end: float, **kwargs) -> None:
super().__init__(number, **kwargs)
self.start = start
self.end = end
def interpolate_mobject(self, alpha: float) -> None:
value = self.start + (alpha * (self.end - self.start))
self.mobject.set_value(value)
class CountingScene(Scene):
def construct(self):
number = DecimalNumber().set_color(WHITE).scale(5)
number.add_updater(lambda number: number.move_to(ORIGIN))
self.add(number)
self.wait()
self.play(Count(number, 0, 100), run_time=4, rate_func=linear)
self.wait()
class MobjectExample(Scene):
def construct(self):
p1= [-1,-1,0]
p2= [1,-1,0]
p3= [1,1,0]
p4= [-1,1,0]
a = Line(p1,p2).append_points(Line(p2,p3).points).append_points(Line(p3,p4).points)
point_start= a.get_start()
point_end = a.get_end()
point_center = a.get_center()
self.add(Text(f"a.get_start() = {np.round(point_start,2).tolist()}", font_size=24).to_edge(UR).set_color(YELLOW))
self.add(Text(f"a.get_end() = {np.round(point_end,2).tolist()}", font_size=24).next_to(self.mobjects[-1],DOWN).set_color(RED))
self.add(Text(f"a.get_center() = {np.round(point_center,2).tolist()}", font_size=24).next_to(self.mobjects[-1],DOWN).set_color(BLUE))
self.add(Dot(a.get_start()).set_color(YELLOW).scale(2))
self.add(Dot(a.get_end()).set_color(RED).scale(2))
self.add(Dot(a.get_top()).set_color(GREEN_A).scale(2))
self.add(Dot(a.get_bottom()).set_color(GREEN_D).scale(2))
self.add(Dot(a.get_center()).set_color(BLUE).scale(2))
self.add(Dot(a.point_from_proportion(0.5)).set_color(ORANGE).scale(2))
self.add(*[Dot(x) for x in a.points])
self.add(a)
class HelloLaTeX(Scene):
def construct(self):
tex = Tex(r"\LaTeX", font_size=144)
self.add(tex)
class IncorrectLaTeXSubstringColoring(Scene):
def construct(self):
equation = MathTex(
r"e^x = x^0 + x^1 + \frac{1}{2} x^2 + \frac{1}{6} x^3 + \cdots + \frac{1}{n!} x^n + \cdots"
)
equation.set_color_by_tex("x", YELLOW)
self.add(equation)
class MovingFrameBox(Scene):
def construct(self):
text=MathTex(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
self.play(Write(text))
framebox1 = SurroundingRectangle(text[1], buff = .1)
framebox2 = SurroundingRectangle(text[3], buff = .1)
self.play(
Create(framebox1),
)
self.wait()
self.play(
ReplacementTransform(framebox1,framebox2),
)
self.wait()
$ manim -pql scene.py
1: AnimatedSquareToCircle
2: CountingScene
3: DifferentRotations
4: HelloLaTeX
5: IncorrectLaTeXSubstringColoring
6: MobjectExample
7: MovingFrameBox
8: SquareToCircle
Choose number corresponding to desired scene/arguments.
(Use comma separated list for multiple entries)
Choice(s): 7
