Stable random color algorithm

Posted by Olmo on Stack Overflow See other posts from Stack Overflow or by Olmo
Published on 2010-06-02T01:26:28Z Indexed on 2010/06/02 1:33 UTC
Read the original article Hit count: 458

Filed under:
|
|
|
|

Here we have an interesting real-world algorithm requirement involving colors.

1) Nice random colors: In ordeeing to draw a beautifull chart (i.e: pie chart) we need to pick a random set of Colors that:

a) are different enought

b) Play nicely

Doesnt Look hard. For example u fix bright and saturation and divide hue in steps of 360/Num_sectors

2) Stable: given Pie1 with sectors with labes ('A','B','C') and Pie2 with sector with labels ('B','C','D'), will be nice if color('B',pie1)= color('B',pie2) and the same for 'C' and so on, so people don't get crazy when seeing similar updated charts, even if some sectors appear some dissapeared or the number of sectors changed. The label is the only stable thing.

3) hard-coded colors: the algorithm allows hardcoded label->color relationships as an input but stills doing a good work (1 & 2) for the rest of free labels.

I think this algorithm, even if it looks quite ad-hoc, will be usefull in more then one situation.

Any ideas?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about color