animation¶
- class janim.anims_core.animation.Animation(*, at: float = 0, duration: float | ForeverType = 1, rate_func: RateFunc = <function smooth>, name: str | None = None)¶
Bases:
objectBase class of animations
Defines an animation that lasts from
attoat + duration- Parameters:
at – The start time of the animation
duration – The duration of the animation; can be
FOREVER, for example, to create a continuously active Updaterrate_func – Sets the interpolation function, defaulting to
smooth()name – Changes the name displayed on the timeline label in the preview interface. It does not affect rendering; if not set, it defaults to the class name
Warning
Animation objects cannot be reused, for example, this will cause unexpected behavior:
anim1 = Transform(a, b) anim2 = Transform(b, a) self.play(anim1) self.play(anim2) self.play(anim1)
Correct way:
self.play(Transform(a, b)) self.play(Transform(b, a)) self.play(Transform(a, b))
The logic of animation intervals in JAnim:
The
t_rangeof a newly created regularAnimationobject will be adjusted as it is nested within animation groups such asAnimGroupWhen the outermost layer calls
finalize(), it indicates that the animation interval has been finalized (this is automatically called byplay()orprepare()). At this point, the animation interval is considered fixed, and operations such as floating-point alignment are performed. After this,t_rangeshould no longer be modified- label_color: tuple[float, float, float] = (192, 198, 205)¶
- shift_range(delta: float) Self¶
Shift the time-range by
delta
- scale_range(k: float) Self¶
Scale the time-range by factor
k(scaled relative tot=0)
- force_order_ctx: ContextVar[int | None] = <ContextVar name='Animation.force_order_ctx' default=None>¶
Used to forcibly specify the order of the marked animation
with ContextSetter(Animation.force_order_ctx, xxxanim._order): ...
Used to mark animations during delayed execution based on an order from an earlier time, allowing
StackableAnimationanimations to be inserted into the appropriate position in the animation stack
- finalize() None¶
Finalizes the animation interval. This triggers floating-point alignment of the time interval (see
TimeAligner) and some other marking operations
- get_alpha_on_global_t(global_t: float) float¶
- transfer_params(other: Animation) None¶
Synchronizes animation parameters from
other, includingt_rangeandrate_func(s), to this animation object
- global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>¶