-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
32 lines (25 loc) · 829 Bytes
/
sketch.js
File metadata and controls
32 lines (25 loc) · 829 Bytes
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
var fixedrect, movingrect;
function setup() {
createCanvas(800,400);
fixedrect = createSprite(400, 200, 150, 50);
fixedrect.shapeColor = "hotpink";
movingrect = createSprite(200,100, 80,40);
movingrect.shapeColor = "cyan";
}
function draw() {
background(0);
movingrect.x = World.mouseX;
movingrect.y = World.mouseY;
if(movingrect.x - fixedrect.x < movingrect.width/2 + fixedrect.width/2 &&
fixedrect.x - movingrect.x < movingrect.width/2 + fixedrect.width/2 &&
movingrect.y - fixedrect.y < movingrect.height/2 + fixedrect.height/2 &&
fixedrect.y - movingrect.y < movingrect.height/2 + fixedrect.height/2){
movingrect.shapeColor = "red";
fixedrect.shapeColor = "red";
}
else{
fixedrect.shapeColor = "hotpink";
movingrect.shapeColor = "cyan";
}
drawSprites();
}