Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix aspect_ratio other than 16:9 issue #2056

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions manimlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -473,7 +472,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,
})
Expand Down Expand Up @@ -520,3 +519,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']
10 changes: 6 additions & 4 deletions manimlib/constants.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
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
from manimlib.typing import ManimColor, Vect3


# 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
Expand Down
3 changes: 3 additions & 0 deletions manimlib/utils/shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

Expand Down Expand Up @@ -112,6 +113,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
Expand Down