多边星

限定名称: manim.mobject.geometry.polygram.Polygram

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

基类: VMobject

一个广义的Polygon,允许不连续的边集合。

参数:
  • vertex_groups (Point3DLike_Array) –

    构成Polygram的顶点组。

    每组的第一个顶点会重复以闭合形状。每个点必须是三维的:[x,y,z]

  • color (ParsableManimColor) – Polygram的颜色。

  • kwargs (Any) – 转发给父类构造函数。

示例

示例: 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()

方法

get_vertex_groups

获取Polygram的顶点组。

get_vertices

获取Polygram的顶点。

round_corners

Polygram的角进行圆角处理。

属性

animate (动画)

用于动画化 self 的任何方法的应用。

animation_overrides (动画覆盖)

颜色

depth (深度)

mobject 的深度。

fill_color (填充颜色)

如果存在多种颜色(用于渐变),则返回第一种颜色

height (高度)

mobject 的高度。

n_points_per_curve (每条曲线的点数)

sheen_factor (光泽因子)

stroke_color (描边颜色)

width (宽度)

mobject 的宽度。

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

初始化自身。有关准确签名,请参阅 help(type(self))。

参数:
get_vertex_groups()[source]

获取Polygram的顶点组。

返回:

Polygram的顶点组。

返回类型:

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的顶点。

返回:

Polygram的顶点。

返回类型:

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的角进行圆角处理。

参数:
  • radius (float | list[float]) – Polygram角的曲率。

  • evenly_distribute_anchors (bool) – 将长线段分成按比例大小的段。

  • components_per_rounded_corner (int) – 用于表示圆角曲线的点数。

返回类型:

自身

另请参阅

圆角矩形

注意

如果radius以单个值提供,则相同的半径将应用于所有角。如果radius是一个列表,则各个值将按顺序应用,第一个角接收radius[0],第二个角接收radius[1],依此类推。半径列表将根据需要重复。

提供components_per_rounded_corner值是为了根据需要微调圆角的保真度。对于大多数形状,2是一个合适的值,但如果圆角特别大,可能需要更大的值。允许的最小值为2,代表曲线的起点和终点。3将导致起点、中点和终点,意味着将生成2条曲线。

提供evenly_distribute_anchors选项是为了使线段(圆角处理后每条线剩余的部分)可以细分为与圆角平均密度相似的密度。这在需要均匀分布曲线以便后续变换动画的情况下可能有用。但请注意,启用此选项可能导致对象包含比原始对象多得多的点,特别是在圆角曲线很小的情况下。

示例

示例: 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)