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:
objectParameters passed when calling the function of
Updater, used to mark time information and animation progress.- global_t: float¶
- alpha: float¶
- extra_data: Any | None¶
- property elapsed: float¶
- class janim.anims.updater.StepUpdaterParams(global_t: float, dt: float, range: TimeRange, n: int, _updater: StepUpdater)¶
Bases:
objectParameters passed when calling the function of
StepUpdater, used to mark time information and animation progress.- global_t: float¶
- dt: float¶
- 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,GenericModifies 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=Truemeans the updater is only applied to the root item; you need to setroot_only=Falseto apply the updater to all descendant items as well.See also the
UpdaterExamplein 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,GenericModifies the data of a group based on time parameters.
Warning
This Updater assumes that
funcwill not change the descendant item structure ofitem. 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- 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:
AnimationUpdater created based on item transformations
See
update()for details- label_color: tuple[float, float, float] = (214, 185, 253)¶
- updater(data: Item, p: UpdaterParams) None¶
- class janim.anims.updater.MethodUpdaterArgsBuilder(item: Item)¶
Bases:
objectAllows the same operations to be performed after both
.updateand.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:
AnimationDisplays item based on time parameters.
In other words, for each frame of
ItemUpdater,funcis executed, and the item returned byfuncis displayed.By default:
The passed
itemwill be replaced by the item returned by the last frame of the animation. Setbecome_at_end=Falseto disable this behavior.The passed
itemwill be hidden at the beginning of the animation and shown after the animation ends. Sethide_at_begin=Falseandshow_at_end=Falseto disable this behavior.If
item=Noneis passed, both of the above points are invalid.
See also the
UpdaterExamplein API Demonstration- label_color: tuple[float, float, float] = (242, 218, 255)¶
- call(p: UpdaterParams) Item¶
- 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,GenericUpdates the item step by step, calling
funceverystepseconds to perform the next update- label_color: tuple[float, float, float] = (242, 218, 255)¶
- add_post_updater(updater: StepUpdaterFn[T]) Self¶