manim.mobject.geometry.Polygram

class Polygram(*vertex_groups, color='#58C4DD', **kwargs)[source]

Bases: manim.mobject.types.vectorized_mobject.VMobject

A generalized Polygon, allowing for disconnected sets of edges.

Parameters
  • vertex_groups (Iterable[Sequence[float]]) –

    The groups of vertices making up the 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 Polygram.

  • kwargs – Forwarded to the parent constructor.

Examples

Example: PolygramExample

from manim import *

import numpy as np

class PolygramExample(Scene):
    def construct(self):
        hexagram = Polygram(
            [[0, 2, 0], [-np.sqrt(3), -1, 0], [np.sqrt(3), -1, 0]],
            [[-np.sqrt(3), 1, 0], [0, -2, 0], [np.sqrt(3), 1, 0]],
        )
        self.add(hexagram)

        dot = Dot()
        self.play(MoveAlongPath(dot, hexagram), run_time=5, rate_func=linear)
        self.remove(dot)
        self.wait()

Methods

get_vertex_groups

Gets the vertex groups of the Polygram.

get_vertices

Gets the vertices of the Polygram.

round_corners

Rounds off the corners of the Polygram.

Attributes

animate

Used to animate the application of a method.

animation_overrides

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

get_vertex_groups()[source]

Gets the vertex groups of the Polygram.

Returns

The vertex groups of the Polygram.

Return type

numpy.ndarray

Examples

>>> poly = Polygram([ORIGIN, RIGHT, UP], [LEFT, LEFT + UP, 2 * LEFT])
>>> poly.get_vertex_groups()
array([[[ 0.,  0.,  0.],
        [ 1.,  0.,  0.],
        [ 0.,  1.,  0.]],

       [[-1.,  0.,  0.],
        [-1.,  1.,  0.],
        [-2.,  0.,  0.]]])
get_vertices()[source]

Gets the vertices of the Polygram.

Returns

The vertices of the Polygram.

Return type

numpy.ndarray

Examples

>>> sq = Square()
>>> sq.get_vertices()
array([[ 1.,  1.,  0.],
       [-1.,  1.,  0.],
       [-1., -1.,  0.],
       [ 1., -1.,  0.]])
round_corners(radius=0.5)[source]

Rounds off the corners of the Polygram.

Parameters

radius (float) – The curvature of the corners of the Polygram.

Examples

Example: PolygramRoundCorners

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

class PolygramRoundCorners(Scene):
    def construct(self):
        star = Star(outer_radius=2)

        shapes = VGroup(star)
        shapes.add(star.copy().round_corners(radius=0.1))
        shapes.add(star.copy().round_corners(radius=0.25))

        shapes.arrange(RIGHT)
        self.add(shapes)

See also

RoundedRectangle