# vispy.color.color_array module

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

  Bases: `ColorArray`

  A single color

  Parameters:
    color str | 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.

    alpha float | 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.

    clip bool

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

  Bases: `object`

  An array of colors

  Parameters:
    color str | 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')]`.

    alpha float | 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.

    clip bool

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

    Return a copy

  darker(dv=0.1, copy=True)

    Produce a darker color (if possible)

    Parameters:
      dv float

        Amount to decrease the color value by.

      copy bool

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

    Returns:
      color instance of ColorArray

        The darkened Color.

  extend(colors)

    Extend a ColorArray with new colors

    Parameters:
      colors instance 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)

    Produce a lighter color (if possible)

    Parameters:
      dv float

        Amount to increase the color value by.

      copy bool

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

    Returns:
      color instance 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

previous

vispy.color.tests.test_color module

next

vispy.color.color_space module