A community-maintained Python framework for creating mathematical animations.
MovingCamera has started working
Grant Sanderson8376ac431e0b
diff --git a/camera.py b/camera.pyindex fa9eec15c..ff37a5ff3 100644--- a/camera.py+++ b/camera.py@@ -85,8 +85,8 @@ class Camera(object):def display_region(self, region):(h, w) = self.pixel_shapescalar = 2*self.space_shape[0] / h- xs = scalar*np.arange(-w/2, w/2)- ys = -scalar*np.arange(-h/2, h/2)+ xs = scalar*np.arange(-w/2, w/2)+self.space_center[0]+ ys = -scalar*np.arange(-h/2, h/2)+self.space_center[1]x_array = np.dot(np.ones((h, 1)), xs.reshape((1, w)))y_array = np.dot(ys.reshape(h, 1), np.ones((1, w)))covered = region.condition(x_array, y_array)@@ -153,7 +153,7 @@ class Camera(object):])def adjusted_thickness(self, thickness):- big_shape = PRODUCTION_QUALITY_DISPLAY_CONFIG["shape"]+ big_shape = PRODUCTION_QUALITY_DISPLAY_CONFIG["pixel_shape"]factor = sum(big_shape)/sum(self.pixel_shape)return 1 + (thickness-1)/factor@@ -178,7 +178,7 @@ class MovingCamera(Camera):of a given mobject"""DEFAULT_CONFIG = {- "aligned_dimension" : "height" #or "width"+ "aligned_dimension" : "width" #or height}def __init__(self, mobject, **kwargs):digest_locals(self)@@ -186,7 +186,19 @@ class MovingCamera(Camera):def capture_mobjects(self, *args, **kwargs):self.space_center = self.mobject.get_center()- #TODO+ self.realign_space_shape()+ Camera.capture_mobjects(self, *args, **kwargs)++ def realign_space_shape(self):+ height, width = self.space_shape+ if self.aligned_dimension == "height":+ self.space_shape = (self.mobject.get_height()/2, width)+ else:+ self.space_shape = (height, self.mobject.get_width()/2)+ self.resize_space_shape(+ 0 if self.aligned_dimension == "height" else 1+ )+diff --git a/constants.py b/constants.pyindex 06ade3e5e..8561a22a4 100644--- a/constants.py+++ b/constants.py@@ -1,24 +1,21 @@import osimport numpy as np-DEFAULT_HEIGHT = 1440DEFAULT_WIDTH = 2560DEFAULT_FRAME_DURATION = 0.04+#There might be other configuration than pixel_shape later...PRODUCTION_QUALITY_DISPLAY_CONFIG = {- "shape" : (DEFAULT_HEIGHT, DEFAULT_WIDTH),- "frame_duration" : DEFAULT_FRAME_DURATION,+ "pixel_shape" : (DEFAULT_HEIGHT, DEFAULT_WIDTH),}MEDIUM_QUALITY_DISPLAY_CONFIG = {- "shape" : (720, 1280),- "frame_duration" : 0.04,+ "pixel_shape" : (720, 1280),}LOW_QUALITY_DISPLAY_CONFIG = {- "shape" : (480, 640),- "frame_duration" : 0.04,+ "pixel_shape" : (480, 640),}diff --git a/scene/scene.py b/scene/scene.pyindex 71ecfd3c8..ec56cde9a 100644--- a/scene/scene.py+++ b/scene/scene.py@@ -18,17 +18,14 @@ from mobject import Mobjectclass Scene(object):DEFAULT_CONFIG = {- "shape" : (DEFAULT_HEIGHT, DEFAULT_WIDTH),+ "camera" : None,"frame_duration" : DEFAULT_FRAME_DURATION,"construct_args" : [],- "background" : None,}def __init__(self, **kwargs):digest_config(self, kwargs)- self.camera = Camera(- pixel_shape = self.shape,- background = self.background- )+ if not self.camera:+ self.camera = Camera()self.frames = []self.mobjects = []self.num_animations = 0@@ -48,6 +45,9 @@ class Scene(object):self.name = namereturn self+ def set_camera(self, camera):+ self.camera = camera+def get_frame(self):return self.camera.get_image()diff --git a/scene/tk_scene.py b/scene/tk_scene.pyindex 2d9c23591..dac217b7e 100644--- a/scene/tk_scene.py+++ b/scene/tk_scene.py@@ -11,8 +11,8 @@ class TkSceneRoot(Tkinter.Tk):Tkinter.Tk.__init__(self)kwargs = {- "height" : scene.shape[0],- "width" : scene.shape[1],+ "height" : scene.camera.pixel_shape[0],+ "width" : scene.camera.pixel_shape[1],}self.frame = Tkinter.Frame(self, **kwargs)self.frame.pack()