API 参考:SVG 与位图(svg)

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

ArcBrace

贴合圆弧的大括号标注:沿曲线中点展开的弧形括号。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VMobjectFromSVGPath VMobjectFromSVGPath VMobject->VMobjectFromSVGPath Brace Brace VMobjectFromSVGPath->Brace ArcBrace ArcBrace Brace->ArcBrace

参数

arc

None,Arc | None

direction

array([1., 0., 0.]),Vector3DLike

API 文档

class manim.ArcBrace(arc: Arc | None = None, direction: Vector3DLike = array([1., 0., 0.]), **kwargs: Any)

基类:Brace

Brace

贴合图形边缘的大括号:自动缩放适应目标宽度,配合标签写标注公式。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VMobjectFromSVGPath VMobjectFromSVGPath VMobject->VMobjectFromSVGPath Brace Brace VMobjectFromSVGPath->Brace

参数

mobject

—,Mobject

direction

array([ 0., -1., 0.]),Vector3DLike

buff

0.2,float

sharpness

2,float

stroke_width

0,float

fill_opacity

1.0,float

background_stroke_width

0,float

background_stroke_color

ManimColor('#000000'),ParsableManimColor

快速上手

brace = Brace(group, DOWN, label="sum")

API 文档

class manim.Brace(mobject: Mobject, direction: Vector3DLike = array([0., -1., 0.]), buff: float = 0.2, sharpness: float = 2, stroke_width: float = 0, fill_opacity: float = 1.0, background_stroke_width: float = 0, background_stroke_color: ParsableManimColor = ManimColor('#000000'), **kwargs: Any)

基类:VMobjectFromSVGPath

get_direction() → Vector3D

Returns the direction from the center to the brace tip.

get_tex(*tex: str, **kwargs: Any) → MathTex

Places the tex at the brace tip.

Parameters

tex

The tex to be placed at the brace tip.

kwargs

Any further keyword arguments are passed to put_at_tip() which is used to position the tex at the brace tip.

Returns

MathTex

get_text(*text: str, **kwargs: Any) → Tex

Places the text at the brace tip.

Parameters

text

The text to be placed at the brace tip.

kwargs

Any additional keyword arguments are passed to put_at_tip() which is used to position the text at the brace tip.

Returns

Tex

get_tip() → Point3D

Returns the point at the brace tip.

put_at_tip(mob: Mobject, use_next_to: bool = True, **kwargs: Any) → Self

Puts the given mobject at the brace tip.

Parameters

mob

The mobject to be placed at the tip.

use_next_to

If true, then next_to() is used to place the mobject at the tip.

kwargs

Any additional keyword arguments are passed to next_to() which is used to put the mobject next to the brace tip.

BraceBetweenPoints

两点之间的括号:不依附具体对象,任意位置放标注。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VMobjectFromSVGPath VMobjectFromSVGPath VMobject->VMobjectFromSVGPath Brace Brace VMobjectFromSVGPath->Brace BraceBetweenPoints BraceBetweenPoints Brace->BraceBetweenPoints

参数

point_1

—,Point3DLike

point_2

—,Point3DLike

direction

array([0., 0., 0.]),Vector3DLike

API 文档

class manim.BraceBetweenPoints(point_1: Point3DLike, point_2: Point3DLike, direction: Vector3DLike = array([0., 0., 0.]), **kwargs: Any)

基类:Brace

BraceLabel

括号 + 标签的组合体:一行代码完成这组等于某公式的标注。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject BraceLabel BraceLabel VMobject->BraceLabel

参数

obj

—,Mobject

text

—,str

brace_direction

array([ 0., -1., 0.]),Vector3DLike

label_constructor

<class 'manim.mobject.text.…

font_size

48,float

buff

0.2,float

brace_config

None,dict[str, Any] | None

API 文档

class manim.BraceLabel(obj: Mobject, text: str, brace_direction: Vector3DLike = array([ 0., -1., 0.]), label_constructor: type[SingleStringMathTex | Text] = <class 'manim.mobject.text.tex_mobject.MathTex'>, font_size: float = 48, buff: float = 0.2, brace_config: dict[str, Any] | None=None, **kwargs: Any)

基类:VMobject

BraceText

Brace 的 Text 标签便捷版:标签自动用 Text 渲染。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject BraceLabel BraceLabel VMobject->BraceLabel BraceText BraceText BraceLabel->BraceText

参数

obj

—,Mobject

text

—,str

label_constructor

<class 'manim.mobject.text.…

API 文档

class manim.BraceText(obj: Mobject, text: str, label_constructor: type[SingleStringMathTex | Text] = <class 'manim.mobject.text.text_mobject.Text'>, **kwargs: Any)

