-
-
Save stdclass/976877 to your computer and use it in GitHub Desktop.
Make RGB Colors Lighter / Darker
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
/* | |
* Make RGB-Colors lighter / darker | |
*/ | |
var color = function(c,m,f,d){d=Math.round(f?f:0.2*256)*(m?-1:1);function k(i){return Math[m?'max':'min'](c[i]+d,m?0:255)}return[k(0),k(1),k(2)]} | |
/** | |
* @param array RGB Colors | |
* @param bool (false)(default) Lighter / (true) Darker | |
* @param floar Ratio (default: 0.2 ) | |
*/ | |
color( [255, 100, 100 ], false, 0.3 ); // makes rgb(255,100,100) 30 percent lighter | |
color( [255, 100, 100 ], true, 0.3 ); // makes rgb(255,100,100) 30 percent darker |
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
function(c,m,f,d){d=Math.round(f?f:0.2*256)*(m?-1:1);function k(i){return Math[m?'max':'min'](c[i]+d,m?0:255)}return[k(0),k(1),k(2)]} |
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
{ | |
"name": "color", | |
"keywords": [ "color" ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about using sign instead of booleans to determine lighter/darker?