summaryrefslogtreecommitdiff
path: root/client/effects.js
diff options
context:
space:
mode:
authorYuval Adam <yuval@y3xz.com>2015-06-29 17:38:37 +0300
committerYuval Adam <yuval@y3xz.com>2015-06-29 17:38:37 +0300
commitba4f31524941937277a9a19dde05257c88e15658 (patch)
tree702251950f366b8340c039707854a3870b290d5e /client/effects.js
parent7f38c8bcdd45f0c5dcfa3b8d5c2bf3d8294d5d69 (diff)
First batch of clusterfck
Diffstat (limited to 'client/effects.js')
-rw-r--r--client/effects.js37
1 files changed, 11 insertions, 26 deletions
diff --git a/client/effects.js b/client/effects.js
index 01b79c7..1135e04 100644
--- a/client/effects.js
+++ b/client/effects.js
@@ -25,14 +25,12 @@ Effects = (function() {
size: [w, h]
}));
- // console.log(w, h, x, y, color.red, color.green, color.blue);
-
- cols.push(
+ cols.push([
Math.round(256 * color.red),
Math.round(256 * color.green),
Math.round(256 * color.blue),
- 1 // alpha
- );
+ ]);
+
var rec = new paper.Path.Rectangle({
point: [x * gridSize, y * gridSize],
size: [gridSize, gridSize],
@@ -44,30 +42,17 @@ Effects = (function() {
p.view.draw();
- cols = new Uint8Array(cols);
-
- var quant = new RgbQuant({
- colors: 2,
- minHueCols: 16
- });
- quant.sample(cols);
- var palette = quant.palette(true);
- var newcolors = quant.reduce(cols);
+ var k = new KMeans();
+ k.cluster(cols, 2);
+ var centroids = k.centroids;
- // if (window.gb === undefined)
- // window.gb = [];
- // window.gb.push(palette[0][0], palette[0][1], palette[0][2], 0.16);
- // window.gb.push(palette[1][0], palette[1][1], palette[1][2], 0.16);
-
- var newcolors2 = [];
- for (var x=0; x < gridDim * gridDim; x++) {
- newcolors2.push([newcolors[(x*4)], newcolors[(x*4)+1], newcolors[(x*4)+2]]);
- // skip dummy alpha value (x*4)+3
- }
+ var newcols = _.map(cols, function(col) {
+ return centroids[k.classify(col)];
+ })
Session.set(id + ':colors', cols);
- Session.set(id + ':palette', palette);
- Session.set(id + ':newcolors', newcolors2);
+ Session.set(id + ':palette', centroids);
+ Session.set(id + ':newcolors', newcols);
});
}