From: Tobiah on 8 Apr 2010 12:46 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? Thanks, Toby From: Chris Colbert on 8 Apr 2010 13:06 On Thu, Apr 8, 2010 at 12:46 PM, Tobiah wrote:> 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? > > Thanks, > > Toby > -- > http://mail.python.org/mailman/listinfo/python-list > In [43]: possible = [] In [44]: for i in range(2**8): ....: h = hex(i).lstrip('0x') ....: while len(h) < 2: ....: h = '0' + h ....: possible.append(h) ....: ....: In [45]: full = [r + g + b for r in possible for g in possible for b in possible] In [46]: len(full) Out[46]: 16777216 In [47]: 2**24 Out[47]: 16777216 From: Richard Thomas on 8 Apr 2010 13:08 On Apr 8, 5:46 pm, Tobiah wrote:> 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? > > Thanks, > > Toby Look at the colorsys module. http://docs.python.org/library/colorsys.html?highlight=colorsys#module-colorsys From: Tobiah on 8 Apr 2010 13:14 > Look at the colorsys module.> > http://docs.python.org/library/colorsys.html?highlight=colorsys#module- colorsys That so rocks. Thanks! From: Gary Herron on 8 Apr 2010 13:14 Tobiah wrote:> 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? > > Thanks, > > Toby > Use the hue-saturation-value color space, and call hsv_to_rgb from the standard Python library to convert to RGB. Enjoy! Gary Herron 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.  |  Next  |  Last Pages: 1 2 3 4 Prev: catch clipboard status in gnomeNext: Pythonic list reordering