animation

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

Bases: object

Base class of animations

Defines an animation that lasts from at to at + 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 Updater

  • rate_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_range of a newly created regular Animation object will be adjusted as it is nested within animation groups such as AnimGroup

When the outermost layer calls finalize(), it indicates that the animation interval has been finalized (this is automatically called by play() or prepare()). At this point, the animation interval is considered fixed, and operations such as floating-point alignment are performed. After this, t_range should 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 to t=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 StackableAnimation animations 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, including t_range and rate_func(s), to this animation object

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