Skip to content

Commit 2393d6c

Browse files
committed
Allow Swap to accept Group and VGroup and add example
1 parent 3c6a1ee commit 2393d6c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

manim/animation/transform.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
RendererType,
4646
)
4747
from ..mobject.mobject import Group, Mobject
48+
from ..mobject.types.vectorized_mobject import VGroup
4849
from ..utils.paths import path_along_arc, path_along_circles
4950
from ..utils.rate_functions import smooth, squish_rate_func
5051

@@ -729,7 +730,10 @@ def construct(self):
729730
def __init__(
730731
self, *mobjects: Mobject, path_arc: float = 90 * DEGREES, **kwargs
731732
) -> None:
732-
self.group = Group(*mobjects)
733+
if len(mobjects) == 1 and isinstance(mobjects[0], (Group, VGroup)):
734+
self.group = mobjects[0]
735+
else:
736+
self.group = Group(*mobjects)
733737
super().__init__(self.group, path_arc=path_arc, **kwargs)
734738

735739
def create_target(self) -> Group:
@@ -741,7 +745,21 @@ def create_target(self) -> Group:
741745

742746

743747
class Swap(CyclicReplace):
744-
pass # Renaming, more understandable for two entries
748+
"""Another name for :class:`~.CyclicReplace`, which is more understandable for two entries.
749+
750+
Examples
751+
--------
752+
.. manim :: SwapExample
753+
754+
class SwapExample(Scene):
755+
def construct(self):
756+
text_a = Text("A").move_to(LEFT)
757+
text_b = Text("B").move_to(RIGHT)
758+
text_group = Group(text_a, text_b)
759+
self.play(FadeIn(text_group))
760+
self.play(Swap(text_group))
761+
self.wait()
762+
"""
745763

746764

747765
# TODO, this may be deprecated...worth reimplementing?

0 commit comments

Comments
 (0)