Skip to content

Instantly share code, notes, and snippets.

@lamp
Created March 27, 2012 18:02
Show Gist options
  • Select an option

  • Save lamp/2218461 to your computer and use it in GitHub Desktop.

Select an option

Save lamp/2218461 to your computer and use it in GitHub Desktop.
nice js code to keep
var colour_map = (function(colours){
var map = {},
intervals = 100 / (colours.length - 1),
count = 0,
returnable = [];
$.each(colours, function(i, col){
var next = parseInt(colours[i + 1], 16),
current = parseInt(col, 16),
count_dir = (next > current),
difference = (count_dir)? next - current : current - next,
increment = parseInt(difference / intervals),
interval_colours = [];
if(isNaN(next)) return;
returnable.push(current.toString(16));
for(i = 1; i < intervals - 1; i++){
var value = (count_dir)? current + (increment * i): current - (increment * i);
returnable.push(value.toString(16));
}
});
returnable.push(colours[colours.length - 1]);
return returnable;
})(colours);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment