diff --git a/manimlib/config.py b/manimlib/config.py index 5c796c6777..de13d9cbdd 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -13,7 +13,6 @@ from manimlib.logger import log from manimlib.utils.dict_ops import merge_dicts_recursively from manimlib.utils.init_config import init_customization -from manimlib.constants import FRAME_HEIGHT from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -476,7 +475,7 @@ def get_camera_config(args: Namespace, custom_config: dict) -> dict: "pixel_width": width, "pixel_height": height, "frame_config": { - "frame_shape": ((width / height) * FRAME_HEIGHT, FRAME_HEIGHT), + "frame_shape": ((width / height) * get_frame_height(), get_frame_height()), }, "fps": fps, }) @@ -523,3 +522,18 @@ def get_configuration(args: Namespace) -> dict: "embed_exception_mode": custom_config["embed_exception_mode"], "embed_error_sound": custom_config["embed_error_sound"], } + +def get_frame_height(): + return 8.0 + +def get_aspect_ratio(): + cam_config = get_camera_config(parse_cli(), get_custom_config()) + return cam_config['pixel_width'] / cam_config['pixel_height'] + +def get_default_pixel_width(): + cam_config = get_camera_config(parse_cli(), get_custom_config()) + return cam_config['pixel_width'] + +def get_default_pixel_height(): + cam_config = get_camera_config(parse_cli(), get_custom_config()) + return cam_config['pixel_height'] \ No newline at end of file diff --git a/manimlib/constants.py b/manimlib/constants.py index ac0345ec6d..e883173a9f 100644 --- a/manimlib/constants.py +++ b/manimlib/constants.py @@ -1,6 +1,8 @@ from __future__ import annotations import numpy as np +from manimlib.config import get_aspect_ratio,get_default_pixel_width,get_default_pixel_height,get_frame_height + from typing import TYPE_CHECKING if TYPE_CHECKING: from typing import List @@ -8,15 +10,15 @@ # Sizes relevant to default camera frame -ASPECT_RATIO: float = 16.0 / 9.0 -FRAME_HEIGHT: float = 8.0 +ASPECT_RATIO: float = get_aspect_ratio() +FRAME_HEIGHT: float = get_frame_height() FRAME_WIDTH: float = FRAME_HEIGHT * ASPECT_RATIO FRAME_SHAPE: tuple[float, float] = (FRAME_WIDTH, FRAME_HEIGHT) FRAME_Y_RADIUS: float = FRAME_HEIGHT / 2 FRAME_X_RADIUS: float = FRAME_WIDTH / 2 -DEFAULT_PIXEL_HEIGHT: int = 1080 -DEFAULT_PIXEL_WIDTH: int = 1920 +DEFAULT_PIXEL_HEIGHT: int = get_default_pixel_height() +DEFAULT_PIXEL_WIDTH: int = get_default_pixel_width() DEFAULT_FPS: int = 30 SMALL_BUFF: float = 0.1 diff --git a/manimlib/utils/shaders.py b/manimlib/utils/shaders.py index bb950119e2..69963d0890 100644 --- a/manimlib/utils/shaders.py +++ b/manimlib/utils/shaders.py @@ -7,6 +7,9 @@ from PIL import Image import numpy as np +from manimlib.config import parse_cli +from manimlib.config import get_configuration +from manimlib.constants import ASPECT_RATIO from manimlib.utils.directories import get_shader_dir from manimlib.utils.file_ops import find_file @@ -95,6 +98,8 @@ def get_shader_code_from_file(filename: str) -> str | None: with open(filepath, "r") as f: result = f.read() + + result = re.sub(r"\s+ASPECT_RATIO\s+=\s+[\s0-9/.]+", f" ASPECT_RATIO = {ASPECT_RATIO}", result) # To share functionality between shaders, some functions are read in # from other files an inserted into the relevant strings before