-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
30 lines (27 loc) · 826 Bytes
/
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
var fixedRect;
var MovingRect;
function setup() {
createCanvas(800,400);
fixedRect = createSprite(200,200,50,80);
fixedRect.shapeColor = "green";
MovingRect = createSprite(400,200,80,40);
MovingRect.shapeColor = "green";
}
function draw() {
background("black");
MovingRect.y = mouseY;
MovingRect.x = mouseX;
if(MovingRect.x-fixedRect.x<fixedRect.width/2+MovingRect.width/2 &&
fixedRect.x-MovingRect.x<fixedRect.width/2+MovingRect.width/2 &&
MovingRect.y-fixedRect.y<fixedRect.height/2+MovingRect.height/2 &&
fixedRect.y-MovingRect.y<fixedRect.height/2+MovingRect.height/2){
fixedRect.shapeColor = "red";
MovingRect.shapeColor = "red";
}
else{
fixedRect.shapeColor = "green";
MovingRect.shapeColor = "green";
}
console.log(MovingRect.x-fixedRect.x);
drawSprites();
}