Exemple #1
0
    def __init__(
        self,
        uv_surface: Surface,
        image_file: str,
        dark_image_file: str | None = None,
        **kwargs
    ):
        if not isinstance(uv_surface, Surface):
            raise Exception("uv_surface must be of type Surface")
        # Set texture information
        if dark_image_file is None:
            dark_image_file = image_file
            self.num_textures = 1
        else:
            self.num_textures = 2
        self.texture_paths = {
            "LightTexture": get_full_raster_image_path(image_file),
            "DarkTexture": get_full_raster_image_path(dark_image_file),
        }

        self.uv_surface = uv_surface
        self.uv_func = uv_surface.uv_func
        self.u_range: tuple[float, float] = uv_surface.u_range
        self.v_range: tuple[float, float] = uv_surface.v_range
        self.resolution: tuple[float, float] = uv_surface.resolution
        self.gloss: float = self.uv_surface.gloss
        super().__init__(**kwargs)
Exemple #2
0
 def __init__(self, filename, **kwargs):
     path = get_full_raster_image_path(filename)
     self.image = Image.open(path)
     self.pixel_array = np.array(self.image)
     self.texture_paths = {"Texture": path}
     super().__init__(**kwargs)
     self.change_to_rgba_array()
Exemple #3
0
 def __init__(self, filename_or_array, **kwargs):
     digest_config(self, kwargs)
     if isinstance(filename_or_array, str):
         path = get_full_raster_image_path(filename_or_array)
         image = Image.open(path).convert(self.image_mode)
         self.pixel_array = np.array(image)
     else:
         self.pixel_array = np.array(filename_or_array)
     self.change_to_rgba_array()
     if self.invert:
         self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3]
     AbstractImageMobject.__init__(self, **kwargs)
Exemple #4
0
 def __init__(self, filename_or_array, **kwargs):
     digest_config(self, kwargs)
     if isinstance(filename_or_array, str):
         path = get_full_raster_image_path(filename_or_array)
         image = Image.open(path).convert(self.image_mode)
         self.pixel_array = np.array(image)
     else:
         self.pixel_array = np.array(filename_or_array)
     self.change_to_rgba_array()
     if self.invert:
         self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3]
     AbstractImageMobject.__init__(self, **kwargs)
Exemple #5
0
    def get_background_array(self, file_name):
        if file_name in self.file_name_to_pixel_array_map:
            return self.file_name_to_pixel_array_map[file_name]
        full_path = get_full_raster_image_path(file_name)
        image = Image.open(full_path)
        back_array = np.array(image)

        pixel_array = self.pixel_array
        if not np.all(pixel_array.shape == back_array.shape):
            back_array = self.resize_background_array_to_match(
                back_array, pixel_array)

        self.file_name_to_pixel_array_map[file_name] = back_array
        return back_array
Exemple #6
0
    def get_background_array(self, file_name):
        if file_name in self.file_name_to_pixel_array_map:
            return self.file_name_to_pixel_array_map[file_name]
        full_path = get_full_raster_image_path(file_name)
        image = Image.open(full_path)
        back_array = np.array(image)

        pixel_array = self.pixel_array
        if not np.all(pixel_array.shape == back_array.shape):
            back_array = self.resize_background_array_to_match(
                back_array, pixel_array
            )

        self.file_name_to_pixel_array_map[file_name] = back_array
        return back_array
Exemple #7
0
 def init_background(self):
     height = self.get_pixel_height()
     width = self.get_pixel_width()
     if self.background_image is not None:
         path = get_full_raster_image_path(self.background_image)
         image = Image.open(path).convert(self.image_mode)
         # TODO, how to gracefully handle backgrounds
         # with different sizes?
         self.background = np.array(image)[:height, :width]
         self.background = self.background.astype(self.pixel_array_dtype)
     else:
         background_rgba = color_to_int_rgba(self.background_color,
                                             self.background_opacity)
         self.background = np.zeros((height, width, self.n_channels),
                                    dtype=self.pixel_array_dtype)
         self.background[:, :] = background_rgba
Exemple #8
0
    def __init__(self, filename_or_array, **kwargs):
        digest_config(self, kwargs)
        if isinstance(filename_or_array, str):
            try:
                path = get_full_raster_image_path(filename_or_array)
            except IOError:
                warnings.warn(
                    f"No image {filename_or_array}, falling back to default")
                path = os.path.join(FILE_DIR, "default_image.png")

            image = Image.open(path).convert(self.image_mode)
            self.pixel_array = np.array(image)
        else:
            self.pixel_array = np.array(filename_or_array)
        self.change_to_rgba_array()
        if self.invert:
            self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3]
        AbstractImageMobject.__init__(self, **kwargs)
Exemple #9
0
 def init_background(self):
     height = self.get_pixel_height()
     width = self.get_pixel_width()
     if self.background_image is not None:
         path = get_full_raster_image_path(self.background_image)
         image = Image.open(path).convert(self.image_mode)
         # TODO, how to gracefully handle backgrounds
         # with different sizes?
         self.background = np.array(image)[:height, :width]
         self.background = self.background.astype(self.pixel_array_dtype)
     else:
         background_rgba = color_to_int_rgba(
             self.background_color, self.background_opacity
         )
         self.background = np.zeros(
             (height, width, self.n_channels),
             dtype=self.pixel_array_dtype
         )
         self.background[:, :] = background_rgba
Exemple #10
0
 def __init__(self, filename: str, **kwargs):
     self.set_image_path(get_full_raster_image_path(filename))
     super().__init__(**kwargs)
Exemple #11
0
 def __init__(self, filename, **kwargs):
     path = get_full_raster_image_path(filename)
     self.image = Image.open(path)
     self.texture_path = path
     Mobject.__init__(self, **kwargs)
 def __init__(self, filename, **kwargs):
     path = get_full_raster_image_path(filename)
     self.image = Image.open(path)
     self.texture_paths = {"Texture": path}
     super().__init__(**kwargs)