animation

class janim.anims_core.animation.Animation(*, at: float = 0, duration: float | ForeverType = 1, rate_func: RateFunc = <function smooth>, name: str | None = None)

基类:object

动画基类

定义了从 at 持续至 at + duration 的动画

参数:
  • at -- 动画的开始时间

  • duration -- 动画的持续时间;可以是 FOREVER,比如创建持续生效的 Updater

  • rate_func -- 设定插值函数,默认为 smooth()

  • name -- 更改在预览界面中时间轴标签上显示的名字,与画面渲染无关;若不设置则默认为类名

警告

动画对象不能复用,例如这样会导致意外行为:

anim1 = Transform(a, b)
anim2 = Transform(b, a)
self.play(anim1)
self.play(anim2)
self.play(anim1)

正确写法:

self.play(Transform(a, b))
self.play(Transform(b, a))
self.play(Transform(a, b))

JAnim 中动画区段的逻辑:

刚创建出来的普通 Animation 对象的 t_range,会随着与 AnimGroup 等动画组的嵌套而被调整

当最外层调用 finalize() ,表示确定动画区段(会由 play() 或 prepare() 自动调用), 则我们就认为动画区段得到确定,会进行浮点数对齐等操作,在这之后,就不应对 t_range 进行修改了

label_color: tuple[float, float, float] = (192, 198, 205)
shift_range(delta: float) → Self

以 delta 的变化量移动时间区段

scale_range(k: float) → Self

以 k 的倍率缩放时间区段(相对于 t=0 进行缩放)

force_order_ctx: ContextVar[int | None] = <ContextVar name='Animation.force_order_ctx' default=None>

用于强制指定所标记的动画顺序

with ContextSetter(Animation.force_order_ctx, xxxanim._order):
    ...

用于在延迟执行中,基于较早时刻的某个顺序来标记,从而使得 StackableAnimation 动画能插入到动画堆栈中的合适位置

finalize() → None

让动画的区段确定下来,这会触发对时间区段的浮点数对齐( 请参考 TimeAligner )以及一些其它标记

get_alpha_on_global_t(global_t: float) → float
transfer_params(other: Animation) → None

将 other 中的动画参数,包括 t_range 和 rate_func(s), 同步到该动画对象上

global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>
schedule_show_and_hide(item: Item, show_at_begin: bool, hide_at_end: bool) → None