跳转至

多边形

影片代码
import manimgx as m


class PolygonsHero(m.Scene):
    def construct(self) -> None:
        shapes = m.VGroup(
            m.Triangle(color=m.BLUE),
            m.Square(side_length=1.8, color=m.GREEN),
            m.Rectangle(width=2.6, height=1.5, color=m.YELLOW),
            m.RoundedRectangle(width=2.6, height=1.5, corner_radius=0.4, color=m.TEAL),
            m.RegularPolygon(n=6, color=m.RED),
            m.Star(color=m.GOLD),
        )
        names = [
            "Triangle",
            "Square",
            "Rectangle",
            "RoundedRectangle",
            "RegularPolygon",
            "Star",
        ]
        cells = m.VGroup()
        for shape, name in zip(shapes, names, strict=True):
            label = m.Text(name, font="monospace", font_size=26)
            cells.add(m.VGroup(shape, label.next_to(shape, m.DOWN, buff=0.4)))
        cells.arrange_in_grid(rows=2, buff=(1, 0.8))
        self.play(m.LaggedStart(*[m.Create(cell[0]) for cell in cells], lag_ratio=0.15))
        self.play(m.FadeIn(m.VGroup(*[cell[1] for cell in cells])))
        self.wait()

多边形是由直边构成的形状,从一个角到下一个角,再从最后一个角回到第一个角。将你的角点传给 m.Polygon,或者使用一个现成的:三角形、正方形、矩形、正多边形、星形。每个多边形都可以圆角化其角。

多角形(polygram)是在一个形状中的若干个多边形;多边形是只有一个的多角形。

Polygon

代码
import manimgx as m


class PolygonExample(m.Scene):
    def construct(self) -> None:
        triangle = m.Polygon([-6, -2, 0], [-1.5, -2, 0], [-3.5, 2.5, 0])
        arrowhead = m.Polygon(
            [1, -2.5, 0],
            [6, 0, 0],
            [1, 2.5, 0],
            [2.5, 0, 0],
            color=m.YELLOW,
            fill_opacity=0.5,
        )
        self.play(m.Create(triangle), m.Create(arrowhead))

多边形:从每个顶点到下一个的直边,以及从最后一个回到第一个; 未加样式时为蓝色。

m.Polygon(*vertices, **kwargs)
*vertices

顶点,按绕其顺序。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(self, *vertices: Point3DLike, **kwargs: Unpack[Style]) -> None:
    super().__init__(vertices, **kwargs)

Polygram

代码
import numpy as np

import manimgx as m


class PolygramExample(m.Scene):
    def construct(self) -> None:
        r = np.sqrt(3)
        hexagram = m.Polygram(
            [[0, 2, 0], [-r, -1, 0], [r, -1, 0]],
            [[-r, 1, 0], [0, -2, 0], [r, 1, 0]],
        )
        framed = m.Polygram(
            [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]],
            [[-1, -1, 0], [-1, 1, 0], [1, 1, 0], [1, -1, 0]],
            color=m.YELLOW,
            fill_opacity=0.5,
        )
        self.play(m.Create(m.VGroup(hexagram, framed).arrange(buff=2)))

由穿过顶点组的直边构成的形状:每组为一个闭合路径,从顶点到顶点再回到第一个; 未加样式时为蓝色。

各组构成一个 mobject,一起填充和描边。重叠处,填充按其路径绕各点的次数计数: 一个反向运行的内部组是一个洞。

顶点按所给方式使用:之后更改其数组不会改变任何形状。

m.Polygram(*vertex_groups, **kwargs)
*vertex_groups

顶点组,每组按绕其路径的顺序。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(
    self, *vertex_groups: Point3DLike_Array, **kwargs: Unpack[Style]
) -> None:
    super().__init__(**kwargs)
    for vertices in vertex_groups:
        first_vertex, *vertices = vertices
        first_vertex = np.array(first_vertex)
        self.start_new_path(first_vertex)
        self.add_points_as_corners(np.array([*vertices, first_vertex]))

get_vertices

多边星的顶点,一组接一组:每条曲线的起点(圆角后也包括弧和边)。

polygon.get_vertices()

返回 一个 (n, 3) 的点数组,以场景坐标表示。

源码

manimgx\mobjects\shapes.py

