timeline¶
- class janim.timeline.timeline.Timeline(*args, **kwargs)¶
Bases:
PausePointsMixin,AudiosAndSubtitlesMixin,DebugMixin,TimelineCoreInherit this class and implement the
construct()method to implement the logic of building animationsCall
build()to get the constructedTimelineobject
This class implements its functionality through several base classes. You can refer to the following categories to find the corresponding documentation:
Core functionality:
TimelineCore“Pause points” functionality:
PausePointsMixinFor audio and subtitles, refer to:
Audio functionality:
AudiosMixinSubtitle functionality:
SubtitlesMixinCombination of both:
AudiosAndSubtitlesMixin
Special debugging functionality (not fully polished, use with caution):
DebugMixin
- abstractmethod construct() None¶
Implement this method to build the animation logic
- build_indent_ctx: ContextVar[int] = <ContextVar name='Timeline.build_indent_ctx'>¶
- build(*, quiet=False, hide_subtitles=False, show_debug_notice=False) BuiltTimeline¶
Build the animation and return it
- CONFIG: Config | None = None¶
Defining this variable in a subclass can serve to set configuration, for example:
class Example(Timeline): CONFIG = Config( font=['Consolas', 'LXGW WenKai Lite'] ) def construct(self) -> None: ...
For available configurations, see also
Config
- config_context()¶
The first
withcall occurs in thebuild()method, where the currentconfig_ctx_varcontext is merged with theCONFIGof itself and each of its parent classes to form this Timeline object’sself._config_contextFor subsequent
withcalls, the inner code block will restore the state ofself._config_contextto ensure consistency within the relevant context
- static get_context(raise_exc: Literal[True] = True) Timeline¶
- static get_context(raise_exc: Literal[False]) Timeline | None
Call this method to get the current
Timelineobject being constructingBy default, calling this method outside the
construct()method will raise aTimelineLookupErrorerror. This can be disabled by settingraise_exc=False; in the same situation, it will returnNoneinstead of raising an error- Parameters:
raise_exc – Whether to raise an error when unavailable
- class GuiCommand(global_t: float, text: str, frame: FrameType)¶
Bases:
object
- exception GuiCommandInterrupt(command: GuiCommand)¶
Bases:
Exception
- class janim.timeline.timeline.BuiltTimeline(timeline: Timeline)¶
Bases:
objectInstance returned after running
Timeline.build()- property cfg: Config | ConfigGetter¶
This property can be used to obtain the configuration from the context in which the Timeline was built
It can be used to avoid using
config_context()in simple scenarios, for example:built.cfg.preview_fps
- property frame_count: int¶
- get_audio_samples_of_frame(fps: int, framerate: int, frame: int, *, count: int = 1) ndarray¶
Extract the audio stream of a specific frame
- get_audio_samples_between(framerate: int, begin: float, end: float) ndarray¶
- current_camera_info(*, as_time: float | None = None) CameraInfo¶
Get the current
CameraInfoinformationHere, “current” means the
global_tmoment from the last call torender_all(); you can also specify it by passingas_time
- render_all(ctx: Context, global_t: float, *, camera: Camera | None = None) bool¶
Render all visible items
- capture(global_t: float, *, transparent: bool = True, ctx: Context | None = None) Image¶
- to_item(**kwargs) TimelineItem¶
Use this method to insert another Timeline into a Timeline
For example:
class Sub1(Timeline): def construct(self): text = Text('text from Sub1') text.points.shift(UP) self.play( Rotate(text, TAU, about_point=LEFT * 2), duration=4 ) class Sub2(Timeline): def construct(self): text = Text('text from Sub2') text.points.shift(DOWN) self.play( Rotate(text, TAU, about_point=RIGHT * 2), duration=4 ) class Test(Timeline): def construct(self): tl1 = Sub1().build().to_item().show() tl2 = Sub2().build().to_item().show() self.forward_to(tl2.end)
In this example,
Sub1andSub2are inserted intoTestAdditional parameters:
delay: How many seconds to delay before starting playback of this Timelinefirst_frame_duration: How many seconds the first frame lastskeep_last_frame: Whether to keep displaying the last frame after the Timeline ends
- to_playback_control_item(**kwargs) TimelinePlaybackControlItem¶
Use this method to insert another Timeline into a Timeline
And similar to
Video, you can usestart,stop, andseekto control playback progressExample:
class Sub(Timeline): def construct(self): self.play( ItemUpdater( None, lambda p: Text(f'{p.global_t:.2f}') ), duration=8 ) class Test(Timeline): def construct(self): sub = Sub().build().to_playback_control_item().show() sub.start() self.forward(2) sub.start(speed=0.1) self.forward(2) sub.seek(0).start(speed=4) self.forward(2)
Warning
By default, playback is not started; you need to use
startto begin playbackAdditional parameters:
keep_last_frame: Whether to keep displaying the last frame after the Timeline ends
- class janim.timeline.timeline.TimelineItem(built: BuiltTimeline, *, delay: float = 0, first_frame_duration: float = 0, keep_last_frame: bool = False, **kwargs)¶
Bases:
ItemSee
BuiltTimeline.to_item()for details- class TIRenderer¶
Bases:
Renderer- render(item: TimelineItem)¶
- renderer_cls¶
alias of
TIRenderer
- start() Self¶
Start playing the sub-timeline from the current moment, keeping the first frame displayed before this moment
- property end: float¶
- class janim.timeline.timeline.PlaybackControl(*args, loop: bool = False, **kwargs)¶
Bases:
object- start(*, speed: int = 1) Self¶
- stop() Self¶
- seek(t: float) Self¶
- compute_time(t: float, total: float | None = None) float¶
- class janim.timeline.timeline.TimelinePlaybackControlItem(built: BuiltTimeline, *, keep_last_frame: bool = False, **kwargs)¶
Bases:
PlaybackControl,ItemSee
BuiltTimeline.to_playback_control_item()for details- class TPCIRenderer¶
Bases:
Renderer- render(item: TimelinePlaybackControlItem)¶
- renderer_cls¶
alias of
TPCIRenderer