Question

I'd like to create a function to give N equidistant RGB colors. How do we define "distance" in this case? Well, I'm not too sure, but I was thinking to use a color wheel definition.

Color wheel

Hence, if I can create a method such as

public Color colorForAngle(int theta)

Then I would be able to divide 360/N and then extract out the N equidistant colors. Does that make sense? Anyone have a better idea how to get equidistant colors in Java? Anything built in that might help?

The point here is to find N colors that are sufficiently (or as much as possible) dissimilar. For instance, if N was 3, then the colors [255, 0, 0], [0, 255, 0], and [0, 0, 255] seem as far apart as possible.

Was it helpful?

Solution 2

The important point here is that there is no exact answer, different color spaces have (slightly) different color wheels. I think that the "best" color space for this purpose would be the CIELAB as noted in an answer to Function for creating color wheels , because this was designed to approximate human vision.

However, Java has no built-in support for CIELAB, so either you write the support for it, or you can say that HSB is "good enough" (probably it is), and use Color.getHSBColor as noted in other answers.

OTHER TIPS

This sounds like it would be better suited to use HSV rather than RGB, as extracting equidistant colors from a circular representation of the color spectrum would be trivial.

As Andrew noted, you could use the following function: Color.getHSBColor(H,S,B)

Well I can't say about a wheel,but long back I wrote an animation,Where i changed the colour's after a specific time.The main lines:

            colorIndex++;  // A number between 0 and 100.
            if (colorIndex > 100)
               colorIndex = 0;
            float hue = colorIndex / 100.0F;  // Between 0.0F and 1.0F.
            display.setColor( Color.getHSBColor(hue,1,1) );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top