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

adjust_out_of_range_points

If any of the points in the passed array are out of the viable range, they are adjusted suitably.

adjusted_thickness

param thickness

apply_fill

Fills the cairo context

apply_stroke

Applies a stroke to the VMobject in the cairo context.

cache_cairo_context

Caches the passed Pixel array into a Cairo Context

capture_mobject

Capture mobjects by storing it in pixel_array.

capture_mobjects

Capture mobjects by printing them on pixel_array.

convert_pixel_array

Converts a pixel array from values that have floats in then to proper RGB values.

display_image_mobject

Displays an ImageMobject by changing the pixel_array suitably.

display_multiple_background_colored_vmobjects

Displays multiple vmobjects that have the same color as the background.

display_multiple_image_mobjects

Displays multiple image mobjects by modifying the passed pixel_array.

display_multiple_non_background_colored_vmobjects

Displays multiple VMobjects in the cairo context, as long as they don't have background colors.

display_multiple_point_cloud_mobjects

Displays multiple PMobjects by modifying the passed pixel array.

display_multiple_vectorized_mobjects

Displays multiple VMobjects in the pixel_array

display_point_cloud

Displays a PMobject by modifying the Pixel array suitably.

display_vectorized

Displays a VMobject in the cairo context

get_background_colored_vmobject_displayer

Returns the background_colored_vmobject_displayer if it exists or makes one and returns it if not.

get_cached_cairo_context

Returns the cached cairo context of the passed pixel array if it exists, and None if it doesn't.

get_cairo_context

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.

get_coords_of_all_pixels

Returns the cartesian coordinates of each pixel.

get_fill_rgbas

Returns the RGBA array of the fill of the passed VMobject

get_image

Returns an image from the passed pixel array, or from the current frame if the passed pixel array is none.

get_mobjects_to_display

Used to get the list of mobjects to display with the camera.

get_stroke_rgbas

Gets the RGBA array for the stroke of the passed VMobject.

get_thickening_nudges

param thickness

init_background

Initialize the background.

is_in_frame

Checks whether the passed mobject is in frame or not.

make_background_from_func

Makes a pixel array for the background by using coords_to_colors_func to determine each pixel's color.

on_screen_pixels

Returns array of pixels that are on the screen from a given array of pixel_coordinates

overlay_PIL_image

Overlays a PIL image on the passed pixel array.

overlay_rgba_array

Overlays an RGBA array on top of the given Pixel array.

points_to_pixel_coords

reset

Resets the camera's pixel array to that of the background

reset_pixel_shape

This method resets the height and width of a single pixel to the passed new_height and new_width.

resize_frame_shape

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.

set_background

Sets the background to the passed pixel_array after converting to valid RGB values.

set_background_from_func

Sets the background to a pixel array using coords_to_colors_func to determine each pixel's color.

set_cairo_context_color

Sets the color of the cairo context

set_cairo_context_path

Sets a path for the cairo context with the vmobject passed

set_frame_to_background

set_pixel_array

Sets the pixel array of the camera to the passed pixel array.

thickened_coordinates

Returns thickened coordinates for a passed array of pixel coords and a thickness to thicken by.

transform_points_pre_display

type_or_raise

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

adjusted_thickness(thickness)[source]#
Parameters

thickness (float) –

Return type

float

apply_fill(ctx, vmobject)[source]#

Fills the cairo context

Parameters
  • ctx (Context) – The cairo context

  • vmobject (VMobject) – The VMobject

Returns

The camera object.

Return type

Camera

apply_stroke(ctx, vmobject, background=False)[source]#

Applies a stroke to the VMobject in the cairo context.

Parameters
  • ctx (Context) – The cairo context

  • vmobject (VMobject) – The VMobject

  • background (bool) – Whether or not to consider the background when applying this stroke width, by default False

Returns

The camera object with the stroke applied.

Return type

Camera

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
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

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

Camera

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) –

display_vectorized(vmobject, ctx)[source]#

Displays a VMobject in the cairo context

Parameters
  • vmobject (VMobject) – The Vectorized Mobject to display

  • ctx (Context) – The cairo context to use.

Returns

The camera object

Return type

Camera

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

get_thickening_nudges(thickness)[source]#
Parameters

thickness (float) –

Return type

np.array

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

Camera

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_color(ctx, rgbas, vmobject)[source]#

Sets the color of the cairo context

Parameters
  • ctx (Context) – The cairo context

  • rgbas (ndarray) – The RGBA array with which to color the context.

  • vmobject (VMobject) – The VMobject with which to set the color.

Returns

The camera object

Return type

Camera

set_cairo_context_path(ctx, vmobject)[source]#

Sets a path for the cairo context with the vmobject passed

Parameters
  • ctx (Context) – The cairo context

  • vmobject (VMobject) – The VMobject

Returns

Camera object after setting cairo_context_path

Return type

Camera

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().

Returns

The type of mobjects, if it can be rendered.

Return type

Type[Mobject]

Raises

TypeError – When mobject is not an instance of a class that can be rendered.

Parameters

mobject (Mobject) –