animation¶
警告
这部分内容涉及 JAnim 实现原理,可能较为复杂,若没有研究源码的需求,你应酌情阅读
- class janim.anims.animation.Animation(*, at: float = 0, duration: float | ForeverType = 1, rate_func: RateFunc = <function smooth>, name: str | None = None)¶
基类:
object动画基类
创建一个从
at持续至at + duration的动画duration可以是FOREVER(一般用于Display, 以及特殊情况下的DataUpdater等, 但是AnimGroup及其衍生类不能传入FOREVER)指定
rate_func可以设定插值函数,默认为janim.utils.rate_funcs.smooth()即平滑插值设置
name可以将文字显示在预览界面的时间轴标签上,不影响渲染(如果不设置则默认为类名)
警告
动画对象不能复用,例如这样会导致意外行为:
class Test(Timeline): def construct(self): a = Square() b = Circle() anim1 = Transform(a, b) anim2 = Transform(b, a) self.play(anim1) self.play(anim2) self.play(anim1)
正确写法:
class Test(Timeline): def construct(self): a = Square() b = Circle() self.play(Transform(a, b)) self.play(Transform(b, a)) self.play(Transform(a, b))
- label_color: tuple[float, float, float] = (192, 198, 205)¶
- shift_range(delta: float) Self¶
以
delta的变化量移动时间区段
- scale_range(k: float) Self¶
以
k的倍率缩放时间区段(相对于t=0进行缩放)
- finalize() None¶
- get_alpha_on_global_t(global_t: float) float¶
- global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>¶
- class janim.anims.animation.ItemAnimation(item: Item, *, show_at_begin: bool = True, hide_at_end: bool = False, **kwargs)¶
基类:
Animation- auto_detect = True¶
- class ApplyParams(global_t: 'float', anims: 'list[ItemAnimation]', index: 'int')¶
基类:
object- global_t: float¶
- anims: list[ItemAnimation]¶
- index: int¶
- apply(data: Item, p: ApplyParams) None¶
- apply(data: None, p: ApplyParams) Item
将
global_t时的动画效果作用到data上其中
- class janim.anims.animation.ApplyAligner(item: Item, stacks: list[AnimStack], **kwargs)¶
-
- pre_apply(data: Item, p: ApplyParams) None¶
- class janim.anims.animation.TimeRange(at: float, end: float | ForeverType)¶
基类:
object标识了从
at开始,到end结束的时间区段end也可以是FOREVER- at: float¶
时间区段的开始时刻
- end: float | ForeverType¶
时间区段的结束时刻
- property duration: float¶
时间区段的时长,即
end - at,如果end=FOREVER则抛出AssertionError
- property num_duration: float¶
当
end不是FOREVER时,与duration()一致当
end是FOREVER时,此时返回0
(这用于
AnimGroup对end=FOREVER的子动画的处理,也就是把这种子动画当成end=at来计算时间)
- property num_end: float¶
当
end不是FOREVER时,此时返回end当
end是FOREVER时,此时返回at
(这用于
AnimGroup对end=FOREVER的子动画的处理,也就是把这种子动画当成end=at来计算时间)
- set(at: float, end: float | ForeverType) None¶
设置该时间区段的范围
- shift(delta: float) None¶
以
delta的变化量移动时间区段
- scale(k: float) None¶
以
k的倍率缩放时间区段(相对于t=0进行缩放)