I am trying to generate colors on the fly for a chart control. I want the colors to be visually distinctive. I don't just want the colors to be distinctive from the adjacent colors, but all colors generated so far.
I also don't want to have to have a known color collection size. Some algorithms I have seen for this require the number of things to color to be known. I want to implement a GetNextColor() for my color generator so I will not know at the time of choosing how many colors I will ultimately have and choosing a number up front feels wrong.
I am not just trying to graph a bunch of stuff in different colors, I am interested in this problem and want some feedback.
Here's where I'm at:
- Using the HSV color space.
- The hue is a value from [0-360] where 0
and 360 are the same (reddish).
- Hue starts at 0, I ad 27 (so that
when it cycles around it doesn't land on the same color it started
on), take MOD 360.
- For S and V (both between 0 and 1) I start out at a low number like
.25
- Run through about 20 hues
- Then take a high number like .85
- Run through 20 hues
- Then start bisecting to get the most distant
values that haven't been used yet.
This isn't a very effective method, it works OK, but it could be much
more scientific. It started out with a lot of thought and then
morphed into this mess.
Any ideas on how to do this elegantly?
(It shouldn't matter, but I am using C# and I will post code when I get back to my computer I have all this stuff on.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…