-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobstacles.js
More file actions
43 lines (38 loc) · 1.08 KB
/
obstacles.js
File metadata and controls
43 lines (38 loc) · 1.08 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
var startPos;
var endPos;
var drawrect = false;
function mousePressed() {
console.log("PRESSED!");
startPos = createVector(mouseX, mouseY);
console.log(startPos);
drawrect = true;
locked = true;
}
function mouseReleased() {
console.log("RELEASED !");
endPos = createVector(mouseX, mouseY);
console.log(endPos);
locked = false;
}
function Obstacle() {
this.corner1 = createVector(startPos.x, startPos.y);
this.corner2 = createVector(endPos.x, endPos.y);
this.show = function () {
var width = abs(this.corner1.x - this.corner2.x);
var height = abs(this.corner1.y - this.corner2.y);
stroke(0);
fill(45);
var corner = createVector(
this.corner1.x < this.corner2.x ? this.corner1.x : this.corner2.x,
this.corner1.y < this.corner2.y ? this.corner1.y : this.corner2.y
);
this.corner1 = corner;
this.corner2.x = this.corner1.x + width;
this.corner2.y = this.corner1.y + height;
rect(corner.x, corner.y, width, height);
};
console.log(this.corner1);
console.log(this.corner2);
console.log(width);
console.log(height);
}