timeline¶
- class janim.timeline.timeline.Timeline(*args, **kwargs)¶
基类:
PausePointsMixin,AudiosAndSubtitlesMixin,DebugMixin,TimelineCore继承该类并实现
construct()方法,以实现动画的构建逻辑调用
build()可以得到构建完成的Timeline对象
该类由若干基类实现功能,你可按照以下的分类跳转以参考对应的文档:
核心功能:
TimelineCore“暂停点”功能:
PausePointsMixin对于音频与字幕,可参考:
音频功能:
AudiosMixin字幕功能:
SubtitlesMixin对二者的结合:
AudiosAndSubtitlesMixin
特殊的调试功能(但不太完善,慎用):
DebugMixin
- abstractmethod construct() None¶
继承该方法以实现动画的构建逻辑
- build(*, quiet=False, hide_subtitles=False, show_debug_notice=False) BuiltTimeline¶
构建动画并返回
- CONFIG: Config | None = None¶
在子类中定义该变量可以起到设置配置的作用,例如:
class Example(Timeline): CONFIG = Config( font=['Consolas', 'LXGW WenKai Lite'] ) def construct(self) -> None: ...
关于可使用的配置,另见
Config
- config_context()¶
在
build()方法中会发生第一次with调用, 将当前的config_ctx_var上下文,与自己及各个父类的CONFIG, 合并为该 Timeline 对象的self._config_context如果是之后的
with调用,则会让内部代码块恢复self._config_context的状态, 用于保证在相关上下文中的一致性
- static get_context(raise_exc: Literal[True] = True) Timeline¶
- static get_context(raise_exc: Literal[False]) Timeline | None
调用该方法可以得到当前正在构建的
Timeline对象默认情况下,在
construct()方法外调用时,会抛出TimelineLookupError错误; 可以使用raise_exc=False禁用,在同样的情况下会返回None而非抛出错误- 参数:
raise_exc -- 在不可用时,是否抛出错误
- class GuiCommand(global_t: float, text: str, frame: FrameType)¶
基类:
object
- exception GuiCommandInterrupt(command: GuiCommand)¶
基类:
Exception
- class janim.timeline.timeline.BuiltTimeline(timeline: Timeline)¶
基类:
object运行
Timeline.build()后返回的实例- property cfg: Config | ConfigGetter¶
可以使用该属性获取 Timeline 构建时的上下文中的配置
可用于在简单场景中避免使用
config_context(),例如:built.cfg.preview_fps
- property frame_count: int¶
- get_audio_samples_of_frame(fps: int, framerate: int, frame: int, *, count: int = 1) ndarray¶
提取特定帧的音频流
- get_audio_samples_between(framerate: int, begin: float, end: float) ndarray¶
- current_camera_info(*, as_time: float | None = None) CameraInfo¶
得到当前的
CameraInfo信息这里“当前”的含义是,上次调用
render_all()的global_t时刻;或者也可以传入as_time指定
- capture(global_t: float, *, transparent: bool = True, ctx: Context | None = None) Image¶
- to_item(**kwargs) TimelineItem¶
使用该方法可以在一个 Timeline 中插入另一个 Timeline
例如:
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)
这个例子中,在
Test中插入了Sub1和Sub2额外参数:
delay: 延迟多少秒开始该 Timeline 的播放first_frame_duration: 第一帧持续多少秒keep_last_frame: 是否在 Timeline 结束后仍然保留最后一帧的显示
- to_playback_control_item(**kwargs) TimelinePlaybackControlItem¶
使用该方法可以在一个 Timeline 中插入另一个 Timeline
并且与
Video类似,可以使用start、stop以及seek控制播放进度例:
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)
警告
在默认情况下未开始播放,需要使用
start以开始播放额外参数:
keep_last_frame: 是否在 Timeline 结束后仍然保留最后一帧的显示
- class janim.timeline.timeline.TimelineItem(built: BuiltTimeline, *, delay: float = 0, first_frame_duration: float = 0, keep_last_frame: bool = False, **kwargs)¶
基类:
Item- class TIRenderer¶
基类:
Renderer- render(item: TimelineItem)¶
- renderer_cls¶
TIRenderer的别名
- start() Self¶
从当前时刻开始播放子时间轴,在此时刻之前保持显示第一帧
- property end: float¶
- class janim.timeline.timeline.PlaybackControl(*args, loop: bool = False, **kwargs)¶
基类:
object- start(*, speed: float = 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)¶
基类:
PlaybackControl,Item详见
BuiltTimeline.to_playback_control_item()- class TPCIRenderer¶
基类:
Renderer- render(item: TimelinePlaybackControlItem)¶
- renderer_cls¶
TPCIRenderer的别名