Skip to content Skip to sidebar Skip to footer

Generate Gradient Step Based On Dynamic Value, Including Decimals

Based on this question, which has a fabulous answer for values from 0..1, I tried to modify the function to include the min and max values. function getColor(value, min, max){

Solution 1:

This seems to work very well:

functiongetColor(value, min, max){
    if (value > max) value = max;
    var v = (value-min) / (max-min);
    var hue=((1 - v)*120).toString(10);
    return ["hsl(",hue,",100%,50%)"].join("");
}

edit: adjusted based on comments below

Post a Comment for "Generate Gradient Step Based On Dynamic Value, Including Decimals"