-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFallingCircles.js
63 lines (46 loc) · 1.1 KB
/
FallingCircles.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class FallingCircles {
constructor(x, y, value) {
this.x = x;
this.y = y;
this.r = 10;
this.gravity = random(-2, 2);
this.gravity2 = random(1, 2);
this.val = value;
this.saturation = 100;
this.c = color('hsb('+ this.val +', 100%, ' + this.saturation + '%)');
}
show(){
fill(this.c);
ellipse(this.x, this.y, this.r);
}
moving(){
this.y += this.gravity;
this.x += this.gravity2;
}
randomWalker(){
if(frameCount % 5 == 0){
let choice = int(random(4));
if (choice == 0) {
this.x+=3; // move right
} else if (choice == 1) {
this.x-=3; // move left
} else if (choice == 2) {
this.y+=3; // move down
} else {
this.y-=3; // move up
}
this.x = constrain(this.x,0,width-1);
this.y = constrain(this.y,0,height-1);
}
}
grow(){
this.r += 0.1;
}
increaseSaturation(){
// console.log(val);
this.c = color('hsb('+ this.val +', 100%, ' + this.saturation + '%)');
if (this.saturation > 10) { // should be 10
this.saturation = this.saturation - 0.3;
}
}
}