跳转至

Manim

Mathematical Animations WITH EASE

Manim’s documentation

Manim Tutorial Series

check manim version

manim --version

Text Only
1
2
3
4
PS C:\Users\eric> manim --version
Manim Community v0.18.0

## uninstall manim
pip uninstall manim
Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PS C:\Users\eric> pip uninstall manim
Found existing installation: manim 0.18.0
Uninstalling manim-0.18.0:
  Would remove:
    c:\users\eric\appdata\local\programs\python\python312\lib\site-packages\manim-0.18.0.dist-info\*
    c:\users\eric\appdata\local\programs\python\python312\lib\site-packages\manim\*
    c:\users\eric\appdata\local\programs\python\python312\scripts\manim.exe
    c:\users\eric\appdata\local\programs\python\python312\scripts\manimce.exe
Proceed (Y/n)? y
  Successfully uninstalled manim-0.18.0

install manim

pip install manim

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
PS C:\Users\eric> pip install manim
Collecting manim
  Downloading manim-0.18.1-py3-none-any.whl.metadata (10 kB)
Requirement already satisfied: Pillow>=9.1 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (9.5.0)
Requirement already satisfied: Pygments>=2.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (2.17.2)
Requirement already satisfied: click>=8.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (8.1.7)
Requirement already satisfied: cloup>=2.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (2.1.2)
Requirement already satisfied: decorator>=4.3.2 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (5.1.1)
Requirement already satisfied: isosurfaces>=0.1.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (0.1.0)
Requirement already satisfied: manimpango<1.0.0,>=0.5.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (0.5.0)
Requirement already satisfied: mapbox-earcut>=1.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (1.0.1)
Requirement already satisfied: moderngl<6.0.0,>=5.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (5.10.0)
Requirement already satisfied: moderngl-window>=2.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (2.4.4)
Requirement already satisfied: networkx>=2.6 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (3.2.1)
Requirement already satisfied: numpy>=1.26 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (1.26.4)
Requirement already satisfied: pycairo<2.0.0,>=1.13 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (1.26.0)
Requirement already satisfied: pydub>=0.20.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (0.25.1)
Requirement already satisfied: rich>=12.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (13.7.1)
Requirement already satisfied: scipy>=1.6.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (1.12.0)
Requirement already satisfied: screeninfo>=0.7 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (0.8.1)
Requirement already satisfied: skia-pathops>=0.7.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (0.8.0.post1)
Requirement already satisfied: srt>=3.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (3.5.3)
Requirement already satisfied: svgelements>=1.8.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (1.9.6)
Requirement already satisfied: tqdm>=4.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (4.66.2)
Requirement already satisfied: typing-extensions>=4.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (4.10.0)
Requirement already satisfied: watchdog>=2.0.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from manim) (3.0.0)
Requirement already satisfied: colorama in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from click>=8.0->manim) (0.4.6)
Requirement already satisfied: glcontext<3,>=2.5.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from moderngl<6.0.0,>=5.0.0->manim) (2.5.0)
Requirement already satisfied: pyglet>=2.0dev23 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from moderngl-window>=2.0.0->manim) (2.0.14)
Requirement already satisfied: pyrr<1,>=0.10.3 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from moderngl-window>=2.0.0->manim) (0.10.3)
Requirement already satisfied: markdown-it-py>=2.2.0 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from rich>=12.0.0->manim) (3.0.0)
Requirement already satisfied: mdurl~=0.1 in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from markdown-it-py>=2.2.0->rich>=12.0.0->manim) (0.1.2)
Requirement already satisfied: multipledispatch in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (from pyrr<1,>=0.10.3->moderngl-window>=2.0.0->manim) (1.0.0)
Downloading manim-0.18.1-py3-none-any.whl (585 kB)
   ---------------------------------------- 585.2/585.2 kB 3.4 MB/s eta 0:00:00
Installing collected packages: manim
Successfully installed manim-0.18.1

Install

install ffmpeg-python

Text Only
1
pip install ffmpeg-python

install ffmpeg-python

Text Only
1
pip install ffmpeg-python

No module named pkg_resources

Text Only
1
pip install --upgrade setuptools

install manim

Text Only
1
pip install manim

update pip

Text Only
1
A new release of pip is available: 24.0 -> 24.1

py.exe -m pip install --upgrade pip

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
PS C:\Users\eric> py.exe -m pip install --upgrade pip
Requirement already satisfied: pip in c:\users\eric\appdata\local\programs\python\python312\lib\site-packages (24.0)
Collecting pip
  Downloading pip-24.1-py3-none-any.whl.metadata (3.6 kB)
