Cool, I had done the same sum as a way to teach myself Manim (@manim_community). pic.twitter.com/UABD23DHRu
— Eric Severson (@EricESeverson) July 8, 2021
The #Airfoil-model of Joukowsky/Жуковского. How to design the lifting unit of an #aircraft in 1910?https://t.co/2EXuzMdCgM#Aerodynamics #Animation @manim_community pic.twitter.com/wVtn0we29j
— A. Bakir (@EngBakir) September 13, 2021
Tomography visualized! (Link to full video below) pic.twitter.com/nHwHsXuLIB
— Kolibril (@kolibril13) August 24, 2021
manimcommunity/manim:stable
Shift + Enter
to execute cells.
config
some options
can be setup, e.g., output video width or log verbosity:
from manim import *
config.media_width = "80%"
config.verbosity = "WARNING"
%%manim -qm CircleToSquare
class CircleToSquare(Scene):
def construct(self):
blue_circle = Circle(color=BLUE, fill_opacity=0.5)
green_square = Square(color=GREEN, fill_opacity=0.8)
self.play(Create(blue_circle))
self.wait()
self.play(Transform(blue_circle, green_square))
self.wait()
Circle
, Square
Create
, Transform
%%manim -qm HelloCircle
class HelloCircle(Scene):
def construct(self):
circle = Circle()
blue_circle = circle.set_color(BLUE).set_opacity(0.5)
label = Text("A wild circle appears!")
label.next_to(blue_circle, DOWN, buff=0.5)
self.play(Create(blue_circle), Write(label))
self.wait()
next_to
, move_to
, shift
UP
, DOWN
, RIGHT
, LEFT
.animate
syntax – method animationsrotate
, scale
, move_to
modify mobjects. .animate
!%%manim -qm CircleAnnouncement
class CircleAnnouncement(Scene):
def construct(self):
blue_circle = Circle(color=BLUE, fill_opacity=0.5)
announcement = Text("Let us draw a circle.")
self.play(Write(announcement))
self.wait()
self.play(announcement.animate.next_to(blue_circle, UP, buff=0.5))
self.play(Create(blue_circle))
.animate
syntax – method animations%%manim -qm AnimateSyntax
class AnimateSyntax(Scene):
def construct(self):
triangle = Triangle(color=RED, fill_opacity=1)
self.play(DrawBorderThenFill(triangle))
self.play(triangle.animate.shift(LEFT))
self.play(triangle.animate.shift(RIGHT).scale(2))
self.play(triangle.animate.rotate(PI/3))
.animate
syntax – method animations.animate
works by directly interpolating between initial and target mobject, this can lead to unintended effects.%%manim -qm DifferentRotations
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()
\
" in Python strings need to be escaped (\\
), or a raw string (r"..."
) needs to be used.%%manim -qm CauchyIntegralFormula
class CauchyIntegralFormula(Scene):
def construct(self):
formula = MathTex(
r"[z^n]f(z) = \frac{1}{2\pi i}\oint_{\gamma} \frac{f(z)}{z^{n+1}}~dz"
)
self.play(Write(formula), run_time=3)
self.wait()
{{ ... }}
.%%manim -qm TransformEquation
class TransformEquation(Scene):
def construct(self):
eq1 = MathTex("42 {{ a^2 }} + {{ b^2 }} = {{ c^2 }}")
eq2 = MathTex("42 {{ a^2 }} = {{ c^2 }} - {{ b^2 }}")
eq3 = MathTex(r"a^2 = \frac{c^2 - b^2}{42}")
self.add(eq1)
self.wait()
self.play(TransformMatchingTex(eq1, eq2))
self.wait()
self.play(TransformMatchingShapes(eq2, eq3))
self.wait()
TransformMatchingTex
, TransformMatchingShapes
%%manim -qm PlotDemo
import numpy as np
class PlotDemo(Scene):
def construct(self):
ax = Axes(x_range=[-1, 5, 1], y_range=[-2, 2, 1])
f = lambda x: np.sin(x*PI) * x/2
plot = ax.get_graph(f, color=GREEN)
area = ax.get_area(plot, x_range=[1, 3])
self.add(ax)
self.wait()
self.play(Create(plot))
self.play(DrawBorderThenFill(area))
self.wait()
%%manim -v WARNING -qm ErdosRenyiGraph
import networkx as nx
nxgraph = nx.erdos_renyi_graph(14, 0.5)
class ErdosRenyiGraph(Scene):
def construct(self):
G = Graph.from_networkx(nxgraph, layout="spring", layout_scale=3.5)
self.play(Create(G))
self.play(*[G[v].animate.move_to(5*RIGHT*np.cos(ind/7 * PI) +
3*UP*np.sin(ind/7 * PI))
for ind, v in enumerate(G.vertices)])
self.play(Uncreate(G))