mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
4.8 KiB
4.8 KiB
Animation Module README
Overview
The animation module is the core of Manim's animation system. It provides classes and utilities for creating and managing animations of mobjects (mathematical objects).
Key Components
1. Base Animation Class (animation.py
)
- Purpose: Base class for all animations in Manim
- Key Features:
- Manages animation timing and interpolation
- Handles mobject updates during animation
- Provides core animation functionality
- Usage:
class CustomAnimation(Animation): def interpolate(self, alpha): # Custom interpolation logic pass
2. Transform Animations (transform.py
)
- Purpose: Handles transformations between mobjects
- Key Classes:
Transform
: Base transformation classReplacementTransform
: Replaces one mobject with anotherTransformFromCopy
: Creates a copy for transformationMoveToTarget
: Moves mobject to its target position
- Usage:
scene.play(Transform(circle, square)) scene.play(ReplacementTransform(text1, text2))
3. Creation Animations (creation.py
)
- Purpose: Animates the creation of mobjects
- Key Classes:
ShowCreation
: Draws mobject from start to endWrite
: Writes text or equationsDrawBorderThenFill
: Draws border then fills
- Usage:
scene.play(ShowCreation(circle)) scene.play(Write(text))
4. Fading Animations (fading.py
)
- Purpose: Handles fade in/out animations
- Key Classes:
FadeIn
: Fades in a mobjectFadeOut
: Fades out a mobjectFadeInFrom
: Fades in from a specific direction
- Usage:
scene.play(FadeIn(circle)) scene.play(FadeOut(text))
5. Movement Animations (movement.py
)
- Purpose: Handles movement and rotation animations
- Key Classes:
MoveAlongPath
: Moves along a pathRotate
: Rotates mobjectApplyMethod
: Applies a method with animation
- Usage:
scene.play(MoveAlongPath(dot, path)) scene.play(Rotate(circle, PI/2))
6. Composition Animations (composition.py
)
- Purpose: Combines multiple animations
- Key Classes:
AnimationGroup
: Plays animations simultaneouslySuccession
: Plays animations in sequenceLaggedStart
: Starts animations with delay
- Usage:
scene.play(AnimationGroup( FadeIn(circle), Write(text), lag_ratio=0.5 ))
7. Indication Animations (indication.py
)
- Purpose: Highlights and draws attention to mobjects
- Key Classes:
Flash
: Creates a flash effectIndicate
: Highlights a mobjectShowPassingFlash
: Shows a passing flash
- Usage:
scene.play(Flash(circle)) scene.play(Indicate(text))
8. Update Animations (update.py
)
- Purpose: Updates mobjects based on functions
- Key Classes:
UpdateFromFunc
: Updates based on functionUpdateFromAlphaFunc
: Updates based on alpha
- Usage:
def update_func(mob): mob.rotate(0.1) scene.play(UpdateFromFunc(circle, update_func))
Interaction with Other Modules
-
Mobject Module:
- Animations operate on mobjects
- Uses mobject properties and methods for transformations
- Interacts with mobject families and groups
-
Scene Module:
- Scenes play and manage animations
- Handles timing and synchronization
- Manages animation queues and playback
-
Camera Module:
- Animations can affect camera position
- Camera movements are handled as animations
- 3D animations interact with camera orientation
Best Practices
-
Animation Timing:
- Use appropriate
run_time
for smooth animations - Consider
lag_ratio
for sequential animations - Use
rate_func
for custom timing curves
- Use appropriate
-
Performance:
- Group similar animations together
- Use
AnimationGroup
for parallel animations - Consider using
LaggedStart
for complex sequences
-
Code Organization:
- Create custom animations for reusable effects
- Use composition for complex animations
- Keep animations focused and modular
Example Usage
class ComplexAnimation(Scene):
def construct(self):
# Create mobjects
circle = Circle()
square = Square()
text = Text("Example")
# Basic animations
self.play(ShowCreation(circle))
self.wait()
# Transform animation
self.play(Transform(circle, square))
self.wait()
# Composition of animations
self.play(AnimationGroup(
FadeIn(text),
Indicate(square),
lag_ratio=0.5
))
# Custom animation
def update_func(mob, alpha):
mob.rotate(alpha * TAU)
self.play(UpdateFromAlphaFunc(square, update_func))