From 3a65eb4d2cec652d8de653bf7a4a874c2c6876c8 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 15 Dec 2022 09:56:01 -0800 Subject: [PATCH] Kill CONFIG in ImageMobject --- manimlib/mobject/types/image_mobject.py | 42 ++++++++++++++----------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/manimlib/mobject/types/image_mobject.py b/manimlib/mobject/types/image_mobject.py index dd993319..b4900de9 100644 --- a/manimlib/mobject/types/image_mobject.py +++ b/manimlib/mobject/types/image_mobject.py @@ -9,27 +9,31 @@ from manimlib.utils.bezier import inverse_interpolate from manimlib.utils.images import get_full_raster_image_path from manimlib.utils.iterables import listify +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from typing import Sequence, Tuple + from manimlib.constants import ManimColor, np_vector + class ImageMobject(Mobject): - CONFIG = { - "height": 4, - "opacity": 1, - "shader_folder": "image", - "shader_dtype": [ - ('point', np.float32, (3,)), - ('im_coords', np.float32, (2,)), - ('opacity', np.float32, (1,)), - ] - } + shader_folder: str = "image" + shader_dtype: Sequence[Tuple[str, type, Tuple[int]]] = [ + ('point', np.float32, (3,)), + ('im_coords', np.float32, (2,)), + ('opacity', np.float32, (1,)), + ] - def __init__(self, filename: str, **kwargs): - self.set_image_path(get_full_raster_image_path(filename)) - super().__init__(**kwargs) - - def set_image_path(self, path: str) -> None: - self.path = path - self.image = Image.open(path) - self.texture_paths = {"Texture": path} + def __init__( + self, + filename: str, + height: float = 4.0, + **kwargs + ): + self.height = height + self.image_path = get_full_raster_image_path(filename) + self.image = Image.open(self.image_path) + super().__init__(texture_paths={"Texture": self.image_path}, **kwargs) def init_data(self) -> None: self.data = { @@ -51,7 +55,7 @@ class ImageMobject(Mobject): def set_color(self, color, opacity=None, recurse=None): return self - def point_to_rgb(self, point: np.ndarray) -> np.ndarray: + def point_to_rgb(self, point: np_vector) -> np_vector: x0, y0 = self.get_corner(UL)[:2] x1, y1 = self.get_corner(DR)[:2] x_alpha = inverse_interpolate(x0, x1, point[0])