item¶
- janim.items.item.mockable(func)¶
使得
.astype后可以调用被@mockable修饰的方法
- class janim.items.item.Item(*args, children: list[Item] | None = None, **kwargs)¶
-
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
- depth¶
- init_connect() 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]¶
- 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不同
- 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)¶
复制物件
- store()¶
- 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¶
- 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()
- show(root_only=False) Self¶
显示物件
- hide(root_only=False) Self¶
隐藏物件