def get_vertices(self) -> Point3D_Array:
    """多边星的顶点,一组接一组:每条曲线的起点(圆角后也包括弧和边)。

    Returns:
        一个 (n, 3) 的点数组,以场景坐标表示。
    """
    return self.get_start_anchors()

get_vertex_groups

多边星的顶点,按其所在闭合路径分组。

polygon.get_vertex_groups()

返回 一个 (n, 3) 点数组的列表,每条闭合路径一个。

源码

manimgx\mobjects\shapes.py

def get_vertex_groups(self) -> list[Point3D_Array]:
    """多边星的顶点,按其所在闭合路径分组。

    Returns:
        一个 (n, 3) 点数组的列表,每条闭合路径一个。
    """
    vertex_groups = []
    group = []
    for start, end in zip(
        self.get_start_anchors(), self.get_end_anchors(), strict=True
    ):
        group.append(start)
        if self.consider_points_equals(end, group[0]):
            vertex_groups.append(np.array(group))
            group = []
    return vertex_groups

round_corners

PolygramRoundCornersExample
代码
import manimgx as m


class PolygramRoundCornersExample(m.Scene):
    def construct(self) -> None:
        square = m.Square(2.8, color=m.YELLOW)
        shapes = m.VGroup(
            m.Star(outer_radius=1.5),
            m.Star(outer_radius=1.5).round_corners(0.25),
            square.round_corners([0.1, 0.4, 0.8, 1.2]),
            m.Triangle(radius=1.6, color=m.GREEN).round_corners(-0.5),
        ).arrange(buff=0.5)
        self.add(shapes)

圆整多边星的角:用与两边相切的 radius 弧替换每个角。

弧至多在每边一半处相切:对某角过大的半径会被缩小。负半径向另一方向圆整, 切入一个凹弧。

polygon.round_corners(radius=0.5, evenly_distribute_anchors=False, components_per_rounded_corner=2)
radius

弧的半径,以场景单位计;或每组的每个角一个半径的列表, 从其第二个顶点的角起(其第一个顶点的角最后),在各角上重复: 其长度必须整除角数。

evenly_distribute_anchors

是否将直边分成与弧的曲线大致等长的曲线, 使轮廓的点沿其均匀分布(变换随后更均匀地移动它们)。

components_per_rounded_corner

每条弧经多少个锚点绘制:2 为一条三次贝塞尔曲线。

源码

manimgx\mobjects\shapes.py

def round_corners(
    self,
    radius: float | list[float] = 0.5,
    evenly_distribute_anchors: bool = False,
    components_per_rounded_corner: int = 2,
) -> Self:
    """圆整多边星的角:用与两边相切的 `radius` 弧替换每个角。

    弧至多在每边一半处相切:对某角过大的半径会被缩小。负半径向另一方向圆整,
    切入一个凹弧。

    Args:
        radius: 弧的半径,以场景单位计;或每组的每个角一个半径的列表,
            从其第二个顶点的角起(其第一个顶点的角最后),在各角上重复:
            其长度必须整除角数。
        evenly_distribute_anchors: 是否将直边分成与弧的曲线大致等长的曲线,
            使轮廓的点沿其均匀分布(变换随后更均匀地移动它们)。
        components_per_rounded_corner: 每条弧经多少个锚点绘制:2 为一条三次贝塞尔曲线。

    Examples:
        ```python
        import manimgx as m


        class PolygramRoundCornersExample(m.Scene):
            def construct(self) -> None:
                square = m.Square(2.8, color=m.YELLOW)
                shapes = m.VGroup(
                    m.Star(outer_radius=1.5),
                    m.Star(outer_radius=1.5).round_corners(0.25),
                    square.round_corners([0.1, 0.4, 0.8, 1.2]),
                    m.Triangle(radius=1.6, color=m.GREEN).round_corners(-0.5),
                ).arrange(buff=0.5)
                self.add(shapes)
        ```
    """
    if radius == 0:
        return self
    new_points: list[Point3D_Array] = []
    for vertex_group in self.get_vertex_groups():
        arcs = []
        if isinstance(radius, (int, float)):
            radius_list = [radius] * len(vertex_group)
        else:
            radius_list = radius * ceil(len(vertex_group) / len(radius))
        for current_radius, (v1, v2, v3) in zip(
            radius_list, adjacent_n_tuples(list(vertex_group), 3), strict=True
        ):
            vect1 = v2 - v1
            vect2 = v3 - v2
            unit_vect1 = normalize(vect1)
            unit_vect2 = normalize(vect2)
            angle = angle_between_vectors(vect1, vect2)
            angle *= np.sign(current_radius)
            cut_off_length = current_radius * np.tan(angle / 2)
            max_cut_off = min(np.linalg.norm(vect1), np.linalg.norm(vect2)) / 2
            cut_off_length = np.clip(cut_off_length, -max_cut_off, max_cut_off)
            sign = np.sign(np.cross(vect1, vect2)[2])
            arc = ArcBetweenPoints(
                v2 - unit_vect1 * cut_off_length,
                v2 + unit_vect2 * cut_off_length,
                angle=sign * angle,
                num_components=components_per_rounded_corner,
            )
            arcs.append(arc)
        average_arc_length = 1.0
        if evenly_distribute_anchors:
            nonzero_length_arcs = [arc for arc in arcs if len(arc.points) > 4]
            if len(nonzero_length_arcs) > 0:
                total_arc_length = sum(
                    [arc.get_arc_length() for arc in nonzero_length_arcs]
                )
                num_curves = (
                    sum([len(arc.points) for arc in nonzero_length_arcs]) / 4
                )
                average_arc_length = total_arc_length / num_curves
        arcs = [arcs[-1], *arcs[:-1]]

        for arc1, arc2 in adjacent_pairs(arcs):
            new_points.append(arc1.points)
            line = Line(arc1.get_end(), arc2.get_start())
            if evenly_distribute_anchors:
                line.insert_n_curves(ceil(line.get_length() / average_arc_length))
            new_points.append(line.points)
    self.set_points(np.concatenate(new_points) if new_points else np.array([]))
    return self

