JavaScript. I have an array of numbers
var values = [1,20,12,6,9];
I need to create a new array of the same size such that:
"#3E296B"
"#FFFFFF"
. "#3E296B"
segueing into "#FFFFFF"
proportionately to their valuesi.e. my new array should be approximately like: var colors = [white, blue, less_blue, less_less_blue, less_blue]
(I wrote in words to simplify)
Here is a library that solves this exact problem:
https://github.com/anomal/RainbowVis-JS
So after including it you would do something like:
var rainbow = new Rainbow();
rainbow.setSpectrum('#ffffff', '#3E296B');
rainbow.setNumberRange(1, 20);
rainbow.colourAt(number); // based on the numbers from your array, this would return the color you want