DEV Community

Cover image for Getting Started with Manim A Step-by-Step Guide
Eric Dequevedo
Eric Dequevedo

Posted on • Originally published at rics-notebook.com

Getting Started with Manim A Step-by-Step Guide

๐Ÿ“š Introduction

Manim, short for Mathematical Animation Engine, is a powerful Python library that allows you to create stunning animations and visualizations of mathematical concepts. Created by Grant Sanderson, the mind behind the popular YouTube channel 3Blue1Brown, Manim has gained a dedicated following among educators, researchers, and math enthusiasts.

In this tutorial, we'll walk you through the process of setting up Manim and creating your first animation. Whether you're a seasoned Python developer or a beginner looking to explore the world of mathematical visualization, this guide will provide you with the foundation you need to get started with Manim.

๐Ÿ› ๏ธ Setting Up Manim

Before we dive into creating animations, let's make sure you have Manim properly set up on your system. Follow these steps to install Manim:

  1. Install Python: Manim requires Python 3.7 or later. If you don't have Python installed, you can download it from the official Python website (https://www.python.org) and follow the installation instructions for your operating system.

  2. Install Manim: Open a terminal or command prompt and run the following command to install Manim using pip:

   pip install manim
Enter fullscreen mode Exit fullscreen mode

This will install the latest version of Manim along with its dependencies.

  1. Verify the Installation: To ensure that Manim is installed correctly, run the following command:
   manim --version
Enter fullscreen mode Exit fullscreen mode

If Manim is installed properly, you should see the version number printed in the terminal.

๐ŸŽฌ Creating Your First Animation

Now that you have Manim set up, let's create a simple animation to get a feel for how it works. We'll create an animation that showcases the creation of a circle and a square.

  1. Create a New Python File: Open your favorite text editor and create a new file. Save it with a .py extension, for example, first_animation.py.

  2. Import Manim: At the top of your Python file, import the necessary Manim classes:

   from manim import *
Enter fullscreen mode Exit fullscreen mode
  1. Define the Animation Class: Create a new class that inherits from Scene, which is the base class for creating animations in Manim:
   class FirstAnimation(Scene):
       def construct(self):
           # Animation code goes here
Enter fullscreen mode Exit fullscreen mode

The construct method is where you'll define the animation sequence.

  1. Create Shapes: Inside the construct method, create a circle and a square using Manim's built-in shape classes:
   circle = Circle()
   square = Square()
Enter fullscreen mode Exit fullscreen mode
  1. Position the Shapes: Set the positions of the circle and square using the next_to method:
   square.next_to(circle, RIGHT)
Enter fullscreen mode Exit fullscreen mode

This will position the square to the right of the circle.

  1. Animate the Shapes: Use the create method to animate the creation of the shapes:
   self.play(Create(circle), Create(square))
Enter fullscreen mode Exit fullscreen mode

The play method is used to animate objects on the screen.

  1. Save and Run the Animation: Save your Python file and run the following command in the terminal, replacing first_animation.py with the name of your file:
   manim first_animation.py FirstAnimation -p
Enter fullscreen mode Exit fullscreen mode

This command will render the animation and open it in a video player.

Congratulations! You've just created your first animation using Manim. You should see a circle and a square appearing on the screen.

๐ŸŽจ Customizing Your Animation

Manim provides a wide range of options for customizing your animations. Here are a few examples:

  • Changing Colors: You can change the color of shapes using the color parameter:
  circle = Circle(color=RED)
  square = Square(color=BLUE)
Enter fullscreen mode Exit fullscreen mode
  • Adding Text: You can add text to your animation using the Text class:
  text = Text("Hello, Manim!")
  self.play(Write(text))
Enter fullscreen mode Exit fullscreen mode
  • Animating Transformations: Manim allows you to animate transformations between shapes using the Transform class:
  self.play(Transform(circle, square))
Enter fullscreen mode Exit fullscreen mode

This will animate the transformation of the circle into a square.

๐Ÿ““ Learning More

This tutorial provides a basic introduction to Manim, but there's much more to explore. Here are some resources to help you dive deeper into Manim:

  • Official Manim Documentation: The official Manim documentation (https://docs.manim.community/) is a comprehensive resource that covers all aspects of the library. It includes detailed guides, examples, and API references.

  • Manim Community: The Manim community (https://www.manim.community/) is a vibrant group of developers, educators, and enthusiasts who share their knowledge and creations. Joining the community is a great way to learn from others and get inspiration for your own projects.

  • Manim Tutorials: There are numerous tutorials and video courses available online that dive deeper into Manim. A quick search on platforms like YouTube or Udemy will yield a wealth of resources to help you expand your Manim skills.

๐ŸŒŸ Conclusion

Manim is a powerful tool for creating stunning mathematical animations and visualizations. With its intuitive Python API and extensive documentation, Manim makes it easy to bring your mathematical ideas to life.

By following this step-by-step guide, you've learned how to set up Manim, create your first animation, and customize it to suit your needs. As you continue to explore Manim, you'll discover endless possibilities for creating engaging and informative visualizations.

So go ahead and let your creativity run wild! Use Manim to explain complex concepts, showcase mathematical beauty, or simply have fun with animations. The world of mathematical visualization awaits you.

Top comments (0)