A community-maintained Python framework for creating mathematical animations.
Better creation Example in docs & buff parameter in arrange (#825)
kolibril1320f8af059620
diff --git a/manim/animation/creation.py b/manim/animation/creation.pyindex 0c8aff24c..8540fb34f 100644--- a/manim/animation/creation.py+++ b/manim/animation/creation.py@@ -4,31 +4,50 @@ r"""Animate the display or removal of a mobject from a scene.:hide_source:from manim import ManimBanner-class CreationModule(Scene):def construct(self):- texts = [Text('manim'), Text('manim')]- texts[0].shift(LEFT * 2 + UP)- texts[1].shift(RIGHT * 2 + UP)+ s1 = Square()+ s2 = Square()+ s3 = Square()+ s4 = Square()+ VGroup(s1, s2, s3, s4).set_x(0).arrange(buff=1.9).shift(UP)+ s5 = Square()+ s6 = Square()+ s7 = Square()+ VGroup(s5, s6, s7).set_x(0).arrange(buff=2.6).shift(2 * DOWN)+ t1 = Text("Write").scale(0.5).next_to(s1, UP)+ t2 = Text("AddTextLetterByLetter").scale(0.5).next_to(s2, UP)+ t3 = Text("ShowCreation").scale(0.5).next_to(s3, UP)+ t4 = Text("Uncreate").scale(0.5).next_to(s4, UP)+ t5 = Text("DrawBorderThenFill").scale(0.5).next_to(s5, UP)+ t6 = Text("ShowIncreasingSubsets").scale(0.45).next_to(s6, UP)+ t7 = Text("ShowSubmobjectsOneByOne").scale(0.45).next_to(s7, UP)++ self.add(s1, s2, s3, s4, s5, s6, s7, t1, t2, t3, t4, t5, t6, t7)++ texts = [Text("manim").scale(0.6), Text("manim").scale(0.6)]+ texts[0].move_to(s1.get_center())+ texts[1].move_to(s2.get_center())self.add(*texts)objs = [ManimBanner().scale(0.25) for _ in range(5)]- for idx, obj in enumerate(objs):- obj.shift(LEFT * 6 + RIGHT * (2.75 * idx) + DOWN)+ objs[0].move_to(s3.get_center())+ objs[1].move_to(s4.get_center())+ objs[2].move_to(s5.get_center())+ objs[3].move_to(s6.get_center())+ objs[4].move_to(s7.get_center())self.add(*objs)self.play(# text creationWrite(texts[0]),AddTextLetterByLetter(texts[1]),-# mobject creationShowCreation(objs[0]),Uncreate(objs[1]),DrawBorderThenFill(objs[2]),ShowIncreasingSubsets(objs[3]),ShowSubmobjectsOneByOne(objs[4]),-run_time=3,)diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 1ebe6b411..e232e3db7 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -1027,9 +1027,32 @@ class Mobject(Container):def family_members_with_points(self):return [m for m in self.get_family() if m.get_num_points() > 0]- def arrange(self, direction=RIGHT, center=True, **kwargs):+ def arrange(+ self,+ direction=RIGHT,+ buff=DEFAULT_MOBJECT_TO_MOBJECT_BUFFER,+ center=True,+ **kwargs,+ ):+ """sort mobjects next to each other on screen.++ Examples+ --------++ .. manim:: Example+ :save_last_frame:++ class Example(Scene):+ def construct(self):+ s1 = Square()+ s2 = Square()+ s3 = Square()+ s4 = Square()+ x = VGroup(s1, s2, s3, s4).set_x(0).arrange(buff=1.0)+ self.add(x)+ """for m1, m2 in zip(self.submobjects, self.submobjects[1:]):- m2.next_to(m1, direction, **kwargs)+ m2.next_to(m1, direction, buff, **kwargs)if center:self.center()return selfdiff --git a/tests/control_data/graphical_units_data/geometry/ArrangeTest.npz b/tests/control_data/graphical_units_data/geometry/ArrangeTest.npznew file mode 100644index 000000000..4c80a2a02Binary files /dev/null and b/tests/control_data/graphical_units_data/geometry/ArrangeTest.npz differdiff --git a/tests/template_generate_graphical_units_data.py b/tests/template_generate_graphical_units_data.pyindex ee91f4525..3f8afa1e2 100644--- a/tests/template_generate_graphical_units_data.py+++ b/tests/template_generate_graphical_units_data.py@@ -7,12 +7,12 @@ from tests.helpers.graphical_units import set_test_scene# More about graphical unit tests: https://github.com/ManimCommunity/manim/wiki/Testing#graphical-unit-test-class YourClassHere(Scene):+class YourClassTest(Scene): # e.g. RoundedRectangleTestdef construct(self):circle = Circle()self.play(Animation(circle))set_test_scene(- YourClassHere, "<module_name>"-) # <module_name> can be e.g. "geometry" or "movements"+ YourClassTest, "INSERT_MODULE_NAME"+) # INSERT_MODULE_NAME can be e.g. "geometry" or "movements"diff --git a/tests/test_graphical_units/test_geometry.py b/tests/test_graphical_units/test_geometry.pyindex 86720b603..cee3eef72 100644--- a/tests/test_graphical_units/test_geometry.py+++ b/tests/test_graphical_units/test_geometry.py@@ -126,6 +126,15 @@ class RoundedRectangleTest(Scene):self.play(Animation(a))+class ArrangeTest(Scene):+ def construct(self):+ s1 = Square()+ s2 = Square()+ x = VGroup(s1, s2).set_x(0).arrange(buff=1.4)+ self.add(x)+ self.wait()++MODULE_NAME = "geometry"