ColorMap

class compas.colors.ColorMap[source]

Bases: object

Class providing a map for 256 distinct colors of a specific color palette.

Parameters:
colorssequence[tuple[float, float, float]]

A sequence of colors forming the map. The number of colors in the sequence should be 256.

Raises:
ValueError

If the number of colors in the sequence is not 256.

Examples

>>> import random
>>> cmap = ColorMap.from_palette('bamako')
>>> for i in range(100):
...     color = cmap(random.random())
...
>>> cmap = ColorMap.from_mpl('viridis')
>>> n = 100
>>> for i in range(n):
...     color = cmap(i, minval=0, maxval=n - 1)
...
Attributes:
colorslist[compas.colors.Color]

The colors of the map.

Methods

from_color

Construct a color map from a single color by varying luminance.

from_mpl

Construct a color map from matplotlib.

from_palette

Construct a color map from a named palette.

from_rgb

Construct a color map from the complete rgb color space.

from_three_colors

Construct a color map from three colors.

from_two_colors

Create a color map from two colors.