How to find equidistant colors in different colorspaces? - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-08-19T09:08:13Z https://mathematica.stackexchange.com/feeds/question/141825 http://www.creativecommons.org/licenses/by-sa/3.0/rdf https://mathematica.stackexchange.com/q/141825 3 How to find equidistant colors in different colorspaces? Majis https://mathematica.stackexchange.com/users/36426 2017-04-04T18:38:11Z 2017-04-04T18:38:11Z <p>I can find equidistant colors in the LAB colorspace. Since, it is complicated, I first calculated the values of a and b for equidistant points on the AB plane and incremented the L values gradually for each point. Below is what I've done so far:</p> <pre><code>getLABColors[n_] := ( RM = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], Cos[\[Theta]]}}; coord = {{1}, {1}}; l = Table[x, {x, 0, 1, 1/(n - 1)}]; ab = Table[RM.coord, {\[Theta], 0, 2 Pi , 2 Pi /(n - 1)}]; a = Table[ab[[i]][][], {i, 1, n, 1}]; b = Table[ab[[i]][][], {i, 1, n, 1}]; labcolors = Table[LABColor[N[l[[i]]], N[a[[i]]], N[b[[i]]]], {i, 1, n, 1}] ); </code></pre> <p>Using this, I can find 6 equidistant colors:</p> <pre><code>labcolors = getLABColors </code></pre> <p>and the result is:</p> <pre><code>{LABColor[0., 1., 1.], LABColor[ 0.2, -0.6420395219202061, 1.260073510670101], LABColor[ 0.4, -1.3968022466674206`, -0.22123174208247431`], LABColor[ 0.6, -0.22123174208247431`, -1.3968022466674206`], LABColor[ 0.8, 1.260073510670101, -0.6420395219202061], LABColor[1., 1., 1.]} </code></pre> <p>When I tried to visualise the points on the 3D Gamut, I found the point lie on the surface of the gamut in the form of a spiral of one complete turn as I wanted.</p> <pre><code>Show[ChromaticityPlot3D["LAB", FillingStyle -&gt; Opacity[0.2]], ChromaticityPlot3D[labcolors, PlotStyle -&gt; PointSize[.02]]] </code></pre> <p><a href="https://i.stack.imgur.com/zG3l9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zG3l9.png" alt="enter image description here"></a></p> <p>I tried to do the same with RGB colorspace but did not get the expected result.</p> <pre><code>getRGBColors[n_] := ( RM = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], Cos[\[Theta]]}}; coord = {{1}, {1}}; b = Table[x, {x, 0, 1, 1/(n - 1)}]; rg = Table[RM.coord, {\[Theta], 0, 2 Pi , 2 Pi /(n - 1)}]; r = Sort[Rescale[Table[N[rg[[i]][][]], {i, 1, n, 1}]]]; g = Sort[Rescale[Table[N[rg[[i]][][]], {i, 1, n, 1}]]]; rgbcolors = Table[RGBColor[N[r[[i]]], N[g[[i]]], N[b[[i]]]], {i, 1, n, 1}] ); rgbcolors = getRGBColors; Show[ChromaticityPlot3D["RGB", FillingStyle -&gt; Opacity[0.5]], ChromaticityPlot3D[rgbcolors, PlotStyle -&gt; PointSize[.02]]] </code></pre> <p><a href="https://i.stack.imgur.com/IjP7B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IjP7B.png" alt="enter image description here"></a></p> <p>(a) What is the correct way to fix this? (b) How can I extend this to other color spaces? (c) Is it possible to achieve this in a far better and faster way than the approach I have followed?</p> <p>[It will be a bonus if the color values for the points can be displayed on the chromaticity plot either statically or on mouse hover.]</p>