Chapter 3.2: Installing Manim & Your First Animation

Get Manim Running and Create Your First Scene

๐ŸŽจ PROJECT 3.2 | Difficulty: Intermediate | Time: 15 minutes

๐Ÿ’ป Interactive Options:

Note

Special Note: This project is designed for students who have completed the first chapter of CS Quests and are familiar with Python basics. If youโ€™re new to programming, consider starting with the earlier lessons before diving into this project.

Another Special Note: This project requires a local Python environment for full functionality. While we provide examples and code snippets here, some features may not run directly in the browser. For the best experience, consider setting up the project on your own computer.

๐Ÿš€ Installing Manim with UV

Option 1: Using UV (Recommended)

# Create a new manim project
mkdir manim-project
cd manim-project

# Initialize UV
uv init

# Add manim
uv add manim

# Manim also needs FFmpeg (for video) and LaTeX (for equations)

Install Dependencies:

macOS:

brew install ffmpeg
brew install --cask mactex-no-gui  # Or: brew install basictex

Windows:

# Install FFmpeg from ffmpeg.org
# Install MiKTeX from miktex.org

Linux:

sudo apt install ffmpeg texlive-latex-base texlive-fonts-recommended

Option 2: Quick Start (Jupyter/Online) - Use Manim Community Online - Run in Google Colab with !pip install manim

๐ŸŽฌ Your First Scene

Create first_scene.py:

from manim import *

class HelloManim(Scene):
    def construct(self):
        # Create text
        text = Text("Hello, Manim!", font_size=72)
        
        # Animate it
        self.play(Write(text))
        self.wait(2)
        self.play(FadeOut(text))

Render it:

uv run manim -pql first_scene.py HelloManim

Flags explained: - -p: Preview after rendering - -q: Quality (l=low, m=medium, h=high, k=4K) - -s: Save last frame as image

๐ŸŽจ Basic Shapes

from manim import *

class BasicShapes(Scene):
    def construct(self):
        # Create shapes
        circle = Circle(radius=1, color=BLUE)
        square = Square(side_length=2, color=RED)
        triangle = Triangle(color=GREEN)
        
        # Position them
        circle.shift(LEFT * 3)
        triangle.shift(RIGHT * 3)
        
        # Animate
        self.play(Create(circle))
        self.play(Create(square))
        self.play(Create(triangle))
        self.wait(1)
        
        # Transform
        self.play(Transform(circle, square))
        self.wait(1)

๐ŸŽฏ Colors and Styling

from manim import *

class ColorDemo(Scene):
    def construct(self):
        # Predefined colors
        shapes = VGroup(
            Circle(color=RED),
            Circle(color=BLUE),
            Circle(color=GREEN),
            Circle(color=YELLOW),
            Circle(color=PURPLE)
        ).arrange(RIGHT, buff=0.5)
        
        # Custom colors (RGB or hex)
        custom = Circle(color="#FF6B6B")
        
        # Opacity and fills
        filled_circle = Circle()
        filled_circle.set_fill(BLUE, opacity=0.7)
        filled_circle.set_stroke(WHITE, width=3)
        
        self.play(Create(shapes))
        self.wait(1)

โœจ Animation Timing

from manim import *

class TimingExample(Scene):
    def construct(self):
        circle = Circle()
        
        # Sequential animations
        self.play(Create(circle), run_time=2)  # Takes 2 seconds
        self.wait(1)  # Pause for 1 second
        self.play(circle.animate.shift(RIGHT * 2), run_time=1)
        
        # Simultaneous animations
        square = Square().shift(LEFT * 2)
        self.play(
            FadeIn(square),
            circle.animate.shift(DOWN),
            run_time=1
        )

๐Ÿ† Practice Challenges

Challenge 1: Shape Dance

Create a scene where:

  1. Three shapes (circle, square, triangle) appear
  2. They rotate 360 degrees simultaneously
  3. They change colors
  4. They disappear with different effects

Challenge 2: Name Animation

Animate your name:

  1. Write it letter by letter
  2. Change the color
  3. Make it grow and shrink
  4. Rotate it

๐Ÿš€ Whatโ€™s Next?

Now that you can create and animate basic objects, weโ€™ll learn:

  • Mathematical functions and graphs
  • LaTeX equations
  • Complex transformations