-
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) · 785 Bytes
/
Copy pathsketch.js
File metadata and controls
32 lines (25 loc) · 785 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, 50, 50);
fixedRect.shapeColor = "green";
movingRect = createSprite(400, 200, 70, 30);
movingRect.shapeColor = "green";
}
function draw() {
background(0);
movingRect.x = mouseX;
movingRect.y = 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{
movingRect.shapeColor = "green";
fixedRect.shapeColor = "green";
}
drawSprites();
}