summaryrefslogtreecommitdiff
path: root/public/js/mp/dye.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/mp/dye.js')
-rw-r--r--public/js/mp/dye.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/public/js/mp/dye.js b/public/js/mp/dye.js
new file mode 100644
index 0000000..d4c016b
--- /dev/null
+++ b/public/js/mp/dye.js
@@ -0,0 +1,30 @@
+"use strict";
+var mp = function(mp) {
+ mp.dye = {
+ getChannel: getChannel
+ };
+ var channel = [null, "R", "G", "Y", "B", "M", "C", "W"];
+ function getChannel(color) {
+ var r = color[0], g = color[1], b = color[2],
+ max = Math.max(r, g, b);
+
+ if (max == 0) {
+ // Black
+ return { channel: null, intensity: 0 };
+ }
+
+ var min = Math.min(r, g, b), intensity = r + g + b;
+
+ var idx;
+
+ if (min != max && (min != 0 || (intensity != max && intensity != 2 * max))) {
+ // Not pure
+ idx = 0;
+ } else {
+ idx = (r != 0) | ((g != 0) << 1) | ((b != 0) << 2);
+ }
+
+ return { channel: channel[idx], intensity: max };
+ }
+ return mp;
+}(mp || {});