vispy.color.color_array module

class vispy.color.color_array.Color(color='black', alpha=None, clip=False)[source]

Bases: vispy.color.color_array.ColorArray

A single color

Parameters
colorstr | tuple

If str, can be any of the names in vispy.color.get_color_names. Can also be a hex value if it starts with '#' as '#ff0000'. If array-like, it must be an 1-dimensional array with 3 or 4 elements.

alphafloat | None

If no alpha is not supplied in color entry and alpha is None, then this will default to 1.0 (opaque). If float, it will override the alpha value in color, if provided.

clipbool

If True, clip the color values.

property RGB

Nx3 array of RGBA uint8s

property RGBA

Nx4 array of RGBA uint8s

property alpha

Length-N array of alpha floats

property hex

Numpy array with N elements, each one a hex triplet string

property hsv

Nx3 array of HSV floats

property is_blank

Boolean indicating whether the color is invisible.

property lab
property rgb

Nx3 array of RGB floats

property rgba

Nx4 array of RGBA floats

property value

Length-N array of color HSV values

class vispy.color.color_array.ColorArray(color=(0.0, 0.0, 0.0), alpha=None, clip=False, color_space='rgb')[source]

Bases: object

An array of colors

Parameters
colorstr | tuple | list of colors

If str, can be any of the names in vispy.color.get_color_names. Can also be a hex value if it starts with '#' as '#ff0000'. If array-like, it must be an Nx3 or Nx4 array-like object. Can also be a list of colors, such as ['red', '#00ff00', ColorArray('blue')].

alphafloat | None

If no alpha is not supplied in color entry and alpha is None, then this will default to 1.0 (opaque). If float, it will override any alpha values in color, if provided.

clipbool

Clip the color value.

color_space‘rgb’ | ‘hsv’

‘rgb’ (default) : color tuples are interpreted as (r, g, b) components. ‘hsv’ : color tuples are interpreted as (h, s, v) components.

Notes

Under the hood, this class stores data in RGBA format suitable for use on the GPU.

Examples

There are many ways to define colors. Here are some basic cases:

>>> from vispy.color import ColorArray
>>> r = ColorArray('red')  # using string name
>>> r
<ColorArray: 1 color ((1.0, 0.0, 0.0, 1.0))>
>>> g = ColorArray((0, 1, 0, 1))  # RGBA tuple
>>> b = ColorArray('#0000ff')  # hex color
>>> w = ColorArray()  # defaults to black
>>> w.rgb = r.rgb + g.rgb + b.rgb
>>>hsv_color = ColorArray(color_space="hsv", color=(0, 0, 0.5))
>>>hsv_color
<ColorArray: 1 color ((0.5, 0.5, 0.5, 1.0))>
>>> w == ColorArray('white')
True
>>> w.alpha = 0
>>> w
<ColorArray: 1 color ((1.0, 1.0, 1.0, 0.0))>
>>> rgb = ColorArray(['r', (0, 1, 0), '#0000FFFF'])
>>> rgb
<ColorArray: 3 colors ((1.0, 0.0, 0.0, 1.0) ... (1.0, 0.0, 0.0, 1.0))>
>>> rgb == ColorArray(['red', '#00ff00', ColorArray('blue')])
True
property RGB

Nx3 array of RGBA uint8s

property RGBA

Nx4 array of RGBA uint8s

property alpha

Length-N array of alpha floats

copy()[source]

Return a copy

darker(dv=0.1, copy=True)[source]

Produce a darker color (if possible)

Parameters
dvfloat

Amount to decrease the color value by.

copybool

If False, operation will be carried out in-place.

Returns
colorinstance of ColorArray

The darkened Color.

extend(colors)[source]

Extend a ColorArray with new colors

Parameters
colorsinstance of ColorArray

The new colors.

property hex

Numpy array with N elements, each one a hex triplet string

property hsv

Nx3 array of HSV floats

property lab
lighter(dv=0.1, copy=True)[source]

Produce a lighter color (if possible)

Parameters
dvfloat

Amount to increase the color value by.

copybool

If False, operation will be carried out in-place.

Returns
colorinstance of ColorArray

The lightened Color.

property rgb

Nx3 array of RGB floats

property rgba

Nx4 array of RGBA floats

property value

Length-N array of color HSV values