-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
33 lines (26 loc) · 897 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
31
32
33
var fixed_rect, moving_rect;
function setup() {
createCanvas(800,400);
fixed_rect = createSprite(400, 200, 50, 100);
fixed_rect.shapeColor = "green";
fixed_rect.debug = true;
moving_rect = createSprite(300, 200, 50, 100);
moving_rect.shapeColor = "green";
moving_rect.debug = true;
}
function draw() {
background(255,255,255);
moving_rect.x = mouseX;
moving_rect.y = mouseY;
if(moving_rect.x - fixed_rect.x < fixed_rect.width/2 + moving_rect.width/2 &&
fixed_rect.x - moving_rect.x < fixed_rect.width/2 + moving_rect.width/2 &&
moving_rect.y - fixed_rect.y < fixed_rect.width/2 + moving_rect.width/2 &&
fixed_rect.y - moving_rect.y < fixed_rect.width/2 + moving_rect.width/2){
moving_rect.shapeColor = "red";
fixed_rect.shapeColor = "red";
}else{
moving_rect.shapeColor = "green";
fixed_rect.shapeColor = "green";
}
drawSprites();
}