Downloading pip-24.1-py3-none-any.whl (1.8 MB)
   ---------------------------------------- 1.8/1.8 MB 5.8 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 24.0
    Uninstalling pip-24.0:
      Successfully uninstalled pip-24.0
Successfully installed pip-24.1

check pip version

pip --version

Text Only
1
2
PS C:\Users\eric> pip --version
pip 24.1 from C:\Users\eric\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12)

install colour

Text Only
1
pip install colour

code example 1

testprj.py

Python
1
2
3
4
5
6
7
from manim import *
class FirstExample(Scene):
    def construct(self):
        blue_circle = Circle(color=BLUE, fill_opacity=0.5)
        green_square = Square(color=GREEN, fill_opacity=0.8)
        green_square.next_to(blue_circle, RIGHT)
        self.add(blue_circle, green_square)

run

Text Only
1
manim -qm -p ./testprj.py FirstExample

code example 2

testprj.py

Python
1
2
3
4
5
6
from manim import *

class SecondExample(Scene):
    def construct(self):
        ax = Axes(x_range=(-3,3),y_range=(-3,3))
        self.add(ax)

manim -qm -p ./testprj.py SecondExample

Text Only
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
PS D:\work\manim_work\ModernManim\codes\simple\03> manim -qm -p ./testprj.py SecondExample
Manim Community v0.18.1

[06/23/24 23:19:18] INFO                                                                       scene_file_writer.py:737
                             File ready at
                             'D:\work\manim_work\ModernManim\codes\simple\03\media\images\test
                             prj\SecondExample_ManimCE_v0.18.1.png'

                    INFO     Rendered SecondExample                                                        scene.py:247
                             Played 0 animations
                    INFO     Previewed File at:                                                         file_ops.py:231
                             'D:\work\manim_work\ModernManim\codes\simple\03\media\images\testprj\Secon
                             dExample_ManimCE_v0.18.1.png'

code example 3

testprj.py

Python
1
2
3
4
5
6
7
from manim import *

class SecondExample(Scene):
    def construct(self):
        ax = Axes(x_range=(-3,3),y_range=(-3,3))
        curve = ax.plot( lambda x:(x+2)*x*(x-2)/2,color=RED)
        self.add(ax,curve)

code example 4

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

class SecondExample(Scene):
    def construct(self):
        ax = Axes(x_range=(-3,3),y_range=(-3,3))
        curve = ax.plot( lambda x:(x+2)*x*(x-2)/2,color=RED)
        area = ax.get_area(curve, x_range=(-2,0))
        self.add(ax, curve, area)

code example 5

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

class SecondExample(Scene):
    def construct(self):
        ax = Axes(x_range=(-3,3),y_range=(-3,3))
        curve = ax.plot( lambda x:(x+2)*x*(x-2)/2,color=RED)
        area = ax.get_area(curve, x_range=(-2,0))
        self.add(ax, curve, area)

code example 6

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from manim import *

class SecondExample(Scene):
    def construct(self):
        ax = Axes(x_range=(-3,3),y_range=(-3,3))
        curve = ax.plot( lambda x:(x+2)*x*(x-2)/2,color=RED)
        area = ax.get_area(curve, x_range=(-2,0))
        self.play(Create(ax), Create(curve))
        self.play(FadeIn(area))
        self.wait(2)

code example 7

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from manim import *

class SecondExample(Scene):
    def construct(self):
        ax = Axes(x_range=(-3,3),y_range=(-3,3))
        curve = ax.plot( lambda x:(x+2)*x*(x-2)/2,color=RED)
        area = ax.get_area(curve, x_range=(-2,0))
        self.play(Create(ax,run_time=2), Create(curve,run_time=5))
        self.play(FadeIn(area))
        self.wait(2)

code example 8 SquareToCircle

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

class SquareToCircle(Scene):
    def construct(self):
        green_square = Square(color=GREEN,fill_opacity=0.5)
        self.play(DrawBorderThenFill(green_square))
        blue_circle = Circle(color=BLUE, fill_opacity=0.5)
        self.play(Transform(green_square, blue_circle))

code example 9

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from manim import *

class Positioning(Scene):
    def construct(self):
        plane = NumberPlane()
        self.add(plane)

        # next_to from episode 1
        red_dot = Dot(color=RED)
        green_dot = Dot(color=GREEN)
        green_dot.next_to(red_dot,RIGHT+UP) # RIGHT == [1,0,0]
        self.add(red_dot, green_dot)

code example 10

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from manim import *

