I am using the following LightenDarkenColor function to collect lighten and darken colors.
After calling it few times as follows:
var LightenDarkenColor = function(col, amt) {
var usePound = true;
if (col[0] == "#") {
col = col.slice(1);
usePound = true;
}
var num = parseInt(col, 16);
var r = (num >> 16) + amt;
if (r > 255) r = 255;
else if (r < 0) r = 0;
var b = ((num >> 8) & 0x00FF) + amt;
if (b > 255) b = 255;
else if (b < 0) b = 0;
var g = (num & 0x0000FF) + amt;
if (g > 255) g = 255;
else if (g < 0) g = 0;
var output = (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16);
console.log(col + " x " + amt + " = " + output);
return output;
}
LightenDarkenColor('#1d4ed8', 80);
LightenDarkenColor('#1d4ed8', 50);
LightenDarkenColor('#1d4ed8', 20);
LightenDarkenColor('#1d4ed8', 10);
LightenDarkenColor('#1d4ed8', 0);
LightenDarkenColor('#1d4ed8', -10);
LightenDarkenColor('#1d4ed8', -20);
LightenDarkenColor('#1d4ed8', -50);
The output are:
1d4ed8 x 80 = #6d9eff
1d4ed8 x 50 = #4f80ff
1d4ed8 x 20 = #3162ec
1d4ed8 x 10 = #2758e2
1d4ed8 x 0 = #1d4ed8
1d4ed8 x -10 = #1344ce
1d4ed8 x -20 = #93ac4
1d4ed8 x -50 = #1ca6
What I am missing in the LightenDarkenColor() function?
Last two color code does not a valid color code ...