Skip to content

Commit 0d4dcf1

Browse files
committed
feat(lib): add zoom animation
1 parent 98fa534 commit 0d4dcf1

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

manim_slides/slide.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,71 @@ def construct(self):
630630

631631
return AnimationGroup(*animations, **kwargs)
632632

633+
def zoom(
634+
self,
635+
current: Sequence[Mobject] = [],
636+
future: Sequence[Mobject] = [],
637+
scale: float = 4.0,
638+
out: bool = False,
639+
fade_in_kwargs: Mapping[str, Any] = {},
640+
fade_out_kwargs: Mapping[str, Any] = {},
641+
**kwargs: Any,
642+
) -> AnimationGroup:
643+
"""
644+
Returns a zoom animation that will fade out all the current objects,
645+
and fade in all the future objects. Objects are faded in a direction
646+
that goes towards the camera.
647+
648+
:param current: A sequence of mobjects to remove from the scene.
649+
:param future: A sequence of mobjects to add to the scene.
650+
:param scale: How much the objects are scaled.
651+
:param out: If set, the objects fade in the opposite direction.
652+
:param fade_in_kwargs: Keyword arguments passed to
653+
:class:`FadeIn<manim.animation.fading.FadeIn>`.
654+
:param fade_out_kwargs: Keyword arguments passed to
655+
:class:`FadeOut<manim.animation.fading.FadeOut>`.
656+
:param kwargs: Keyword arguments passed to
657+
:class:`AnimationGroup<manim.animation.composition.AnimationGroup>`.
658+
659+
Examples
660+
--------
661+
662+
.. manim-slides:: ZoomExample
663+
664+
from manim import *
665+
from manim_slides import Slide
666+
667+
class ZoomExample(Slide):
668+
def construct(self):
669+
circle = Circle(radius=3, color=BLUE)
670+
square = Square()
671+
text = Text("This is a zoom example").next_to(square, DOWN)
672+
beautiful = Text("Beautiful, no?")
673+
674+
self.play(Create(circle))
675+
self.next_slide()
676+
677+
self.play(self.zoom(circle, Group(square, text)))
678+
self.next_slide()
679+
680+
self.play(self.zoom(Group(square, text), beautiful, out=True))
681+
"""
682+
scale_in = 1.0 / scale
683+
scale_out = scale
684+
685+
if out:
686+
scale_in, scale_out = scale_out, scale_in
687+
688+
animations = []
689+
690+
for mobject in future:
691+
animations.append(FadeIn(mobject, scale=scale_in, **fade_in_kwargs))
692+
693+
for mobject in current:
694+
animations.append(FadeOut(mobject, scale=scale_out, **fade_out_kwargs))
695+
696+
return AnimationGroup(*animations, **kwargs)
697+
633698

634699
class ThreeDSlide(Slide, ThreeDScene): # type: ignore
635700
"""

0 commit comments

Comments
 (0)