-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
25 lines (22 loc) · 725 Bytes
/
sketch.js
File metadata and controls
25 lines (22 loc) · 725 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
var fixedRect, movingRect;
function setup() {
createCanvas(800,400);
fixedRect = createSprite(400, 200, 100, 40);
movingRect = createSprite(200,200,100,40);
}
function draw() {
background(255,255,255);
movingRect.x = mouseX;
movingRect.y = mouseY;
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){
movingRect.shapeColor="Red";
fixedRect.shapeColor="Red";
}else{
movingRect.shapeColor="Blue";
fixedRect.shapeColor="Blue";
}
drawSprites();
}