How to calculate gradient color with javascript

Sometimes, in a table or an area, several colors of the same color from light to dark are needed, as shown in the figure:

if the required colors are few, the color difference is large, and the required colors are small, the color difference is small, as follows Figure:






At this time, the calculation of the gradient color of the same color system is used. The algorithm is as follows:

function getItemColors (colorLevel) {
    var colors= [];
    //default darkest color
    var red = 134,green = 108, blue = 184;
    //The lightest color is 239,239,239 For example: the lightest color red is 239, then the difference is 239-134=105
    var maxRed = 105, maxGreen = 131, maxBlue = 55;
    var level = colorLevel;
    while(level--) {
       colors.push( 'rgb('+red +','+green+','+blue+')');
       red += parseInt(maxRed/colorLevel);
       green += parseInt(maxGreen/colorLevel);
       blue += parseInt(maxBlue/colorLevel);
    }
    return colors;
}

*&**&**&**&**&**&**&**&**&**&*Happy dividing line*&**&**&**&**&** &**&**&**&**&**&**&*
I'm getting married soon, happy

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326456877&siteId=291194637