class Positioning(Scene):
    def construct(self):
        plane = NumberPlane()
        self.add(plane)

        # next_to from episode 1
        red_dot = Dot(color=RED)
        green_dot = Dot(color=GREEN)
        green_dot.next_to(red_dot,RIGHT+UP) # RIGHT == [1,0,0]
        self.add(red_dot, green_dot)

        # shift
        s = Square(color=ORANGE)
        s.shift(2*UP + 4*RIGHT)
        self.add(s)

        # move_to
        c = Circle(color=PURPLE)
        c.move_to([-3,-2,0])
        self.add(c)

        ## align_to
        c2 = Circle(radius=0.5, color = RED, fill_opacity=0.5)
        c3 = c2.copy().set_color(YELLOW)
        c4 = c2.copy().set_color(ORANGE)
        c2.align_to(s, UP)
        c3.align_to(s, RIGHT)
        c4.align_to(s, UP+RIGHT)
        self.add(c2, c3, c4)

code example 11

testprj.py

Python
1
2
3
4
5
6
7
8
9
from manim import *

class CriticalPoints(Scene):
    def construct(self):
        c = Circle(color=GREEN,fill_opacity=0.5)
        self.add(c)

        for d in [(0,0,0), UP, UR, RIGHT, DR, DOWN, DL, LEFT, UL]:
            self.add(Cross(scale_factor=0.2).move_to(c.get_critical_point(d)))

code example 12 Percent

testprj.py

Python
1
2
3
4
5
6
7
from manim import *
from manim.utils.unit import Percent, Pixels

class UsefulUnits(Scene):
    def construct(self):
        for perc in range(5,51,5):
            self.add(Circle(radius=perc*Percent(X_AXIS)))

code example 13

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *
from manim.utils.unit import Percent, Pixels

class UsefulUnits(Scene):
    def construct(self):
        for perc in range(5,51,5):
            #self.add(Circle(radius=perc*Percent(X_AXIS)))
            self.add(Square(side_length=2*perc*Percent(Y_AXIS),color=YELLOW))

code example 14 Star

testprj.py

Python
1
2
3
4
5
6
7
from manim import *

class Grouping(Scene):
    def construct(self):
        stars = VGroup(*[Star(color=YELLOW,fill_opacity=1).scale(0.5) for _ in range(20)])
        stars.arrange_in_grid(4,5,buff=0.2)
        self.add(stars)

manim cfg write -l cwd

Text Only
1
manim cfg write -l cwd

code example 15

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

config.background_color = YELLOW

class SimpleScene(Scene):
    def construct(self):
        tri = Triangle(color=PURPLE, fill_opacity=0.5)
        self.add(tri)

code example 16

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from manim import *

config.background_color = BLACK
config.frame_width = 10
config.frame_height = 10

config.pixel_width = 500
config.pixel_height = 500

class SimpleScene(Scene):
    def construct(self):
        plane = NumberPlane(x_range=(-8,8),y_range=(-5,5))
        tri = Triangle(color=PURPLE, fill_opacity=0.5)
        self.add(plane, tri)

code example 17

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

config.background_color = BLACK

class ChangeDefaults(Scene):
    def construct(self):
        text = Text("Hello World!")
        self.add(text)

code example 18

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from manim import *
from colour import Color

def myHSV(hue, s = 0.96, v = 0.98):
    return ManimColor.from_hsv([hue,s,v])        

class BasicAnimations(Scene):
    def construct(self):
        polys = VGroup(
            *[RegularPolygon(5, radius=1, fill_opacity=0.5, color=myHSV(j/5)
                             )
                             for j in range(5)]
        ).arrange(RIGHT)
        self.play(DrawBorderThenFill(polys), run_time=2)
        self.play(
            Rotate(polys[0],PI,rate_func=lambda t:t), # rate_func = linear
            Rotate(polys[1],PI,rate_func=smooth), # default behavior
            Rotate(polys[2],PI,rate_func=lambda t: np.sin(t*PI)),
            Rotate(polys[3],PI,rate_func=there_and_back),
            Rotate(polys[4],PI,rate_func=lambda t:1-abs(1-2*t)),
            run_time=2
        )
        self.wait()

code example 19

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

class AnimateSyntax(Scene):
    def construct(self):
        s = Square()
        self.play(s.animate.shift(RIGHT)) # animation of shift by RIGHT
        self.play(s.animate(run_time=2).scale(3)) # supports animation keywords
        self.play(s.animate.scale(1/2).shift(2*LEFT)) # supports chaining

code example 20

testprj.py

Python
1
2
3
4
5
6
7
8
from manim import *

