updater

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, range: TimeRange, n: int, _updater: StepUpdater)

Bases: object

StepUpdater 调用时会传递的参数,用于标注时间信息以及动画进度

global_t: 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 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 才会对所有后代物件也应用该 updater

See 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, Generic

Modifies 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

data: Item
stack: AnimStack
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)
class ActionType(*values)

Bases: Enum

GetAttr = 0
Call = 1
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: 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: UpdaterExample

label_color: tuple[float, float, float] = (242, 218, 255)
call(p: UpdaterParams) Item
get_renderer(item: Item) Renderer
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