I would like to know how to calculate a set of colors that will be distinct from each other.
My application will involve many (up to 100 or more?) distinct items that I want to graph; I would like each one to have its own color, and for that color to be distinguishable from other colors on the graph. I suppose if I just get 100 (or 200) distinct colors I can put them in an array and use them that way, but I still have to figure out what they would be.
I've searched enough to convince myself that, if this can be found, I don't know the right keywords to use.
Does anyone have color-generating algorithms that take into account whether the colors are liable to be visibly distinct?
A secondary goal, of course, is to have them reasonably pleasant to look at.
I have no idea how to generate 100 different colors that are evenly distributed about the spectrum but you might find the HSL Color easier to work with. Maybe you can start by creating 30 different Hues. Then for each hue you create 4 different tones/shades.
Joined: May 29, 2005
Perhaps I should have said "100 Color objects". I don't care whether the algorithm to generate them uses hex, int, or sanskrit, as long as I can get a color object out each one.
I don't care if they are uniformly distributed -- not a goal here. I've tried loops of integers making different red, green, and blue values to make colors with, and have generated enough palettes to make me dizzy. But it seems like the colors are all garish, or too hard to distinguish from one another, and I'm hoping for something that will do better.
Perhaps there isn't such a thing -- perhaps color theory hasn't gotten this far yet, and all the people who deal with things that need colors get a palette from some human that did it manually. But I keep hoping (and, in this case, asking).
There are, with java.awt.Color, 16 million different colors possible (actually 16,777,216 or 256^3). They can all be represented as ints between 0 and 16,777,215. If we change that to HEX you get FFFFFF, better known as white. So what you can do is start at color 0 (HEX 000000, black), then add a number each time (e.g. FFFFFF / 100). Color has a constructor that can take such an int.
That said, this will indeed generate random colors. That's because to a computer, a color is nothing more than a number (or a set of numbers if you separate into RGB). It can't tell if color FF46A3 is a nice color or not.
OP here -- I think I've satisfied myself that the answer to my question is: "There isn't one, really".
There is the set of "Internet Safe Colors", which start from 00 00 00 and add 33 hex to each of the red, green, and blue values in turn to get a set of RGB colors; this is the KIND of algorithm I was looking for, but the resulting colors are not always easily distinguishable from each other, and the 33 hex appears arbitrary, chosen for its calculation convenience as opposed to anything about the resulting colors.
There's the "X11 color" set, which (according to Wikipedia) is just a set that's been included in X installations for so long no one really remembers where it came from. The latter's primary purpose appears to be to map each color to a name so it can be specified by name. I have not detected a pattern to the numbers that result in the colors that I can use to calculate them.
Someone pointed out that regular JPG files only have 256 colors, and that asking to get 100 that were all distinct is likely a tall order. It's good to keep that in mind.
So I'm back to storing a list of colors for what I want to do, and going through the tedious job of choosing such colors (something I wish I had more talent for).
I discovered an additional requirement -- since I am putting text in the same box as the color, I need the color to be light enough that black text will show up reasonably well.
Thanks to all that posted -- I did learn things about colors from the suggestions and code posted here. If someone's really interested, I'll post my set of colors when I feel like I've got a reasonable set.
Thanks for the link. This does not do what I want either; many pairs of colors in that palette are not easily distinguished from each other. Second, what I want (or wanted) was an algorithm to generate those colors, and the example program just uses the standard javaJColorChooser. I suppose I could look up the source for that, but it doesn't actually do what I want.