API 参考:SVG 与位图(svg)¶
共 7 个类,按字母排序。每个类含中文说明、继承链、参数表与上手示例,API 文档由 autodoc 从 manim v0.21.0 源码自动生成;带完整中文精讲的类见 API 索引。
ArcBrace¶
贴合圆弧的大括号标注:沿曲线中点展开的弧形括号。
继承关系¶
参数¶
|
None,Arc | None |
|---|---|
|
array([1., 0., 0.]),Vector3DLike |
API 文档¶
Brace¶
贴合图形边缘的大括号:自动缩放适应目标宽度,配合标签写标注公式。
继承关系¶
参数¶
|
—,Mobject |
|---|---|
|
array([ 0., -1., 0.]),Vector3DLike |
|
0.2,float |
|
2,float |
|
0,float |
|
1.0,float |
|
0,float |
|
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)¶
-
- 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¶
- 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¶
- 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¶
两点之间的括号:不依附具体对象,任意位置放标注。
继承关系¶
参数¶
|
—,Point3DLike |
|---|---|
|
—,Point3DLike |
|
array([0., 0., 0.]),Vector3DLike |
API 文档¶
BraceLabel¶
括号 + 标签的组合体:一行代码完成这组等于某公式的标注。
继承关系¶
参数¶
|
—,Mobject |
|---|---|
|
—,str |
|
array([ 0., -1., 0.]),Vector3DLike |
|
|
|
48,float |
|
0.2,float |
|
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 渲染。
继承关系¶
参数¶
|
—,Mobject |
|---|---|
|
—,str |
|
|
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:图标、自定义图形直接导入,可控每个子路径。
继承关系¶
参数¶
|
None,str | os.PathLike | None |
|---|---|
|
True,bool |
|
2,float | None |
|
None,float | None |
|
None |
|
None,float | None |
|
None |
|
None,float | None |
|
None |
|
None,float | None |
|
None,float | None |
|
None,dict | None |
|
None,dict | None |
|
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_MAPcaching dictionary.
- init_svg_mobject(use_svg_cache: bool) Self¶
Checks whether the SVG has already been imported and generates it if not.
See also¶
- 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.
VMobjectFromSVGPath¶
由单个 SVG path 数据字符串构造 VMobject 的底层工具,可程序化生成路径。
继承关系¶
参数¶
|
—,se.Path |
|---|---|
|
False,bool |
|
False,bool |
|
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
pointsand therefore the shape.Gets called upon creation. This is an empty method that can be implemented by subclasses.