item

janim.items.item.mockable(func)

使得 .astype 后可以调用被 @mockable 修饰的方法

class janim.items.item.Item(*args, children: list[Item] | None = None, **kwargs)

基类:Relation[Item]

Item 是物件的基类

除了使用 item[0] item[1] 进行下标索引外,还可以使用列表索引和布尔索引

  • 列表索引,例如 item[0, 1, 3], 即 Group(item[0], item[1], item[3])

  • 布尔索引,例如 item[False, True, False, True, True] 表示取出 Group(item[1], item[3], item[4])

    也就是将那些为 True 的位置取出组成一个 Group

renderer_cls

Renderer 的别名

depth
init_connect() None
set_component(key: str, cmpt: Component) None
broadcast_refresh_of_component(cmpt: Component, func: Callable | str, recurse_up=False, recurse_down=False) Self

mark_refresh() 进行 recurse_up/down 的处理

set(**styles) Self

设置物件以及子物件的样式,与 apply_styles() 只影响自身不同的是,该方法也会影响所有子物件

classmethod get_available_styles() list[str]
apply_style(depth: float | None = None, **kwargs) Self

设置物件自身的样式,不影响子物件

另见:set()

do(func: Callable[[Self], Any]) Self

使用 func 对物件进行操作,并返回 self 以方便链式调用

is_null() bool
property anim: Self

例如:

self.play(
    item.anim.points.scale(2).r.color.set('green')
)

该例子会创建将 item 缩放 2 倍并且设置为绿色的补间动画

并且可以向动画传入参数:

self.play(
    item.anim(duration=2, rate_func=linear)
    .points.scale(2).r.color.set('green')
)

.r 表示从组件回到物件,这样就可以调用其它组件的功能

property update: Self

例如:

self.play(
    item.update.points.shift(RIGHT * 2),
    item.update(rate_func=rush_into).color.set(GREEN)
)

该例子会创建将 item 向右移动两个单位并且设置为绿色的 updater,并且二者的 rate_func 不同

replicate(n: int) Group[Self]

复制 n 个自身,并作为一个 Group 返回

可以将 item * n 作为该方法的简写

astype(cls: type[T]) T

使得可以调用当前物件中没有的组件

例:

group = Group(
    Rect()
    Circle()
)

在这个例子中,并不能 group.color.set(BLUE) 来设置子物件中的颜色, 但是可以使用 group.astype(VItem).color.set(BLUE) 来做到

也可以使用简写 group(VItem).color.set(BLUE)

get_parents()
get_children()
not_changed(other: Self) bool
current(*, as_time: float | None = None, root_only=False) Self

由当前时间点获得当前物件(考虑动画作用后的结果)

copy(*, root_only: bool = False)

复制物件

become(other: Item, *, auto_visible: bool = True) Self

将该物件的数据设置为与传入的物件相同(以复制的方式,不是引用)

store()
restore(other: Item) Self
become_current() Self

使用该方法可以中断动画过程,使物件立刻成为当前动画作用下的结果

小技巧

物件本身是不会一直随着动画改变数据的

在需要使用动画后的状态进行 .anim 等操作时较为实用

classmethod align_for_interpolate(item1: Item, item2: Item) AlignedData[Self]

进行数据对齐,以便插值

interpolate(item1: ~janim.items.item.Item, item2: ~janim.items.item.Item, alpha: float, *, path_func: PathFunc = <function straight_path>) None

进行插值(仅对该物件进行,不包含后代物件)

apart_alpha(n: int) None
fix_in_frame(on: bool = True, *, root_only: bool = False) Self

固定在屏幕上,也就是即使摄像头移动位置也不会改变在屏幕上的位置

is_fix_in_frame() bool
class SavedState(state: 'T', root_only: 'bool')

基类:Generic

state: T
root_only: bool
save_state(key: str = '', root_only: bool = False) Self

保存物件状态,后续可使用 load_state() 恢复,例如:

item.save_state()

# ...

item.load_state()

或者创建恢复动画:

self.play(item.anim.load_state())

例如可以用在,保存摄像机初始状态,在复杂的动画后恢复摄像机位置等场景中

NumberPlane((-2, 2), (-2, 2), faded_line_ratio=1).show()

self.camera.save_state()

self.play(
    self.camera.anim.points.rotate(40 * DEGREES)
)
self.play(
    self.camera.anim.points.rotate(70 * DEGREES, axis=UP)
)

self.play(
    self.camera.anim.load_state()
)
load_state(key: str = '') Self

恢复物件状态,详见 save_state()

generate_target() Self

拷贝生成一个 .target 物件,用于设置目标状态,最后使用 MoveToTarget 创建过渡动画

例如:

txt = Text('A Matrix')
mat = TypstMatrix([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])

self.play(Write(txt))

Group(txt.generate_target(), mat).points.arrange(DOWN)

self.play(
    MoveToTarget(txt),
    FadeIn(mat, UP)
)
self.forward()
create_renderer() Renderer
show(root_only=False) Self

显示物件

hide(root_only=False) Self

隐藏物件