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:
- ๐ Open in JupyterLite
- ๐ฅ Download Notebook (Challenge)
- ๐ก Note: Manim requires FFmpeg and LaTeX for full functionality
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 basictexWindows:
# Install FFmpeg from ffmpeg.org
# Install MiKTeX from miktex.orgLinux:
sudo apt install ffmpeg texlive-latex-base texlive-fonts-recommendedOption 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 HelloManimFlags 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:
- Three shapes (circle, square, triangle) appear
- They rotate 360 degrees simultaneously
- They change colors
- They disappear with different effects
Challenge 2: Name Animation
Animate your name:
- Write it letter by letter
- Change the color
- Make it grow and shrink
- 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