Skip to content
Merged
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6ca620d
added docstings to mobject
kolibril13 Mar 31, 2021
3884b78
updated code
kolibril13 Mar 31, 2021
ac670c7
second code environment stroke
kolibril13 Mar 31, 2021
bbf514d
added flip example
kolibril13 Mar 31, 2021
54f2145
fixed format
kolibril13 Mar 31, 2021
67bff33
fixed format2
kolibril13 Mar 31, 2021
f716a4c
further docstings
kolibril13 Mar 31, 2021
7646a44
Merge branch 'master' into added_docstings_mobject
kolibril13 Mar 31, 2021
a1fc6a9
run black and small change
kolibril13 Mar 31, 2021
0fcd4c0
Merge remote-tracking branch 'fork/added_docstings_mobject' into adde…
kolibril13 Mar 31, 2021
181aa53
Apply suggestions from code review
kolibril13 Apr 1, 2021
9ccde7f
Update manim/mobject/mobject.py
kolibril13 Apr 1, 2021
f0ab5c4
Update manim/mobject/mobject.py
kolibril13 Apr 1, 2021
83aa7de
Update manim/mobject/mobject.py
kolibril13 Apr 1, 2021
f4d34ac
Update manim/mobject/mobject.py
kolibril13 Apr 1, 2021
d831bd2
fix error
kolibril13 Apr 1, 2021
0d6b746
added some typehints
kolibril13 Apr 1, 2021
8ffb417
added further docstings
kolibril13 Apr 1, 2021
fab4276
Merge branch 'master' into added_docstings_mobject
huguesdevimeux Apr 1, 2021
e57adfd
added some typehints
kolibril13 Apr 1, 2021
4333708
Merge remote-tracking branch 'fork/added_docstings_mobject' into adde…
kolibril13 Apr 1, 2021
3e73bad
added some more typehints
kolibril13 Apr 1, 2021
e679e26
black
kolibril13 Apr 1, 2021
934d9f5
Added more instances of :class: to Mobject
jsonvillanueva Apr 2, 2021
862978d
Merge branch 'master' into added_docstings_mobject
jsonvillanueva Apr 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,11 @@ def scale(self, scale_factor: float, **kwargs) -> "Mobject":
return self

def rotate_about_origin(self, angle, axis=OUT, axes=[]):
"""Rotates the :class:`~.Mobject` about the ORIGIN, which is at [0,0,0]."""
return self.rotate(angle, axis, about_point=ORIGIN)

