title: How do I generate contrasting colors?
body: <p>My application contains a line graph which can display 20 or more datasets at once, but typically it will be displaying less than 5. I'd like each dataset to have a unique color. </p>
  
  <p>Currently I'm doing this:</p>
  
  <pre><code>setHsl(i * 255.0 / session-&gt;getNumDataSets(), 255, 128);
  </code></pre>
  
  <p>It works, but has the downside that two consecutive datasets will have very similar colors. I'd like it so that each color generated will be as contrasting as possible against all previous colors generated. </p>
  
  <p>What is a better way to generate the colors?</p>
  
  <p>Here is my second attempt:</p>
  
  <pre><code>double pos = 0;
  if (wheel.size() == 0)
  {
      wheel.append(0.0);
      wheel.append(1.0);
  }
  else
  {
      double gap = 0;
      double hi = 0;
      double lo = 0;
  
      for (int i = 0; i &lt; wheel.size() - 1; i++)
      {
          double g = wheel[i + 1] - wheel[i];
          if (g &gt; gap)
          {
              gap = g;
              lo = wheel[i];
              hi = wheel[i + 1];
          }
      }
  
      pos = (hi - lo) / 2.0 + lo;
  
      wheel.append(pos);
      qSort(wheel);
  }
  
  QColor c;
  c.setHsl(pos * 255.0, 255, 128);
  return c.toRgb();
  </code></pre>
  
  <p>My idea is that the first color, is position 0 on the color wheel. Then for every following color, I go around the color wheel, looking for the biggest gap between colors, and once I've found it, I insert a new color into that gap. It seems to work better, but still isn't perfect, since once the gaps become small, consecutive colors become similar again.</p>