Skip to content

Instantly share code, notes, and snippets.

@azzlack
Created February 3, 2015 07:48
Show Gist options
  • Save azzlack/cdadf79aacfe0ca92da7 to your computer and use it in GitHub Desktop.
Save azzlack/cdadf79aacfe0ca92da7 to your computer and use it in GitHub Desktop.
Change a colors luminosity
var changeColorLuminosity = function (hexcolor, luminosity) {
var hex = hexcolor.replace(/[^0-9a-f]/gi, '');
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i * 2, 2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * luminosity)), 255)).toString(16);
rgb += ("00" + c).substr(c.length);
}
return rgb;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment