diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-12-11 16:15:06 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-12-11 16:15:06 -0500 |
| commit | 2de4442f9aeb6a4fc5d49fab8a15b41d87ff2fe4 (patch) | |
| tree | be82d6abf894943528e358bf22ab472687835808 /js/draw.js | |
| parent | 66488f43e9c19e3c286ff93c051af21ce01c5b86 (diff) | |
starting to write this stuff the fishbone thing is screwing me up
Diffstat (limited to 'js/draw.js')
| -rw-r--r-- | js/draw.js | 87 |
1 files changed, 59 insertions, 28 deletions
@@ -1,32 +1,63 @@ +var draw = (function(){ -function draw (lex, x, y, erasing) { - stamp (canvas, brush, x, y, erasing) -} + var last_point = [0,0] + + function down (e, lex, point) { + erasing = (e.which == "3" || e.ctrlKey) + if (e.shiftKey) { + line (lex, last_point, point, erasing) + } + else { + stamp (canvas, brush, point[0], point[1], erasing) + } + last_point[0] = point[0] + last_point[1] = point[1] + } + + function move (e, lex, point) { + line(lex, last_point, point, erasing) + last_point[0] = point[0] + last_point[1] = point[1] + } + + function point (lex, x, y, erasing) { + stamp (canvas, brush, x, y, erasing) + } -function line (lex, a, b, erasing) { - var len = dist(a[0], a[1], b[0], b[1]) - var bw = 1 - var x, y, i; - for (var i = 0; i < len; i += bw) { - x = lerp(i / len, a[0], b[0]) - y = lerp(i / len, a[1], b[1]) - stamp (canvas, brush, x, y, erasing) - } -} + function line (lex, a, b, erasing) { + var len = dist(a[0], a[1], b[0], b[1]) + var bw = 1 + var x, y, i; + for (var i = 0; i < len; i += bw) { + x = lerp(i / len, a[0], b[0]) + y = lerp(i / len, a[1], b[1]) + 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 = round( s + x-hh ) - t = round( t + y-hh ) - if (lex.opacity > 0 && 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 stamp (canvas, brush, x, y, erasing) { + hh = brush.w/2|0 + brush.forEach(function(lex, s, t){ + s = round( s + x-hh ) + t = round( t + y-hh ) + if (lex.opacity > 0 && 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) + } + } + }) + } + + var draw = {} + draw.down = down + draw.move = move + draw.stamp = stamp + draw.line = line + draw.point = point + return draw + +})() |
