Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
633 changes: 626 additions & 7 deletions manimlib/camera/camera.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions manimlib/camera/mapping_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


class MappingCamera(Camera):
"""Camera object that allows mapping
between objects.
"""
CONFIG = {
"mapping_func": lambda p: p,
"min_num_curves": 50,
Expand Down
58 changes: 58 additions & 0 deletions manimlib/camera/moving_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,65 @@ def __init__(self, frame=None, **kwargs):

# TODO, make these work for a rotated frame
def get_frame_height(self):
"""Returns the height of the frame.

Returns
-------
float
The height of the frame.
"""
return self.frame.get_height()

def get_frame_width(self):
"""Returns the width of the frame

Returns
-------
float
The width of the frame.
"""
return self.frame.get_width()

def get_frame_center(self):
"""Returns the centerpoint of the frame in cartesian coordinates.

Returns
-------
np.array
The cartesian coordinates of the center of the frame.
"""
return self.frame.get_center()

def set_frame_height(self, frame_height):
"""Sets the height of the frame in MUnits.

Parameters
----------
frame_height : int, float
The new frame_height.
"""
self.frame.stretch_to_fit_height(frame_height)

def set_frame_width(self, frame_width):
"""Sets the width of the frame in MUnits.

Parameters
----------
frame_width : int, float
The new frame_width.
"""
self.frame.stretch_to_fit_width(frame_width)

def set_frame_center(self, frame_center):
"""Sets the centerpoint of the frame.

Parameters
----------
frame_center : np.array, list, tuple, Mobject
The point to which the frame must be moved.
If is of type mobject, the frame will be moved to
the center of that mobject.
"""
self.frame.move_to(frame_center)

def capture_mobjects(self, mobjects, **kwargs):
Expand All @@ -74,9 +118,19 @@ def capture_mobjects(self, mobjects, **kwargs):
# context used for updating should be regenerated
# at each frame. So no caching.
def get_cached_cairo_context(self, pixel_array):
"""
Since the frame can be moving around, the cairo
context used for updating should be regenerated
at each frame. So no caching.
"""
return None

def cache_cairo_context(self, pixel_array, ctx):
"""
Since the frame can be moving around, the cairo
context used for updating should be regenerated
at each frame. So no caching.
"""
pass

# def reset_frame_center(self):
Expand All @@ -94,5 +148,9 @@ 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

Returns
-------
list
"""
return [self.frame]
33 changes: 33 additions & 0 deletions manimlib/camera/multi_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,36 @@


class MultiCamera(MovingCamera):
"""Camera Object that allows for multiple perspectives.
"""
CONFIG = {
"allow_cameras_to_capture_their_own_display": False,
}

def __init__(self, *image_mobjects_from_cameras, **kwargs):
"""Initalises the MultiCamera

Parameters:
-----------
*image_mobjects_from_cameras : ImageMobject

**kwargs
Any valid keyword arguments of MovingCamera.
"""
self.image_mobjects_from_cameras = []
for imfc in image_mobjects_from_cameras:
self.add_image_mobject_from_camera(imfc)
MovingCamera.__init__(self, **kwargs)

def add_image_mobject_from_camera(self, image_mobject_from_camera):
"""Adds an ImageMobject that's been obtained from the camera
into the list `self.image_mobject_from_cameras`

Parameters
----------
image_mobject_from_camera : ImageMobject
The ImageMobject to add to self.image_mobject_from_cameras
"""
# A silly method to have right now, but maybe there are things
# we want to guarantee about any imfc's added later.
imfc = image_mobject_from_camera
Expand All @@ -34,6 +53,13 @@ def update_sub_cameras(self):
)

def reset(self):
"""Resets the MultiCamera.

Returns
-------
MultiCamera
The reset MultiCamera
"""
for imfc in self.image_mobjects_from_cameras:
imfc.camera.reset()
MovingCamera.reset(self)
Expand All @@ -51,6 +77,13 @@ def capture_mobjects(self, mobjects, **kwargs):
MovingCamera.capture_mobjects(self, mobjects, **kwargs)

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

Returns
-------
list
"""
return [self.frame] + [
imfc.camera.frame
for imfc in self.image_mobjects_from_cameras
Expand Down
Loading