Triangle

TriangleExample
代码
import manimgx as m


class TriangleExample(m.Scene):
    def construct(self) -> None:
        triangles = m.VGroup(
            m.Triangle(),
            m.Triangle(radius=2, color=m.YELLOW, fill_opacity=0.5),
            m.Triangle(radius=2, start_angle=-m.PI / 2, color=m.GREEN),
        ).arrange(buff=1)
        self.add(triangles)

等边三角形,朝上,其顶点在半径为 1 的圆上,除非另给;未加样式时为蓝色。

m.Triangle(**kwargs)
radius

其顶点所在圆的半径,以场景单位计(默认 1)。

start_angle

其第一个顶点的角度,以弧度计,从正 x 轴起逆时针(默认 None:顶点数为奇数时 正上方有一个顶点,为偶数时在右侧)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

源码

manimgx\mobjects\shapes.py

def __init__(self, **kwargs: Unpack[RegularPolygonOptions]) -> None:
    super().__init__(n=3, **kwargs)

Square

SquareExample
代码
import manimgx as m


class SquareExample(m.Scene):
    def construct(self) -> None:
        squares = m.VGroup(
            m.Square(),
            m.Square(3, color=m.BLUE, fill_opacity=0.5),
            m.Square(4, color=m.YELLOW, grid_xstep=1, grid_ystep=1),
        ).arrange(buff=1)
        self.add(squares)

正方形,未指定大小时边长 2,圆心在原点;未加样式时为白色。

m.Square(side_length=2.0, **kwargs)
side_length

其边长,以场景单位计。

grid_xstep

其网格竖线之间的距离,从其左边起,以场景单位计(默认 None:无竖线)。

grid_ystep

其网格横线之间的距离,从其顶边起,以场景单位计(默认 None:无横线)。

mark_paths_closed

为兼容 Manim 而接受;被忽略。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

源码

manimgx\mobjects\shapes.py

def __init__(self, side_length: float = 2.0, **kwargs: Unpack[GridOptions]) -> None:
    super().__init__(height=side_length, width=side_length, **kwargs)

side_length

正方形边长,以场景单位计:其前两个顶点之间的距离。设置它可将正方形 缩放到该边长,关于其圆心。

square.side_length
源码

manimgx\mobjects\shapes.py

def side_length(self) -> float:
    """正方形边长,以场景单位计:其前两个顶点之间的距离。设置它可将正方形
    缩放到该边长,关于其圆心。"""
    return float(np.linalg.norm(self.get_vertices()[0] - self.get_vertices()[1]))

Rectangle

RectangleExample
代码
import manimgx as m


