title: Map integer to color in rainbow spectrum
body: <p>I want to color <strong>k</strong> clusters of points in a 2D grid. Right now I using a naive approach.</p>
  
  <p>I'm using RGB to set a color, the G component is fix, R is counted down gradually, B is counted up gradually. So the first cluster has R set to 255 and the last to 0, vice versa for B.</p>
  
  <pre><code>int r = 255, g = 80, b = 0;
  // do stuff
  int step = 255 / k;
  // loop over data
  int cluster = getCurrentCluster();
  int currentR = r - (cluster * step);
  int currentG = g;
  int currentB = b + (cluster * step);
  </code></pre>
  
  <p>The current solution is working and effektive. It's possible to differentiate the clusters by colors</p>
  
  <p><img src="https://i.stack.imgur.com/nxVCP.png" alt="colored voronoi cells that show result of cluster analysis with k-means clustering. K is set to 30, number of elements is 5M, image dimension is square with 1M pixels"></p>
  
  <p>But I don't like it, and would prefer rainbow colors or at least a richer spectrum.</p>
  
  <p>How can I achieve that? How can I map an integer in interval [0, k) to a color that meets my requirements?</p>
  
  <p>Another approach that came to my mind was to map the integer to a wave length in a given interval, e.g. 400 nm to 800 nm (should roughly be the rainbow spectrum, if I recall correctly) and convert the wavelength to RGB.</p>