Created
February 3, 2015 07:48
-
-
Save azzlack/cdadf79aacfe0ca92da7 to your computer and use it in GitHub Desktop.
Change a colors luminosity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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