class RectangleExample(m.Scene):
    def construct(self) -> None:
        grid = m.Rectangle(
            m.YELLOW, height=3, width=4, grid_xstep=1, grid_ystep=0.5
        )
        rectangles = m.VGroup(
            m.Rectangle(),
            m.Rectangle(m.BLUE, height=4, width=1.5, fill_opacity=0.5),
            grid,
        ).arrange(buff=1)
        self.add(rectangles)

矩形,未指定大小时宽 4 高 2,圆心在原点;未加样式时为白色。

其顶点从右上角起逆时针排列。带 grid_xstep 或 grid_ystep 时划分为网格: 跨越的线,即其 grid_lines,以其 color 绘制。

m.Rectangle(color=None, height=2.0, width=4.0, grid_xstep=None, grid_ystep=None, mark_paths_closed=False, **kwargs)
color

其颜色,可按位置给出(Rectangle(BLUE));None 表示白色。

height

其高度,以场景单位计。

width

其宽度,以场景单位计。

grid_xstep

其网格竖线之间的距离,从其左边起,以场景单位计;None 表示无。

grid_ystep

其网格横线之间的距离,从其顶边起,以场景单位计;None 表示无。

mark_paths_closed

为兼容 Manim 而接受;被忽略。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(
    self,
    color: Colors | None = None,
    height: float = 2.0,
    width: float = 4.0,
    grid_xstep: float | None = None,
    grid_ystep: float | None = None,
    mark_paths_closed: bool = False,
    **kwargs: Unpack[StyleBase],
) -> None:
    style = Style(**kwargs) if color is None else Style(**kwargs, color=color)
    color = (style_defaults(type(self)) | style).get("color", WHITE)
    super().__init__(UR, UL, DL, DR, **style)
    self.stretch_to_fit_width(width)
    self.stretch_to_fit_height(height)

    v = self.get_vertices()
    line_color = color or WHITE
    self.grid_lines = VGroup()
    """其网格的线:竖线组再接横线组,即其拥有的;一个子对象,
    除非为空(无网格时)。"""
    if grid_xstep:
        grid_xstep = abs(grid_xstep)
        count = int(width / grid_xstep)
        grid = VGroup(
            *(
                Line(
                    v[1] + i * grid_xstep * RIGHT,
                    v[1] + i * grid_xstep * RIGHT + height * DOWN,
                    color=line_color,
                )
                for i in range(1, count)
            )
        )
        self.grid_lines.add(grid)
    if grid_ystep:
        grid_ystep = abs(grid_ystep)
        count = int(height / grid_ystep)
        grid = VGroup(
            *(
                Line(
                    v[1] + i * grid_ystep * DOWN,
                    v[1] + i * grid_ystep * DOWN + width * RIGHT,
                    color=line_color,
                )
                for i in range(1, count)
            )
        )
        self.grid_lines.add(grid)
    if self.grid_lines:
        self.add(self.grid_lines)

grid_lines

其网格的线:竖线组再接横线组,即其拥有的;一个子对象, 除非为空(无网格时)。

RoundedRectangle

RoundedRectangleExample
代码
import manimgx as m


class RoundedRectangleExample(m.Scene):
    def construct(self) -> None:
        leaf = m.RoundedRectangle([0, 1.2, 0, 1.2], height=3, width=3)
        rectangles = m.VGroup(
            m.RoundedRectangle(),
            m.RoundedRectangle(1.5, height=4, width=4, color=m.BLUE),
            leaf.set_color(m.YELLOW),
        ).arrange(buff=1)
        self.add(rectangles)

圆角矩形,未指定大小时宽 4 高 2;未加样式时为白色。

m.RoundedRectangle(corner_radius=0.5, **kwargs)
corner_radius

其角的半径,以场景单位计;或其左上、左下、右下、右上角 半径的列表,按此顺序,一或两个时重复(见 round_corners)。

height

其高度,以场景单位计(默认 2)。

width

其宽度,以场景单位计(默认 4)。

grid_xstep

其网格竖线之间的距离,从其左边起,以场景单位计(默认 None:无竖线)。

grid_ystep

其网格横线之间的距离,从其顶边起,以场景单位计(默认 None:无横线)。

mark_paths_closed

为兼容 Manim 而接受;被忽略。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

源码

manimgx\mobjects\shapes.py

