Camera#
Qualified name: manim.camera.camera.Camera
- class Camera(background_image=None, frame_center=array([0., 0., 0.]), image_mode='RGBA', n_channels=4, pixel_array_dtype='uint8', cairo_line_width_multiple=0.01, use_z_index=True, background=None, pixel_height=None, pixel_width=None, frame_height=None, frame_width=None, frame_rate=None, **kwargs)[source]#
Bases:
object
Base camera class.
This is the object which takes care of what exactly is displayed on screen at any given moment.
- Parameters
background_image (str | None) – The path to an image that should be the background image. If not set, the background is filled with
self.background_color
background (np.ndarray | None) – What
background
is set to. By default,None
.pixel_height (int | None) – The height of the scene in pixels.
pixel_width (int | None) – The width of the scene in pixels.
kwargs – Additional arguments (
background_color
,background_opacity
) to be set.frame_center (np.ndarray) –
image_mode (str) –
n_channels (int) –
pixel_array_dtype (str) –
cairo_line_width_multiple (float) –
use_z_index (bool) –
frame_height (float | None) –
frame_width (float | None) –
frame_rate (float | None) –
Methods
If any of the points in the passed array are out of the viable range, they are adjusted suitably.
- param thickness
Fills the cairo context
Applies a stroke to the VMobject in the cairo context.
Caches the passed Pixel array into a Cairo Context
Capture mobjects by storing it in
pixel_array
.Capture mobjects by printing them on
pixel_array
.Converts a pixel array from values that have floats in then to proper RGB values.
Displays an ImageMobject by changing the pixel_array suitably.
Displays multiple vmobjects that have the same color as the background.
Displays multiple image mobjects by modifying the passed pixel_array.
Displays multiple VMobjects in the cairo context, as long as they don't have background colors.
Displays multiple PMobjects by modifying the passed pixel array.
Displays multiple VMobjects in the pixel_array
Displays a PMobject by modifying the Pixel array suitably.
Displays a VMobject in the cairo context
Returns the background_colored_vmobject_displayer if it exists or makes one and returns it if not.
Returns the cached cairo context of the passed pixel array if it exists, and None if it doesn't.
Returns the cairo context for a pixel array after caching it to self.pixel_array_to_cairo_context If that array has already been cached, it returns the cached version instead.
Returns the cartesian coordinates of each pixel.
Returns the RGBA array of the fill of the passed VMobject
Returns an image from the passed pixel array, or from the current frame if the passed pixel array is none.
Used to get the list of mobjects to display with the camera.
Gets the RGBA array for the stroke of the passed VMobject.
- param thickness
Initialize the background.
Checks whether the passed mobject is in frame or not.
Makes a pixel array for the background by using coords_to_colors_func to determine each pixel's color.
Returns array of pixels that are on the screen from a given array of pixel_coordinates
Overlays a PIL image on the passed pixel array.
Overlays an RGBA array on top of the given Pixel array.
points_to_pixel_coords
Resets the camera's pixel array to that of the background
This method resets the height and width of a single pixel to the passed new_height and new_width.
Changes frame_shape to match the aspect ratio of the pixels, where fixed_dimension determines whether frame_height or frame_width remains fixed while the other changes accordingly.
Sets the background to the passed pixel_array after converting to valid RGB values.
Sets the background to a pixel array using coords_to_colors_func to determine each pixel's color.
Sets the color of the cairo context
Sets a path for the cairo context with the vmobject passed
set_frame_to_background
Sets the pixel array of the camera to the passed pixel array.
Returns thickened coordinates for a passed array of pixel coords and a thickness to thicken by.
transform_points_pre_display
Return the type of mobject, if it is a type that can be rendered.
Attributes
background_color
background_opacity
- adjust_out_of_range_points(points)[source]#
If any of the points in the passed array are out of the viable range, they are adjusted suitably.
- Parameters
points (ndarray) – The points to adjust
- Returns
The adjusted points.
- Return type
np.array
- apply_stroke(ctx, vmobject, background=False)[source]#
Applies a stroke to the VMobject in the cairo context.
- cache_cairo_context(pixel_array, ctx)[source]#
Caches the passed Pixel array into a Cairo Context
- Parameters
pixel_array (ndarray) – The pixel array to cache
ctx (Context) – The context to cache it into.
- capture_mobject(mobject, **kwargs)[source]#
Capture mobjects by storing it in
pixel_array
.This is a single-mobject version of
capture_mobjects()
.- Parameters
mobject (Mobject) – Mobject to capture.
kwargs (Any) – Keyword arguments to be passed to
get_mobjects_to_display()
.
- capture_mobjects(mobjects, **kwargs)[source]#
Capture mobjects by printing them on
pixel_array
.This is the essential function that converts the contents of a Scene into an array, which is then converted to an image or video.
- Parameters
mobjects (Iterable[Mobject]) – Mobjects to capture.
kwargs – Keyword arguments to be passed to
get_mobjects_to_display()
.
Notes
For a list of classes that can currently be rendered, see
display_funcs()
.
- convert_pixel_array(pixel_array, convert_from_floats=False)[source]#
Converts a pixel array from values that have floats in then to proper RGB values.
- Parameters
pixel_array (np.ndarray | list | tuple) – Pixel array to convert.
convert_from_floats (bool) – Whether or not to convert float values to ints, by default False
- Returns
The new, converted pixel array.
- Return type
np.array
- display_image_mobject(image_mobject, pixel_array)[source]#
Displays an ImageMobject by changing the pixel_array suitably.
- Parameters
image_mobject (AbstractImageMobject) – The imageMobject to display
pixel_array (ndarray) – The Pixel array to put the imagemobject in.
- display_multiple_background_colored_vmobjects(cvmobjects, pixel_array)[source]#
Displays multiple vmobjects that have the same color as the background.
- Parameters
cvmobjects (list) – List of Colored VMobjects
pixel_array (ndarray) – The pixel array.
- Returns
The camera object.
- Return type
- display_multiple_image_mobjects(image_mobjects, pixel_array)[source]#
Displays multiple image mobjects by modifying the passed pixel_array.
- Parameters
image_mobjects (list) – list of ImageMobjects
pixel_array (ndarray) – The pixel array to modify.
- display_multiple_non_background_colored_vmobjects(vmobjects, pixel_array)[source]#
Displays multiple VMobjects in the cairo context, as long as they don’t have background colors.
- Parameters
vmobjects (list) – list of the VMobjects
pixel_array (ndarray) – The Pixel array to add the VMobjects to.
- display_multiple_point_cloud_mobjects(pmobjects, pixel_array)[source]#
Displays multiple PMobjects by modifying the passed pixel array.
- Parameters
pmobjects (list) – List of PMobjects
pixel_array (ndarray) – The pixel array to modify.
- display_multiple_vectorized_mobjects(vmobjects, pixel_array)[source]#
Displays multiple VMobjects in the pixel_array
- Parameters
vmobjects (list) – list of VMobjects to display
pixel_array (ndarray) – The pixel array
- display_point_cloud(pmobject, points, rgbas, thickness, pixel_array)[source]#
Displays a PMobject by modifying the Pixel array suitably.. TODO: Write a description for the rgbas argument. :param pmobject: Point Cloud Mobject :param points: The points to display in the point cloud mobject :param rgbas: :param thickness: The thickness of each point of the PMobject :param pixel_array: The pixel array to modify.
- Parameters
pmobject (PMobject) –
points (list) –
rgbas (ndarray) –
thickness (float) –
pixel_array (ndarray) –
- get_background_colored_vmobject_displayer()[source]#
Returns the background_colored_vmobject_displayer if it exists or makes one and returns it if not.
- Returns
Object that displays VMobjects that have the same color as the background.
- Return type
BackGroundColoredVMobjectDisplayer
- get_cached_cairo_context(pixel_array)[source]#
Returns the cached cairo context of the passed pixel array if it exists, and None if it doesn’t.
- Parameters
pixel_array (ndarray) – The pixel array to check.
- Returns
The cached cairo context.
- Return type
cairo.Context
- get_cairo_context(pixel_array)[source]#
Returns the cairo context for a pixel array after caching it to self.pixel_array_to_cairo_context If that array has already been cached, it returns the cached version instead.
- Parameters
pixel_array (ndarray) – The Pixel array to get the cairo context of.
- Returns
The cairo context of the pixel array.
- Return type
cairo.Context
- get_coords_of_all_pixels()[source]#
Returns the cartesian coordinates of each pixel.
- Returns
The array of cartesian coordinates.
- Return type
np.ndarray
- get_fill_rgbas(vmobject)[source]#
Returns the RGBA array of the fill of the passed VMobject
- Parameters
vmobject (VMobject) – The VMobject
- Returns
The RGBA Array of the fill of the VMobject
- Return type
np.array
- get_image(pixel_array=None)[source]#
Returns an image from the passed pixel array, or from the current frame if the passed pixel array is none.
- Parameters
pixel_array (np.ndarray | list | tuple | None) – The pixel array from which to get an image, by default None
- Returns
The PIL image of the array.
- Return type
PIL.Image
- get_mobjects_to_display(mobjects, include_submobjects=True, excluded_mobjects=None)[source]#
Used to get the list of mobjects to display with the camera.
- Parameters
mobjects (Iterable[Mobject]) – The Mobjects
include_submobjects (bool) – Whether or not to include the submobjects of mobjects, by default True
excluded_mobjects (list | None) – Any mobjects to exclude, by default None
- Returns
list of mobjects
- Return type
list
- get_stroke_rgbas(vmobject, background=False)[source]#
Gets the RGBA array for the stroke of the passed VMobject.
- Parameters
vmobject (VMobject) – The VMobject
background (bool) – Whether or not to consider the background when getting the stroke RGBAs, by default False
- Returns
The RGBA array of the stroke.
- Return type
np.ndarray
- init_background()[source]#
Initialize the background. If self.background_image is the path of an image the image is set as background; else, the default background color fills the background.
- is_in_frame(mobject)[source]#
Checks whether the passed mobject is in frame or not.
- Parameters
mobject (Mobject) – The mobject for which the checking needs to be done.
- Returns
True if in frame, False otherwise.
- Return type
bool
- make_background_from_func(coords_to_colors_func)[source]#
Makes a pixel array for the background by using coords_to_colors_func to determine each pixel’s color. Each input pixel’s color. Each input to coords_to_colors_func is an (x, y) pair in space (in ordinary space coordinates; not pixel coordinates), and each output is expected to be an RGBA array of 4 floats.
- Parameters
coords_to_colors_func (Callable[[ndarray], ndarray]) – The function whose input is an (x,y) pair of coordinates and whose return values must be the colors for that point
- Returns
The pixel array which can then be passed to set_background.
- Return type
np.array
- on_screen_pixels(pixel_coords)[source]#
Returns array of pixels that are on the screen from a given array of pixel_coordinates
- Parameters
pixel_coords (ndarray) – The pixel coords to check.
- Returns
The pixel coords on screen.
- Return type
np.array
- overlay_PIL_image(pixel_array, image)[source]#
Overlays a PIL image on the passed pixel array.
- Parameters
pixel_array (np.ndarray) – The Pixel array
image (Image) – The Image to overlay.
- overlay_rgba_array(pixel_array, new_array)[source]#
Overlays an RGBA array on top of the given Pixel array.
- Parameters
pixel_array (ndarray) – The original pixel array to modify.
new_array (ndarray) – The new pixel array to overlay.
- reset()[source]#
Resets the camera’s pixel array to that of the background
- Returns
The camera object after setting the pixel array.
- Return type
- reset_pixel_shape(new_height, new_width)[source]#
This method resets the height and width of a single pixel to the passed new_height and new_width.
- Parameters
new_height (float) – The new height of the entire scene in pixels
new_width (float) – The new width of the entire scene in pixels
- resize_frame_shape(fixed_dimension=0)[source]#
Changes frame_shape to match the aspect ratio of the pixels, where fixed_dimension determines whether frame_height or frame_width remains fixed while the other changes accordingly.
- Parameters
fixed_dimension (int) – If 0, height is scaled with respect to width else, width is scaled with respect to height.
- set_background(pixel_array, convert_from_floats=False)[source]#
Sets the background to the passed pixel_array after converting to valid RGB values.
- Parameters
pixel_array (np.ndarray | list | tuple) – The pixel array to set the background to.
convert_from_floats (bool) – Whether or not to convert floats values to proper RGB valid ones, by default False
- set_background_from_func(coords_to_colors_func)[source]#
Sets the background to a pixel array using coords_to_colors_func to determine each pixel’s color. Each input pixel’s color. Each input to coords_to_colors_func is an (x, y) pair in space (in ordinary space coordinates; not pixel coordinates), and each output is expected to be an RGBA array of 4 floats.
- Parameters
coords_to_colors_func (Callable[[ndarray], ndarray]) – The function whose input is an (x,y) pair of coordinates and whose return values must be the colors for that point
- set_cairo_context_path(ctx, vmobject)[source]#
Sets a path for the cairo context with the vmobject passed
- set_pixel_array(pixel_array, convert_from_floats=False)[source]#
Sets the pixel array of the camera to the passed pixel array.
- Parameters
pixel_array (np.ndarray | list | tuple) – The pixel array to convert and then set as the camera’s pixel array.
convert_from_floats (bool) – Whether or not to convert float values to proper RGB values, by default False
- thickened_coordinates(pixel_coords, thickness)[source]#
Returns thickened coordinates for a passed array of pixel coords and a thickness to thicken by.
- Parameters
pixel_coords (ndarray) – Pixel coordinates
thickness (float) – Thickness
- Returns
Array of thickened pixel coords.
- Return type
np.array
- type_or_raise(mobject)[source]#
Return the type of mobject, if it is a type that can be rendered.
If mobject is an instance of a class that inherits from a class that can be rendered, return the super class. For example, an instance of a Square is also an instance of VMobject, and these can be rendered. Therefore, type_or_raise(Square()) returns True.
- Parameters
mobject (Mobject) – The object to take the type of.
Notes
For a list of classes that can currently be rendered, see
display_funcs()
.