Re: Unique Set of n Colors
Re: Unique Set of n Colors
- Subject: Re: Unique Set of n Colors
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 23 Jul 2007 13:30:27 -0700
On Jul 23, 2007, at 1:00 PM, I. Savant wrote:
I need to generate a set of n unique colors for use in a pie chart.
The set of colors must be unique and sufficiently distinct whether n=1
or n=100 (I realize the higher the 'n', the less distinct the colors
will be). The colors must also be distributed such that red and
slightly-darker-red aren't right next to one-another.
Further, the set of colors cannot be randomly generated. This is the
problem I'm running into with the examples I've been able to google so
far; the set of colors must be exactly the same for n from one run to
the next. Randomizing the channels fails my requirements as I have a
rather strict storage space requirement and an integer representing a
"color scheme" or "mode" is far nicer than a set of up to 100 colors
for each pie chart the user cranks out.
I've spent a good hour googling around, trawling the cocoa-dev
archives, etc. but cannot find a good approach. This, of course, is
after spending *more* hours trying to develop something on my own that
looks good, but to no avail.
Do any of you graphics guys / gals have anything useful or know of
any good examples or open-source projects that do something similar?
I have needed to do something like this over the years in a number of
contexts...
It is pretty easy:
- start with the Hue/Saturation/Brightness colorspace.
- Create N colors by creating N different Hues, starting with a value
of zero and adding (N * (1/N)) to the hue to create each color
Hue 0 and Hue 1.0 are the same; bright red. So, you'll want to cap it
at about, say somewhere around 0.9 -- (N * (0.9 / N)) for each
increment.
You can then reorder the resulting array of colors to achieve more
slice-to-slice contrast. I generally found that taking every third
color was pleasing... that is, if you needed 9 colors and generated:
123456789
You would reorder it as:
147258369
This also allows you to play with the saturation and brightness to
make the overall appearance less of a pure color eye explosion.
b.bum
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden