-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathBallon.js
49 lines (44 loc) · 1.13 KB
/
Ballon.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
41
42
43
44
45
46
47
48
49
class Ballon {
constructor() {
this.r = random(90, 150);
this.pos = createVector(random(width), random(height, height + random(300, 700)));
this.upStep = random(4, 6);
this.red = random(100, 255);
this.green = random(100, 255);
this.blue = random(100, 255);
this.lineLen = random(150, 250);
}
show() {
// line
push();
stroke(255);
strokeWeight(2);
line(this.pos.x, this.pos.y + this.r / 2 + 10, this.pos.x, this.pos.y + this.lineLen);
pop();
push();
// balloon
fill(this.red, this.green, this.blue, 170);
noStroke();
ellipse(this.pos.x, this.pos.y, this.r, this.r + 10);
// balloon tie
ellipse(this.pos.x, this.pos.y + this.r / 2 + 10, 10, 7);
pop();
}
up() {
this.pos.y -= this.upStep;
}
checkEdge() {
if (this.pos.y < 0 + this.r / 2 + 5) {
this.pos.y = 0 + this.r / 2 + 5;
}
}
mouseHover() {
if (this.pos.x + this.r / 2 > mouseX && this.pos.x - this.r / 2 < mouseX) {
if (this.pos.y + this.r / 2 > mouseY && this.pos.y - this.r / 2 < mouseY) {
return true;
}
} else {
return false;
}
}
}