summaryrefslogtreecommitdiff
path: root/public/js/palette.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2013-03-06 13:04:57 -0500
committerJules Laplace <jules@okfoc.us>2013-03-06 13:04:57 -0500
commit87ce8c3d94aa9f9178818735f75c981a7bc462d3 (patch)
treeb5d5317398bef4fc0f50ce9c02affca5f8cb42cc /public/js/palette.js
parentc44715ddb22eba13d697355722292eb926681dbe (diff)
starting rewrite with two-canvas editor
Diffstat (limited to 'public/js/palette.js')
-rw-r--r--public/js/palette.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/public/js/palette.js b/public/js/palette.js
new file mode 100644
index 0000000..a2db196
--- /dev/null
+++ b/public/js/palette.js
@@ -0,0 +1,46 @@
+$("#palette").load(function(){
+ console.log("hello");
+ var offset = $("#palette").offset();
+ var paletteImg = $("#palette")[0];
+ var palette = cq(paletteImg);
+ var pattern, mask;
+ var color = new Color( 0, 0, 0 );
+
+ // $("body").append(palette.canvas);
+
+ $("#palette").click(function(e){
+ // they are all 8x8
+ // the first one starts at (15, 5), next one is 16 pixels down or to the right
+ // there are 16 rows and 6 columns, so 92 patterns total
+ var point = new Point(e, offset);
+ click(point);
+ });
+ var click = function(point) {
+ point.subtract({ x: 15, y: 5 });
+ point.quantize( 18, 16 );
+ point.add({ x: 15, y: 5 });
+
+ pattern = palette.clone().crop( point.x, point.y, 8, 8 );
+ mask = pattern.colorToMask("#fff");
+ pattern.applyMask(mask);
+ patternURI = pattern.clone().blend( color.toString(), "screen", 1.0 ).canvas.toDataURL("image/png");
+ document.body.style.backgroundImage = 'url(' + patternURI + ')';
+ }
+
+ var random = function(){
+ var point = new Point(paletteImg.width, paletteImg.height).scale( Math.random(), Math.random() ).floor();
+ click(point);
+ }
+ random();
+
+ for (var i in colors) {
+ var swatch = colors[i].swatch();
+ document.body.appendChild(swatch);
+ swatch.onclick = function(){
+ color = $(this).data("color");
+ p = cq(paletteImg);
+ patternURI = pattern.clone().blend( color.toString(), "screen", 1.0 ).canvas.toDataURL("image/png");
+ document.body.style.backgroundImage = 'url(' + patternURI + ')';
+ }
+ }
+}); \ No newline at end of file