Skip to content

Commit fb799e7

Browse files
kolibril13pre-commit-ci[bot]jsonvillanueva
authored
Further docstrings and examples for :class:~.Mobject (#1232)
* added further docsting to mobject.py * added colour * removed np.random * invert docsting * black + get numpy back * match docstrings * Update manim/mobject/mobject.py * Update manim/mobject/mobject.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update manim/mobject/mobject.py Co-authored-by: Jason Villanueva <[email protected]> * Apply suggestions from code review Co-authored-by: Jason Villanueva <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jason Villanueva <[email protected]>
1 parent 8213d6e commit fb799e7

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

manim/mobject/mobject.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def add_to_back(self, *mobjects: "Mobject") -> "Mobject":
386386
return self
387387

388388
def remove(self, *mobjects: "Mobject") -> "Mobject":
389-
"""Remove submobjects.
389+
"""Remove :attr:`submobjects`.
390390
391391
The mobjects are removed from :attr:`submobjects`, if they exist.
392392
@@ -635,12 +635,13 @@ def show(self, camera=None):
635635
self.get_image(camera=camera).show()
636636

637637
def save_image(self, name=None):
638+
"""Saves an image of only this :class:`Mobject` at its position to a png file."""
638639
self.get_image().save(
639640
Path(config.get_dir("video_dir")).joinpath((name or str(self)) + ".png")
640641
)
641642

642643
def copy(self) -> "Mobject":
643-
"""Create and return an identical copy of the Mobject including all submobjects.
644+
"""Create and return an identical copy of the :class:`Mobject` including all :attr:`submobjects`.
644645
645646
Returns
646647
-------
@@ -1649,6 +1650,7 @@ def fade(self, darkness=0.5, family=True):
16491650
return self
16501651

16511652
def get_color(self):
1653+
"""Returns the color of the :class:`~.Mobject`"""
16521654
return self.color
16531655

16541656
##
@@ -1879,12 +1881,15 @@ def match_coord(self, mobject: "Mobject", dim, direction=ORIGIN):
18791881
)
18801882

18811883
def match_x(self, mobject: "Mobject", direction=ORIGIN):
1884+
"""Match x coord. to the x coord. of another :class:`~.Mobject`."""
18821885
return self.match_coord(mobject, 0, direction)
18831886

1884-
def match_y(self, mobject: "Mobject", direction=ORIGIN):
1887+
def Match_y(self, mobject: "Mobject", direction=ORIGIN):
1888+
"""Match y coord. to the x coord. of another :class:`~.Mobject`."""
18851889
return self.match_coord(mobject, 1, direction)
18861890

18871891
def match_z(self, mobject: "Mobject", direction=ORIGIN):
1892+
"""Match z coord. to the x coord. of another :class:`~.Mobject`."""
18881893
return self.match_coord(mobject, 2, direction)
18891894

18901895
def align_to(
@@ -1954,7 +1959,7 @@ def arrange(
19541959
center=True,
19551960
**kwargs,
19561961
):
1957-
"""Sorts mobjects next to each other on screen.
1962+
"""Sorts :class:`~.Mobject` next to each other on screen.
19581963
19591964
Examples
19601965
--------
@@ -2011,19 +2016,68 @@ def shuffle(self, recursive=False):
20112016
random.shuffle(self.submobjects)
20122017

20132018
def invert(self, recursive=False):
2019+
"""Inverts the list of :attr:`submobjects`.
2020+
2021+
Examples
2022+
--------
2023+
2024+
.. manim:: InvertSumobjectsExample
2025+
2026+
class InvertSumobjectsExample(Scene):
2027+
def construct(self):
2028+
s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
2029+
s2= s.copy()
2030+
s2.invert()
2031+
s2.shift(DOWN)
2032+
self.play(Write(s), Write(s2))
2033+
"""
20142034
if recursive:
20152035
for submob in self.submobjects:
20162036
submob.invert(recursive=True)
20172037
list.reverse(self.submobjects)
20182038

20192039
# Just here to keep from breaking old scenes.
20202040
def arrange_submobjects(self, *args, **kwargs):
2041+
"""Arrange the position of :attr:`submobjects` with a small buffer.
2042+
2043+
Examples
2044+
--------
2045+
2046+
.. manim:: ArrangeSumobjectsExample
2047+
:save_last_frame:
2048+
2049+
class ArrangeSumobjectsExample(Scene):
2050+
def construct(self):
2051+
s= VGroup(*[Dot().shift(i*0.1*RIGHT*np.random.uniform(-1,1)+UP*np.random.uniform(-1,1)) for i in range(0,15)])
2052+
s.shift(UP).set_color(BLUE)
2053+
s2= s.copy().set_color(RED)
2054+
s2.arrange_submobjects()
2055+
s2.shift(DOWN)
2056+
self.add(s,s2)
2057+
2058+
"""
20212059
return self.arrange(*args, **kwargs)
20222060

20232061
def sort_submobjects(self, *args, **kwargs):
2062+
"""Sort the :attr:`submobjects`"""
20242063
return self.sort(*args, **kwargs)
20252064

20262065
def shuffle_submobjects(self, *args, **kwargs):
2066+
"""Shuffles the order of :attr:`submobjects`
2067+
2068+
Examples
2069+
--------
2070+
2071+
.. manim:: SuffleSumobjectsExample
2072+
2073+
class SuffleSumobjectsExample(Scene):
2074+
def construct(self):
2075+
s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
2076+
s2= s.copy()
2077+
s2.shuffle_submobjects()
2078+
s2.shift(DOWN)
2079+
self.play(Write(s), Write(s2))
2080+
"""
20272081
return self.shuffle(*args, **kwargs)
20282082

20292083
# Alignment

0 commit comments

Comments
 (0)