Polygram#

Qualified name: manim.mobject.geometry.polygram.Polygram

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

Bases: VMobject

A generalized Polygon, allowing for disconnected sets of edges.

Parameters:
  • vertex_groups (Point3D) –

    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 (ParsableManimColor) – 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()
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 any method of self.

animation_overrides

color

depth

The depth of the mobject.

fill_color

If there are multiple colors (for gradient) this returns the first one

height

The height of the mobject.

n_points_per_curve

sheen_factor

stroke_color

width

The width of the mobject.

_original__init__(*vertex_groups, color=ManimColor('#58C4DD'), **kwargs)#

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • vertex_groups (Point3D) –

  • color (ParsableManimColor) –

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, evenly_distribute_anchors=False, components_per_rounded_corner=2)[source]#

Rounds off the corners of the Polygram.

Parameters:
  • radius (float | list[float]) – The curvature of the corners of the Polygram.

  • evenly_distribute_anchors (bool) – Break long line segments into proportionally-sized segments.

  • components_per_rounded_corner (int) – The number of points used to represent the rounded corner curve.

Return type:

Self

See also

RoundedRectangle

Note

If radius is supplied as a single value, then the same radius will be applied to all corners. If radius is a list, then the individual values will be applied sequentially, with the first corner receiving radius[0], the second corner receiving radius[1], etc. The radius list will be repeated as necessary.

The components_per_rounded_corner value is provided so that the fidelity of the rounded corner may be fine-tuned as needed. 2 is an appropriate value for most shapes, however a larger value may be need if the rounded corner is particularly large. 2 is the minimum number allowed, representing the start and end of the curve. 3 will result in a start, middle, and end point, meaning 2 curves will be generated.

The option to evenly_distribute_anchors is provided so that the line segments (the part part of each line remaining after rounding off the corners) can be subdivided to a density similar to that of the average density of the rounded corners. This may be desirable in situations in which an even distribution of curves is desired for use in later transformation animations. Be aware, though, that enabling this option can result in an an object containing significantly more points than the original, especially when the rounded corner curves are small.

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)
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)