timeline¶
- class janim.anims.timeline.Timeline(*args, **kwargs)¶
基类:
object继承该类并实现
construct()方法,以实现动画的构建逻辑调用
build()可以得到构建完成的动画对象- CONFIG: Config | None = None¶
在子类中定义该变量可以起到设置配置的作用,例如:
class Example(Timeline): CONFIG = Config( font=['Consolas', 'LXGW WenKai Lite'] ) def construct(self) -> None: ...
另见:
Config
- ctx_var: ContextVar = <ContextVar name='Timeline.ctx_var' default=None>¶
- static get_context(raise_exc=True) Timeline | None¶
调用该方法可以得到当前正在构建的
Timeline对象如果在
construct()方法外调用,且raise_exc=True(默认),则抛出TimelineLookupError
- class TimeOfCode(time: float, line: int)¶
基类:
object标记
construct()执行到的代码行数所对应的时间- time: float¶
- line: int¶
- class ScheduledTask(at: float, func: Callable, args: list, kwargs: dict)¶
基类:
object另见
schedule()- at: float¶
- func: Callable¶
- args: list¶
- kwargs: dict¶
- class PlayAudioInfo(audio: Audio, range: TimeRange, clip_range: TimeRange)¶
基类:
object调用
play_audio()的参数信息
- class SubtitleInfo(text: str, range: TimeRange, kwargs: dict, subtitle: Text)¶
基类:
object调用
subtitle()的参数信息- text: str¶
- kwargs: dict¶
- class PausePoint(at: 'float', at_previous_frame: 'bool')¶
基类:
object- at: float¶
- at_previous_frame: bool¶
- class ItemHistory¶
基类:
object
- abstractmethod construct() None¶
继承该方法以实现动画的构建逻辑
- build(*, quiet=False, hide_subtitles=False) TimelineAnim¶
构建动画并返回
- schedule(at: float, func: Callable, *args, **kwargs) None¶
计划执行
会在进度达到
at时,对func进行调用, 可传入*args和**kwargs
- timeout(delay: float, func: Callable, *args, **kwargs) None¶
相当于 schedule(self.current_time + delay, func, *args, **kwargs)
- forward(dt: float = 1, *, _detect_changes=True, _record_lineno=True) None¶
向前推进
dt秒
- forward_to(t: float, *, _detect_changes=True) None¶
向前推进到
t秒的时候
- pause_point(*, offset: float = 0, at_previous_frame: bool = True) None¶
标记在预览界面中,执行到当前时间点时会暂停
at_previous_frame控制是在前一帧暂停(默认)还是在当前帧暂停offset表示偏移多少秒,例如offset=2则是当前位置 2s 后在 GUI 界面中,可以使用
Ctrl+Z快速移动到前一个暂停点,Ctrl+C快速移动到后一个
- audio_and_subtitle(file_path: str, subtitle: str | Iterable[str], *, clip: tuple[float, float] | None | EllipsisType = Ellipsis, delay: float = 0, mul: float | Iterable[float] | None = None, **subtitle_kwargs) TimeRange¶
播放音频,并在对应的区间显示字幕
如果
clip=...(默认,省略号),则表示自动确定裁剪区间,将前后的空白去除(可以传入clip=None禁用自动裁剪)如果
mul不是None,则会将音频振幅乘以该值
- play_audio(audio: Audio, *, delay: float = 0, begin: float = 0, end: float = -1, clip: tuple[float, float] | None = None) TimeRange¶
在当前位置播放音频
可以指定
begin和end表示裁剪区段可以指定在当前位置往后
delay秒才开始播放若指定
clip,则会覆盖begin和end(可以将clip视为这二者的简写)
返回值表示播放的时间段
- has_audio() bool¶
是否有可以播放的音频
- get_audio_samples_of_frame(fps: float, framerate: int, frame: int, *, count: int = 1) ndarray¶
提取特定帧的音频流
- subtitle(text: str | Iterable[str], duration: float = 1, delay: float = 0, scale: float | Iterable[float] = 0.8, use_typst_text: bool | Iterable[bool] = False, surrounding_color: JAnimColor = BLACK, surrounding_alpha: float = 0.5, font: str | Iterable[str] = [], depth: float = -100000.0, **kwargs) TimeRange¶
- subtitle(text: str | Iterable[str], range: TimeRange, **kwargs) TimeRange
添加字幕
文字可以传入一个列表,纵向排列显示
可以指定在当前位置往后
delay秒才显示duration表示持续时间scale表示对文字的缩放,默认为0.8,可以传入列表表示对各个文字的缩放use_typst_text表示是否使用TypstText,可以传入列表表示各个文字是否使用
返回值表示显示的时间段
- place_subtitle(subtitle: Text | TypstText, range: TimeRange) None¶
被
subtitle()调用以将字幕放置到合适的位置:对于同一批添加的字幕
[a, b],则a放在b的上面如果在上文所述的
[a, b]仍存在时,又加入了一个c,则c放在最上面
- has_subtitle() bool¶
- track_item_and_descendants(item: Item, *, root_only: bool = False) None¶
相当于对
item及其所有的后代物件调用track()
- detect_changes_of_all() None¶
检查所有物件是否有产生变化并记录
- detect_changes(items: Iterable[Item], *, as_time: float | None = None) None¶
检查指定的列表中的物件是否有产生变化并记录(仅检查自身而不包括子物件的)
- register_dynamic(item: Item, dynamic: DynamicItem, static: Item | None, begin: float, end: float, static_replaceable: bool) None¶
- get_construct_lineno() int | None¶
得到当前在
construct()中执行到的行数
- get_lineno_at_time(time: float)¶
根据
time得到对应执行到的行数
- static fmt_time(t: float) str¶
- dbg_time(ext_msg: str = '') None¶
- class janim.anims.timeline.SourceTimeline(*args, **kwargs)¶
基类:
Timeline与
Timeline相比,会在背景显示源代码- build(*, quiet=False, hide_subtitles=False) TimelineAnim¶
构建动画并返回
- class janim.anims.timeline.TimelineAnim(timeline: Timeline, **kwargs)¶
基类:
AnimGroup运行
Timeline.build()后返回的动画组self.display_anim是由Timeline.construct()中执行Timeline.show()和Timeline.hide()而产生的self.user_anim是显式使用了Timeline.prepare()或Timeline.play()而产生的
- property cfg: Config | ConfigGetter¶
- current_camera_info() CameraInfo¶
- anim_on(local_t: float) None¶
将
local_t换算为alpha并调用anim_on_alpha()
- render_all(ctx: Context) None¶
调用所有的
RenderCall进行渲染
- capture_ctx: mgl.Context | None = None¶
- capture_fbo: mgl.Framebuffer | None = None¶
- capture() Image¶