Skip to content

Instantly share code, notes, and snippets.

@chiplay
chiplay / get_color
Created May 29, 2012 16:43
Get Color by Percent
function get_color(start = "000000",end = "ffffff",percent = 50)
{
// start should always be darker
var sr = start.slice(0,2), sg = start.slice(2,2), sb = start.slice(4,2), er = end.slice(0,2), eg = end.slice(2,2), eb = end.slice(4,2);
var r = Math.ceil(((parseInt(er,16) - parseInt(sr,16))*percent)+parseInt(sr,16)), g = Math.ceil(((parseInt(eg,16) - parseInt(sg,16))*percent)+parseInt(sg,16)), b = Math.ceil(((parseInt(eb,16) - parseInt(sb,16))*percent)+parseInt(sb,16));
var hex = (r << 16) | (g << 8) | b;
return "#"+hex.toString(16);
}