[ACCEPTED]-Generate unique colours-color-space

Accepted answer
Score: 13

Using the RGB color model is not a good 8 way to get a good color mix. It's better 7 to use another color model to generate your 6 color, and then convert from that color 5 model to RGB.

I suggest you the HSV or HSL color model 4 instead, in particular you want to vary 3 the Hue.

If you want X different color values, vary 2 them from 0 to 360 with a step size of 360 1 divided by X.

Score: 4

Whats your sample space... how many items 5 are we talking.

You could build up an array 4 of RGB Triples from

for(int r = 0; r < 255; r = r+16)
   for(int g = 0; g < 255; g = g+16)
      for(int b = 0; b < 255; b = b+16)
           // take r, g, b and add it to a list

Then randomise your list 3 and iterate through it. that'd give you 2 16^3 (4096) different colors before a repeated 1 color.

Score: 4

In general RGB isn't a great color space 9 for doing these sorts of things because 8 it's perceptually nonlinear, for starters. This 7 means that equal distances moved between 6 RGB triplets do not look equally different 5 to our eyes.

I'd probably work in the L*c*h* space 4 (see also) space, or HSL space, and just generate 3 a uniform spacing in hue. These spaces 2 have been designed to be approximately perceptually 1 linear.

Score: 2

Google "delta e cie 2000"; the colour-difference 17 formula is useful for determining apparent 16 (visual) distance between 2 colours. (On 15 a monitor; there's a different formula for 14 pigments.) It operates on colours in Lab 13 space (props to simon), but applies a perceptual 12 calculation of difference.

We found that 11 a number around 1.5 was sufficient to ensure 10 visually distinct colours (i.e. you can tell the 9 difference if they are near one another), but 8 if you want identifiable colours (you can find any colour 7 in a legend) you'll need to bump that up.

As 6 to creating a set of colours... I'd probably 5 start at some corner of Lab space, and walk 4 around it using a step size that gives large 3 enough visual differences (note: it's not 2 linear, so step size will probably have 1 to be adaptive) and then randomize the list.

Score: 0

This is very similar to the four-colour 3 problem relating to colouring maps, this 2 might yield some interesting solutions for 1 you:

Four colour theorem

Score: 0

If you just need a set of perceptually-distinct 19 colors (and not an algorithm to generate 18 them) I have created a free tool on my website 17 that does just that:

Instead of just using 16 even spacing in RGB or HSV space (which 15 are not uniformly distributed with respect 14 to human perception) the tool allows you 13 to generate a grid of values in HSV space 12 and it then uses the CMC(I:c) standard for color 11 distance to throw out colors that are perceptually 10 too close to each other. (The 'threshold' slider 9 on the second tab allows you to control 8 how visually distinct the colors must be, showing 7 you the results in realtime.)

In the end, you 6 can sort your list of generated colors by 5 various criteria, and then evenly 'shuffle' that 4 list so that you are guaranteed to have 3 visually-distinct values adjacent to each 2 other in the list. (I recommend an 'Interleave' value 1 of about 5.)

As of this writing the tool works well with Chrome, Safari, and (via a shim) Firefox; IE9 does not support HTML5 range input sliders, which the UI uses extensively for interactive exploration.

More Related questions