class AnimateSyntax(Scene):
    def construct(self):
        s = Square(color=GREEN, fill_opacity=0.5)
        c = Circle(color=RED, fill_opacity=0.5)
        self.add(s,c)
        self.play(s.animate.shift(UP), c.animate.shift(DOWN))

code example 21

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from manim import *

class AnimateSyntax(Scene):
    def construct(self):
        s = Square(color=GREEN, fill_opacity=0.5)
        c = Circle(color=RED, fill_opacity=0.5)
        self.add(s,c)
        self.play(s.animate.shift(UP), c.animate.shift(DOWN))
        self.play(VGroup(s,c).animate.arrange(RIGHT,buff=1))
        self.play(c.animate(rate_func=linear).shift(RIGHT).scale(2))

code example 22

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from manim import *

class AnimationMechanisms(Scene):
    def construct(self):
        c = Circle()

        c.generate_target()
        c.target.set_fill(color=GREEN, opacity=0.5)
        c.target.shift(2*RIGHT + UP).scale(0.5)
        self.add(c)
        self.wait()        
        self.play(MoveToTarget(c))

code example 23

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from manim import *
from colour import Color

def myHSV(hue, s = 0.96, v = 0.98):
    return ManimColor.from_hsv([hue,s,v])        

class SimpleCustomAnimation(Scene):
    def construct(self):
        def spiral_out(mobject, t):
            radius = 4 * t
            angle = 2 * t + 2 * PI
            mobject.move_to(radius * (np.cos(angle)*RIGHT + np.sin(angle)*UP) )
            mobject.set_color(myHSV(t))
            mobject.set_opacity(1-t)

        d = Dot(color=WHITE)
        self.add( d )
        self.play(UpdateFromAlphaFunc(d, spiral_out, run_time=3))

code example 24

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from manim import *

class Disperse(Animation):
    def __init__(self, mobject, dot_radius= 0.05, dot_number=100, **kwargs):
        super().__init__(mobject,**kwargs)
        self.dot_radius = dot_radius
        self.dot_number = dot_number

    def begin(self):
        dots = VGroup(
            *[Dot(radius=self.dot_radius).move_to(self.mobject.point_from_proportion(p))
            for p in np.linspace(0, 1, self.dot_number)]
        )

        for dot in dots:
            dot.initial_position = dot.get_center()
            dot.shift_vector = 2 * ( dot.get_center() - self.mobject.get_center() )
        dots.set_opacity(0)
        self.mobject.add(dots)
        self.dots = dots
        super().begin()

    def clean_up_from_scene(self, scene:"Scene") -> None:
        super().clean_up_from_scene(scene)
        scene.remove(self.dots)

    def interpolate_mobject(self,alpha):
        if alpha <= 0.5:
            self.mobject.set_opacity(1-2*alpha, family=False)
            self.dots.set_opacity(2*alpha)
        else:
            self.mobject.set_opacity(0)
            self.dots.set_opacity( 2 * ( 1 - alpha ) )
            for dot in self.dots:
                dot.move_to(dot.initial_position + 2*(alpha-0.5)*dot.shift_vector)

class CustomAnimationExample(Scene): 
    def construct(self):
        st = Star(color=YELLOW, fill_opacity=1).scale(3)
        self.add(st)
        self.wait()
        self.play(Disperse(st, dot_number=200, run_time=4))

code example 25

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from manim import *

class AllUpdaterTypes(Scene): 
    def construct(self):
        blue_dot = Dot(color=BLUE)
        dot_label = Text("Hello dot!").next_to(blue_dot, UP)
        dot_label.add_updater(
            lambda mobject: mobject.next_to(blue_dot, UP)
        )
        self.add(blue_dot, dot_label)
        self.play(blue_dot.animate.shift(RIGHT))
        self.play(blue_dot.animate.scale(3))
        self.play(blue_dot.animate.center())

code example 26

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from manim import *

class AllUpdaterTypes(Scene): 
    def construct(self):
        red_dot = Dot(color=RED).shift(LEFT)
        pointer = Arrow(ORIGIN, RIGHT).next_to(red_dot, LEFT)
        pointer.add_updater( # place arrow left of dot
            lambda mob: mob.next_to(red_dot, LEFT)
        )

        def shifter(mob, dt): # make dot curve 2 munits RIGHT/sec
            mob.shift(2*dt*RIGHT)

        red_dot.add_updater(shifter)

        def scene_scaler(dt): # scale mobject depending on distance to ORIGIN
            for mob in self.mobjects:
                mob.set(width=2/(1 + np.linalg.norm(mob.get_center())))

        self.add_updater(scene_scaler)

        self.add(red_dot, pointer);
        self.update_self(0)
        self.wait(5)

