API 参考:核心与其他

共 4 个类,按字母排序。每个类含中文说明、继承链、参数表与上手示例,API 文档由 autodoc 从 manim v0.21.0 源码自动生成;带完整中文精讲的类见 API 索引。

CairoRenderer

Cairo 渲染器:默认的 2D 矢量光栅化后端,把 VMobject 画成帧。

参数

file_writer_class

<class 'manim.scene.scene_f…,type[SceneFileWriter]

camera_class

None,type[Camera] | None

skip_animations

False,bool

API 文档

class manim.CairoRenderer(file_writer_class: type[SceneFileWriter] = <class 'manim.scene.scene_file_writer.SceneFileWriter'>, camera_class: type[Camera] | None = None, skip_animations: bool = False, **kwargs: Any)

基类:object

A renderer using Cairo.

Attributes

num_playsint

Number of play() functions in the scene.

timefloat

Time elapsed since initialisation of scene.

add_frame(frame: PixelArray, num_frames: int = 1) → None

Adds a frame to the video_file_stream

Parameters
frame

The frame to add, as a pixel array.

num_frames

The number of times to add frame.

freeze_current_frame(duration: float) → None

Adds a static frame to the movie for a given duration. The static frame is the current frame.

Parameters
duration

[description]

get_frame() → PixelArray

Gets the current frame as NumPy array.

Returns
PixelArray

NumPy array of pixel values of each pixel in screen. The shape of the array is height x width x 3.

save_static_frame_data(scene: Scene, static_mobjects: Iterable[Mobject]) → PixelArray | None

Compute and save the static frame, that will be reused at each frame to avoid unnecessarily computing static mobjects.

Parameters
scene

The scene played.

static_mobjects

Static mobjects of the scene. If None, self.static_image is set to None.

Returns
PixelArray | None

The static image computed. The return value is None if there are no static mobjects in the scene.

show_frame(scene: Scene) → None

Opens the current frame in the Default Image Viewer of your system.

update_frame(scene: Scene, mobjects: Iterable[Mobject] | None = None, include_submobjects: bool = True, ignore_skipping: bool = True, **kwargs: Any) → None

Update the frame.

Parameters

scene

mobjects

list of mobjects

include_submobjects

ignore_skipping

**kwargs

update_skipping_status() → None

This method is used internally to check if the current animation needs to be skipped or not. It also checks if the number of animations that were played correspond to the number of animations that need to be played, and raises an EndSceneEarlyException if they don't correspond.

CapStyleType

线帽样式枚举:butt/round/square,控制线段端点形状。

API 文档

class manim.CapStyleType(*values)

基类:Enum

Collection of available cap styles.

See the example below for a visual illustration of the different cap styles.

Examples

class CapStyleVariants(Scene):
    def construct(self):
        arcs = VGroup(*[
            Arc(
                radius=1,
                start_angle=0,
                angle=TAU / 4,
                stroke_width=20,
                color=GREEN,
                cap_style=cap_style,
            )
            for cap_style in CapStyleType
        ])
        arcs.arrange(RIGHT, buff=1)
        self.add(arcs)
        for arc in arcs:
            label = Text(arc.cap_style.name, font_size=24).next_to(arc, DOWN)
            self.add(label)

LineJointType

线连接样式枚举:miter/round/bevel,控制折角处形状。

API 文档

class manim.LineJointType(*values)

基类:Enum

Collection of available line joint types.

See the example below for a visual illustration of the different joint types.

Examples

class LineJointVariants(Scene):
    def construct(self):
        mob = VMobject(stroke_width=20, color=GREEN).set_points_as_corners([
            np.array([-2, 0, 0]),
            np.array([0, 0, 0]),
            np.array([-2, 1, 0]),
        ])
        lines = VGroup(*[mob.copy() for _ in range(len(LineJointType))])
        for line, joint_type in zip(lines, LineJointType):
            line.joint_type = joint_type

        lines.arrange(RIGHT, buff=1)
        self.add(lines)
        for line in lines:
            label = Text(line.joint_type.name).next_to(line, DOWN)
            self.add(label)

RendererType

渲染器类型枚举:选择 cairo 或 OpenGL 渲染后端。

API 文档

class manim.RendererType(*values)

基类:Enum

An enumeration of all renderer types that can be assigned to the config.renderer attribute.

Manim's configuration allows assigning string values to the renderer setting, the values are then replaced by the corresponding enum object. In other words, you can run:

config.renderer = "opengl"

and checking the renderer afterwards reveals that the attribute has assumed the value:

<RendererType.OPENGL: 'opengl'>
CAIRO = 'cairo'

A renderer based on the cairo backend.

OPENGL = 'opengl'

An OpenGL-based renderer.