Polygram¶
Qualified name: manim.mobject.geometry.polygram.Polygram
- class Polygram(*vertex_groups, color=ManimColor('#58C4DD'), **kwargs)[source]¶
Bases:
VMobjectA generalized
Polygon, allowing for disconnected sets of edges.- Parameters:
vertex_groups (Point3DLike_Array) –
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 (ManimColor) – The color of the
Polygram.kwargs (Any) – 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
Gets the vertex groups of the
Polygram.Gets the vertices of the
Polygram.Rounds off the corners of the
Polygram.Attributes
alwaysCall a method on a mobject every frame.
animateUsed to animate the application of any method of
self.animation_overridescolordepthThe depth of the mobject.
fill_colorIf there are multiple colors (for gradient) this returns the first one
heightThe height of the mobject.
n_points_per_curvesheen_factorstroke_colorwidthThe width of the mobject.
- _original__init__(*vertex_groups, color=ManimColor('#58C4DD'), **kwargs)¶
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
vertex_groups (Point3DLike_Array)
color (ParsableManimColor)
kwargs (Any)
- get_vertex_groups()[source]¶
Gets the vertex groups of the
Polygram.- Returns:
The list of vertex groups of the
Polygram.- Return type:
list[Point3D_Array]
Examples
>>> poly = Polygram([ORIGIN, RIGHT, UP, LEFT + UP], [LEFT, LEFT + UP, 2 * LEFT]) >>> groups = poly.get_vertex_groups() >>> len(groups) 2 >>> groups[0] array([[ 0., 0., 0.], [ 1., 0., 0.], [ 0., 1., 0.], [-1., 1., 0.]]) >>> groups[1] array([[-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
RoundedRectangleNote
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 ¶
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)