Generating a rainbow?
gherron at islandtraining.com
Thu Apr 8 19:14:43 CEST 2010
> I'm having a difficult time with this. I want
> to display a continuous range of hues using HTML
> hex representation (#RRGGBB). How would I go
> about scanning through the hues in order to
> make a rainbow?
Use the hue-saturation-value color space, and call hsv_to_rgb from the
standard Python library to convert to RGB. Enjoy!
from colorsys import hsv_to_rgb
for hue ....:
rgb = hsv_to_rgb(hue, saturation, value)
Let 'hue' run from 0 (red) through 2/3 (blue) Hues from 2/3 to 1 get
into purples and magentas, which are not spectral (i.e., rainbow) colors.
Set 'saturation' to perhaps 0.5 (for a washed out effect) through 1.0
(for pure color). Even an intensely colorful rainbow has lots of white
light mixed in with it; a saturation of 0.5 is probably good.
Set 'value' to something in the range of 0 to 1 to control brightness.
More information about the Python-list