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 的别名

global_renderer: dict[tuple[type, mgl.Context], Renderer] = {}

共用的渲染器,用于 is_temporary=True 的物件

depth
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) None

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

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

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

另见:set()

set_style(depth: float | None = None, **kwargs) Self
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 表示从组件回到物件,这样就可以调用其它组件的功能

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, skip_dynamic=False) Self

当前物件

  • 如果此时在回放和 Updater 中,则返回对应时间的历史物件

  • 在其余情况下,包括该物件没有历史记录的情况,则返回物件自身

copy(*, root_only=False, as_time: float | None = None, skip_dynamic: bool = False) Self

复制物件

become(other: Item) Self

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

store() Self
restore(other: Item) Self
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
cmpt_init_datas = {'depth': _ItemMeta._CmptInitData(info=<janim.components.component.CmptInfo object>, decl_cls=<class 'janim.items.item.Item'>)}
fix_in_frame(on: bool = True, *, root_only: bool = False) Self

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

is_fix_in_frame() bool
classmethod get_global_renderer() None
create_renderer() None
render() None
show(**kwargs) Self

显示物件

hide(**kwargs) Self

隐藏物件