Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Refactoring and bug fixes to moving_camera, multi_camera, zoomed_scene mix

Grant Sandersonf0b8ae7647fc
diff --git a/camera/moving_camera.py b/camera/moving_camera.py
index 2b1085a0e..053a7ebbc 100644
--- a/camera/moving_camera.py
+++ b/camera/moving_camera.py
@@ -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]
diff --git a/camera/multi_camera.py b/camera/multi_camera.py
index 102e8d973..ee0a2c127 100644
--- a/camera/multi_camera.py
+++ b/camera/multi_camera.py
@@ -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
+ ]
diff --git a/scene/moving_camera_scene.py b/scene/moving_camera_scene.py
index 7d777804a..29e1430f6 100644
--- a/scene/moving_camera_scene.py
+++ b/scene/moving_camera_scene.py
@@ -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:
- return moving_mobjects
+ 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
diff --git a/scene/zoomed_scene.py b/scene/zoomed_scene.py
index fb959ff0c..00ac598ba 100644
--- a/scene/zoomed_scene.py
+++ b/scene/zoomed_scene.py
@@ -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(),