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?
Edit for Eric: you're right that is impossible to guarantee the stability of colors for each label as new labels appear and disappear. But I'm happy if is stable enought.
1.- the less labels change the color, the better
2.- the less the color change, the better
I was thinking in something like:
1.- every label gets a random hue value using hash(label)%360
2.- in order to guarantee that they are different enought, we divide the hue circle in a fixed amount of steps (i.e: 2*num_labels) and try to 'round' the previous hue values to the new differentiated ones
3.- in the case of different labels going to the same rounded hue value, we break the tie somehow and move the point somewhere else.
I'm not really sure how to consider the hardcoded colors then...
Thanks again Erik