title: Convert a number between 1 and 16777215 to a colour value
body: <p>I'm trying to convert a number between 1 and 16,777,215 to any colour format (RGB/HSL/HEX) that increments through the colour spectrum using Javascript/jQuery. </p>
  
  <p>The number 16,777,215 is the total possible combinations of RGB(255,255,255) which is 32 bit colour. </p>
  
  <p>I initially thought converting the value to a hex value using toString(16) would increment through the spectrum, however as the number increases it seems to work through different lightness values instead and flashes. An example of this unwanted behaviour is here <a href="http://jsfiddle.net/2z82auka/" rel="nofollow noreferrer">http://jsfiddle.net/2z82auka/</a></p>
  
  <pre><code>var colour = 16777215;
  window.setInterval(function(){
      colour -= 1000;
      $('body').css({background:'#' + colour.toString(16)});
  }, 50);
  </code></pre>
  
  <p>How can I convert a value between 1 and 16777215 to a colour on the colour spectrum shown below?</p>
  
  <p><img src="https://i.stack.imgur.com/Tw550.png" alt="Wanted outcome"></p>