core

Manim’s (internal) color data structure and some utilities for color conversion.

This module contains the implementation of ManimColor, the data structure internally used to represent colors.

The preferred way of using these colors is by importing their constants from manim:

>>> from manim import RED, GREEN, BLUE
>>> print(RED)
#FC6255

Note this way uses the name of the colors in UPPERCASE.

Note

The colors of type “C” have an alias equal to the colorname without a letter, e.g. GREEN = GREEN_C

Type Aliases

class ParsableManimColor
ManimColor | int | str | RGB_Tuple_Int | RGB_Tuple_Float | RGBA_Tuple_Int | RGBA_Tuple_Float | RGB_Array_Int | RGB_Array_Float | RGBA_Array_Int | RGBA_Array_Float

ParsableManimColor represents all the types which can be parsed to a color in Manim.

Classes

ManimColor

Internal representation of a color.

Functions

average_color(*colors)[source]

Determines the Average color of the given parameters

Returns:

The average color of the input

Return type:

ManimColor

Parameters:

colors (ParsableManimColor)

color_gradient(reference_colors, length_of_output)[source]

Creates a list of colors interpolated between the input array of colors with a specific number of colors

Parameters:
  • reference_colors (Sequence[ParsableManimColor]) – The colors to be interpolated between or spread apart

  • length_of_output (int) – The number of colors that the output should have, ideally more than the input

Returns:

A list of ManimColor’s which has the interpolated colors

Return type:

list[ManimColor] | ManimColor

color_to_int_rgb(color)[source]

Helper function for use in functional style programming refer to to_int_rgb() in ManimColor

Parameters:

color (ParsableManimColor) – A color

Returns:

the corresponding int rgb array

Return type:

RGB_Array_Int

color_to_int_rgba(color, alpha=1.0)[source]

Helper function for use in functional style programming refer to to_int_rgba_with_alpha() in ManimColor

Parameters:
  • color (ParsableManimColor) – A color

  • alpha (float, optional) – alpha value to be used in the color, by default 1.0

Returns:

the corresponding int rgba array

Return type:

RGBA_Array_Int

color_to_rgb(color)[source]

Helper function for use in functional style programming. Refer to to_rgb() in ManimColor.

Parameters:

color (ParsableManimColor) – A color

Returns:

the corresponding rgb array

Return type:

RGB_Array_Float

color_to_rgba(color, alpha=1)[source]

Helper function for use in functional style programming refer to to_rgba_with_alpha() in ManimColor

Parameters:
  • color (ParsableManimColor) – A color

  • alpha (float, optional) – alpha value to be used in the color, by default 1

Returns:

the corresponding rgba array

Return type:

RGBA_Array_Float

get_shaded_rgb(rgb, point, unit_normal_vect, light_source)[source]
Parameters:
  • rgb (ndarray[Any, dtype[Any]])

  • point (ndarray[Any, dtype[Any]])

  • unit_normal_vect (ndarray[Any, dtype[Any]])

  • light_source (ndarray[Any, dtype[Any]])

Return type:

RGBA_Array_Float

hex_to_rgb(hex_code)[source]

Helper function for use in functional style programming refer to to_hex() in ManimColor

Parameters:

hex_code (str) – A hex string representing a color

Returns:

RGB array representing the color

Return type:

RGB_Array_Float

interpolate_arrays(arr1, arr2, alpha)[source]

Helper function used in Manim to fade between two objects smoothly

Parameters:
  • arr1 (npt.NDArray[Any]) – The first array of colors

  • arr2 (npt.NDArray[Any]) – The second array of colors

  • alpha (float) – The alpha value corresponding to the interpolation point between the two inputs

Returns:

The interpolated value of the to arrays

Return type:

np.ndarray

interpolate_color(color1, color2, alpha)[source]

Standalone function to interpolate two ManimColors and get the result refer to interpolate() in ManimColor

Parameters:
  • color1 (ManimColor) – First ManimColor

  • color2 (ManimColor) – Second ManimColor

  • alpha (float) – The alpha value determining the point of interpolation between the colors

Returns:

The interpolated ManimColor

Return type:

ManimColor

invert_color(color)[source]

Helper function for use in functional style programming refer to invert() in ManimColor

Parameters:

color (ManimColor) – A ManimColor

Returns:

The linearly inverted ManimColor

Return type:

ManimColor

random_bright_color()[source]

Returns you a random bright color

Warning

This operation is very expensive please keep in mind the performance loss.

Returns:

A bright ManimColor

Return type:

ManimColor

random_color()[source]

Return you a random ManimColor

Warning

This operation is very expensive please keep in mind the performance loss.

Returns:

_description_

Return type:

ManimColor

rgb_to_color(rgb)[source]

Helper function for use in functional style programming refer to from_rgb() in ManimColor

Parameters:

rgb (RGB_Array_Float | RGB_Tuple_Float) – A 3 element iterable

Returns:

A ManimColor with the corresponding value

Return type:

ManimColor

rgb_to_hex(rgb)[source]

Helper function for use in functional style programming refer to from_rgb() in ManimColor

Parameters:

rgb (RGB_Array_Float | RGB_Tuple_Float) – A 3 element iterable

Returns:

A hex representation of the color, refer to to_hex() in ManimColor

Return type:

str

rgba_to_color(rgba)[source]

Helper function for use in functional style programming refer to from_rgba() in ManimColor

Parameters:

rgba (RGBA_Array_Float | RGBA_Tuple_Float) – A 4 element iterable

Returns:

A ManimColor with the corresponding value

Return type:

ManimColor