Refactoring and bug fixes to moving_camera, multi_camera, zoomed_scene mix

This commit is contained in:
Grant Sanderson
2018-05-11 13:15:34 -07:00
parent 2a74f3a687
commit f0b8ae7647
4 changed files with 23 additions and 16 deletions

View File

@ -49,3 +49,10 @@ class MovingCamera(Camera):
else:
self.frame_shape = (self.frame.get_height(), width)
self.resize_frame_shape(fixed_dimension=self.fixed_dimension)
def get_mobjects_indicating_movement(self):
"""
Returns all mobjets whose movement implies that the camera
should think of all other mobjects on the screen as moving
"""
return [self.frame]

View File

@ -53,3 +53,8 @@ class MultiCamera(MovingCamera):
imfc.camera.capture_mobjects(to_add, **kwargs)
MovingCamera.capture_mobjects(self, mobjects, **kwargs)
def get_mobjects_indicating_movement(self):
return [self.frame] + [
imfc.camera.frame
for imfc in self.image_mobjects_from_cameras
]

View File

@ -2,6 +2,7 @@ from __future__ import absolute_import
from scene.scene import Scene
from camera.moving_camera import MovingCamera
from utils.iterables import list_update
class MovingCameraScene(Scene):
@ -18,10 +19,14 @@ class MovingCameraScene(Scene):
return self
def get_moving_mobjects(self, *animations):
# TODO: Code repetition from ZoomedScene
moving_mobjects = Scene.get_moving_mobjects(self, *animations)
if self.camera_frame in moving_mobjects:
# When the camera is moving, so is everything,
return self.mobjects
else:
all_moving_mobjects = self.camera.extract_mobject_family_members(
moving_mobjects
)
movement_indicators = self.camera.get_mobjects_indicating_movement()
for movement_indicator in movement_indicators:
if movement_indicator in all_moving_mobjects:
# When one of these is moving, the camera should
# consider all mobjects to be moving
return list_update(self.mobjects, moving_mobjects)
return moving_mobjects

View File

@ -81,16 +81,6 @@ class ZoomedScene(MovingCameraScene):
else:
self.add_foreground_mobjects(*to_add)
def get_moving_mobjects(self, *animations):
moving_mobjects = MovingCameraScene.get_moving_mobjects(self, *animations)
zoomed_mobjects = [self.zoomed_camera.frame, self.zoomed_display]
moving_zoomed_mobjects = set(moving_mobjects).intersection(zoomed_mobjects)
if self.zoom_activated and moving_zoomed_mobjects:
# If either of the zoomed_mobjects are moving, then so is
# everything
return self.mobjects
return moving_mobjects
def get_zoom_factor(self):
return fdiv(
self.zoomed_camera.frame.get_width(),