A community-maintained Python framework for creating mathematical animations.
Fixed some camera bugs
Grant Sanderson22d889f6dc65
diff --git a/camera/camera.py b/camera/camera.pyindex 16e687faf..2251cfb0c 100644--- a/camera/camera.py+++ b/camera/camera.py@@ -57,6 +57,7 @@ class Camera(object):def __init__(self, background=None, **kwargs):digest_config(self, kwargs, locals())self.rgb_max_val = np.iinfo(self.pixel_array_dtype).max+ self.cairo_context = None # For vectorized renderingself.init_background()self.resize_frame_shape()self.reset()@@ -162,6 +163,7 @@ class Camera(object):pixel_array, convert_from_floats)if not (hasattr(self, "pixel_array") and self.pixel_array.shape == converted_array.shape):self.pixel_array = converted_array+ self.cairo_context = Noneelse:# Set in placeself.pixel_array[:, :, :] = converted_array[:, :, :]@@ -301,7 +303,7 @@ class Camera(object):return ctxdef get_cairo_context(self):- if not hasattr(self, "cairo_context"):+ if self.cairo_context is None:ctx = self.create_new_cairo_context()self.cairo_context = ctxelse:@@ -448,7 +450,7 @@ class Camera(object):new_pa = self.pixel_array.reshape((ph * pw, rgba_len))new_pa[indices] = rgbas- self.pixel_array = new_pa.reshape((ph, pw, rgba_len))+ self.set_pixel_array(new_pa.reshape((ph, pw, rgba_len)))def display_multiple_image_mobjects(self, image_mobjects):for image_mobject in image_mobjects:@@ -489,6 +491,7 @@ class Camera(object):mode="RGBA")new_ul_coords = center_coords - np.array(sub_image.size) / 2+ new_ul_coords = new_ul_coords.astype(int)full_image.paste(sub_image,box=(@@ -498,7 +501,6 @@ class Camera(object):new_ul_coords[1] + sub_image.size[1],))-# Paint on top of existing pixel arrayself.overlay_PIL_image(full_image)@@ -506,8 +508,9 @@ class Camera(object):self.overlay_PIL_image(Image.fromarray(arr, mode="RGBA"))def overlay_PIL_image(self, image):- self.pixel_array = np.array(- Image.alpha_composite(self.get_image(), image)+ self.pixel_array[:, :] = np.array(+ Image.alpha_composite(self.get_image(), image),+ dtype='uint8')def adjust_out_of_range_points(self, points):diff --git a/camera/three_d_camera.py b/camera/three_d_camera.pyindex 68b843142..e7b40035d 100644--- a/camera/three_d_camera.py+++ b/camera/three_d_camera.py@@ -37,7 +37,8 @@ class ThreeDCamera(MovingCamera):CONFIG = {"sun_vect": 5 * UP + LEFT,"shading_factor": 0.2,- "distance": 5.,+ "distance": 5.0,+ "default_distance": 5.0,"phi": 0, # Angle off z axis"theta": -TAU / 4, # Rotation about z axis}@@ -176,4 +177,4 @@ class ThreeDCamera(MovingCamera):new_points = np.dot(points, matrix.T)self.frame_center = self.moving_center.points[0]- return Camera.points_to_pixel_coords(self, new_points)+ return MovingCamera.points_to_pixel_coords(self, new_points)