Skip to content

Instantly share code, notes, and snippets.

@phawk
Created October 6, 2012 12:22
Show Gist options
  • Save phawk/3844781 to your computer and use it in GitHub Desktop.
Save phawk/3844781 to your computer and use it in GitHub Desktop.
function getAverageColour() {
var colour;
var r = 0;
var g = 0;
var b = 0;
var lis = $('.pen li');
for (var index = 0, len = lis.length; index < len; index++) {
var li = $(lis[index]);
r = r+ parseInt(li.attr('red'));
g = g+ parseInt(li.attr('green'));
b = g+ parseInt(li.attr('blue'));
if (index+1 == $('.pen').children().length) {
colour = {r:Math.round(r/(index+1)), g:Math.round(g/(index+1)), b:Math.round(b/(index+1))};
return colour;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment