mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
144 lines
2.9 KiB
Markdown
144 lines
2.9 KiB
Markdown
![]() |
# Scene Module README
|
||
|
|
||
|
## Overview
|
||
|
The scene module provides the framework for creating and managing animations in Manim. It handles the organization, timing, and rendering of animations and mobjects.
|
||
|
|
||
|
## Key Components
|
||
|
|
||
|
### 1. Base Scene Class (`scene.py`)
|
||
|
- **Purpose**: Base class for all scenes
|
||
|
- **Key Features**:
|
||
|
- Manages animation playback
|
||
|
- Handles mobject organization
|
||
|
- Controls scene timing
|
||
|
- **Methods**:
|
||
|
- `play`: Plays animations
|
||
|
- `wait`: Pauses scene
|
||
|
- `add`: Adds mobjects
|
||
|
- `remove`: Removes mobjects
|
||
|
- **Usage**:
|
||
|
```python
|
||
|
class CustomScene(Scene):
|
||
|
def construct(self):
|
||
|
# Scene implementation
|
||
|
pass
|
||
|
```
|
||
|
|
||
|
### 2. Interactive Scene (`interactive_scene.py`)
|
||
|
- **Purpose**: Handles user interaction
|
||
|
- **Key Features**:
|
||
|
- User input handling
|
||
|
- Real-time updates
|
||
|
- Interactive controls
|
||
|
- **Usage**:
|
||
|
```python
|
||
|
class InteractiveExample(InteractiveScene):
|
||
|
def construct(self):
|
||
|
# Interactive implementation
|
||
|
pass
|
||
|
```
|
||
|
|
||
|
### 3. Scene File Writer (`scene_file_writer.py`)
|
||
|
- **Purpose**: Handles scene output
|
||
|
- **Key Features**:
|
||
|
- Video file generation
|
||
|
- Frame rendering
|
||
|
- Progress tracking
|
||
|
- **Usage**:
|
||
|
```python
|
||
|
writer = SceneFileWriter(scene)
|
||
|
writer.begin()
|
||
|
# Scene rendering
|
||
|
writer.finish()
|
||
|
```
|
||
|
|
||
|
### 4. Scene Embed (`scene_embed.py`)
|
||
|
- **Purpose**: Embeds scenes in other contexts
|
||
|
- **Key Features**:
|
||
|
- Jupyter notebook support
|
||
|
- Web embedding
|
||
|
- Interactive previews
|
||
|
- **Usage**:
|
||
|
```python
|
||
|
embed = SceneEmbed(scene)
|
||
|
embed.display()
|
||
|
```
|
||
|
|
||
|
## Scene Features
|
||
|
|
||
|
### 1. Animation Management
|
||
|
- Sequence control
|
||
|
- Timing management
|
||
|
- Animation grouping
|
||
|
|
||
|
### 2. Mobject Management
|
||
|
- Organization
|
||
|
- Layering
|
||
|
- State tracking
|
||
|
|
||
|
### 3. Output Control
|
||
|
- Video generation
|
||
|
- Frame rendering
|
||
|
- Quality settings
|
||
|
|
||
|
## Interaction with Other Modules
|
||
|
|
||
|
1. **Mobject Module**:
|
||
|
- Scenes contain and manage mobjects
|
||
|
- Controls mobject updates
|
||
|
- Handles mobject rendering
|
||
|
|
||
|
2. **Animation Module**:
|
||
|
- Scenes play animations
|
||
|
- Manages animation timing
|
||
|
- Controls animation sequence
|
||
|
|
||
|
3. **Camera Module**:
|
||
|
- Scenes control camera
|
||
|
- Manages camera movements
|
||
|
- Handles rendering
|
||
|
|
||
|
## Best Practices
|
||
|
|
||
|
1. **Scene Organization**:
|
||
|
- Clear structure
|
||
|
- Logical flow
|
||
|
- Proper timing
|
||
|
|
||
|
2. **Animation Management**:
|
||
|
- Smooth transitions
|
||
|
- Appropriate timing
|
||
|
- Clear sequences
|
||
|
|
||
|
3. **Performance**:
|
||
|
- Efficient rendering
|
||
|
- Proper cleanup
|
||
|
- Resource management
|
||
|
|
||
|
## Example Usage
|
||
|
|
||
|
```python
|
||
|
class ExampleScene(Scene):
|
||
|
def construct(self):
|
||
|
# Create mobjects
|
||
|
circle = Circle()
|
||
|
square = Square()
|
||
|
text = Text("Example")
|
||
|
|
||
|
# Organize scene
|
||
|
self.add(circle)
|
||
|
self.wait()
|
||
|
|
||
|
# Animate
|
||
|
self.play(
|
||
|
Transform(circle, square),
|
||
|
Write(text)
|
||
|
)
|
||
|
self.wait()
|
||
|
|
||
|
# Clean up
|
||
|
self.play(
|
||
|
FadeOut(square),
|
||
|
FadeOut(text)
|
||
|
)
|
||
|
```
|