animation

警告

这部分内容涉及 JAnim 实现原理,可能较为复杂,若没有研究源码的需求,你应酌情阅读

class janim.anims.animation.TimeRange(at: float, duration: float)

基类:object

标识了从 at 开始,持续时间为 duration 的时间区段

endat + duration

at: float
duration: float
property end: float
copy() TimeRange
class janim.anims.animation.Animation(*, at: float = 0, duration: float = 1.0, rate_func: RateFunc = <function smooth>)

基类:object

动画基类

label_color: tuple[float, float, float] = (128, 132, 137)
compute_global_range(at: float, duration: float) None

计算 Timeline 上的时间范围

该方法是被 set_global_range() 调用以计算的

set_render_call_list(lst: list[RenderCall]) None

设置绘制调用,具体参考 RenderCall

anim_pre_init() None

detect_changes_of_all() 执行之前调用的初始化方法

anim_init() None

detect_changes_of_all() 执行之后调用的初始化方法

anim_on(local_t: float) None

local_t 换算为 alpha 并调用 anim_on_alpha()

get_alpha_on_global_t(global_t: float) float

传入全局 global_t,得到物件在该时刻应当处于哪个 alpha 的插值

is_visible(global_t: float) bool
global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>

对该值进行设置,使得进行 anim_on()render() 时不需要将 global_t 作为参数传递也能获取到

anim_on_alpha(alpha: float) None

动画在 alpha 处的行为

class janim.anims.animation.RenderCall(depth: Cmpt_Depth, func: Callable[[], None])

基类:object

绘制调用

  • depth: 该绘制的深度

  • func: 该绘制所调用的函数

具体机制:

  • 在每个动画对象中,都会使用 set_render_call_list() 来设置该动画进行绘制时所执行的函数

  • 在进行渲染(具体参考 render_all() )时,会按照深度进行排序,依次对 func 进行调用,深度越高的越先调用

例:

depth: Cmpt_Depth
func: Callable[[], None]