somewhat OT: function to produce n as distinct colors as possible

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Wed Jun 16 04:53:35 EDT 2004


On Wed, 16 Jun 2004 11:13:42 +0300, rumours say that Edvard Majakari
<edvard+news at majakari.net> might have written:

>Ok, not strictly Python related: I wonder if any of you graphical Python
>folks have run accross some handy resource for the given topic.

>The problem is that of producing histograms, where n distinct items can be
>plotted simultaneously. However, when n goes over 6 it is not very easy to
>make up colors that are easily distinguishable from each other. So, now
>I'm thinking of two alternatives:

>1. Create an algorithm distinct_colors(n, bg), which produces n-1 as
>   distinct colors as possible (where bg is one of the colors) and returns
>   those colors in RGB color model as tuple of decimals (r, g, b). 
>
>   Eg. distinct_colors(4, (255, 255, 255)) would return
>
>   ((255, 0, 0), (0, 255, 0), (0, 0, 255))
>
>  assuming that "pure-rgb" red, green and blue are visually the three as
>  distinct colors as possible from white.

[snip]

I think the algorithm would be easier in the (hue, saturation,
brightness) domain instead of the (red, green, blue) one.  Try selecting
colours evenly spaced in the hue axis.

The colorsys module shall be your good friend for conversions to and fro
:)
-- 
TZOTZIOY, I speak England very best,
"I have a cunning plan, m'lord" --Sean Bean as Odysseus/Ulysses



More information about the Python-list mailing list