Permalink
Browse files

generalize 'draw' a bit

  • Loading branch information...
brandly committed Feb 24, 2014
1 parent 493c0e2 commit d6d6c7e2227c615ee3fba6b9624d720e4226f9e8
Showing with 13 additions and 13 deletions.
  1. +13 −13 src/snapchat.js
View
@@ -112,31 +112,31 @@
bigCanvas.width = w.innerWidth;
bigCanvas.height = w.innerHeight;
- var last = null;
- function draw(element, coords) {
- bigContext.beginPath();
- bigContext.strokeStyle = currentColor.toString();
- bigContext.lineWidth = 5;
- bigContext.lineJoin = 'round';
- bigContext.moveTo(last.x, last.y);
- bigContext.lineTo(coords.x, coords.y);
- bigContext.closePath();
- bigContext.stroke();
+ var previousCoords = null;
+ function draw(context, start, end) {
+ context.beginPath();
+ context.strokeStyle = currentColor.toString();
+ context.lineWidth = 5;
+ context.lineJoin = 'round';
+ context.moveTo(start.x, start.y);
+ context.lineTo(end.x, end.y);
+ context.closePath();
+ context.stroke();
}
bigCanvas.addEventListener(events.down, function(e) {
function drawMove(e) {
var coords = relativeMouseCoords(e, bigCanvas);
- draw(bigCanvas, coords);
- last = relativeMouseCoords(e, bigCanvas);
+ draw(bigContext, previousCoords, coords);
+ previousCoords = coords;
}
function removeListeners(e) {
bigCanvas.removeEventListener(events.move, drawMove);
bigCanvas.removeEventListener(events.up, removeListeners);
}
- last = relativeMouseCoords(e, bigCanvas);
+ previousCoords = relativeMouseCoords(e, bigCanvas);
bigCanvas.addEventListener(events.move, drawMove);
bigCanvas.addEventListener(events.up, removeListeners);
});

0 comments on commit d6d6c7e

Please sign in to comment.