def rotate(self, angle, axis=OUT, **kwargs):
"""Rotates the :class:`~.Mobject` about a certain point."""
if config["use_opengl_renderer"]:
rot_matrix_T = rotation_matrix_transpose(angle, axis)
self.apply_points_function(
Expand All @@ -1028,6 +1030,22 @@ def rotate(self, angle, axis=OUT, **kwargs):
return self

def flip(self, axis=UP, **kwargs):
"""Flips/Mirrors an mobject about its center.

Examples
--------

.. manim:: FlipExample
:save_last_frame:

class FlipExample(Scene):
def construct(self):
s= Line(LEFT, RIGHT+UP).shift(4*LEFT)
self.add(s)
s2= s.copy().flip()
self.add(s2)

"""
return self.rotate(TAU / 2, axis, **kwargs)

def stretch(self, factor, dim, **kwargs):
Expand Down Expand Up @@ -1398,12 +1416,15 @@ def set_coord(self, value, dim, direction=ORIGIN):
return self

def set_x(self, x, direction=ORIGIN):
"""Set x value of the center of the :class:`~.Mobject` (``int`` or ``float``)"""
return self.set_coord(x, 0, direction)

def set_y(self, y, direction=ORIGIN):
"""Set y value of the center of the :class:`~.Mobject` (``int`` or ``float``)"""
return self.set_coord(y, 1, direction)

def set_z(self, z, direction=ORIGIN):
"""Set z value of the center of the :class:`~.Mobject` (``int`` or ``float``)"""
return self.set_coord(z, 2, direction)

def space_out_submobjects(self, factor=1.5, **kwargs):
Expand All @@ -1415,6 +1436,7 @@ def space_out_submobjects(self, factor=1.5, **kwargs):
def move_to(
self, point_or_mobject, aligned_edge=ORIGIN, coor_mask=np.array([1, 1, 1])
):
"""Move center of the :class:`~.Mobject` to certain coordinate."""
if isinstance(point_or_mobject, Mobject):
target = point_or_mobject.get_critical_point(aligned_edge)
else:
Expand Down Expand Up @@ -1590,6 +1612,7 @@ def get_color(self):
##

def save_state(self):
"""Save the current state (position, color & size). Can be restored with :meth:`~.Mobject.restore`."""
if hasattr(self, "saved_state"):
# Prevent exponential growth of data
self.saved_state = None
Expand All @@ -1598,6 +1621,7 @@ def save_state(self):
return self

def restore(self):
"""Restores the state that was previously saved with :meth:`~.Mobject.saved_state`."""
if not hasattr(self, "saved_state") or self.save_state is None:
raise Exception("Trying to restore without having saved")
self.become(self.saved_state)
Expand Down Expand Up @@ -1687,6 +1711,7 @@ def get_corner(self, direction):
return self.get_critical_point(direction)

def get_center(self):
"""Get center coordinates"""
return self.get_critical_point(np.zeros(self.dim))

def get_center_of_mass(self):
Expand All @@ -1698,15 +1723,19 @@ def get_boundary_point(self, direction):
return all_points[index]

def get_top(self):
"""Get top coordinates"""
return self.get_edge_center(UP)

def get_bottom(self):
"""Get bottom coordinates"""
return self.get_edge_center(DOWN)

def get_right(self):
"""Get right coordinates"""
return self.get_edge_center(RIGHT)

def get_left(self):
"""Get left coordinates"""
return self.get_edge_center(LEFT)

def get_zenith(self):
Expand All @@ -1721,33 +1750,39 @@ def length_over_dim(self, dim):
) - self.reduce_across_dimension(np.min, np.min, dim)

def get_coord(self, dim, direction=ORIGIN):
"""Meant to generalize get_x, get_y, get_z"""
"""Meant to generalize ``get_x``, ``get_y`` and ``get_z``"""
return self.get_extremum_along_dim(dim=dim, key=direction[dim])

def get_x(self, direction=ORIGIN):
"""Returns x coordinate of the center of the mobject as ``numpy.float64`` """
return self.get_coord(0, direction)

def get_y(self, direction=ORIGIN):
"""Returns y coordinate of the center of the mobject as ``numpy.float64`` """
return self.get_coord(1, direction)

def get_z(self, direction=ORIGIN):
"""Returns z coordinate of the center of the mobject as ``numpy.float64`` """
return self.get_coord(2, direction)

def get_start(self):
"""Returns the point, where the stroke that surrounds the :class:`~.Mobject` starts.
self.throw_error_if_no_points()
if config["use_opengl_renderer"]:
return np.array(self.data["points"][0])
else:
return np.array(self.points[0])

def get_end(self):
"""Returns the point, where the stroke that surrounds the :class:`~.Mobject` ends."""
self.throw_error_if_no_points()
if config["use_opengl_renderer"]:
return np.array(self.data["points"][-1])
else:
return np.array(self.points[-1])

def get_start_and_end(self):
"""Returns starting and ending point of a stroke as a ``tuple``. """
return self.get_start(), self.get_end()

def point_from_proportion(self, alpha):
Expand All @@ -1770,6 +1805,7 @@ def get_z_index_reference_point(self):
return z_index_group.get_center()

def has_points(self):
"""Check if :class:`~.Mobject` contains points."""
return len(self.points) > 0

def has_no_points(self):
Expand Down