Skip to content
Open
Changes from all commits
Commits
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
34 changes: 27 additions & 7 deletions manim/mobject/geometry/polygram.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class Polygram(VMobject, metaclass=ConvertToOpenGL):
Parameters
----------
vertex_groups
The groups of vertices making up the :class:`Polygram`.
A 2D numpy array of shape (N,3) where N is the number of points, each such points
itself being a 1D numpy array of shape (3,), for example: ``[x,y,z]``.
These points are the vertices making up the :class:`Polygram`.

The first vertex in each group is repeated to close the shape.
Each point must be 3-dimensional: ``[x,y,z]``
color
The color of the :class:`Polygram`.
kwargs
Expand Down Expand Up @@ -305,7 +306,17 @@ class Polygon(Polygram):
Parameters
----------
vertices
The vertices of the :class:`Polygon`.
The vertices (i.e. corner points) of the :class:`Polygon`.
It is a 2D numpy array of shape (N, 3), when passed in New style.
To keep backwards compatibility, users can pass vertices either in New style or in Legacy style:

New style: `vertices` is a 2D array of shape (N, 3) where N is the number of corner points that make up the
Polygon. Each point should be a 1D numpy array of shape (3,) representing a point in 3D space.
Example: Polygon(np.array([...]))

Legacy style: Individual points (i.e. individual vertices) are passed one after another, separated by commas.
Example: Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0])

kwargs
Forwarded to the parent constructor.

Expand All @@ -316,7 +327,7 @@ class Polygon(Polygram):

class PolygonExample(Scene):
def construct(self):
isosceles = Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0])
isosceles = Polygon([[-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0]]) # New style
position_list = [
[4, 1, 0], # middle right
[4, -2.5, 0], # bottom right
Expand All @@ -325,12 +336,21 @@ def construct(self):
[2, 1, 0], # middle
[4, 3, 0], # top right
]
square_and_triangles = Polygon(*position_list, color=PURPLE_B)
square_and_triangles = Polygon(*position_list, color=PURPLE_B) # legacy style
self.add(isosceles, square_and_triangles)
"""

def __init__(self, *vertices: Point3DLike, **kwargs: Any) -> None:
super().__init__(vertices, **kwargs)
def __init__(
self,
vertices: Point3DLike_Array | Point3DLike,
*args: Point3DLike,
**kwargs: Any,
) -> None:
if args:
all_vertices = np.array([vertices, *args], dtype=float)
else:
all_vertices = np.array(vertices, dtype=float)
super().__init__(all_vertices, **kwargs)


class RegularPolygram(Polygram):
Expand Down
Loading