| name | animation-patterns |
| description | Production animation patterns including reveal, transform, progressive reveal, emphasis, and cleanup patterns. |
Animation Patterns
Production-quality animation patterns for mathematical visualizations.
Reveal Patterns
Simple Reveal
self.play(Write(text), run_time=1.5)
self.wait(1)
self.play(Create(shape), run_time=1)
self.play(DrawBorderThenFill(shape), run_time=1.5)
Dramatic Entrance
self.play(GrowFromCenter(obj), run_time=1.5)
self.play(GrowFromEdge(obj, LEFT), run_time=1)
self.play(SpinInFromNothing(obj), run_time=1.5)
Fade Variants
self.play(FadeIn(obj))
self.play(FadeIn(obj, shift=UP))
self.play(FadeIn(obj, shift=DOWN * 0.5))
self.play(FadeIn(obj, scale=0.5))
Transform Patterns
Basic Transform
self.play(Transform(a, b))
self.play(ReplacementTransform(a, b))
self.play(FadeTransform(a, b))
Matching Transforms
self.play(TransformMatchingShapes(text1, text2))
eq1 = MathTex("a", "+", "b", "=", "c")
eq2 = MathTex("a", "=", "c", "-", "b")
self.play(TransformMatchingTex(eq1, eq2))
Staged Transform
self.play(a.animate.move_to(b.get_center()))
self.play(Transform(a, b))
self.play(a.animate.set_color(b.get_color()))
self.play(Transform(a, b))
Progressive Reveal Patterns
LaggedStart
elements = [Circle(), Square(), Triangle()]
self.play(LaggedStart(
*[Create(e) for e in elements],
lag_ratio=0.3
), run_time=3)
LaggedStartMap
group = VGroup(Circle(), Square(), Triangle())
self.play(LaggedStartMap(
Create,
group,
lag_ratio=0.2
), run_time=2)
self.play(LaggedStartMap(
FadeIn,
group,
lag_ratio=0.1,
shift=UP * 0.5
), run_time=2)
Progressive Data Points
points = VGroup(*[Dot(axes.c2p(x, y)) for x, y in data])
self.play(LaggedStart(
*[FadeIn(p, scale=0.5) for p in points],
lag_ratio=0.02
), run_time=3)
Sequential Section Reveal
formula = MathTex("y", "=", "m", "x", "+", "b")
self.play(Write(formula[0:2]))
self.wait(0.5)
self.play(Write(formula[2:4]))
self.wait(0.5)
self.play(Write(formula[4:]))
Emphasis Patterns
Indicate
self.play(Indicate(obj))
self.play(Indicate(obj, color=YELLOW))
self.play(Indicate(obj, scale_factor=1.2))
Circumscribe
self.play(Circumscribe(obj))
self.play(Circumscribe(obj, color=RED))
self.play(Circumscribe(obj, shape=Rectangle))
Flash
self.play(Flash(obj))
self.play(Flash(obj, color=YELLOW, flash_radius=0.5))
FocusOn
self.play(FocusOn(obj))
self.play(FocusOn(point))
Wiggle
self.play(Wiggle(obj))
Combined Emphasis
def emphasize(self, obj):
self.play(Indicate(obj, color=YELLOW))
self.play(Circumscribe(obj, color=YELLOW))
self.play(Flash(obj))
self.wait(2)
Cleanup Patterns
Explicit Tracking
class MyScene(Scene):
def setup(self):
self.tracked = []
def track(self, *mobjects):
for m in mobjects:
self.tracked.append(m)
self.add(m)
return mobjects[0] if len(mobjects) == 1 else mobjects
def cleanup(self, keep=None):
keep = keep or []
to_remove = [m for m in self.tracked if m not in keep]
if to_remove:
self.play(*[FadeOut(m) for m in to_remove])
self.tracked = list(keep)
Group Cleanup
section1_objects = VGroup(title, subtitle, diagram)
self.play(FadeOut(section1_objects))
Transition Pattern
def transition_to_next_section(self, keep=None):
"""Fade out current section, prepare for next"""
keep = keep or []
to_remove = [m for m in self.mobjects if m not in keep]
if to_remove:
self.play(*[FadeOut(m) for m in to_remove], run_time=0.5)
self.wait(0.5)
Dynamic Update Patterns
ValueTracker with always_redraw
tracker = ValueTracker(0)
dot = always_redraw(
lambda: Dot(axes.c2p(tracker.get_value(), f(tracker.get_value())))
)
self.add(dot)
self.play(tracker.animate.set_value(5), run_time=3)
Manual Updater
def update_label(label):
label.next_to(dot, UP)
label.add_updater(update_label)
self.add(label)
label.clear_updaters()
Dynamic Area
tracker = ValueTracker(-3)
area = always_redraw(
lambda: axes.get_area(
graph,
x_range=[-3, tracker.get_value()],
color=BLUE
)
)
self.add(area)
self.play(tracker.animate.set_value(3), run_time=4)
Composition Patterns
Simultaneous
self.play(
Create(circle),
Write(label),
FadeIn(background)
)
Succession
self.play(Succession(
Create(circle),
Wait(0.5),
circle.animate.set_color(RED),
Wait(0.5),
FadeOut(circle)
))
AnimationGroup
self.play(AnimationGroup(
Create(circle),
Create(square),
lag_ratio=0.5,
run_time=2
))
Best Practices
Timing Guidelines
| Animation Type | run_time | wait_after |
|---|
| Title/label | 1.0s | 0.5s |
| Simple shape | 1.0s | 0.5s |
| Formula | 1.5-2.0s | 1.0-2.0s |
| Complex formula | 2.0s | 4.0s |
| Transform | 1.5-2.0s | 1.0s |
| Emphasis | 0.5-1.0s | 0.5s |
| Data reveal | 2.0-3.0s | 1.0s |
Pacing Principles
self.play(Write(text), run_time=0.5)
self.play(Write(new_formula), run_time=2)
self.wait(4)
self.play(Transform(a, b), run_time=3, rate_func=smooth)
self.play(Flash(result))
self.wait(6)
Avoid Anti-Patterns
self.play(Write(complex_formula), run_time=0.3)
self.play(Write(complex_formula), run_time=2)
self.wait(4)
self.play(anim1)
self.play(anim2)
self.play(anim3)
self.play(anim1)
self.wait(1)
self.play(anim2)
self.wait(0.5)
self.play(anim3)