core¶
- class janim.timeline.core.ScheduledTask(global_t: float, func: Callable, args: tuple, kwargs: dict, early_invoked: bool = False)¶
Bases:
objectThe 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,argsandkwargswill be passed tofuncfor invocationSee 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:
objectAdditional rendering registered by some special animation classes
- func: RenderGroupFn¶
- class janim.timeline.core.TimeOfCode(time: float, line: int)¶
Bases:
objectMarks 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
timecorrespond to this line of code
- time: float¶
- line: int¶
- class janim.timeline.core.TimelineCore(*args, **kwargs)¶
Bases:
objectEncapsulates the core functionality of
Timeline. It is extended through inheritance from other classes to form theTimelineclass. For information about the extended functionality, see the documentation ofTimelineThis class only exists for the convenience of JAnim’s internal code organization and cannot be used independently. When using JAnim, simply use
TimelinedirectlyHint
All methods in this class can be used directly in
Timeline- forward(dt: float = 1, *, _detect_changes=True, _record_lineno=True)¶
Advance by
dtseconds
- 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
funcwhen the progress reachesglobal_t.*argsand**kwargscan 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 callingfunc
- 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 callingfunc
- 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
itemto be automatically checked for state changes and records those changes on eachforwardandplay
- track_item_and_descendants(item: Item, *, root_only: bool = False) None¶
Equivalent to calling
track()onitemand 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)
- hide_all() None¶
Hide all items currently displayed
- 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:
objectContains objects related to item display
self.stackis theAnimStackobjectself.visiblilityis a list that stores the time points when an item is shown or hiddenElements 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 8sThis recording method is the basis for the operation of
TimelineCore.is_visible(),TimelineCore.show(), andTimelineCore.hide()
self.rendererrepresents the renderer object being used
- is_visible_at(t: float) bool¶
Whether the item is visible at time
t
- class janim.timeline.core.ItemAppearances(time_aligner: TimeAligner)¶
Bases:
defaultdict[Item,ItemAppearance]Essentially, it is a
dictof{Item: ItemAppearance}However, if
keydoes not exist, anItemAppearancecorresponding to thekeyitem will be created automatically, and its current state will be recorded as the initial state