views:

207

answers:

2

Hi all,
Here's my situation. Say I have two columns of data containing different elements. I'd like to highlight with a different color, all matching elements between those two columns. Each of those elements has an ID, so I was thinking of creating a mapping function to tie an ID to a hex color. Any suggestions?

This is what I was thinking: Add an arbitrary number, say 111, to each hex number to generate the new color (and mod it take care of overflow)... so 111*id + Starting hex number.

Is this reasonable? Does anyone have a suggestion for the 111 so that the colors are diverse early on, but don't mod to the same value that quickly? Say I'd like 50 unique colors, as diverse as possible.

Thanks,
Michael

+1  A: 

http://stackoverflow.com/questions/180/function-for-creating-color-wheels

This will be of help

DevDevDev
+1  A: 

While the HSV colour space is probably better in terms of giving you "different-looking" colours, RGB is probably "good enough".

You could just let Red, Green and Blue be one of {0, 40, 7F, FF}. This gives 4x4x4 = 64 colours. Something like this:

Red = ID % 4
Grn = (ID / 4) % 4
Blu = (ID / 16) % 4

print hex(floor(Red * 255 / 3)) //etc

The human eye is supposed to detect changes in Green more readily than Red/Blue. So if you need some more colours you can let Red and Blue take on 4 possible values and Green take on 5 (giving 80 colours).

If you don't want consecutive IDs to be too close together in colour you can create an array that maps IDs to a shuffled set of numbers.

Also if your IDs aren't all nicely consecutive from 0 to 63 then you could make your program find all the IDs that are actually used and map them to numbers between 0 and 63.

Artelius