-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreehandTool.js
More file actions
44 lines (41 loc) · 1.29 KB
/
freehandTool.js
File metadata and controls
44 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function FreehandTool(){
//set an icon and a name for the object
this.icon = "assets/freehand.jpg";
this.name = "freehand";
//to smoothly draw we'll draw a line from the previous mouse location
//to the current mouse location. The following values store
//the locations from the last frame. They are -1 to start with because
//we haven't started drawing yet.
var previousMouseX = -1;
var previousMouseY = -1;
//modified to work with layers
this.draw = function (pg = currentLayer) {
//if the mouse is pressed
if (mouseIsPressed) {
//check if they previousX and Y are -1. set them to the current
//mouse X and Y if they are.
if (previousMouseX == -1) {
previousMouseX = mouseX;
previousMouseY = mouseY;
}
//if we already have values for previousX and Y we can draw a line from
//there to the current mouse location
else {
pg.line(previousMouseX, previousMouseY, mouseX, mouseY);
previousMouseX = mouseX;
previousMouseY = mouseY;
}
}
//if the user has released the mouse we want to set the previousMouse values
//back to -1.
//try and comment out these lines and see what happens!
else {
previousMouseX = -1;
previousMouseY = -1;
}
//saves after unselecting tool
this.unselectTool = function () {
currentLayer.loadPixels();
};
};
}