mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 19:46:21 +08:00
Merge branch 'master' of github.com:3b1b/manim into alt-calc
This commit is contained in:
@ -199,15 +199,6 @@ class Mobject(Container):
|
||||
)
|
||||
return self
|
||||
|
||||
def apply_function_to_position(self, function):
|
||||
self.move_to(function(self.get_center()))
|
||||
return self
|
||||
|
||||
def apply_function_to_submobject_positions(self, function):
|
||||
for submob in self.submobjects:
|
||||
submob.apply_function_to_position(function)
|
||||
return self
|
||||
|
||||
def apply_matrix(self, matrix, **kwargs):
|
||||
# Default to applying matrix about the origin, not mobjects center
|
||||
if len(kwargs) == 0:
|
||||
|
@ -7,49 +7,23 @@ from PIL import Image
|
||||
from constants import *
|
||||
|
||||
from mobject.mobject import Mobject
|
||||
from mobject.shape_matchers import SurroundingRectangle
|
||||
from utils.bezier import interpolate
|
||||
from utils.color import color_to_int_rgb
|
||||
from utils.config_ops import digest_config
|
||||
from utils.images import get_full_raster_image_path
|
||||
|
||||
|
||||
class AbstractImageMobject(Mobject):
|
||||
class ImageMobject(Mobject):
|
||||
"""
|
||||
Automatically filters out black pixels
|
||||
"""
|
||||
CONFIG = {
|
||||
"height": 2.0,
|
||||
"pixel_array_dtype": "uint8",
|
||||
}
|
||||
|
||||
def get_pixel_array(self):
|
||||
raise Exception("Not implemented")
|
||||
|
||||
def set_color(self):
|
||||
# Likely to be implemented in subclasses, but no obgligation
|
||||
pass
|
||||
|
||||
def init_points(self):
|
||||
# Corresponding corners of image are fixed to these 3 points
|
||||
self.points = np.array([
|
||||
UP + LEFT,
|
||||
UP + RIGHT,
|
||||
DOWN + LEFT,
|
||||
])
|
||||
self.center()
|
||||
h, w = self.get_pixel_array().shape[:2]
|
||||
self.stretch_to_fit_height(self.height)
|
||||
self.stretch_to_fit_width(self.height * w / h)
|
||||
|
||||
def copy(self):
|
||||
return self.deepcopy()
|
||||
|
||||
|
||||
class ImageMobject(AbstractImageMobject):
|
||||
CONFIG = {
|
||||
"filter_color": "black",
|
||||
"invert": False,
|
||||
# "use_cache" : True,
|
||||
"height": 2.0,
|
||||
"image_mode": "RGBA",
|
||||
"pixel_array_dtype": "uint8",
|
||||
}
|
||||
|
||||
def __init__(self, filename_or_array, **kwargs):
|
||||
@ -63,7 +37,7 @@ class ImageMobject(AbstractImageMobject):
|
||||
self.change_to_rgba_array()
|
||||
if self.invert:
|
||||
self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3]
|
||||
AbstractImageMobject.__init__(self, **kwargs)
|
||||
Mobject.__init__(self, **kwargs)
|
||||
|
||||
def change_to_rgba_array(self):
|
||||
pa = self.pixel_array
|
||||
@ -79,9 +53,6 @@ class ImageMobject(AbstractImageMobject):
|
||||
pa = np.append(pa, alphas, axis=2)
|
||||
self.pixel_array = pa
|
||||
|
||||
def get_pixel_array(self):
|
||||
return self.pixel_array
|
||||
|
||||
def set_color(self, color, alpha=None, family=True):
|
||||
rgb = color_to_int_rgb(color)
|
||||
self.pixel_array[:, :, :3] = rgb
|
||||
@ -92,6 +63,19 @@ class ImageMobject(AbstractImageMobject):
|
||||
self.color = color
|
||||
return self
|
||||
|
||||
def init_points(self):
|
||||
# Corresponding corners of image are fixed to these
|
||||
# Three points
|
||||
self.points = np.array([
|
||||
UP + LEFT,
|
||||
UP + RIGHT,
|
||||
DOWN + LEFT,
|
||||
])
|
||||
self.center()
|
||||
h, w = self.pixel_array.shape[:2]
|
||||
self.stretch_to_fit_height(self.height)
|
||||
self.stretch_to_fit_width(self.height * w / h)
|
||||
|
||||
def set_opacity(self, alpha):
|
||||
self.pixel_array[:, :, 3] = int(255 * alpha)
|
||||
return self
|
||||
@ -106,30 +90,5 @@ class ImageMobject(AbstractImageMobject):
|
||||
mobject1.pixel_array, mobject2.pixel_array, alpha
|
||||
).astype(self.pixel_array_dtype)
|
||||
|
||||
# TODO, add the ability to have the dimensions/orientation of this
|
||||
# mobject more strongly tied to the frame of the camera it contains,
|
||||
# in the case where that's a MovingCamera
|
||||
|
||||
|
||||
class ImageMobjectFromCamera(AbstractImageMobject):
|
||||
CONFIG = {
|
||||
"default_display_frame_config": {
|
||||
"stroke_width": 3,
|
||||
"stroke_color": WHITE,
|
||||
"buff": 0,
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, camera, **kwargs):
|
||||
self.camera = camera
|
||||
AbstractImageMobject.__init__(self, **kwargs)
|
||||
|
||||
def get_pixel_array(self):
|
||||
return self.camera.get_pixel_array()
|
||||
|
||||
def add_display_frame(self, **kwargs):
|
||||
config = dict(self.default_display_frame_config)
|
||||
config.update(kwargs)
|
||||
self.display_frame = SurroundingRectangle(self, **config)
|
||||
self.add(self.display_frame)
|
||||
return self
|
||||
def copy(self):
|
||||
return self.deepcopy()
|
||||
|
Reference in New Issue
Block a user