def capture_mobjects(self, mobjects, **kwargs): self.update_sub_cameras() for imfc in self.image_mobjects_from_cameras: to_add = list(mobjects) if not self.allow_cameras_to_capture_their_own_display: to_add = list_difference_update(to_add, imfc.get_family()) imfc.camera.capture_mobjects(to_add, **kwargs) MovingCamera.capture_mobjects(self, mobjects, **kwargs)
def capture_mobjects(self, mobjects, **kwargs): self.update_sub_cameras() for imfc in self.image_mobjects_from_cameras: to_add = list(mobjects) if not self.allow_cameras_to_capture_their_own_display: to_add = list_difference_update( to_add, imfc.submobject_family() ) imfc.camera.capture_mobjects(to_add, **kwargs) MovingCamera.capture_mobjects(self, mobjects, **kwargs)
def __init__(self, *args, **kwargs): MovingCamera.__init__(self, *args, **kwargs) self.unit_sun_vect = self.sun_vect / np.linalg.norm(self.sun_vect) # rotation_mobject lives in the phi-theta-distance space # TODO, use ValueTracker for this instead self.rotation_mobject = VectorizedPoint() # Moving_center lives in the x-y-z space # It representes the center of rotation self.moving_center = VectorizedPoint(self.frame_center) self.set_position(self.phi, self.theta, self.distance)
def setup_zoomed_camera(self): self.little_rectangle = self.big_rectangle.copy() self.little_rectangle.scale(1. / self.zoom_factor) self.little_rectangle.move_to(self.little_rectangle_start_position) self.zoomed_camera = MovingCamera( self.little_rectangle, pixel_shape=self.zoomed_canvas_pixel_shape, background=self.zoomed_camera_background) self.add(self.little_rectangle) #TODO, is there a better way to hanld this? self.zoomed_camera.adjusted_thickness = lambda x: x
def setup(self): self.camera_frame = ScreenRectangle(height = FRAME_HEIGHT) self.camera_frame.set_stroke(width = 0) self.camera = MovingCamera( self.camera_frame, **self.camera_config ) return self
def display_multiple_vectorized_mobjects(self, vmobjects, pixel_array): # camera_point = self.spherical_coords_to_point( # *self.get_spherical_coords() # ) def z_key(vmob): # Assign a number to a three dimensional mobjects # based on how close it is to the camera three_d_status = should_shade_in_3d(vmob) has_points = vmob.get_num_points() > 0 if three_d_status and has_points: return vmob.get_center()[2] else: return 0 MovingCamera.display_multiple_vectorized_mobjects( self, sorted(vmobjects, key=z_key), pixel_array)
def setup(self): MovingCameraScene.setup(self) # Initialize camera and display zoomed_camera = MovingCamera(**self.zoomed_camera_config) zoomed_display = ImageMobjectFromCamera( zoomed_camera, **self.zoomed_camera_image_mobject_config) zoomed_display.add_display_frame() for mob in zoomed_camera.frame, zoomed_display: mob.stretch_to_fit_height(self.zoomed_display_height) mob.stretch_to_fit_width(self.zoomed_display_width) zoomed_camera.frame.scale(self.zoom_factor) # Position camera and display zoomed_camera.frame.move_to(self.zoomed_camera_frame_starting_position) if self.zoomed_display_center is not None: zoomed_display.move_to(self.zoomed_display_center) else: zoomed_display.to_corner(self.zoomed_display_corner, buff=self.zoomed_display_corner_buff) self.zoomed_camera = zoomed_camera self.zoomed_display = zoomed_display
def reset(self): for imfc in self.image_mobjects_from_cameras: imfc.camera.reset() MovingCamera.reset(self) return self
def __init__(self, *image_mobjects_from_cameras, **kwargs): self.image_mobjects_from_cameras = [] for imfc in image_mobjects_from_cameras: self.add_image_mobject_from_camera(imfc) MovingCamera.__init__(self, **kwargs)
class ZoomedScene(Scene): """ Move around self.little_rectangle to determine which part of the screen is zoomed in on. """ CONFIG = { "zoomed_canvas_frame_shape": (3, 3), "zoomed_canvas_center": None, "zoomed_canvas_corner": UP + RIGHT, "zoomed_canvas_corner_buff": DEFAULT_MOBJECT_TO_EDGE_BUFFER, "zoomed_camera_background": None, "little_rectangle_start_position": ORIGIN, "zoom_factor": 6, "square_color": WHITE, "zoom_activated": False, } def activate_zooming(self): self.generate_big_rectangle() self.setup_zoomed_canvas() self.setup_zoomed_camera() self.zoom_activated = True def animate_activate_zooming(self): self.activate_zooming() self.play(*map(FadeIn, [self.little_rectangle, self.big_rectangle])) def disactivate_zooming(self): self.remove(self.big_rectangle, self.little_rectangle) self.zoom_activated = False def get_zoomed_camera_mobject(self): return self.little_rectangle def get_zoomed_screen(self): return self.big_rectangle def generate_big_rectangle(self): height, width = self.zoomed_canvas_frame_shape self.big_rectangle = Rectangle(height=height, width=width, color=self.square_color) if self.zoomed_canvas_center is not None: self.big_rectangle.shift(self.zoomed_canvas_center) elif self.zoomed_canvas_corner is not None: self.big_rectangle.to_corner(self.zoomed_canvas_corner, buff=self.zoomed_canvas_corner_buff) self.add(self.big_rectangle) def setup_zoomed_canvas(self): upper_left = self.big_rectangle.get_corner(UP + LEFT) lower_right = self.big_rectangle.get_corner(DOWN + RIGHT) pixel_coords = self.camera.points_to_pixel_coords( np.array([upper_left, lower_right])) self.zoomed_canvas_pixel_indices = pixel_coords (up, left), (down, right) = pixel_coords self.zoomed_canvas_pixel_shape = ( right - left, down - up, ) def setup_zoomed_camera(self): self.little_rectangle = self.big_rectangle.copy() self.little_rectangle.scale(1. / self.zoom_factor) self.little_rectangle.move_to(self.little_rectangle_start_position) self.zoomed_camera = MovingCamera( self.little_rectangle, pixel_shape=self.zoomed_canvas_pixel_shape, background=self.zoomed_camera_background) self.add(self.little_rectangle) #TODO, is there a better way to hanld this? self.zoomed_camera.adjusted_thickness = lambda x: x def get_frame(self): frame = Scene.get_frame(self) if self.zoom_activated: (up, left), (down, right) = self.zoomed_canvas_pixel_indices frame[left:right, up:down, :] = self.zoomed_camera.get_image() return frame def set_camera_pixel_array(self, pixel_array): self.camera.set_pixel_array(pixel_array) if self.zoom_activated: (up, left), (down, right) = self.zoomed_canvas_pixel_indices self.zoomed_camera.set_pixel_array(pixel_array[left:right, up:down]) def set_camera_background(self, background): self.set_camera_pixel_array(self, background) #TODO, check this... def reset_camera(self): self.camera.reset() if self.zoom_activated: self.zoomed_camera.reset() def capture_mobjects_in_camera(self, mobjects, **kwargs): self.camera.capture_mobjects(mobjects, **kwargs) if self.zoom_activated: if self.big_rectangle in mobjects: mobjects = list(mobjects) mobjects.remove(self.big_rectangle) self.zoomed_camera.capture_mobjects(mobjects, **kwargs) def get_moving_mobjects(self, *animations): moving_mobjects = Scene.get_moving_mobjects(self, *animations) if self.zoom_activated and self.little_rectangle in moving_mobjects: # When the camera is moving, so is everything, return self.mobjects else: return moving_mobjects