vispy/vispy — pull request #152 by Eric89GXL (2014-02-28 01:14:36+00:00)
Title: WIP: Colors

This adds some basic **Python-side**, user-level color interaction / conversion. I tried to build this to work as cleanly/sanely as possible for users at the Python end, and now need to think hard about how to hook it into the OpenGL/`gloo` pipeline. It may require extensive refactoring or rethinking of what should be where (this is radically different from what @lcampagn talked about), but at least the conversions all seem to work, so refactoring shouldn't be too bad.

The conversions also need to be ported to GLSL, but that should be fairly trivial once I figure out how to interface with `gloo` correctly.

Currently supported on the Python side:

1. Just about all of the color manipulation methods requested by @rougier in #121 (https://github.com/vispy/vispy/issues/121#issuecomment-36036156). See tests for examples.

2. String->color conversion, in particular web colors and hex (e.g. `#ffff00`).

3. RGB, HSV, and CIELAB space support.

4. Storing multiple (or single) colors. This is done by using the `ColorArray` class. This makes using many colors or a single color straightforward (see tests and class docstring). This should essentially cover both single-color and `Palette` use cases.

5. Basic linear gradient support. Based on how `ColorArray` is structured, this took only a few fairly trivial lines.

The goal of the `ColorArray` class is to basically keep everything stored in an Nx4 `._rgba` element. Setting the HSV or Lab values changes the underlying `_rgba` element. I chose to use `np.float64` representations for `_rgba` now to keep calculations as accurate as possible, but there is an argument for possibly making them `np.float32` for easy transfer to/from the GPU.

Feel free to take a look if you'd like, @lcampagn in particular I'd like to know if you can see any way the `ColorArray` class could hook into the `gloo` pipeline, since it would be very nice to keep the manipulation commands similar to how they are now.