3

Suppose that we want to color a number of objects. We start by selecting some color (randomly). Then we want the color of the next object to be significantly different from the colors already used (including the background color, say white). After a number of attempts I was unable to find any smart way to do this. Suppose that the RGBColor model is used. Then my best result was

cl = {RGBColor[1., 1., 1.]};

myFun1[colList_List, {x_?NumericQ, y_?NumericQ, z_?NumericQ}] := 
  Last[ColorDistance[colList, RGBColor[x, y, z], DistanceFunction->"CIE94"]]

oneStep1[cl_List] := 
  (Append[cl, RGBColor[x, y, z] /. 
     Last[NMaximize[
       {myFun1[cl, {x, y, z}], 1 >= x >= 0, 1 >= y >= 0, 1 >= z >= 0}, 
       {x, y, z}]]])

Nest[oneStep1, cl, 5]

Clearly, the result is not good enough (I need at leas 10 significantly different colors).

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Acus
  • 3,669
  • 14
  • 21
  • 3
    Any reason why you couldn't use a pre-defined color space? Table[ColorData["BrightBands"][i], {i, 0, 1, .1}] There are a number of both continuous and discrete sets. – Andy Ross Sep 29 '15 at 13:09
  • @user18792 Isn't this the same question: http://mathematica.stackexchange.com/questions/38722/discrete-colordata-scheme-with-n-colors? – Michael E2 Sep 29 '15 at 16:45
  • Or possibly this: http://mathematica.stackexchange.com/questions/23647/calculating-pleasant-colors-for-source-code-or-web-design/23649#23649? – Michael E2 Sep 29 '15 at 16:47
  • 1
    Is it really necessary to search for suitable colors one after another? I think results should be more pleasant when they're optimized all together. – kirma Sep 29 '15 at 17:05
  • Predefined colors is not good for the following reasons: – Acus Sep 30 '15 at 06:47
  • Objects are generated in the fly (i.e. I dont know in advance how many colors I will need) and 2) I want to give user a chance (an option) to select the color of an object in time of generation. Under this circumstances it is clear that any predefined colors will interfere with user choice. @kirma solution gives good colors, however I would like a strategy, when number of colors is not known in advance.
  • – Acus Sep 30 '15 at 06:56
  • @user18792 Personally, I would pre-generate large number of colors, and then find the "furthermost" color from all reference colors on this set and move this color as the next color to the reference color set, then repeat this process until color list to choose from is empty. This would allow some global planning, but also guarantee that colors being added start with clearly separate ones, and "fill the gaps" later on. Regarding a strategy - I suspect amount of properly distinct colors one can generate is relatively limited, and thus a pre-computed color list would be a good bet. – kirma Sep 30 '15 at 07:17
  • @kirma And then what to do with the user specified colors? His/her choise is free (not limited to the pre-generated colors). Then I will still need procedure to find and remove pre-generated colors which are "closest" to the user's choice. – Acus Sep 30 '15 at 07:40
  • @user18792 Ah, yes, that considerably complicates the problem! In general, I'd want to replace Mma-supplied opaque ColorDistance function with a sufficiently good polynomial approximation, possibly optimized specifically for suprathreshold color difference measure (built-in color distance functions are really designed to measure perceptual "sameness" acceptability of colors, for instance for manufacturing and other reprocution purposes). I suspect this could drastically speed up computation of color groups. – kirma Sep 30 '15 at 07:47