6

Is there a good way to iterate over colors? I know it sounds like a strange question but here's an analogy.

Suppose you write a game where you travel around the Earth. You pick a starting point and then you define a rule that you apply repeatedly. For example: Start at your current location on Earth and then define the great circle that goes through your location and the North and South poles. For every step, travel 10 miles along this circle. Each step takes you to a similar climate as the one before (although sometimes you're awfully wet because you're in the ocean). Or travel 6,000 miles for each step. Now each step is a very different climate.

Now imagine a program that draws elements on the screen with random colors. Maybe you set the increment to a low number, and each color is very similar to the one before. Maybe you set it high, and each color is very different from the one before.

If you use RGB values and increment the R, G and B each by a small amount you get gradual changes until one of the values wraps and you get a sudden change.

With HSB values, the gamut of Hues is circular, so there is no discontinuity. S and B are not, and you may run into a stretch of indistinguishable colors because S is so low that they all look white. Keeping S and B at max is a possibility, although it leaves out a lot of colors.

Each run of the program uses only a small number of colors (10 to 15). I would like to pick values at random so that one time the colors blend harmoniously, one time they clash, one time they are all pastels, one time they are a mix of saturated and pastel, etc.

Mark Lutton
  • 6,567
  • 6
  • 36
  • 52
  • Another way to think of this is "cycling through the colors". Where H, S and B are each 8 bits, keep S and B at 256 and increment H by 1 or 11 or 61. But this will get only 256 colors. Are 256 colors all there are in the world? Or are there some colors with other values of S and B that are different and interesting enough to include? If so, which ones are they, and how do you cycle through them while leaving out the millions that look just like white or black? – Mark Lutton Sep 11 '09 at 14:51

2 Answers2

2

If you draw a color wheel, you can get complementary colors by selecing from the opposite side of the color wheel.

Here's an page that has several variations on that idea, and a nice interactive application to explore them.

http://colorschemedesigner.com/

Mark Harrison
  • 267,774
  • 112
  • 308
  • 434
0

You can do better than 256 colors by thinking about the HSL bicone (see wikipedia HSV/HSL page). It looks a bit like a sphere already and it wouldn't take too much work to translate each point on a sphere to a point on the surface of the bicone. Now the color walking is the same as your planet walking. You're still missing out on desaturated colors, including grays. You could do the same thing with an RGB color cube: just imagine walking the surface -- pick a constant direction or move randomly.

Probably simpler though is to just modify your original RGB idea to use reflection instead of wrapping. If you're at (50, 100, 255) and your step increment is (1, 2, 3), your next color is (51, 102, 252) and your increment is adjusted to (1, 2, -3).

xan
  • 6,931
  • 2
  • 29
  • 43