core

class janim.timeline.core.ScheduledTask(global_t: float, func: Callable, args: tuple, kwargs: dict, early_invoked: bool = False)

Bases: object

The function scheduled to be executed in Timeline and its corresponding parameter information

Parameters:
  • global_t – Global time

  • func – Function body

  • args – Positional arguments

  • kwargs – Keyword arguments

After Timeline reaches global_t, args and kwargs will be passed to func for invocation

See also schedule()

global_t: float
func: Callable
args: tuple
kwargs: dict
early_invoked: bool
class janim.timeline.core.ExtraRenderGroup(t_range: TimeRange, func: RenderGroupFn, related_items: list[Item] | None)

Bases: object

Additional rendering registered by some special animation classes

t_range: TimeRange
func: RenderGroupFn
related_items: list[Item] | None
class janim.timeline.core.TimeOfCode(time: float, line: int)

Bases: object

Marks the time corresponding to the line number of code execution in construct()

Parameters:
  • time – Global time

  • line – The line number in the code file, indicating that all times up to time correspond to this line of code

time: float
line: int
class janim.timeline.core.TimelineCore(*args, **kwargs)

Bases: object

Encapsulates the core functionality of Timeline. It is extended through inheritance from other classes to form the Timeline class. For information about the extended functionality, see the documentation of Timeline

This class only exists for the convenience of JAnim’s internal code organization and cannot be used independently. When using JAnim, simply use Timeline directly

Hint

All methods in this class can be used directly in Timeline

forward(dt: float = 1, *, _detect_changes=True, _record_lineno=True)

Advance by dt seconds

forward_to(t: float, *, _detect_changes=True) None

Advance to time t

prepare(*anims: SupportsAnim, at: float = 0, name: str | None = 'prepare', **kwargs) TimeRange

Apply animations without advancing time

play(*anims: SupportsAnim, name: str | None = 'play', **kwargs) TimeRange

Play animations and advance time to the end of the animations

schedule(global_t: float, func: Callable, *args, **kwargs) None

Schedule execution

Calls func when the progress reaches global_t. *args and **kwargs can be passed to it

schedule_and_detect_changes(global_t: float, func: Callable, *args, **kwargs) None

Similar to schedule(), but records the state of changed items after calling func

timeout(delay: float, func: Callable, *args, **kwargs) None

Equivalent to schedule(self.current_time + delay, func, *args, **kwargs)

timeout_and_detect_changes(delay: float, func: Callable, *args, **kwargs) None

Similar to timeout(), but records the state of changed items after calling func

early_invoke_scheduled_function(func: Callable) bool

Execute a scheduled function ahead of time

Parameters:

func – The previously scheduled function

Returns:

Whether a matching function was found

track(item: Item) None

Causes item to be automatically checked for state changes and records those changes on each forward and play

track_item_and_descendants(item: Item, *, root_only: bool = False) None

Equivalent to calling track() on item and all its descendant items

detect_changes_of_all() None

Checks all tracked items for changes and records them

detect_changes(items: Iterable[Item]) None

Checks items in the specified list for changes and records them

(Only checks itself, excluding descendant items)

compute_item(item: T, global_t: float, readonly: bool) T

See compute()

item_current(item: T, *, as_time: float | None = None, root_only: bool = False) T

See current()

is_visible(item: Item) bool

Determine whether a specific item is currently visible

See also: show(), hide()

show(*roots: Item, root_only=False) None

Show item

hide(*roots: Item, root_only=False) None

Hide item

hide_all() None

Hide all items currently displayed

visible_items() list[Item]

Gets all currently visible items

Returns:

List of items

add_extra_render_group(t_range: TimeRange, func: RenderGroupFn, related_items: list[Item] | None) None

Registers additional rendering for special animation classes such as Transform

get_lineno_at_time(time: float)

Get the corresponding line number based on time.

class janim.timeline.core.ItemAppearance(item: Item, aligner: TimeAligner)

Bases: object

Contains objects related to item display

  • self.stack is the AnimStack object

  • self.visiblility is a list that stores the time points when an item is shown or hidden
    • Elements at even indices (0, 2, …) in the list represent the time points when the item starts being shown, while elements at odd indices (1, 3, …) represent the time points when it is hidden

    • For example, if the list is [3, 4, 8], it means the item is shown at 3s, hidden at 4s, and remains shown after 8s

    • This recording method is the basis for the operation of TimelineCore.is_visible(), TimelineCore.show(), and TimelineCore.hide()

  • self.renderer represents the renderer object being used

is_visible_at(t: float) bool

Whether the item is visible at time t

render(data: Item) None
class janim.timeline.core.ItemAppearances(time_aligner: TimeAligner)

Bases: defaultdict[Item, ItemAppearance]

Essentially, it is a dict of {Item: ItemAppearance}

However, if key does not exist, an ItemAppearance corresponding to the key item will be created automatically, and its current state will be recorded as the initial state