├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ └── stale.yml ├── .gitignore ├── 3d_graph.py ├── README.md ├── create_graph.py ├── displaying_equations.py ├── displaying_text.py ├── manim_jupyter_example.ipynb ├── requirements.txt ├── square_to_circle.py ├── square_to_circle_modify_objects.py └── videos ├── CreateGraph.mp4 ├── SquareToCircle.mp4 ├── SquareToCircleWithModifications.mp4 ├── displayEquations.mp4 └── displayText.mp4 /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: TannerGilbert 4 | patreon: gilberttanner 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Mark stale issues and pull requests 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" 6 | 7 | jobs: 8 | stale: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/stale@v1 14 | with: 15 | repo-token: ${{ secrets.GITHUB_TOKEN }} 16 | stale-pr-message: 'Stale pull request message' 17 | stale-issue-label: 'no-issue-activity' 18 | stale-pr-label: 'no-pr-activity' 19 | stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days' 20 | days-before-stale: 30 21 | days-before-close: 5 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .vscode 3 | media 4 | .ipynb_checkpoints -------------------------------------------------------------------------------- /3d_graph.py: -------------------------------------------------------------------------------- 1 | from manim import * 2 | 3 | class threeDGraph(ThreeDScene): 4 | def construct(self): 5 | axes = ThreeDAxes() 6 | circle=Circle() 7 | self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) 8 | text3d = Text("This is a 3D text") 9 | self.add(circle,axes) 10 | self.add_fixed_in_frame_mobjects(text3d) 11 | text3d.to_corner(UL) 12 | self.add(axes) 13 | self.wait() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Manim Examples 2 | 3 | [![Manim create graph video](https://img.youtube.com/vi/I0MwXnKSIAM/maxresdefault.jpg)](https://youtu.be/I0MwXnKSIAM) 4 | 5 | ## Table of Contents 6 | 7 | * [Installation](#Installation) 8 | * [Linux Installation](#linux-installation) 9 | * [Windows Installation](#windows-installation) 10 | * [Creating your first Scene](#creating-your-first-scene) 11 | * [Displaying text](#displaying-text) 12 | * [Math equations](#math-equations) 13 | * [Creating graphs](#creating-graphs) 14 | 15 | ## Installation 16 | 17 | For installing Manim on your system I recommend following the [Installation guide](https://docs.manim.community/en/stable/installation.html) from the [Manim documentation](https://docs.manim.community/en/stable/index.html). 18 | 19 | ## Creating your first Scene 20 | 21 | Now that you have installed everything correctly you're ready to write your first application. 22 | 23 | ```python 24 | from manim import * 25 | 26 | class SquareToCircle(Scene): 27 | def construct(self): 28 | # Creating shapes 29 | circle = Circle() 30 | square = Square() 31 | 32 | #Showing shapes 33 | self.play(Create(square)) 34 | self.play(Transform(square, circle)) 35 | self.play(FadeOut(square)) 36 | ``` 37 | 38 | ```bash 39 | manim square_to_circle.py SquareToCircle -p -ql 40 | ``` 41 | 42 | [![Manim square to circle](https://img.youtube.com/vi/f6cvI-gxWP8/maxresdefault.jpg)](https://youtu.be/f6cvI-gxWP8) 43 | 44 | Lets break this down step-by-step: 45 | * The import statement on top imports everything needed to use Manim. 46 | * For running animations, you have to create a class that inherits from Manims Scene class. 47 | * Inside the class you need to create the construct method. The construct method is essentially the main method for the class. In it you can write all the code for the animation. 48 | * Inside the construct method I first created two MObjects (Manim Objects) – a circle and a square. Lastly I displayed the shapes using the play method. 49 | 50 | We can also modify the appearance of the objects by adding a few lines of code: 51 | 52 | ```python 53 | from manim import * 54 | 55 | class SquareToCircleWithModifications(Scene): 56 | def construct(self): 57 | circle = Circle() 58 | square = Square() 59 | square.flip(RIGHT) 60 | square.rotate(-3 * TAU / 8) 61 | circle.set_fill(PINK, opacity=0.5) 62 | 63 | self.play(Create(square)) 64 | self.play(Transform(square, circle)) 65 | self.play(FadeOut(square)) 66 | ``` 67 | 68 | [![Manim square to circle](https://img.youtube.com/vi/9R65QDHDGHU/maxresdefault.jpg)](https://youtu.be/9R65QDHDGHU) 69 | 70 | ## Displaying text 71 | 72 | Displaying text is also pretty straight forward. 73 | 74 | ```python 75 | from manim import * 76 | 77 | 78 | class displayText(Scene): 79 | def construct(self): 80 | # Create Text objects 81 | first_line = Text('Create cool animations') 82 | second_line = Text('using Manim') 83 | third_line = Text('Try it out yourself.', color=RED) 84 | 85 | # Position second line underneath first line 86 | second_line.next_to(first_line, DOWN) 87 | 88 | # Displaying text 89 | self.wait(1) 90 | self.play(Write(first_line), Write(second_line)) 91 | self.wait(1) 92 | self.play(ReplacementTransform(first_line, third_line), FadeOut(second_line)) 93 | self.wait(2) 94 | ``` 95 | 96 | In order to display text you need to create a `Text` object and pass it the text you want to write to the screen. After that you can display the text using the play method and some animation. 97 | 98 | [![Manim display text](https://img.youtube.com/vi/J5-1t2ZxTrA/maxresdefault.jpg)](https://youtu.be/J5-1t2ZxTrA) 99 | 100 | ## Math equations 101 | 102 | Math equations can be written in Manim using [LaTeX](https://www.latex-project.org/) – a typesetting system widely used in academia. On of LaTeX big advantages is that it allows you to create good looking math equation with an intuitive system. 103 | 104 | I won't go over LaTeX in this article but if you are curious there are lots of great tutorials out there. 105 | 106 | For equations instead of using a `Text` object you need to use a `Tex` object. When making an equation you need to put a $ at the start and end of the text. 107 | 108 | ```python 109 | text = Text('some text') 110 | equation = Tex('$some equation$') 111 | ``` 112 | 113 | You can add symbols like the summation or integral symbols with two backslashes. 114 | 115 | ```python 116 | alpha = Tex('$\\alpha$') 117 | ``` 118 | 119 | Displaying some text and an equation could look like the following: 120 | 121 | ```python 122 | from manim import * 123 | 124 | 125 | class displayEquations(Scene): 126 | def construct(self): 127 | # Create Tex objects 128 | first_line = Text('Manim also allows you') 129 | second_line = Text('to show beautiful math equations') 130 | equation = Tex('$d\\left(p, q\\right)=d\\left(q, p\\right)=\\sqrt{(q_1-p_1)^2+(q_2-p_2)^2+...+(q_n-p_n)^2}=\\sqrt{\\sum_{i=1}^n\\left(q_i-p_i\\right)^2}$') 131 | 132 | # Position second line underneath first line 133 | second_line.next_to(first_line, DOWN) 134 | 135 | # Displaying text and equation 136 | self.play(Write(first_line), Write(second_line)) 137 | self.wait(1) 138 | self.play(ReplacementTransform(first_line, equation), FadeOut(second_line)) 139 | self.wait(3) 140 | ``` 141 | 142 | [![Manim display text](https://img.youtube.com/vi/E52oMYpL7A8/maxresdefault.jpg)](https://youtu.be/E52oMYpL7A8) 143 | 144 | ## Creating graphs 145 | 146 | Manim also allows us to create and display graphs. 147 | 148 | ```python 149 | from manim import * 150 | 151 | 152 | class CreateGraph(Scene): 153 | def construct(self): 154 | axes = Axes( 155 | x_range=[-3, 3], 156 | y_range=[-5, 5], 157 | axis_config={"color": BLUE}, 158 | ) 159 | 160 | # Create Graph 161 | graph = axes.get_graph(lambda x: x**2, color=WHITE) 162 | graph_label = axes.get_graph_label(graph, label='x^{2}') 163 | 164 | graph2 = axes.get_graph(lambda x: x**3, color=WHITE) 165 | graph_label2 = axes.get_graph_label(graph2, label='x^{3}') 166 | 167 | # Display graph 168 | self.play(Create(axes), Create(graph), Write(graph_label)) 169 | self.wait(1) 170 | self.play(Transform(graph, graph2), Transform(graph_label, graph_label2)) 171 | self.wait(1) 172 | ``` 173 | 174 | [![Manim display text](https://img.youtube.com/vi/I0MwXnKSIAM/maxresdefault.jpg)](https://youtu.be/I0MwXnKSIAM) 175 | 176 | As you can see to create a graph you need to create a method that returns a y value for every x value it gets. In the code above I used lambda functions to specify them but you can also use any other method. After you have created the method you need to pass it to `axes.get_graph`, which creates a mobject out of the method. 177 | 178 | > Note that the method only specifies how the graph should look like and doesn't actually calculate any values yet. 179 | 180 | ## Author 181 | **Gilbert Tanner** -------------------------------------------------------------------------------- /create_graph.py: -------------------------------------------------------------------------------- 1 | from manim import * 2 | 3 | 4 | class CreateGraph(Scene): 5 | def construct(self): 6 | axes = Axes( 7 | x_range=[-3, 3], 8 | y_range=[-5, 5], 9 | axis_config={"color": BLUE}, 10 | ) 11 | 12 | # Create Graph 13 | graph = axes.get_graph(lambda x: x**2, color=WHITE) 14 | graph_label = axes.get_graph_label(graph, label='x^{2}') 15 | 16 | graph2 = axes.get_graph(lambda x: x**3, color=WHITE) 17 | graph_label2 = axes.get_graph_label(graph2, label='x^{3}') 18 | 19 | # Display graph 20 | self.play(Create(axes), Create(graph), Write(graph_label)) 21 | self.wait(1) 22 | self.play(Transform(graph, graph2), Transform(graph_label, graph_label2)) 23 | self.wait(1) -------------------------------------------------------------------------------- /displaying_equations.py: -------------------------------------------------------------------------------- 1 | from manim import * 2 | 3 | 4 | class displayEquations(Scene): 5 | def construct(self): 6 | # Create Tex objects 7 | first_line = Text('Manim also allows you') 8 | second_line = Text('to show beautiful math equations') 9 | equation = Tex('$d\\left(p, q\\right)=d\\left(q, p\\right)=\\sqrt{(q_1-p_1)^2+(q_2-p_2)^2+...+(q_n-p_n)^2}=\\sqrt{\\sum_{i=1}^n\\left(q_i-p_i\\right)^2}$') 10 | 11 | # Position second line underneath first line 12 | second_line.next_to(first_line, DOWN) 13 | 14 | # Displaying text and equation 15 | self.play(Write(first_line), Write(second_line)) 16 | self.wait(1) 17 | self.play(ReplacementTransform(first_line, equation), FadeOut(second_line)) 18 | self.wait(3) -------------------------------------------------------------------------------- /displaying_text.py: -------------------------------------------------------------------------------- 1 | from manim import * 2 | 3 | 4 | class displayText(Scene): 5 | def construct(self): 6 | # Create Text objects 7 | first_line = Text('Create cool animations') 8 | second_line = Text('using Manim') 9 | third_line = Text('Try it out yourself.', color=RED) 10 | 11 | # Position second line underneath first line 12 | second_line.next_to(first_line, DOWN) 13 | 14 | # Displaying text 15 | self.wait(1) 16 | self.play(Write(first_line), Write(second_line)) 17 | self.wait(1) 18 | self.play(ReplacementTransform(first_line, third_line), FadeOut(second_line)) 19 | self.wait(2) -------------------------------------------------------------------------------- /manim_jupyter_example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "language_info": { 4 | "codemirror_mode": { 5 | "name": "ipython", 6 | "version": 3 7 | }, 8 | "file_extension": ".py", 9 | "mimetype": "text/x-python", 10 | "name": "python", 11 | "nbconvert_exporter": "python", 12 | "pygments_lexer": "ipython3", 13 | "version": "3.8.5-final" 14 | }, 15 | "orig_nbformat": 2, 16 | "kernelspec": { 17 | "name": "python385jvsc74a57bd087f38c488be80a9fc038f418faf2f84647a778091af23bb2bde749c99b4ba6e0", 18 | "display_name": "Python 3.8.5 64-bit ('gilbert': virtualenv)" 19 | } 20 | }, 21 | "nbformat": 4, 22 | "nbformat_minor": 2, 23 | "cells": [ 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "source": [ 28 | "from manim import *" 29 | ], 30 | "outputs": [], 31 | "metadata": {} 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "source": [ 37 | "%%manim SquareToCircle -qm -v WARNING\r\n", 38 | "\r\n", 39 | "class SquareToCircle(Scene):\r\n", 40 | " def construct(self):\r\n", 41 | " # Creating shapes\r\n", 42 | " circle = Circle()\r\n", 43 | " square = Square()\r\n", 44 | "\r\n", 45 | " #Showing shapes\r\n", 46 | " self.play(Create(square))\r\n", 47 | " self.play(Transform(square, circle))\r\n", 48 | " self.play(FadeOut(square))\r\n" 49 | ], 50 | "outputs": [ 51 | { 52 | "output_type": "display_data", 53 | "data": { 54 | "text/plain": [ 55 | "" 56 | ], 57 | "text/html": [ 58 | "
[04/10/21 15:19:24] WARNING  ShowCreation has been deprecated in favor of     creation.py:167\n",
59 |        "                             Create. Please use Create instead!                              \n",
60 |        "
\n" 61 | ] 62 | }, 63 | "metadata": {} 64 | }, 65 | { 66 | "output_type": "stream", 67 | "name": "stderr", 68 | "text": [] 69 | }, 70 | { 71 | "output_type": "display_data", 72 | "data": { 73 | "text/plain": [ 74 | "" 75 | ], 76 | "text/html": [ 77 | "" 80 | ] 81 | }, 82 | "metadata": {} 83 | } 84 | ], 85 | "metadata": {} 86 | } 87 | ] 88 | } -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | manim==0.8.0 2 | -------------------------------------------------------------------------------- /square_to_circle.py: -------------------------------------------------------------------------------- 1 | from manim import * 2 | 3 | class SquareToCircle(Scene): 4 | def construct(self): 5 | # Creating shapes 6 | circle = Circle() 7 | square = Square() 8 | 9 | #Showing shapes 10 | self.play(Create(square)) 11 | self.play(Transform(square, circle)) 12 | self.play(FadeOut(square)) 13 | -------------------------------------------------------------------------------- /square_to_circle_modify_objects.py: -------------------------------------------------------------------------------- 1 | from manim import * 2 | 3 | class SquareToCircleWithModifications(Scene): 4 | def construct(self): 5 | circle = Circle() 6 | square = Square() 7 | square.flip(RIGHT) 8 | square.rotate(-3 * TAU / 8) 9 | circle.set_fill(PINK, opacity=0.5) 10 | 11 | self.play(Create(square)) 12 | self.play(Transform(square, circle)) 13 | self.play(FadeOut(square)) -------------------------------------------------------------------------------- /videos/CreateGraph.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerGilbert/Manim-Examples/5539b0adbdfd39e8ecb92049ec773e50a6765491/videos/CreateGraph.mp4 -------------------------------------------------------------------------------- /videos/SquareToCircle.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerGilbert/Manim-Examples/5539b0adbdfd39e8ecb92049ec773e50a6765491/videos/SquareToCircle.mp4 -------------------------------------------------------------------------------- /videos/SquareToCircleWithModifications.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerGilbert/Manim-Examples/5539b0adbdfd39e8ecb92049ec773e50a6765491/videos/SquareToCircleWithModifications.mp4 -------------------------------------------------------------------------------- /videos/displayEquations.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerGilbert/Manim-Examples/5539b0adbdfd39e8ecb92049ec773e50a6765491/videos/displayEquations.mp4 -------------------------------------------------------------------------------- /videos/displayText.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerGilbert/Manim-Examples/5539b0adbdfd39e8ecb92049ec773e50a6765491/videos/displayText.mp4 --------------------------------------------------------------------------------