Files
manim/camera/moving_camera.py
Grant Sanderson 13d7228918 Revert "Merge branch 'master' of github.com:3b1b/manim into alt-calc"
This reverts commit 17a1ea6db500eddfdec75cc727b70737d892e961, reversing
changes made to c8c6e6d9ba77d42c8d50d8187ca2b0427da0079c.
2018-05-21 12:11:46 -07:00

78 lines
2.4 KiB
Python

from __future__ import absolute_import
from constants import FRAME_HEIGHT
from constants import WHITE
from camera.camera import Camera
from mobject.frame import ScreenRectangle
from utils.config_ops import digest_config
class MovingCamera(Camera):
"""
Stays in line with the height, width and position of it's 'frame', which is a Rectangle
"""
CONFIG = {
"fixed_dimension": 0, # width
"default_frame_stroke_color": WHITE,
"default_frame_stroke_width": 0,
}
def __init__(self, frame=None, **kwargs):
"""
frame is a Mobject, (should almost certainly be a rectangle)
determining which region of space the camera displys
"""
digest_config(self, kwargs)
if frame is None:
frame = ScreenRectangle(height=FRAME_HEIGHT)
frame.set_stroke(
self.default_frame_stroke_color,
self.default_frame_stroke_width,
)
self.frame = frame
Camera.__init__(self, **kwargs)
# TODO, make these work for a rotated frame
def get_frame_height(self):
return self.frame.get_height()
def get_frame_width(self):
return self.frame.get_width()
def get_frame_center(self):
return self.frame.get_center()
def set_frame_height(self, frame_height):
self.frame.stretch_to_fit_height(frame_height)
def set_frame_width(self, frame_width):
self.frame.stretch_to_fit_width(frame_width)
def set_frame_center(self, frame_center):
self.frame.move_to(frame_center)
def capture_mobjects(self, mobjects, **kwargs):
# self.reset_frame_center()
# self.realign_frame_shape()
Camera.capture_mobjects(self, mobjects, **kwargs)
# def reset_frame_center(self):
# self.frame_center = self.frame.get_center()
# def realign_frame_shape(self):
# height, width = self.frame_shape
# if self.fixed_dimension == 0:
# self.frame_shape = (height, self.frame.get_width())
# 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]