Karsten Wutzke wrote:
> if I don't find a good algorithm to do a nice randomize
> of the colors so that similar colors are pretty much scattered linearly
> in the array: All red-like colors, if there are 6, appear at indices 0,
> 6, 12, 18, 24, 30.
>
> Does anyone have an idea of how one of these algorithms might look like?
>
> BTW: I only need 36 colors. These are the hues in a 360 deg color circle.
Okay, so if you want pure colors, look into the HSV color space, and fix
V and S at 100%. Now you can vary hue, which varies from 0 to 360
degrees in a circle.
At this point, your problem description breaks down, and there are
multiple solutions depending on your definition of "similar".
Specifically, you can make any number (up to one less than the number of
colors) of revolutions around the circle. With only one revolution,
you'll get colors that are evenly spaced in progression around the
circle so that consecutive colors are similar. With 31 revolutions, I
think you'll you get the greatest possible distance between consecutive
colors while still spacing the colors evenly. In your example of having
6 "red-like" colors that you'd like to space evenly, you'd choose to
make 6 revolutions.
In any case, for n colors and r revolutions around the color circle, the
distance in degrees of hue between consecutive colors is given by:
360 * r / (n - r + 1)
That formula is designed to just miss a making a complete 360 degree
revolution by enough to ensure that your final color distribution is
evenly spaced.
From there, you probably need to convert the HSV color space to RGB.
You should be able to find sample code for that from Google without
difficulty. If you can't, I've got some code around somewhere that I
could look up; some students of mine used HSV some time ago to choose
random brown-like colors for asteroids in an Asteroids game clone during
a middle-school class I taught; I'm sure they wouldn't mind my sharing
the code.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation