I like the random color generation algorithm proposed here by David Crow, but I wonder if there's a way to focus its results around a single color and regulate the results.
My program will be generating graphs that track a number of variables. Each variable belongs to one of 7 categories. I'd like to generate line-colors for these variables that are legible, unique and for which the hue, saturation and luminosity are within a proximate range of a root color which is associated with their category. For example, category Red's variables would be various legible and discernible variations on red.
One solution might be to declare a root color, plus upper and lower boundaries for hue, saturation and luminosity. I could then randomly pull values from within those ranges, but is there a better way to hopscotch within those three dimensions so that the resulting colors have a decent amount of variation, but still leaving space to grow? For example, assume each pipe is a range value and each line is an iteration:
01 > |---------------|---------------|
02 > |-------|-------|---------------|
03 > |-------|-------|-------|-------|
04 > |---|---|-------|-------|-------|
05 > |---|---|---|---|-------|-------|
06 > |---|---|---|---|---|---|-------|
07 > |---|---|---|---|---|---|---|---|
08 > |-|-|---|---|---|---|---|---|---|
09 > |-|-|-|-|---|---|---|---|---|---|
10 > |-|-|-|-|-|-|---|---|---|---|---|
11 > |-|-|-|-|-|-|-|-|---|---|---|---|
12 > |-|-|-|-|-|-|-|-|-|-|---|---|---|
13 > |-|-|-|-|-|-|-|-|-|-|-|-|---|---|
14 > |-|-|-|-|-|-|-|-|-|-|-|-|-|-|---|
15 > |-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
What's the best way to do this? Or is this even the best solution to my problem? A single graph may not plot more than 4 or 5 variables, but the number of variables which can be plotted could be in the hundreds.
Thanks for your help.
You can look at this as a sphere-packing problem in 3D: you want your colors a uniform distance from each other. The best arrangement for this depends on the number of variant colors you need, and finding an optimal solution is not simple. However, a simple mechanism might be to save a sequence of face-centered-cubic coordinates, starting at (0,0,0) and ordered by distance from this origin, and use them in sequence as offsets to your "base" color (scaled by a parameter which sets how different from each other they should look).
If you want to pay maximal attention to detail, note that researchers in color theory and perception have measured the minimum discernible color difference, across the visible gamut. You can use this data adjust your color offset vector (using matrix multiplication, in lieu of the above-mentioned simple scaling), to ensure that your color differences look the same.