def __init__(
    self,
    corner_radius: float | list[float] = 0.5,
    **kwargs: Unpack[RectangleOptions],
) -> None:
    super().__init__(**kwargs)
    self.corner_radius = corner_radius
    self.round_corners(self.corner_radius)

RegularPolygon

RegularPolygonExample
代码
import manimgx as m


class RegularPolygonExample(m.Scene):
    def construct(self) -> None:
        polygons = m.VGroup(
            m.RegularPolygon(radius=1.5),
            m.RegularPolygon(radius=1.5, start_angle=m.PI / 6, color=m.GREEN),
            m.RegularPolygon(5, radius=1.5, color=m.YELLOW),
            m.RegularPolygon(10, radius=1.5, color=m.RED),
        ).arrange(buff=0.5)
        self.add(polygons)

正多边形:n 个顶点均匀分布于圆上,依次相连;未加样式时为蓝色。

m.RegularPolygon(n=6, **kwargs)
n

其顶点和边的数量。

radius

其顶点所在圆的半径,以场景单位计(默认 1)。

start_angle

其第一个顶点的角度,以弧度计,从正 x 轴起逆时针(默认 None:顶点数为奇数时 正上方有一个顶点,为偶数时在右侧)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

源码

manimgx\mobjects\shapes.py

def __init__(self, n: int = 6, **kwargs: Unpack[RegularPolygonOptions]) -> None:
    super().__init__(n, density=1, **kwargs)

RegularPolygram

代码
import manimgx as m


class RegularPolygramExample(m.Scene):
    def construct(self) -> None:
        polygrams = m.VGroup(
            m.RegularPolygram(5, radius=2),
            m.RegularPolygram(7, density=3, radius=2, color=m.YELLOW),
            m.RegularPolygram(6, radius=2, color=m.GREEN),
        ).arrange(buff=1)
        self.play(m.Create(polygrams, run_time=3))

正则星形多边形:圆上均匀分布的点,每个连接到其后第 density 步的点; 未加样式时为蓝色。

密度为 1 时为正多边形;5 个点密度为 2 构成五角星。当点数和密度有公因子时, 各点构成那么多正则多边星,每个从前一个转过:6 个点密度为 2 构成两个三角形, 即六角星。

m.RegularPolygram(num_vertices, *, density=2, radius=1, start_angle=None, **kwargs)
num_vertices

圆上有多少个点。

density

每个点连接到其后多少步的点:1 为多边形。

radius

圆的半径,以场景单位计。

start_angle

第一个点的角度,以弧度计,从正 x 轴起逆时针;None 表示 每个正则多边星有奇数个点时正上方有一个点,偶数时在右侧。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(
    self,
    num_vertices: int,
    *,
    density: int = 2,
    radius: float = 1,
    start_angle: float | None = None,
    **kwargs: Unpack[Style],
) -> None:
    num_gons = np.gcd(num_vertices, density)
    num_vertices //= num_gons
    density //= num_gons

    vertices, self.start_angle = regular_vertices(
        num_vertices, radius=radius, start_angle=start_angle
    )
    order = np.arange(num_vertices) * (density % num_vertices) % num_vertices
    vertex_groups = [vertices[order]]
    for i in range(1, num_gons):
        start_angle = self.start_angle + i / num_gons * TAU / num_vertices
        vertices, _ = regular_vertices(
            num_vertices, radius=radius, start_angle=start_angle
        )
        vertex_groups.append(vertices[order])
    super().__init__(*vertex_groups, **kwargs)

Star

代码
import manimgx as m


class StarExample(m.Scene):
    def construct(self) -> None:
        stars = m.VGroup(
            m.Star(outer_radius=1.5),
            m.Star(7, outer_radius=1.5, color=m.YELLOW),
            m.Star(7, outer_radius=1.5, density=3, color=m.RED),
            m.Star(12, outer_radius=1.5, inner_radius=1, color=m.GREEN),
        ).arrange(buff=0.5)
        self.play(m.Create(stars, run_time=3))

星形:圆上 n 个点,每两点之间在更小圆上有一个顶点;未加样式时为蓝色。

除非给出,内半径取使星形成为其 n 个点在 density 下的 RegularPolygram 轮廓的那个:其边沿正则多边星的线。

m.Star(n=5, *, outer_radius=1, inner_radius=None, density=2, start_angle=TAU / 4, **kwargs)
n

其点数。

outer_radius

其点所在圆的半径,以场景单位计。

