Skip to content

Instantly share code, notes, and snippets.

@stdclass
Forked from 140bytes/LICENSE.txt
Created May 17, 2011 17:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stdclass/976877 to your computer and use it in GitHub Desktop.
Save stdclass/976877 to your computer and use it in GitHub Desktop.
Make RGB Colors Lighter / Darker
/*
* 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
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)]}
{
"name": "color",
"keywords": [ "color" ]
}
@140bytes
Copy link

How about using sign instead of booleans to determine lighter/darker?

@p01
Copy link

p01 commented Jun 2, 2011

@140bytes see my 73bytes long fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment