commit:4dca643fd17e3dfc51ac66c04e6fee5c704103b1
author:Chip Black
committer:Chip Black
date:Sun Oct 18 22:28:27 2015 -0500
parents:4cb956c53cd696d6bb2071c23f2e57b269ba0497
Make pen draw continuously with lines
diff --git a/src/Pen.js b/src/Pen.js
line changes: +10/-4
index 9a3bb96..2191ca2
--- a/src/Pen.js
+++ b/src/Pen.js
@@ -3,19 +3,25 @@ import Controller from './Controller';
 export default class Pen extends Controller {
     constructor(appState) {
         super(appState);
-        this.penIsDown = false;
+        this.previous = null;
     }
 
     down(x, y) {
-        this.penIsDown = true;
+        this.previous = {x, y};
         this.state.pixelEditor.drawPixel(x, y);
     }
     move(x, y) {
-        if (this.penIsDown) {
-            this.state.pixelEditor.drawPixel(x, y);
+        if (this.previous) {
+            if (Math.abs(this.previous.x - x) > 1 || Math.abs(this.previous.y - y) > 1) {
+                this.state.pixelEditor.drawLine(x, y, this.previous.x, this.previous.y);
+            } else {
+                this.state.pixelEditor.drawPixel(x, y);
+            }
+            this.previous = {x, y};
         }
     }
     up(x, y) {
         this.penIsDown = false;
+        this.previous = null;
     }
 }