Refactor visualization into separate class

This commit is contained in:
Arne Schlüter 2015-02-08 10:44:10 +01:00
commit a2b6e437d4
4 changed files with 138 additions and 92 deletions

View file

@ -9,9 +9,9 @@ var colorUtils = {
hexToRGB: function toRGB (color) {
var r = color.substr(1, 2)
, g = color.substr(3, 2)
, b = color.substr(5, 2);
, b = color.substr(5, 2)
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16)];
return [parseInt(r, 16), parseInt(g, 16), parseInt(b, 16)]
},
/**
@ -20,18 +20,18 @@ var colorUtils = {
* @return {String} The mixed color as hex string
*/
mix: function mixColors (colors) {
var rgb = colors.map(colorUtils.hexToRGB);
var rgb = colors.map(colorUtils.hexToRGB)
var result = [ 0, 0, 0 ];
var result = [ 0, 0, 0 ]
for (var i = 0, l = rgb.length; i < l; i++) {
result[0] += rgb[i][0] / l;
result[1] += rgb[i][1] / l;
result[2] += rgb[i][2] / l;
result[0] += rgb[i][0] / l
result[1] += rgb[i][1] / l
result[2] += rgb[i][2] / l
}
return '#' + result[0].toString(16) + result[1].toString(16) + result[2].toString(16);
return '#' + result[0].toString(16) + result[1].toString(16) + result[2].toString(16)
}
}
export default colorUtils;
export default colorUtils