StringMobject¶
该类由 凡人忆拾 编写,旨在让用户更加方便地对物件进行切片操作。
该类的实例支持 TransformMatchingStrings
动画。
该类为 MTex
和 MarkupText
共同的抽象基类。如果想要在将来通过子字符串进行物件的切片,用户应当在创建实例时指定这些子字符串。可以通过 isolate
参数指定子串,
派生类的其它参数(包括 MTex
的 tex_to_color_map
字典键,
MarkupText
的 t2c
字典键等)也可以指定子串,
该文件定义了 Selector
类型如下:
Selector = Union[
str,
re.Pattern,
tuple[Union[int, None], Union[int, None]],
Iterable[Union[
str,
re.Pattern,
tuple[Union[int, None], Union[int, None]]
]]
]
可以通过以下任意一种或多种方式指定子串(详情请参阅各个子类):
isolate
参数(Selector
类型);派生类的部分参数;
派生类特定的文本内部指定模式。
注意
以以上方式指定的所有子串两两不能“部分重合”(一个完全包含另一个是可以的)。
对于指定了至少一个子串的实例,该类将额外生成一份包含颜色信息的SVG(每种颜色对应一个被指定的子串),并按照位置匹配两个 SVG 的各个物件, 使得原始 SVG 的每个物件对应上该颜色标签,从而完成子串与物件的对应。
StringMobject¶
-
class
manimlib.mobject.svg.string_mobject.
StringMobject
(string: str, **kwargs)¶ An abstract base class for MTex and MarkupText
This class aims to optimize the logic of “slicing submobjects via substrings”. This could be much clearer and more user-friendly than slicing through numerical indices explicitly.
Users are expected to specify substrings in isolate parameter if they want to do anything with their corresponding submobjects. isolate parameter can be either a string, a re.Pattern object, or a 2-tuple containing integers or None, or a collection of the above. Note, substrings specified cannot partially overlap with each other.
Each instance of StringMobject generates 2 svg files. The additional one is generated with some color commands inserted, so that each submobject of the original SVGMobject will be labelled by the color of its paired submobject from the additional SVGMobject.
初始化样式,VMobject 的样式有以下
fill
填充样式颜色:
fill_color
或color
不透明度:
fill_opacity
stroke
线条样式颜色:
stroke_color
或color
宽度:
stroke_width
不透明度:
stroke_opacity
gloss
光泽shadow
阴影reflectiveness
反光度
其中, color, opacity, width 属性均可以为一个列表,在渲染时会按照列表对其进行补间
-
select_part
(selector: Selector, index: int = 0) → VGroup¶ 选择
select_parts(selector)
中的第index
个物件组
-
select_parts
(selector: Selector) → VGroup¶ 选择各个
selector
完全覆盖的预指定子串对应的非空物件组构成的VGroup
-
set_parts_color
(selector: Selector, color: ManimColor)¶ 对
selector
对应的物件染色
-
set_parts_color_by_dict
(color_map: dict[Selector, ManimColor])¶ 通过字典批量上色