Math animations
Overview
Animated circle generated with the manim library for Python.
I'm trying out Grant Sanderson's (3Blue1Brown) math animation library for Python. I'm using the community-supported edition of manim, which is the most stable and best documented version.
Installation
I had a lot of trouble installing manim. First I tried to install it on Linux Mint, which I have running in a virtual machine. I followed the official installation instructions, but when I tried to run a demo animation, I got an error saying that manim isn't installed. Then I tried the Windows installation instructions using Chocolatey and tried to run the demo in VSCode, but I got a similar error. I then tried installing manim in a virtual environment in Anaconda, but that didn't work either.
Finally I came across a nice tutorial which shows how to install manim in Google Colab. It almost worked, but I got an error related to the comment in this code:
So I removed the comment (and changed the class name and the fill color of the circle) and I got the animated circle above. I don't understand why the code comment caused a problem, but at least I can finally try out manim!
Design file
You can try out all the code on this page without installing anything on your machine:
manim-basics.ipynb - Google Colab notebook
One code snippet doesn't work. Can you make it work? Please let me know if you figure it out.
Learning the basics
Check out the official quickstart guide for explanations on how all the code on this page works.
Here are more demo animations with code:
%%manim SquareNextToCircle
class SquareNextToCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(ORANGE, opacity=0.5) # set the color and transparency
square = Square() # create a square
square.set_fill(BLUE, opacity=0.5) # set the color and transparency
square.next_to(circle, RIGHT, buff=0.5) # set the position
self.play(Create(circle), Create(square)) # show the shapes on screen
%%manim AnimatedSquareToCircle
class AnimatedSquareToCircle(Scene):
def construct(self):
circle = Circle() # create a circle
square = Square() # create a square
self.play(Create(square)) # show the square on screen
self.play(square.animate.rotate(PI / 4)) # rotate the square
self.play(
ReplacementTransform(square, circle)
) # transform the square into a circle
self.play(
circle.animate.set_fill(ORANGE, opacity=0.5)
) # color the circle on screen
%%manim AnimatedSquareToCircleFlip
class AnimatedSquareToCircleFlip(Scene):
def construct(self):
circle = Circle() # create a circle
square = Square() # create a square
self.play(Create(square)) # show the square on screen
self.play(square.animate.flip()) # flip the square
self.play(
ReplacementTransform(square, circle)
) # transform the square into a circle
self.play(
circle.animate.set_fill(ORANGE, opacity=0.5)
) # color the circle on screen
%%manim AnimatedSquareToCircleShift
class AnimatedSquareToCircleShift(Scene):
def construct(self):
circle = Circle() # create a circle
square = Square() # create a square
self.play(Create(square)) # show the square on screen
vector_1 = Vector([1,2])
vector_2 = Vector([-5,-2])
self.play(square.animate.shift(vector_1, vector_2)) # shift the square
self.play(
ReplacementTransform(square, circle)
) # transform the square into a circle
self.play(
circle.animate.set_fill(ORANGE, opacity=0.5)
) # color the circle on screen
%%manim DifferentRotations
class DifferentRotations(Scene):
def construct(self):
left_square = Square(color=WHITE, fill_opacity=0.7).shift(2 * LEFT)
right_square = Square(color=GREY, fill_opacity=0.7).shift(2 * RIGHT)
self.play(
left_square.animate.rotate(PI), Rotate(right_square, angle=PI), run_time=2
)
self.wait()
Next I'm going to try some of the examples.