From e1cbb0d9034358b5191a4d6da0900b9504950e69 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Nov 2014 10:24:05 -0500 Subject: toggle grid --- js/app.js | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'js/app.js') diff --git a/js/app.js b/js/app.js index 9db7895..54553de 100644 --- a/js/app.js +++ b/js/app.js @@ -90,6 +90,10 @@ function build () { canvas.clear() } + controls.grid = new Tool (grid_el) + controls.grid.use = function(){ + document.body.classList.toggle('grid') + } controls.width = new Lex (width_el) controls.height = new Lex (height_el) @@ -151,7 +155,7 @@ function bind () { }) }); - [controls.square, controls.circle, controls.text, controls.clear].forEach(function(tool){ + [controls.square, controls.circle, controls.text, controls.clear, controls.grid].forEach(function(tool){ tool.span.addEventListener('mousedown', function(e){ tool.focus() }) @@ -197,7 +201,7 @@ function bind () { if (! e.metaKey && ! e.ctrlKey && ! e.altKey) { e.preventDefault() } - console.log(e.keyCode) + // console.log(e.keyCode) switch (e.keyCode) { case 27: // esc if (focused) focused.blur() @@ -218,6 +222,8 @@ function bind () { } }) } + + function int_key (f) { return function (key, keyCode) { var n = parseInt(key) @@ -225,25 +231,6 @@ function int_key (f) { } } - -function draw (lex, x, y, erasing) { - stamp (canvas, brush, x, y, erasing) -} -function stamp (canvas, brush, x, y, erasing) { - hh = brush.w/2|0 - brush.forEach(function(lex, s, t){ - s += x-hh - t += y-hh - if (s >= 0 && s < canvas.w && t >= 0 && t < canvas.h) { - if (erasing) { - canvas.aa[t][s].erase(lex) - } - else { - canvas.aa[t][s].clone(lex) - } - } - }) -} function clamp (n,a,b){ return n < a ? a : n < b ? n : b } function mod (i,n) { return i - n * Math.floor(i / n) } -- cgit v1.2.3-70-g09d2