run

Text Only
1
manim -qm -p --disable_caching ./testprj.py AllUpdaterTypes

code example 27

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from manim import *

class UpdaterAndAnimation(Scene): 
    def construct(self):
        red_dot = Dot(color=RED).shift(LEFT)
        rotating_square = Square()
        rotating_square.add_updater(
            lambda mob, dt: mob.rotate( PI * dt )
        )

        def shifter(mob, dt): # make dot curve 2 munits RIGHT/sec
            mob.shift(2*dt*RIGHT)

        red_dot.add_updater(shifter)

        self.add(red_dot, rotating_square);
        self.wait(1)
        red_dot.suspend_updating()
        self.wait(1)

        self.play(
            red_dot.animate.shift(UP),
            rotating_square.animate.move_to([-2, -2, 0])
        )

code example 28

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from manim import *

class ValueTrackerPlot(Scene): 
    def construct(self):
        line = NumberLine(x_range=[-5,5])
        position = ValueTracker(0) # assign initial value of tracker
        pointer = Vector(DOWN)
        pointer.add_updater( # stick pointer to tracked position
            lambda mob: mob.next_to(
                line.number_to_point(position.get_value()), UP
            )
        )

        pointer.update() # manual executuion of update function
        self.add(line, pointer)
        self.wait()
        self.play(position.animate.set_value(4)) # change tracker  value to 4
        self.play(position.animate.set_value(-2)) #... and to -2

code example 29

testprj.py

Python
1
2
3
4
5
6
7
from manim import *
from manim.opengl import *

class OpenGLIntro(Scene): 
    def construct(self):
        hello_world = Tex("Hello World!").scale(3)
        self.play(Write(hello_world))

run

Text Only
1
manim -qm -p --renderer=opengl ./testprj.py OpenGLIntro

code example 30

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from manim import *
from manim.opengl import *

class OpenGLIntro(Scene): 
    def construct(self):
        hello_world = Tex("Hello World!").scale(3)
        self.play(Write(hello_world))
        self.play(
            self.camera.animate.set_euler_angles(
                theta=-10*DEGREES,
                phi=50*DEGREES
            )
        )
        self.play(FadeOut(hello_world))

code example 31

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from manim import *
from manim.opengl import *

class OpenGLIntro(Scene): 
    def construct(self):
        hello_world = Tex("Hello World!").scale(3)
        self.play(Write(hello_world))
        self.play(
            self.camera.animate.set_euler_angles(
                theta=-10*DEGREES,
                phi=50*DEGREES
            )
        )
        self.play(FadeOut(hello_world))
        surface = OpenGLSurface(
            lambda u,v: (u,v,u*np.sin(v)+v*np.cos(v)),
            u_range=(-3,3),
            v_range=(-3,3)
        )

        surface_mesh = OpenGLSurfaceMesh(surface)
        self.play(Create(surface_mesh))
        self.play(FadeTransform(surface_mesh, surface))
        self.wait()

code example 32 DiGraphExample

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from manim import *

class DiGraphExample(Scene):
    def construct(self):
        D = DiGraph(
            [0,1,2,3,4],
            [
                (0,1),(1,2),(2,3),(3,0),
                (1,3),(2,0),(2,4),(4,3),
            ],
        ).center()
        self.add(D)

code example 33 DiGraphExample

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from manim import *

class DiGraphExample(Scene):
    def construct(self):
        D = DiGraph(
            [0,1,2,3,4],
            [
                (0,1),(1,2),(2,3),(3,0),
                (1,3),(2,0),(2,4),(4,3),
            ],
            layout={
                0: 2*LEFT + 2*DOWN,
                1: 2*RIGHT + 2*DOWN,
                2: 2*RIGHT + 2*UP,
                3: 2*LEFT + 2*UP,
                4: 4*UP,
            },
        ).center()
        self.add(D)

code example 34 DiGraphExample

testprj.py

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from manim import *

class DiGraphExample(Scene):
    def construct(self):
        D = DiGraph(
            [0,1,2,3,4],
            [
                (0,1),(1,2),(2,3),(3,0),
                (1,3),(2,0),(2,4),(4,3),
            ],
            layout={
                0: 2*LEFT + 2*DOWN,
                1: 2*RIGHT + 2*DOWN,
                2: 2*RIGHT + 2*UP,
                3: 2*LEFT + 2*UP,
                4: 4*UP,
            },
            labels=True,
            edge_config={
                "tip_config":{"tip_shape": StealthTip},
            }
        ).center()
        self.play(Create(D))
        self.wait()
        self.play(D.animate.change_layout('circular'))
        self.wait()