manim.mobject.geometry.Polygon

class Polygon(*vertices, color='#58C4DD', **kwargs)[source]

Bases: manim.mobject.types.vectorized_mobject.VMobject

A shape created by defining its vertices.

Parameters
  • vertices (list) – The vertices of the mobject. The first one is repeated to close the shape. Must define 3-dimensions: [x,y,z]

  • color (Colors, optional) – The color of the polygon.

  • kwargs (Any) – Additional arguments to be passed to VMobject

Examples

Example: PolygonExample

../_images/PolygonExample-1.png
from manim import *

class PolygonExample(Scene):
    def construct(self):
        isosceles = Polygon([-5, 1.5, 0], [-2, 1.5, 0], [-3.5, -2, 0])
        position_list = [
            [4, 1, 0],  # middle right
            [4, -2.5, 0],  # bottom right
            [0, -2.5, 0],  # bottom left
            [0, 3, 0],  # top left
            [2, 1, 0],  # middle
            [4, 3, 0],  # top right
        ]
        square_and_triangles = Polygon(*position_list, color=PURPLE_B)
        self.add(isosceles, square_and_triangles)

Methods

get_vertices

Gets the vertices of the polygon.

round_corners

Rounds off the corners of the polygon.

Attributes

animate

Used to animate the application of a method.

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

get_vertices()[source]

Gets the vertices of the polygon.

Examples

>>> sq = Square()
>>> points = sq.get_vertices()
>>> points
array([[ 1.,  1.,  0.],
       [-1.,  1.,  0.],
       [-1., -1.,  0.],
       [ 1., -1.,  0.]])
Returns

Returns a list of the coordinates of polygon’s vertices.

Return type

numpy.ndarray

round_corners(radius=0.5)[source]

Rounds off the corners of the polygon.

Parameters

radius (float, optional) – The curvature of the corners of the polygon.

Examples

Example: PolygonRoundCorners

../_images/PolygonRoundCorners-1.gif
from manim import *

class PolygonRoundCorners(Scene):
    def construct(self):
        points = [[-4, -2, 0], [-2, 2, 0], [4, 2, 0], [2, -2, 0]]
        parallelogram = Polygon(*points, stroke_color=LIGHT_PINK)
        rounded_1 = Polygon(*points, stroke_color=LIGHT_PINK).round_corners(radius=0.5)
        rounded_2 = Polygon(*points, stroke_color=LIGHT_PINK).round_corners(radius=1.5)

        self.play(Transform(parallelogram, rounded_1))
        self.wait(0.5)
        self.play(Transform(parallelogram, rounded_2))
        self.wait(0.5)

See also

RoundedRectangle