基类:BraceLabel

SVGMobject

把 SVG 矢量文件解析成矢量路径的 Mobject:图标、自定义图形直接导入,可控每个子路径。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject SVGMobject SVGMobject VMobject->SVGMobject

参数

file_name

None,str | os.PathLike | None

should_center

True,bool

height

2,float | None

width

None,float | None

color

None

opacity

None,float | None

fill_color

None

fill_opacity

None,float | None

stroke_color

None

stroke_opacity

None,float | None

stroke_width

None,float | None

svg_default

None,dict | None

path_string_config

None,dict | None

use_svg_cache

True,bool

快速上手

icon = SVGMobject("logo.svg")

API 文档

class manim.SVGMobject(file_name: str | PathLike | None = None, should_center: bool = True, height: float | None = 2, width: float | None = None, color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] | None = None, opacity: float | None = None, fill_color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] | None = None, fill_opacity: float | None = None, stroke_color: ManimColor | int | str | NDArray[int64] | tuple[int, int, int] | NDArray[float64] | tuple[float, float, float] | tuple[int, int, int, int] | tuple[float, float, float, float] | None = None, stroke_opacity: float | None = None, stroke_width: float | None = None, svg_default: dict | None = None, path_string_config: dict | None = None, use_svg_cache: bool = True, **kwargs: Any)

基类:VMobject

static apply_style_to_mobject(mob: VMobject, shape: GraphicObject) → VMobject

Apply SVG style information to the converted mobject.

Parameters

mob

The converted mobject.

shape

The parsed SVG element.

static ellipse_to_mobject(ellipse: Ellipse | Circle) → Circle

Convert an ellipse or circle element to a vectorized mobject.

Parameters

ellipse

The parsed SVG ellipse or circle.

generate_config_style_dict() → dict[str, str]

Generate a dictionary holding the default style information.

generate_mobject() → Self

Parse the SVG and translate its elements to submobjects.

get_file_path() → Path

Search for an existing file based on the specified file name.

get_mobjects_from(svg: SVG) → tuple[list[VMobject], dict[str, VGroup]]

Convert the elements of the SVG to a list of mobjects.

Parameters

svg

The parsed SVG file.

static handle_transform(mob: VMobject, matrix: Matrix) → VMobject

Apply SVG transformations to the converted mobject.

Parameters

mob

The converted mobject.

matrix

The transformation matrix determined from the SVG transformation.

property hash_seed: tuple

A unique hash representing the result of the generated mobject points.

Used as keys in the SVG_HASH_TO_MOB_MAP caching dictionary.

init_svg_mobject(use_svg_cache: bool) → Self

Checks whether the SVG has already been imported and generates it if not.

See also

SVGMobject.generate_mobject()

static line_to_mobject(line: Line) → Line

Convert a line element to a vectorized mobject.

Parameters

line

The parsed SVG line.

modify_xml_tree(element_tree: ElementTree) → ElementTree

Modifies the SVG element tree to include default style information.

Parameters

element_tree

The parsed element tree from the SVG file.

move_into_position() → Self

Scale and move the generated mobject into position.

path_to_mobject(path: Path) → VMobjectFromSVGPath

Convert a path element to a vectorized mobject.

Parameters

path

The parsed SVG path.

static polygon_to_mobject(polygon: Polygon) → Polygon

Convert a polygon element to a vectorized mobject.

Parameters

polygon

The parsed SVG polygon.

polyline_to_mobject(polyline: Polyline) → VMobject

Convert a polyline element to a vectorized mobject.

Parameters

polyline

The parsed SVG polyline.

static rect_to_mobject(rect: Rect) → Rectangle

Convert a rectangle element to a vectorized mobject.

Parameters

rect

The parsed SVG rectangle.

static text_to_mobject(text: Text) → VMobject

Convert a text element to a vectorized mobject.

警告

Not yet implemented.

Parameters

text

The parsed SVG text.

VMobjectFromSVGPath

由单个 SVG path 数据字符串构造 VMobject 的底层工具,可程序化生成路径。

继承关系

G Mobject Mobject VMobject VMobject Mobject->VMobject VMobjectFromSVGPath VMobjectFromSVGPath VMobject->VMobjectFromSVGPath

参数

path_obj

—,se.Path

long_lines

False,bool

should_subdivide_sharp_curves

False,bool

should_remove_null_curves

False,bool

API 文档

class manim.VMobjectFromSVGPath(path_obj: Path, long_lines: bool = False, should_subdivide_sharp_curves: bool = False, should_remove_null_curves: bool = False, **kwargs: Any)

基类:VMobject

generate_points() → Self

Initializes points and therefore the shape.

Gets called upon creation. This is an empty method that can be implemented by subclasses.