Skip to content

πŸŽ“ Educational Python animation system using Manim - Perfect code alignment and step-by-step conditional execution visualization

Notifications You must be signed in to change notification settings

yongsa-nut/Manim-python-animation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python 101 Educational Animation System

A Manim-based educational animation system that visualizes Python code execution step-by-step, designed to teach programming fundamentals through clear visual demonstrations.

Features

  • Step-by-step code execution with visual highlighting
  • Curved arrow animations showing data flow
  • Variable memory visualization with real-time updates
  • Calculation overlays demonstrating expression evaluation
  • VS Code Dark+ syntax highlighting
  • Terminal-style output display

Installation

  1. Create and activate a virtual environment:
uv venv
# On Windows: .venv\Scripts\activate
# On macOS/Linux: source .venv/bin/activate
  1. Install dependencies:
uv pip install manim

Usage

Quick Start

Run the basic assignment animation:

./.venv/Scripts/python.exe -m manim -pql main.py BasicAssignment

Available Animations

  1. BasicAssignment - Demonstrates x = 1, x = x + 1, print(x)
  2. MultipleVariables - Shows multiple variable operations
  3. StringOperations - String concatenation example

Quality Settings

  • -pql - Low quality (480p, fast preview)
  • -pqm - Medium quality (720p)
  • -pqh - High quality (1080p)
  • -pqk - 4K quality

Example Commands

# Preview with low quality
./.venv/Scripts/python.exe -m manim -pql main.py BasicAssignment

# Render high quality video
./.venv/Scripts/python.exe -m manim -pqh main.py BasicAssignment

# Test multiple animations
./.venv/Scripts/python.exe -m manim -pql main.py MultipleVariables

Animation Features

Arrow Annotations

The system uses colored arrows to show data flow:

  • Red arrows: Value assignment (e.g., 1 β†’ x)
  • Yellow arrows: Variable substitution in expressions
  • Cyan arrows: Output to terminal

Step-by-Step Execution

For the code x = x + 1:

  1. Highlight line: Shows current executing line
  2. Fetch value: Arrow from memory box to variable in expression
  3. Substitute: Shows x being replaced with 1
  4. Calculate: Displays 1 + 1 = 2
  5. Assign: Arrow showing 2 going to variable x
  6. Update memory: Variable box updates to show new value

Syntax Highlighting

Uses VS Code Dark+ theme colors:

  • Keywords (if, for, def): Blue #569CD6
  • Variables: Light blue #9CDCFE
  • Numbers: Green #B5CEA8
  • Strings: Orange #CE9178
  • Functions: Yellow #DCDCAA

Project Structure

β”œβ”€β”€ main.py                      # Entry point with multiple scenes
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ python_animation.py     # Main animation scene class
β”‚   β”œβ”€β”€ components/              # UI component modules
β”‚   └── utils/                   # Helper utilities
β”œβ”€β”€ media/                       # Generated video files
└── .venv/                       # Virtual environment

Customization

Creating New Animations

  1. Add a new scene class in main.py:
class MyCustomAnimation(PythonAnimation):
    def construct(self):
        self.code_lines = [
            "my_var = 42",
            "result = my_var * 2",
            "print(result)"
        ]
        super().construct()
  1. Run the new animation:
./.venv/Scripts/python.exe -m manim -pql main.py MyCustomAnimation

Timing Configuration

Modify timing in python_animation.py:

# Animation timing (in seconds)
self.wait(1.5)  # Pause duration
run_time=0.8    # Animation speed

Color Schemes

Colors are defined in the colors dictionary in PythonAnimation:

self.colors = {
    'arrow_assignment': "#FF6B6B",  # Red
    'arrow_output': "#4ECDC4",      # Cyan
    'calculation': "#FFD93D"        # Yellow
}

Educational Use

This system is designed for:

  • Programming instructors teaching Python basics
  • Students learning variable assignment and expressions
  • Code visualization in educational videos
  • Step-by-step debugging demonstrations

Best Practices

  1. Start with simple 3-line examples
  2. Use meaningful variable names
  3. Demonstrate one concept per animation
  4. Include print statements to show results

Troubleshooting

Common Issues

  1. Module not found error: Ensure virtual environment is activated
  2. FFmpeg warnings: Install FFmpeg for video processing (optional)
  3. Slow rendering: Use -pql for fast previews during development

Performance Tips

  • Use low quality (-pql) for development
  • Render high quality only for final output
  • Keep animations under 30 seconds for optimal performance

Contributing

  1. Follow the existing code structure
  2. Add new scenes to main.py
  3. Test with low quality before committing
  4. Update documentation for new features

License

Educational use - see project documentation for details.

About

πŸŽ“ Educational Python animation system using Manim - Perfect code alignment and step-by-step conditional execution visualization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages