Skip to content

Instantly share code, notes, and snippets.

@rmehta
Created December 18, 2012 06:49
Show Gist options
  • Save rmehta/4325643 to your computer and use it in GitHub Desktop.
Save rmehta/4325643 to your computer and use it in GitHub Desktop.
Get a lighter / darker shade
var get_hex = function(i) {
i = Math.round(i);
if(i>255) return 'ff';
if(i<0) return '00';
i =i .toString(16);
if(i.length==1) i = '0'+i;
return i;
}
var get_shade = function(color, factor) {
if(color.substr(0,3)=="rgb") {
var rgb = function(r,g,b) {
return get_hex(r) + get_hex(g) + get_hex(b);
}
color = eval(color);
}
var get_int = function(hex) {
return parseInt(hex,16);
}
return get_hex(get_int(color.substr(0,2)) * factor)
+ get_hex(get_int(color.substr(2,2)) * factor)
+ get_hex(get_int(color.substr(4,2)) * factor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment