Convience interfaces to manipulate colors.
This module provides support for manipulating colors.
vispy.color.
Color
(color='black', alpha=None, clip=False)[source]¶A single color
Parameters: | color : str | tuple
alpha : float | None
clip : bool
|
---|
RGB
¶Nx3 array of RGBA uint8s
RGBA
¶Nx4 array of RGBA uint8s
alpha
¶Length-N array of alpha floats
hex
¶Numpy array with N elements, each one a hex triplet string
hsv
¶Nx3 array of HSV floats
is_blank
¶Boolean indicating whether the color is invisible.
rgb
¶Nx3 array of RGB floats
rgba
¶Nx4 array of RGBA floats
value
¶Length-N array of color HSV values
vispy.color.
ColorArray
(color=(0.0, 0.0, 0.0), alpha=None, clip=False, color_space='rgb')[source]¶An array of colors
Parameters: | color : str | tuple | list of colors
alpha : float | None
clip : bool
color_space : ‘rgb’ | ‘hsv’
|
---|
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
RGB
¶Nx3 array of RGBA uint8s
RGBA
¶Nx4 array of RGBA uint8s
alpha
¶Length-N array of alpha floats
darker
(dv=0.1, copy=True)[source]¶Produce a darker color (if possible)
Parameters: | dv : float
copy : bool
|
---|---|
Returns: | color : instance of ColorArray
|
extend
(colors)[source]¶Extend a ColorArray with new colors
Parameters: | colors : instance of ColorArray
|
---|
hex
¶Numpy array with N elements, each one a hex triplet string
hsv
¶Nx3 array of HSV floats
lighter
(dv=0.1, copy=True)[source]¶Produce a lighter color (if possible)
Parameters: | dv : float
copy : bool
|
---|---|
Returns: | color : instance of ColorArray
|
rgb
¶Nx3 array of RGB floats
rgba
¶Nx4 array of RGBA floats
value
¶Length-N array of color HSV values
vispy.color.
Colormap
(colors, controls=None, interpolation='linear')[source]¶A colormap defining several control colors and an interpolation scheme.
Parameters: | colors : list of colors | ColorArray
controls : array-like
interpolation : str
|
---|
Examples
Here is a basic example:
>>> from vispy.color import Colormap
>>> cm = Colormap(['r', 'g', 'b'])
>>> cm[0.], cm[0.5], cm[np.linspace(0., 1., 100)]
interpolation
¶The interpolation mode of the colormap
vispy.color.
BaseColormap
(colors=None)[source]¶Class representing a colormap:
t in [0, 1] –> rgba_color
Parameters: | colors : list of lists, tuples, or ndarrays
|
---|
Notes
Must be overriden. Child classes need to implement:
map
(item)[source]¶Return a rgba array for the requested items.
This function must be overriden by child classes.
This function doesn’t need to implement argument checking on item. It can always assume that item is a (N, 1) array of values between 0 and 1.
Parameters: | item : ndarray
|
---|---|
Returns: | rgba : ndarray
|
Notes
Users are expected to use a colormap with __getitem__()
rather
than map()
(which implements a lower-level API).
vispy.color.
get_colormap
(name, *args, **kwargs)[source]¶Obtain a colormap
Some colormaps can have additional configuration parameters. Refer to their corresponding documentation for more information.
Parameters: | name : str | Colormap
|
---|
Examples
>>> get_colormap('autumn')
>>> get_colormap('single_hue', hue=10)