updater¶
- 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, range: TimeRange, n: int, _updater: StepUpdater)¶
Bases:
objectStepUpdater调用时会传递的参数,用于标注时间信息以及动画进度- global_t: 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 a 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”.
并且,可以对同一个物件作用多个 updater,各个 updater 会依次调用
注意:默认
root_only=True即只对根物件应用该 updater;需要设置root_only=False才会对所有后代物件也应用该 updaterSee also:
UpdaterExample- 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.
注意:该 Updater 假设
func不会改变item后代物件结构,如果改变结构(例如增删子物件、become()结构不一致等情况),则可能导致意外行为- 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, show_at_begin: bool = True, hide_at_end: bool = False, become_at_end: bool = True, **kwargs)¶
Bases:
Animation依据物件的变换而创建的 updater
具体参考
update()- label_color: tuple[float, float, float] = (214, 185, 253)¶
- updater(data: Item, p: UpdaterParams) None¶
- class janim.anims.updater.MethodUpdaterArgsBuilder(item: Item)¶
Bases:
object使得
.anim和.anim(...)后可以进行同样的操作
- 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:
UpdaterExample- label_color: tuple[float, float, float] = (242, 218, 255)¶
- call(p: UpdaterParams) Item¶
- render_calls_callback()¶
- 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按步更新物件,每次间隔
step秒调用func进行下一步更新- label_color: tuple[float, float, float] = (242, 218, 255)¶
- add_post_updater(updater: StepUpdaterFn[T]) Self¶