inner_radius

其内顶点所在圆的半径,以场景单位计;None 表示由 density 设定。

density

无 inner_radius 时,其轮廓所属正则多边星的密度:越高其点越细。 必须大于 0 且小于 n / 2。

start_angle

其第一个点的角度,以弧度计,从正 x 轴起逆时针(默认四分之一圈: 正上方);None 表示 n 为奇数时正上方有一个点,偶数时在右侧。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(
    self,
    n: int = 5,
    *,
    outer_radius: float = 1,
    inner_radius: float | None = None,
    density: int = 2,
    start_angle: float | None = TAU / 4,
    **kwargs: Unpack[Style],
) -> None:
    inner_angle = TAU / (2 * n)
    if (
        inner_radius is None
    ):  # the radius that makes the star's edges lines through `density` points
        if density <= 0 or density >= n / 2:
            raise ValueError(
                f"Incompatible density {density} for number of points {n}"
            )
        outer_angle = TAU * density / n
        inverse_x = 1 - np.tan(inner_angle) * (
            (np.cos(outer_angle) - 1) / np.sin(outer_angle)
        )
        inner_radius = float(outer_radius / (np.cos(inner_angle) * inverse_x))
    outer_vertices, self.start_angle = regular_vertices(
        n, radius=outer_radius, start_angle=start_angle
    )
    inner_vertices, _ = regular_vertices(
        n, radius=inner_radius, start_angle=self.start_angle + inner_angle
    )
    vertices: list[npt.NDArray] = []
    for pair in zip(outer_vertices, inner_vertices, strict=True):
        vertices.extend(pair)
    super().__init__(*vertices, **kwargs)

ArcPolygon

代码
import manimgx as m


class ArcPolygonExample(m.Scene):
    def construct(self) -> None:
        a, b, c = [0, 0, 0], [2.5, 0, 0], [0, 2.5, 0]
        sides = [{"radius": 2, "color": m.RED}, {"angle": 0}, {"angle": 1}]
        shapes = m.VGroup(
            m.ArcPolygon(a, b, c),
            m.ArcPolygon(a, b, c, radius=2, fill_opacity=0.5).set_color(m.BLUE),
            m.ArcPolygon(a, b, c, angle=-m.PI / 3).set_color(m.GREEN),
            m.ArcPolygon(a, b, c, arc_config=sides),
        ).arrange(buff=0.6)
        self.play(m.Create(shapes, run_time=4))

边为弧线的多边形:从每个顶点到下一个的 ArcBetweenPoints, 以及从最后一个回到第一个;未加样式时为白色。

绕顶点逆时针行进,正角度的弧向外凸,负角度的弧向内弯。其轮廓沿弧线, 以其样式填充和描边。弧线也是其子对象,即其 arcs,以各自样式绘制于轮廓之上(未加样式时为白色, 除非 arc_config 另行指定):要为整体上色,也需为它们上色,如同 set_color 等族方法所做。

m.ArcPolygon(*vertices, angle=PI / 4, radius=None, arc_config=None, **kwargs)
*vertices

顶点,按绕其顺序。

angle

每条弧所转过的角度,以弧度计,除非给出 radius 或 arc_config。

radius

每条弧的半径,以场景单位计,代替 angle,除非给出 arc_config; None(或 0)表示使用 angle。

arc_config

弧线的 ArcBetweenPoints 关键字,代替 angle 和 radius: 每条弧一组,或每边一组的列表,第一个顶点的边在前。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(
    self,
    *vertices: Point3DLike,
    angle: float = PI / 4,
    radius: float | None = None,
    arc_config: ArcBetweenOptions | list[ArcBetweenOptions] | None = None,
    **kwargs: Unpack[Style],
) -> None:
    n = len(vertices)
    point_pairs = [(vertices[k], vertices[(k + 1) % n]) for k in range(n)]
    all_arc_configs: Iterable[ArcBetweenOptions]
    if not arc_config:
        config_: ArcBetweenOptions = (
            {"radius": radius} if radius else {"angle": angle}
        )
        all_arc_configs = itertools.repeat(config_, len(point_pairs))
    elif isinstance(arc_config, list):
        assert len(arc_config) == n
        all_arc_configs = arc_config
    else:
        all_arc_configs = itertools.repeat(arc_config, len(point_pairs))
    arcs = [
        ArcBetweenPoints(*pair, **conf)
        for pair, conf in zip(point_pairs, all_arc_configs, strict=True)
    ]
    super().__init__(**kwargs)
    self.add(*arcs)
    for arc in arcs:
        self.append_points(arc.points)
    self.arcs = arcs
    """弧线,每边一条,第一个顶点的边在前;它们也是其子对象。"""

