title: Map a range of values (e.g. [0,255]) to a range of colours (e.g. rainbow: [red,blue]) in JavaScript
body: <p>I'm sure this must be a fairly straightforward, but it's a difficult question to word. I don't even know what to google for.</p>
  
  <p>I'm not looking for any complicated solution. Basically, I'm drawing lines on a Canvas, and I want different colours depending on the length of the line. Usually I just scale, say, the red channel (#ff0000 * (length of line)/(maximum line length)), but this solution isn't ideal. I'm just looking for an equation that will give me a #rrggbb value for a certain position on a rainbow gradient, if that makes sense.</p>
  
  <p>Thank you to whoever can help with this! It's very much appreciated.</p>