-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
41 lines (28 loc) · 825 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
34
35
36
37
38
39
40
var fixrect,movingrect
function setup() {
createCanvas(800,400);
fixrect = createSprite(400, 200, 70, 50);
movingrect = createSprite(600,200,30,20)
fixrect.shapeColor = "green"
movingrect.shapeColor = "green"
movingrect.debug = true
fixrect.debug = true
}
function draw() {
background("black")
movingrect.x = mouseX
movingrect.y = mouseY
touch()
drawSprites()
}
function touch(){
if(movingrect.x-fixrect.x<fixrect.width/2 + movingrect.width/2&&
fixrect.x-movingrect.x<fixrect.width/2 + movingrect.width/2
&& movingrect.y-fixrect.y<fixrect.height/2 + movingrect.height/2&&
fixrect.y-movingrect.y<fixrect.height/2 + movingrect.height/2){
fixrect.shapeColor = "red"
movingrect.shapeColor = "red"
}
else {fixrect.shapeColor = "green"
movingrect.shapeColor = "green"}
}