arcs

弧线,每边一条,第一个顶点的边在前;它们也是其子对象。

ArcPolygonFromArcs

代码
import manimgx as m


class ArcPolygonFromArcsExample(m.Scene):
    def construct(self) -> None:
        a, b, c = [-5.5, -1.3, 0], [-2.5, -1.3, 0], [-4, 1.3, 0]
        pairs = (a, b), (b, c), (c, a)
        sides = [m.ArcBetweenPoints(p, q, radius=3) for p, q in pairs]
        reuleaux = m.ArcPolygonFromArcs(*sides, fill_opacity=0.5)
        left = m.Arc(start_angle=m.PI / 2, angle=m.PI).shift(1.5 * m.RIGHT)
        right = m.Arc(start_angle=-m.PI / 2, angle=m.PI).shift(4.5 * m.RIGHT)
        stadium = m.ArcPolygonFromArcs(left, right, fill_opacity=0.5)
        reuleaux.set_color(m.BLUE)
        stadium.set_color(m.GREEN)
        self.play(m.Create(reuleaux), m.Create(stadium))

由弧线构成的闭合形状:依次每条弧,在不相接处用直线连接到下一条, 最后一条连回第一条;未加样式时为白色。

其轮廓以其样式填充和描边。弧线也是其子对象,即其 arcs,以各自样式绘制于轮廓之上: 要为整体上色,也需为它们上色,如同 set_color 等族方法所做。

m.ArcPolygonFromArcs(*arcs, **kwargs)
*arcs

弧线,按绕其顺序:Arc 或 ArcBetweenPoints。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(self, *arcs: Arc | ArcBetweenPoints, **kwargs: Unpack[Style]) -> None:
    if not all(isinstance(m, (Arc, ArcBetweenPoints)) for m in arcs):
        raise ValueError(
            "All ArcPolygon submobjects must be of type Arc/ArcBetweenPoints"
        )
    super().__init__(**kwargs)
    self.add(*arcs)
    self.arcs = [*arcs]
    """弧线,按顺序;它们也是其子对象。"""

    for arc1, arc2 in adjacent_pairs(arcs):
        self.append_points(arc1.points)
        # the joining line is divided into curves about as long as the arc's, so
        # the outline's points are spread evenly along it
        line = Line(arc1.get_end(), arc2.get_start())
        len_ratio = line.get_length() / arc1.get_arc_length()
        if np.isnan(len_ratio) or np.isinf(len_ratio):
            continue
        line.insert_n_curves(int(arc1.get_num_curves() * len_ratio))
        self.append_points(line.points)

arcs

弧线,按顺序;它们也是其子对象。

屏幕的形状

ScreenRectangle

ScreenRectangleExample
代码
import manimgx as m


class ScreenRectangleExample(m.Scene):
    def construct(self) -> None:
        screens = m.VGroup(
            m.ScreenRectangle(),
            m.ScreenRectangle(aspect_ratio=4 / 3, height=3, color=m.BLUE),
        ).arrange(buff=1)
        self.add(screens)

具有屏幕比例的矩形,未另给时为 16:9 且高 4,圆心在原点;未加样式时为白色。

m.ScreenRectangle(aspect_ratio=16.0 / 9.0, height=4, **kwargs)
aspect_ratio

其宽除以高。

height

其高度,以场景单位计。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

还接受 样式关键字。

源码

manimgx\mobjects\shapes.py

def __init__(
    self,
    aspect_ratio: float = 16.0 / 9.0,
    height: float = 4,
    **kwargs: Unpack[Style],
) -> None:
    super().__init__(width=aspect_ratio * height, height=height, **kwargs)

aspect_ratio

矩形的宽除以高。设置它可将矩形宽拉伸到该比例,关于其圆心;其高不变。

screen_rectangle.aspect_ratio
源码

manimgx\mobjects\shapes.py

def aspect_ratio(self) -> float:
    """矩形的宽除以高。设置它可将矩形宽拉伸到该比例,关于其圆心;其高不变。"""
    return self.width / self.height

