per channel color operations. Color can also take an RGB array

This commit is contained in:
cloudhead 2010-02-25 17:54:59 -05:00
parent 68acd5a06c
commit dbf7c5c30c

View File

@ -2,7 +2,9 @@
// RGB Colors - #ff0014, #eee
//
node.Color = function Color(val) {
if (val.length == 6) {
if (Array.isArray(val)) {
this.value = val;
} else if (val.length == 6) {
this.value = val.match(/.{2}/g).map(function (c) {
return parseInt(c, 16);
});
@ -20,20 +22,32 @@ node.Color.prototype = {
}).join('');
},
'+': function (other) {
return new(node.Color)
(this.value + other.value, this.unit);
var result = [];
for (var c = 0; c < 3; c++) {
result[c] = this.value[c] + other.value[c];
}
return new(node.Color)(result);
},
'-': function (other) {
return new(node.Color)
(this.value - other.value, this.unit);
var result = [];
for (var c = 0; c < 3; c++) {
result[c] = this.value[c] - other.value[c];
}
return new(node.Color)(result);
},
'*': function (other) {
return new(node.Color)
(this.value * other.value, this.unit);
var result = [];
for (var c = 0; c < 3; c++) {
result[c] = this.value[c] * other.value[c];
}
return new(node.Color)(result);
},
'/': function (other) {
return new(node.Color)
(this.value / other.value, this.unit);
var result = [];
for (var c = 0; c < 3; c++) {
result[c] = this.value[c] / other.value[c];
}
return new(node.Color)(result);
}
};