Skip to content

Commit

Permalink
using the mouse drag event to move the drawing on the canvas (#38)
Browse files Browse the repository at this point in the history
this usefull for debuging or if you are trying to find a good starting point
  • Loading branch information
AmrBarghouthi authored and shiffman committed Nov 10, 2018
1 parent 5db5613 commit 2e66eb0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

let editor;
let turtle;
let xOffset = 0;
let yOffset = 0;
let startX = 100;
let startY = 100;
let allCases;

function preload() {
Expand Down Expand Up @@ -43,6 +47,8 @@ function execute(commands, repcount) {
}

function goTurtle() {
console.log({startX:startX,startY:startY});
turtle = new Turtle(startX, startY, 0);
background(0);
push();
turtle.reset();
Expand Down Expand Up @@ -92,3 +98,14 @@ function createTestDataView(cases) {
goTurtle();
});
}

function mousePressed() {
xOffset = mouseX-startX;
yOffset = mouseY-startX;
}

function mouseDragged() {
startX = mouseX-xOffset;
startY = mouseY-yOffset;
goTurtle();
}

0 comments on commit 2e66eb0

Please sign in to comment.