-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch.js
57 lines (49 loc) · 1.03 KB
/
sketch.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
var drawing = [];
var currentPath = [];
var isDrawing = false;
function setup() {
canvas = createCanvas(1440, 750);
canvas.mousePressed(startPath);
canvas.mouseReleased(endPath);
canvas.parent('canvas-container');
}
function startPath() {
isDrawing = true
currentPath = [];
drawing.push(currentPath);
}
function endPath() {
isDrawing = false;
}
function keyPressed() {
if (key==' ') {
drawing = []
} else if (key=='u') {
//undo
drawing.splice(-1, 1)
}
}
function draw() {
background(0);
textSize(32);
text('DRAW', width/2-80, 40);
if (isDrawing) {
var point = {
x: mouseX,
y: mouseY
}
currentPath.push(point);
}
beginShape();
stroke(255);
strokeWeight(4);
noFill();
for (var i=0; i<drawing.length; i++) {
var path = drawing[i];
beginShape();
for (var j=0; j<path.length; j++) {
vertex(path[j].x, path[j].y);
}
endShape();
}
}