多边形¶
限定名称: manim.mobject.geometry.polygram.Polygram
- class Polygram(*vertex_groups, color=ManimColor('#58C4DD'), **kwargs)[source]¶
基础类:
VMobject一个广义的
Polygon,允许不连续的边集。- Parameters:
vertex_groups (Point3D) –
构成
Polygram的顶点组。每个组中的第一个顶点被重复以闭合形状。 每个点必须是三维的:
[x,y,z]颜色 (ParsableManimColor) –
Polygram的颜色。kwargs – 转发给父构造函数。
示例
示例: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()方法
属性
animate用于动画化
self的任何方法的应用。animation_overridescolordepthmobject的深度。
fill_color如果有多种颜色(用于渐变),则返回第一个颜色
heightmobject的高度。
n_points_per_curvesheen_factorstroke_colorwidthmobject的宽度。
- _original__init__(*vertex_groups, color=ManimColor('#58C4DD'), **kwargs)¶
初始化自身。有关准确的签名,请参阅 help(type(self))。
- Parameters:
顶点组 (Point3D)
颜色 (ParsableManimColor)
- get_vertex_groups()[source]¶
获取
Polygram的顶点组。- Returns:
Polygram的顶点组。- Return type:
numpy.ndarray
示例
>>> 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]¶
获取
Polygram的顶点。- Returns:
Polygram的顶点。- Return type:
numpy.ndarray
示例
>>> 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]¶
将
Polygram的角进行圆角处理。- Parameters:
radius (float | list[float]) –
Polygram的角曲率。evenly_distribute_anchors (bool) – 将长线段分割成比例大小的段。
components_per_rounded_corner (int) – 用于表示圆角曲线的点数。
- Return type:
自我
另请参阅
RoundedRectangle注意
如果radius作为单个值提供,则相同的半径将应用于所有角。如果radius是一个列表,则各个值将按顺序应用,第一个角接收radius[0],第二个角接收radius[1],依此类推。半径列表将根据需要重复。
components_per_rounded_corner 值被提供以便根据需要微调圆角的保真度。对于大多数形状来说,2 是一个合适的值,但如果圆角特别大,则可能需要更大的值。2 是允许的最小值,代表曲线的起点和终点。3 将导致一个起点、中点和终点,意味着将生成 2 条曲线。
提供了evenly_distribute_anchors选项,以便线段(在圆角化后每条线剩余的部分)可以被细分为与圆角平均密度相似的密度。这在需要均匀分布的曲线用于后续变换动画的情况下可能是可取的。但请注意,启用此选项可能会导致对象包含比原始对象更多的点,尤其是在圆角曲线较小的情况下。
示例
示例: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)