A community-maintained Python framework for creating mathematical animations.
Changed camera implementation by renaming space_shape to frame_shape, where its height and width actually correspond to the camera's height and width
Grant Sanderson213c615870aa
diff --git a/camera/camera.py b/camera/camera.pyindex e459ebdae..bbd03e32d 100644--- a/camera/camera.py+++ b/camera/camera.py@@ -17,8 +17,8 @@ class Camera(object):CONFIG = {"background_image" : None,"pixel_shape" : (DEFAULT_HEIGHT, DEFAULT_WIDTH),- # Note: space_shape will be resized to match pixel_shape- "space_shape" : (FRAME_Y_RADIUS, FRAME_X_RADIUS),+ # Note: frame_shape will be resized to match pixel_shape+ "frame_shape" : (FRAME_HEIGHT, FRAME_WIDTH),"space_center" : ORIGIN,"background_color" : BLACK,#Points in vectorized mobjects with norm greater@@ -38,7 +38,7 @@ class Camera(object):digest_config(self, kwargs, locals())self.rgb_max_val = np.iinfo(self.pixel_array_dtype).maxself.init_background()- self.resize_space_shape()+ self.resize_frame_shape()self.reset()def __deepcopy__(self, memo):@@ -48,20 +48,20 @@ class Camera(object):self.canvas = Nonereturn copy.copy(self)- def resize_space_shape(self, fixed_dimension = 0):+ def resize_frame_shape(self, fixed_dimension = 0):"""- Changes space_shape to match the aspect ratio+ Changes frame_shape to match the aspect ratioof pixel_shape, where fixed_dimension determines- whether space_shape[0] (height) or space_shape[1] (width)+ whether frame_shape[0] (height) or frame_shape[1] (width)remains fixed while the other changes accordingly."""aspect_ratio = float(self.pixel_shape[1])/self.pixel_shape[0]- space_x_radius, space_y_radius = self.space_shape+ frame_width, frame_height = self.frame_shapeif fixed_dimension == 0:- space_y_radius = aspect_ratio*space_x_radius+ frame_height = aspect_ratio*frame_widthelse:- space_x_radius = space_y_radius/aspect_ratio- self.space_shape = (space_x_radius, space_y_radius)+ frame_width = frame_height/aspect_ratio+ self.frame_shape = (frame_width, frame_height)def init_background(self):if self.background_image is not None:@@ -470,10 +470,10 @@ class Camera(object):def points_to_pixel_coords(self, points):result = np.zeros((len(points), 2))ph, pw = self.pixel_shape- sh, sw = self.space_shape- width_mult = pw/sw/2+ sh, sw = self.frame_shape+ width_mult = pw/swwidth_add = pw/2- height_mult = ph/sh/2+ height_mult = ph/shheight_add = ph/2#Flip on y-axis as you goheight_mult *= -1@@ -510,7 +510,7 @@ class Camera(object):def get_coords_of_all_pixels(self):# These are in x, y order, to help me keep things straight- full_space_dims = np.array(self.space_shape)[::-1] * 2+ full_space_dims = np.array(self.frame_shape)[::-1]full_pixel_dims = np.array(self.pixel_shape)[::-1]# These are addressed in the same y, x order as in pixel_array, but the values in them@@ -520,7 +520,7 @@ class Camera(object):uncentered_pixel_coords * full_space_dims,full_pixel_dims)# Could structure above line's computation slightly differently, but figured (without much- # thought) multiplying by space_shape first, THEN dividing by pixel_shape, is probably+ # thought) multiplying by frame_shape first, THEN dividing by pixel_shape, is probably# better than the other order, for avoiding underflow quantization in the division (whereas# overflow is unlikely to be a problem)@@ -614,18 +614,16 @@ class MovingCamera(Camera):def capture_mobjects(self, *args, **kwargs):self.space_center = self.mobject.get_center()- self.realign_space_shape()+ self.realign_frame_shape()Camera.capture_mobjects(self, *args, **kwargs)- def realign_space_shape(self):- height, width = self.space_shape+ def realign_frame_shape(self):+ height, width = self.frame_shapeif self.aligned_dimension == "height":- self.space_shape = (self.mobject.get_height()/2, width)+ self.frame_shape = (self.mobject.get_height(), width)else:- self.space_shape = (height, self.mobject.get_width()/2)- self.resize_space_shape(- 0 if self.aligned_dimension == "height" else 1- )+ self.frame_shape = (height, self.mobject.get_width())+ self.resize_frame_shape(0 if self.aligned_dimension == "height" else 1)# TODO: Add an attribute to mobjects under which they can specify that they should just# map their centers but remain otherwise undistorted (useful for labels, etc.)@@ -720,7 +718,7 @@ class SplitScreenCamera(MultiCamera):for camera in [self.left_camera, self.right_camera]:camera.pixel_shape = (self.pixel_shape[0], half_width) # TODO: Round up on one if width is oddcamera.init_background()- camera.resize_space_shape()+ camera.resize_frame_shape()camera.reset()MultiCamera.__init__(self, (left_camera, (0, 0)), (right_camera, (0, half_width)))diff --git a/old_projects/basel/basel.py b/old_projects/basel/basel.pyindex a255da13a..370655970 100644--- a/old_projects/basel/basel.py+++ b/old_projects/basel/basel.py@@ -2078,7 +2078,7 @@ class IPTScene1(PiCreatureScene):# use the following for the zoomed insetif show_detail:- self.camera.space_shape = (0.02 * FRAME_Y_RADIUS, 0.02 * FRAME_X_RADIUS)+ self.camera.frame_shape = (0.02 * FRAME_HEIGHT, 0.02 * FRAME_WIDTH)self.camera.space_center = CSCREEN_SCALE = 0.01SCREEN_THICKNESS = 0.02diff --git a/old_projects/brachistochrone/graveyard.py b/old_projects/brachistochrone/graveyard.pyindex ba464eff8..7a4d58db3 100644--- a/old_projects/brachistochrone/graveyard.py+++ b/old_projects/brachistochrone/graveyard.py@@ -30,7 +30,7 @@ class MultilayeredGlass(PhotonScene, ZoomedScene):"num_variables" : 3,"top_color" : BLUE_E,"bottom_color" : BLUE_A,- "zoomed_canvas_space_shape" : (5, 5),+ "zoomed_canvas_frame_shape" : (5, 5),"square_color" : GREEN_B,}def construct(self):diff --git a/old_projects/eoc/chapter3.py b/old_projects/eoc/chapter3.pyindex d7c8bcaea..8c784864a 100644--- a/old_projects/eoc/chapter3.py+++ b/old_projects/eoc/chapter3.py@@ -246,7 +246,7 @@ class DerivativeOfXSquaredAsGraph(GraphScene, ZoomedScene, PiCreatureScene):"little_rect_nudge" : 0.5*(1.5*UP+RIGHT),"graph_origin" : 2.5*DOWN + LEFT,"zoomed_canvas_corner" : UP+LEFT,- "zoomed_canvas_space_shape" : (4, 4),+ "zoomed_canvas_frame_shape" : (4, 4),}def construct(self):self.draw_graph()@@ -2504,7 +2504,7 @@ class LookToFunctionsMeaning(TeacherStudentsScene):class DerivativeFromZoomingInOnSine(IntroduceUnitCircleWithSine, ZoomedScene):CONFIG = {"zoom_factor" : 10,- "zoomed_canvas_space_shape" : (3, 4.5),+ "zoomed_canvas_frame_shape" : (3, 4.5),"include_radial_line_dot" : False,"remove_angle_label" : False,"theta_label" : "",diff --git a/old_projects/eoc/chapter6.py b/old_projects/eoc/chapter6.pyindex d037055a8..cfb0f1206 100644--- a/old_projects/eoc/chapter6.py+++ b/old_projects/eoc/chapter6.py@@ -1418,7 +1418,7 @@ class CompareLadderAndCircle(PiCreatureScene, ThreeDScene):class TwoVariableFunctionAndDerivative(SlopeOfCircleExample):CONFIG = {"zoomed_canvas_corner" : DOWN+RIGHT,- "zoomed_canvas_space_shape" : (3, 4),+ "zoomed_canvas_frame_shape" : (3, 4),}def construct(self):self.setup_plane()@@ -1863,7 +1863,7 @@ class AlternateExample(ZoomedScene):"example_color" : MAROON_B,"zoom_factor" : 10,"zoomed_canvas_corner" : DOWN+RIGHT,- "zoomed_canvas_space_shape" : (3, 4),+ "zoomed_canvas_frame_shape" : (3, 4),}def construct(self):self.add_plane()diff --git a/old_projects/eoc/chapter7.py b/old_projects/eoc/chapter7.pyindex 076209f32..a37963bca 100644--- a/old_projects/eoc/chapter7.py+++ b/old_projects/eoc/chapter7.py@@ -1860,7 +1860,7 @@ class LHopitalExample(LimitCounterExample, PiCreatureScene, ZoomedScene, Reconfi"parabola_color" : YELLOW,"zoomed_canvas_corner" : DOWN+LEFT,"zoom_factor" : 10,- "zoomed_canvas_space_shape" : (5, 5),+ "zoomed_canvas_frame_shape" : (5, 5),"zoomed_canvas_corner_buff" : MED_SMALL_BUFF,"zoomed_rect_center_coords" : (1 + 0.1, -0.03),}diff --git a/old_projects/eoc/old_chapter1.py b/old_projects/eoc/old_chapter1.pyindex 75e7f20f1..d051963f3 100644--- a/old_projects/eoc/old_chapter1.py+++ b/old_projects/eoc/old_chapter1.py@@ -1399,7 +1399,7 @@ class NameDerivative(IntroduceTinyChangeInArea):class DerivativeAsTangentLine(ZoomedScene):CONFIG = {- "zoomed_canvas_space_shape" : (4, 4),+ "zoomed_canvas_frame_shape" : (4, 4),"zoom_factor" : 10,"R_min" : 0,"R_max" : 2.5,diff --git a/scene/zoomed_scene.py b/scene/zoomed_scene.pyindex f7d49e650..5c9ba588b 100644--- a/scene/zoomed_scene.py+++ b/scene/zoomed_scene.py@@ -14,7 +14,7 @@ class ZoomedScene(Scene):which part of the screen is zoomed in on."""CONFIG = {- "zoomed_canvas_space_shape" : (3, 3),+ "zoomed_canvas_frame_shape" : (3, 3),"zoomed_canvas_center" : None,"zoomed_canvas_corner" : UP+RIGHT,"zoomed_canvas_corner_buff" : DEFAULT_MOBJECT_TO_EDGE_BUFFER,@@ -47,7 +47,7 @@ class ZoomedScene(Scene):return self.big_rectangledef generate_big_rectangle(self):- height, width = self.zoomed_canvas_space_shape+ height, width = self.zoomed_canvas_frame_shapeself.big_rectangle = Rectangle(height = height,width = width,