FullScreenRectangle

FullScreenRectangleExample
代码
import manimgx as m


class FullScreenRectangleExample(m.Scene):
    def construct(self) -> None:
        backdrop = m.FullScreenRectangle(
            fill_color=m.DARK_BLUE, fill_opacity=1, stroke_color=m.YELLOW
        )
        self.add(backdrop, m.Text("A backdrop", font_size=96))

与画框等高的屏幕矩形,圆心在原点:未另给时为 16:9 比例,即画框自身的轮廓; 未加样式时为白色。

其高为画框的高(未另行配置时为 8 单位),无论给定何种 height。

m.FullScreenRectangle(**kwargs)
aspect_ratio

其宽除以高(默认 16 / 9)。

height

其高度,以场景单位计(默认 4)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

源码

manimgx\mobjects\shapes.py

def __init__(self, **kwargs: Unpack[ScreenOptions]) -> None:
    super().__init__(**kwargs)
    self.height = config.frame_height

RegularPolygonOptions

RegularPolygon 除顶点数外的关键字, 供传递它们的类使用:其大小和转向,以及样式关键字。

radius

其顶点所在圆的半径,以场景单位计(默认 1)。

start_angle

其第一个顶点的角度,以弧度计,从正 x 轴起逆时针(默认 None:顶点数为奇数时 正上方有一个顶点,为偶数时在右侧)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

radius

其顶点所在圆的半径,以场景单位计(默认 1)。

start_angle

其第一个顶点的角度,以弧度计,从正 x 轴起逆时针(默认 None:顶点数为奇数时 正上方有一个顶点,为偶数时在右侧)。

RectangleOptions

Rectangle 的关键字,供传递它们的类使用:其大小和网格, 以及样式关键字。

height

其高度,以场景单位计(默认 2)。

width

其宽度,以场景单位计(默认 4)。

grid_xstep

其网格竖线之间的距离,从其左边起,以场景单位计(默认 None:无竖线)。

grid_ystep

其网格横线之间的距离,从其顶边起,以场景单位计(默认 None:无横线)。

mark_paths_closed

为兼容 Manim 而接受;被忽略。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

height

其高度,以场景单位计(默认 2)。

width

其宽度,以场景单位计(默认 4)。

ScreenOptions

ScreenRectangle 的关键字,供传递它们的矩形使用: 其比例和高度,以及样式关键字。

aspect_ratio

其宽除以高(默认 16 / 9)。

height

其高度,以场景单位计(默认 4)。

color

填充与描边共用的颜色(默认白色);None 表示该类的默认值。

fill_color

填充的颜色;未给出时为 color。多个颜色沿 sheen_direction 构成渐变。

fill_opacity

填充的不透明度,取值从 0 到 1(默认 0:无填充)。

stroke_color

描边的颜色;未给出时为 color。多个颜色构成渐变。

stroke_opacity

描边的不透明度,取值从 0 到 1(默认 1)。

stroke_width

描边的宽度,以场景单位的百分之一计(默认 4;0:无描边)。

background_stroke_color

绘制于填充之后的轮廓颜色(默认黑色)。

background_stroke_opacity

轮廓的不透明度,取值从 0 到 1(默认 1)。

background_stroke_width

轮廓的宽度,以场景单位的百分之一计(默认 0:无)。

sheen_factor

颜色朝 sheen_direction 变亮的程度,取值从 -1 到 1(默认 0); 负值变暗。

sheen_direction

颜色变亮的方向(默认 UL)。

joint_type

描边在路径转折处的连接方式:圆角、斜切或斜接,按二维场景的绘制方式 (参见 LineJointType;默认 AUTO:斜接)。

cap_style

描边在其显示的每一端的端点样式(开放路径的端点、虚线的端点):圆头、平头 或方头,按二维场景的绘制方式(参见 CapStyleType;默认 AUTO:平头)。

shade_in_3d

三维场景的光是否对该 mobject 着色。

material

其表面在三维场景中如何反射场景的光(参见 Material);None:Manim 的着色(默认)。

name

mobject 的名称;未给出时为其类名。

z_index

其在绘制顺序中的位置:索引较高者绘制于较低者之上 (默认 0)。

target

MoveToTarget 将 mobject 移动至的状态。

aspect_ratio

其宽除以高(默认 16 / 9)。

height

其高度,以场景单位计(默认 4)。