Skip to content

Commit afe1d18

Browse files
Added some examples for Mobject/VMobject methods (#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
1 parent 909ffde commit afe1d18

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

manim/mobject/mobject.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ def has_time_based_updater(self) -> bool:
882882
883883
Returns
884884
-------
885-
class:`bool`
885+
:class:`bool`
886886
``True`` if at least one updater uses the ``dt`` parameter, ``False``
887887
otherwise.
888888
@@ -1905,7 +1905,17 @@ def fade(self, darkness: float = 0.5, family: bool = True) -> Self:
19051905
return self
19061906

19071907
def get_color(self) -> ManimColor:
1908-
"""Returns the color of the :class:`~.Mobject`"""
1908+
"""Returns the color of the :class:`~.Mobject`
1909+
1910+
Examples
1911+
--------
1912+
::
1913+
1914+
>>> from manim import Square, RED
1915+
>>> Square(color=RED).get_color() == RED
1916+
True
1917+
1918+
"""
19091919
return self.color
19101920

19111921
##

manim/mobject/types/vectorized_mobject.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,27 @@ def set_points_as_corners(self, points: Point3D_Array) -> Self:
962962
-------
963963
:class:`VMobject`
964964
``self``
965+
966+
967+
Examples
968+
--------
969+
.. manim:: PointsAsCornersExample
970+
:save_last_frame:
971+
972+
class PointsAsCornersExample(Scene):
973+
def construct(self):
974+
corners = (
975+
# create square
976+
UR, UL,
977+
DL, DR,
978+
UR,
979+
# create crosses
980+
DL, UL,
981+
DR
982+
)
983+
vmob = VMobject(stroke_color=RED)
984+
vmob.set_points_as_corners(corners).scale(2)
985+
self.add(vmob)
965986
"""
966987
nppcc = self.n_points_per_cubic_curve
967988
points = np.array(points)
@@ -1387,6 +1408,22 @@ def point_from_proportion(self, alpha: float) -> Point3D:
13871408
If ``alpha`` is not between 0 and 1.
13881409
:exc:`Exception`
13891410
If the :class:`VMobject` has no points.
1411+
1412+
Example
1413+
-------
1414+
.. manim:: PointFromProportion
1415+
:save_last_frame:
1416+
1417+
class PointFromProportion(Scene):
1418+
def construct(self):
1419+
line = Line(2*DL, 2*UR)
1420+
self.add(line)
1421+
colors = (RED, BLUE, YELLOW)
1422+
proportions = (1/4, 1/2, 3/4)
1423+
for color, proportion in zip(colors, proportions):
1424+
self.add(Dot(color=color).move_to(
1425+
line.point_from_proportion(proportion)
1426+
))
13901427
"""
13911428

13921429
if alpha < 0 or alpha > 1:

0 commit comments

Comments
 (0)