config¶
- janim.utils.config.optional_type_validator(type, typename: str)¶
- class janim.utils.config.Config(*, fps: int = None, preview_fps: int = None, anti_alias_width: float = None, frame_height: float = None, frame_width: float = None, pixel_height: int = None, pixel_width: int = None, background_color: Color = None, font: str | Iterable[str] = None, subtitle_font: str | Iterable[str] = None, audio_framerate: int = None, audio_channels: int = None, wnd_pos: str = None, wnd_monitor: int = None, typst_bin: str = None, typst_shared_preamble: str = None, typst_text_preamble: str = None, typst_math_preamble: str = None, ffmpeg_bin: str = None, ffprobe_bin: str = None, output_dir: str = None, temp_dir: str | Path = None, asset_dir: str | Path | list[str | Path] = None, client_search_port: int = None)¶
基类:
object配置
大部分的参数不作说明,稍微说明一下这些参数:
fps: 输出视频时的帧率preview_fps: 在预览窗口时的帧率在代码内设置
background_color时,不能使用background_color='#RRGGBB',应使用background_color=Color('#RRGGBB')output_dir以:开头时,表示相对于.py文件的路径,例如output_dir=':/videos'
设置配置¶
设置配置的三种方式:
在 Python 代码中,将配置写在时间轴类里
class YourTimeline(Timeline): CONFIG = Config( fps=120, preview_fps=30 ) def construct(self) -> None: ...
另见:
CONFIG使用命令行参数修改全局配置
janim write your_file.py YourTimeline -c fps 120 -c output_dir custom_dir
修改局部代码块的配置
class YourTimeline(Timeline): def construct(self): txt1 = Text('Using default font') with Config(font='Noto Serif CJK SC'): txt2 = Text('Using "Noto Serif CJK SC" font') txt3 = Text('Using default font again') group = Group(txt1, txt2, txt3).show() group.points.arrange(DOWN, aligned_edge=LEFT)
获取配置¶
使用
Config.get.xxx得到属性,例如:class YourTimeline(Timeline): def construct(self): print(Config.get.fps)
更多内容可以参考文档教程的 配置系统 页面
- fps: int¶
- preview_fps: int¶
- anti_alias_width: float¶
- frame_height: float¶
- frame_width: float¶
- pixel_height: int¶
- pixel_width: int¶
- background_color: Color¶
- font: str | Iterable[str]¶
- subtitle_font: str | Iterable[str]¶
- audio_framerate: int¶
- audio_channels: int¶
- wnd_pos: str¶
- wnd_monitor: int¶
- typst_bin: str¶
- typst_text_preamble: str¶
- typst_math_preamble: str¶
- ffmpeg_bin: str¶
- ffprobe_bin: str¶
- output_dir: str¶
- temp_dir: str | Path¶
- asset_dir: str | Path | list[str | Path]¶
- client_search_port: int¶
- janim.utils.config.is_power_plugged() bool¶
- janim.utils.config.default_config = Config(fps=60, preview_fps=60, anti_alias_width=0.015, frame_height=8.0, frame_width=14.222222222222221, pixel_height=1080, pixel_width=1920, background_color=<Color black>, font='Consolas', subtitle_font='', audio_framerate=44100, audio_channels=2, wnd_pos='OR', wnd_monitor=0, typst_bin='typst', typst_shared_preamble='', typst_text_preamble='', typst_math_preamble='', ffmpeg_bin='ffmpeg', ffprobe_bin='ffprobe', output_dir='videos', temp_dir='/tmp/janim', asset_dir='', client_search_port=40565)¶
默认配置
其中:
preview_fps在接入电源时是 60,未接入时是 30temp_dir由操作系统决定
- janim.utils.config.cli_config = Config(fps=None, preview_fps=None, anti_alias_width=None, frame_height=None, frame_width=None, pixel_height=None, pixel_width=None, background_color=None, font=None, subtitle_font=None, audio_framerate=None, audio_channels=None, wnd_pos=None, wnd_monitor=None, typst_bin=None, typst_shared_preamble=None, typst_text_preamble=None, typst_math_preamble=None, ffmpeg_bin=None, ffprobe_bin=None, output_dir=None, temp_dir=None, asset_dir=None, client_search_port=None)¶
命令行配置
会被命令行
--config参数自动修改
- class janim.utils.config.ConfigGetter(config_ctx: list[Config] | None = None)¶
基类:
object与配置数据相关联的数据的获取
请仍然使用
Config.get.xxx来获取定义在该类中的内容- property aspect_ratio: float¶
- property frame_x_radius: float¶
- property frame_y_radius: float¶
- property pixel_to_frame_ratio: float¶
- property default_pixel_to_frame_ratio: float¶
- property left_side: Vect¶
- property right_side: Vect¶
- property bottom: Vect¶
- property top: Vect¶
- formated_output_dir(relative_path: str) str¶
将
:/path/to/file转换为相对于relative_path的路径