stackable

class janim.anims_core.stackable.StackableAnimation(*args, **kwargs)

Bases: Animation

Base class for animations that can be recorded in AnimStack

Mainly implements the stack calling process of apply()

apply(params: ApplyParams) None

For details, see the descriptions of StackableAnimation and ApplyParams

add_to_stack(item: Item, *, _is_display: bool = False) None

Adds this animation to the animation stack of item

debug_str() str

Outputs in the form CLASS_NAME at 0x...... order ANIM_ORDER.

If the animation was generated by another animation (_generate_by), outputs it in the form CLASS_NAME at 0x...... order ANIM_ORDER (from CLASS_NAME at 0x......).

class janim.anims_core.stackable.ApplyParams(data: Item, global_t: float, index: int, anims: list[StackableAnimation])

Bases: object

Single-object parameters passed to apply()

  • data represents the current item state being calculated and needs to be set inside apply()

    It starts as None and gradually has various animation effects applied to it through calls to apply()

    • Initially, data is None and is always initialized by Display

      Because we directly call display() in AnimStack to record a Display object, the first animation in the animation stack is always Display

    • Afterwards, data is retained and passed to the next animation’s apply() function each time, allowing the entire animation stack to be processed and the final display state to be obtained

  • For index, it starts from 0 and gradually increases with each call to apply()

    It represents the index of the currently applied animation in anims

Additionally:

  • global_t represents the current global time

  • index represents the index of the current animation in the animation stack

  • anims is the complete current animation stack

data: Item
global_t: float
index: int
anims: list[StackableAnimation]
class janim.anims_core.stackable.ItemAnimation(item: Item, *, show_at_begin: bool = True, hide_at_end: bool = False, **kwargs)

Bases: StackableAnimation

Base class for most item animations

The main differences between this class and StackableAnimation are:

  • Automatically adds item to the tracking of AnimStack

  • Wraps the show_at_begin and hide_at_end parameters, providing relatively direct control over when items are shown or hidden

class janim.anims_core.stackable.ApplyAligner(item: Item, stacks: list[AnimStack], **kwargs)

Bases: ItemAnimation

Used to handle coordination between multiple animation stacks

Mainly used for GroupUpdater

Description:

A normal StackableAnimation simply applies a single animation stack from beginning to end

However, for example, GroupUpdater needs to wait for the animation stacks of multiple items to reach an expected “gate” simultaneously. Only after all have reached the gate can this GroupUpdater begin execution. After execution finishes, the “gate” opens and allows each animation stack to continue

Mechanism:

When AnimStack encounters an ApplyAligner animation during computation, it first calls its pre_apply() method for preparation (for example, for GroupUpdater, this synchronizes the current animation stack’s calculation state to its internal item group)

After calling pre_apply(), AnimStack uses yield to temporarily suspend the execution of the current animation stack and triggers the computation of the items that need to wait (that is, the stacks collected from the constructor arguments). After all of them have reached the “gate”, it formally executes StackableAnimation.apply() to achieve the desired result

Note: For ApplyAligner instances operating on the same group of items, the same stacks must be passed to ensure that identifier() identifies them correctly

property identifier: int
pre_apply(params: ApplyParams) None