updater

Note

Detailed tutorial: Updater Usage

class janim.anims.updater.UpdaterParams(global_t: float, alpha: float, range: TimeRange, extra_data: Any | None, _updater: _DataUpdater | GroupUpdater | None)

Bases: object

Parameters passed when calling the function of Updater, used to mark time information and animation progress.

global_t: float
alpha: float
range: TimeRange
extra_data: Any | None
property elapsed: float
class janim.anims.updater.StepUpdaterParams(global_t: float, dt: float, range: TimeRange, n: int, _updater: StepUpdater)

Bases: object

Parameters passed when calling the function of StepUpdater, used to mark time information and animation progress.

global_t: float
dt: float
range: TimeRange
n: int
class janim.anims.updater.DataUpdater(item: T, func: DataUpdaterFn[T], *, extra: Callable[[Item], Any | None] = <function DataUpdater.<lambda>>, lag_ratio: float = 0, show_at_begin: bool = True, hide_at_end: bool = False, become_at_end: bool = True, skip_null_items: bool = True, root_only: bool = True, **kwargs)

Bases: Animation, Generic

Modifies the data of an item based on time parameters.

For example:

class Example(Timeline):
    def construct(self) -> None:
        rect = Rect()
        rect.points.to_border(LEFT)

        self.play(
            DataUpdater(
                rect,
                lambda data, p: data.points.rotate(p.alpha * 180 * DEGREES).shift(p.alpha * 6 * RIGHT)
            )
        )

This will create an animation of “a rectangle rotating and moving from the left to the right”.

Additionally, multiple updaters can be applied to the same item, and each updater will be called sequentially.

Hint

By default root_only=True means the updater is only applied to the root item; you need to set root_only=False to apply the updater to all descendant items as well.

See also the UpdaterExample in API Demonstration

label_color: tuple[float, float, float] = (242, 218, 255)
add_post_updater(func: DataUpdaterFn[T]) Self
class janim.anims.updater.GroupUpdater(item: T, func: GroupUpdaterFn[T], *, show_at_begin: bool = True, hide_at_end: bool = False, become_at_end: bool = True, **kwargs)

Bases: Animation, Generic

Modifies the data of a group based on time parameters.

Warning

This Updater assumes that func will not change the descendant item structure of item. If the structure is changed (e.g., adding/removing child items, become() with inconsistent structure, etc.), it may lead to unexpected behavior

label_color: tuple[float, float, float] = (242, 218, 255)
add_post_updater(func: GroupUpdaterFn[T]) Self
class DataGroup(data: 'Item', stack: 'AnimStack', updater: '_GroupUpdater')

Bases: object

data: Item
stack: AnimStack
updater: _GroupUpdater
apply_for_group(global_t: float) None
class janim.anims.updater.MethodUpdater(item: Item, obj: Item | _AsTypeWrapper, show_at_begin: bool = True, hide_at_end: bool = False, become_at_end: bool = True, **kwargs)

Bases: Animation

Updater created based on item transformations

See update() for details

label_color: tuple[float, float, float] = (214, 185, 253)
class ActionType(*values)

Bases: Enum

GetAttr = 0
Call = 1
static get_real_component(attr: Component | _AsTypeWrapper) Component | None
updater(data: Item, p: UpdaterParams) None
class janim.anims.updater.MethodUpdaterArgsBuilder(item: Item)

Bases: object

Allows the same operations to be performed after both .update and .update(...)

class janim.anims.updater.ItemUpdater(item: Item | None, func: ItemUpdaterFn, *, hide_at_begin: bool = True, show_at_end: bool = True, become_at_end: bool = True, **kwargs)

Bases: Animation

Displays item based on time parameters.

In other words, for each frame of ItemUpdater, func is executed, and the item returned by func is displayed.

By default:

  • The passed item will be replaced by the item returned by the last frame of the animation. Set become_at_end=False to disable this behavior.

  • The passed item will be hidden at the beginning of the animation and shown after the animation ends. Set hide_at_begin=False and show_at_end=False to disable this behavior.

  • If item=None is passed, both of the above points are invalid.

See also the UpdaterExample in API Demonstration

label_color: tuple[float, float, float] = (242, 218, 255)
call(p: UpdaterParams) Item
get_renderer(item: Item) Renderer
render_group_fn()
class janim.anims.updater.StepUpdater(item: T, func: StepUpdaterFn[T], step: float = 0.02, *, persistent_cache_step: float = 1, show_at_begin: bool = True, hide_at_end: bool = False, become_at_end: bool = True, rate_func: RateFunc = <function linear>, skip_null_items: bool = True, root_only: bool = True, progress_bar: bool = True, **kwargs)

Bases: Animation, Generic

Updates the item step by step, calling func every step seconds to perform the next update

label_color: tuple[float, float, float] = (242, 218, 255)
add_post_updater(updater: StepUpdaterFn[T]) Self