typst_types¶
- class janim.items.svg.typst_types.TypstMatrix(matrix: Iterable[Iterable[str | float | Points]], delim: str | TypMatDelim | tuple[TypMatDelim, TypMatDelim] | None = None, *, align: TypMatAlignment | None = None, augment: int | str | None = None, gap: str | None = None, row_gap: str | None = None, column_gap: str | None = None, label: bool = False, **kwargs)¶
基类:
TypstText使用 Typst 进行矩阵布局
使用
get_inserted()得到插入的 JAnim 物件使用
get_element()根据行列得到元素(需要传入label=True启用)
传参请参考 Typst 文档 https://typst.app/docs/reference/math/mat/ ,以下给出部分示例
TypstMatrix( [ [1, 2, 3], [4, Arrow(ORIGIN, RIGHT), 6], [7, 8, 9] ], ).show()
TypstMatrix( [ [1, 2, 3], [4, Arrow(ORIGIN, RIGHT), 6], [7, 8, 9] ], gap='2em', ).show()
TypstMatrix( [ [1, 2, 3], [4, Arrow(ORIGIN, RIGHT), 6], [7, 8, 9] ], delim='[', align='right', augment=2, gap='0.5em', )
TypstMatrix( [ [1, 2, 3], [4, Circle(radius=0.25, fill_alpha=0.5), 6], [7, 8, 9] ], delim='[', augment=2, column_gap='0.7em', preamble='#set text(size: 3em)' ).show()
- matrix_labels¶
按照子物件顺序排列的矩阵元素标签
- get_element(row: int, col: int) Group[SVGElemItem] | Points¶
根据行列索引元素
需要在构造
TypstMatrix时传入label=True启用
- get_elements() list[Group[SVGElemItem] | Points]¶
获取矩阵中所有元素
需要在构造
TypstMatrix时传入label=True启用
- get_left_brace() Group[SVGElemItem]¶
获取左大括号元素
需要在构造
TypstMatrix时传入label=True启用
- get_right_brace() Group[SVGElemItem]¶
获取右大括号元素
需要在构造
TypstMatrix时传入label=True启用
- class janim.items.svg.typst_types.DynamicTypst(template: str, dynamic: dict[str, float], post: ~typing.Callable[[~janim.items.svg.typst_types.DynamicTypst], ~typing.Any] = <function DynamicTypst.<lambda>>, **kwargs)¶
基类:
TypstText便于创建参数变化的 Typst 物件的封装
- 参数:
template -- Typst 代码
dynamic -- 声明含有哪些参数及其初始值,这些值可以直接在 Typst 代码中使用
post -- 用于在生成 Typst 对象后,做进一步的调整,例如固定或对齐某个位置
例:
DynamicTypstExample ¶
from janim.imports import * class DynamicTypstExample(Timeline): def construct(self) -> None: dtyp = DynamicTypst( """ #import "@preview/cetz:0.4.2" #import "@preview/cetz-plot:0.1.3": * #let width = 1 #let ang_deg = angle * 1deg #cetz.canvas({ import cetz.draw: * stroke((thickness: 0.7pt, join: "round", paint: white)) let (a, b, c, d) = ( (0, 0), (width, 0), (rel: (width, 0), to: (60deg, width * 3)), (60deg, width * 3), ) line(a, b, c, d, a) let ang_eab = ang_deg let len_ae = width / calc.sin(60deg - ang_eab) * calc.sin(120deg) let e = (ang_eab, len_ae) let g = (a, 100%, 120deg, e) let f = (a, 100%, 60deg, e) line(a, e, f, g, a) line(a, f) for (pos, rel, lab) in ( (a, (-1, -1.2), $A$), (b, (1, -1.5), $B$), (c, (1, 1), $C$), (d, (-1, 1), $D$), (f, (-.5, 1.5), $F$), (g, (-1, 1), $G$), (e, (1, -.5), $E$), ) { content((pos, 17%, (rel: rel)), lab) } }) """, { 'angle': 30, }, post=lambda typ: typ.points.next_to(DR * 2, UL), ).show() self.play( # 在使用 can_keep_structure 之前请先查看文档! dtyp.anim_update(angle=45, can_keep_structure=True), duration=2, ) self.play( dtyp.anim_update(angle=5, can_keep_structure=True), duration=2, )
- anim_update(can_keep_structure: bool = False, **values)¶
创建参数改变的动态动画
如果能保证动态过程不会改变物件结构, 可以传入
can_keep_structure使其基于GroupUpdater动态变化,否则默认使用ItemUpdater设置这个参数的动机是,
GroupUpdater的性质更好,但是它需要物件结构不会改变的前提