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,比如创建持续生效的 Updaterrate_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¶
- global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>¶