A community-maintained Python framework for creating mathematical animations.
Fix :meth:`~OpenGLMobject.shuffle` function and add :meth:`~.invert` to OpenGL (#1783)
Mohammad Al-Fetyanie75520c49ce9
diff --git a/manim/animation/creation.py b/manim/animation/creation.pyindex 0fbf03c5e..65bd8959d 100644--- a/manim/animation/creation.py+++ b/manim/animation/creation.py@@ -332,9 +332,9 @@ class Write(DrawBorderThenFill):super().begin()def finish(self) -> None:+ super().finish()if self.reverse:self.reverse_submobjects()- super().finish()class Unwrite(Write):diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex a80d97c7a..7bcdcf183 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -2433,6 +2433,11 @@ class Mobject:def invert(self, recursive=False):"""Inverts the list of :attr:`submobjects`.+ Parameters+ ----------+ recursive+ If ``True``, all submobject lists of this mobject's family are inverted.+Examples--------@@ -2440,8 +2445,8 @@ class Mobject:class InvertSumobjectsExample(Scene):def construct(self):- s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])- s2= s.copy()+ s = VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])+ s2 = s.copy()s2.invert()s2.shift(DOWN)self.play(Write(s), Write(s2))diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.pyindex 3e17ae429..3783da97d 100644--- a/manim/mobject/opengl_mobject.py+++ b/manim/mobject/opengl_mobject.py@@ -424,6 +424,33 @@ class OpenGLMobject:self.add(*submobject_list)return self+ def invert(self, recursive=False):+ """Inverts the list of :attr:`submobjects`.++ Parameters+ ----------+ recursive+ If ``True``, all submobject lists of this mobject's family are inverted.++ Examples+ --------++ .. manim:: InvertSumobjectsExample++ class InvertSumobjectsExample(Scene):+ def construct(self):+ s = VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])+ s2 = s.copy()+ s2.invert()+ s2.shift(DOWN)+ self.play(Write(s), Write(s2))+ """+ if recursive:+ for submob in self.submobjects:+ submob.invert(recursive=True)+ list.reverse(self.submobjects)+ self.assemble_family()+def digest_mobject_attrs(self):"""Ensures all attributes which are mobjects are included@@ -513,6 +540,7 @@ class OpenGLMobject:for submob in self.submobjects:submob.shuffle(recurse=True)random.shuffle(self.submobjects)+ self.assemble_family()return self# Copying