Skip to content

Commit

Permalink
Added some examples for Mobject/VMobject methods (ManimCommunity#…
Browse files Browse the repository at this point in the history
…3641)

* Add examples to mobject+vmobject methods

* Add missing import

* Separate whitespace to point_from_proportion

* Fixes!

* Changed example of Mobject.get_color

* Remove unneccessary import

* Add in import
  • Loading branch information
JasonGrace2282 authored Apr 1, 2024
1 parent 909ffde commit afe1d18
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
14 changes: 12 additions & 2 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ def has_time_based_updater(self) -> bool:
Returns
-------
class:`bool`
:class:`bool`
``True`` if at least one updater uses the ``dt`` parameter, ``False``
otherwise.
Expand Down Expand Up @@ -1905,7 +1905,17 @@ def fade(self, darkness: float = 0.5, family: bool = True) -> Self:
return self

def get_color(self) -> ManimColor:
"""Returns the color of the :class:`~.Mobject`"""
"""Returns the color of the :class:`~.Mobject`
Examples
--------
::
>>> from manim import Square, RED
>>> Square(color=RED).get_color() == RED
True
"""
return self.color

##
Expand Down
37 changes: 37 additions & 0 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,27 @@ def set_points_as_corners(self, points: Point3D_Array) -> Self:
-------
:class:`VMobject`
``self``
Examples
--------
.. manim:: PointsAsCornersExample
:save_last_frame:
class PointsAsCornersExample(Scene):
def construct(self):
corners = (
# create square
UR, UL,
DL, DR,
UR,
# create crosses
DL, UL,
DR
)
vmob = VMobject(stroke_color=RED)
vmob.set_points_as_corners(corners).scale(2)
self.add(vmob)
"""
nppcc = self.n_points_per_cubic_curve
points = np.array(points)
Expand Down Expand Up @@ -1387,6 +1408,22 @@ def point_from_proportion(self, alpha: float) -> Point3D:
If ``alpha`` is not between 0 and 1.
:exc:`Exception`
If the :class:`VMobject` has no points.
Example
-------
.. manim:: PointFromProportion
:save_last_frame:
class PointFromProportion(Scene):
def construct(self):
line = Line(2*DL, 2*UR)
self.add(line)
colors = (RED, BLUE, YELLOW)
proportions = (1/4, 1/2, 3/4)
for color, proportion in zip(colors, proportions):
self.add(Dot(color=color).move_to(
line.point_from_proportion(proportion)
))
"""

if alpha < 0 or alpha > 1:
Expand Down

0 comments on commit afe1d18

Please sign in to comment.