-
Notifications
You must be signed in to change notification settings - Fork 0
/
rainDrops.js
47 lines (42 loc) · 1021 Bytes
/
rainDrops.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
class Rain{
constructor(){
this.x = random(-width,width);
this.y = random(-height,height);
this.z = random(width);
}
show(){
fill(200, 200, 200);
noStroke();
this.sx = map(this.x/this.z,0,1,0,width);
this.sy = map(this.y/this.z,0,1,0,height);
this.r = map(this.z,0,width,8,0);
circle(this.sx,this.sy,this.r);
}
update(){
this.z = this.z-6;
if(this.z<1){
this.x = random(-width,width);
this.y = random(-height,height);
this.z = width;
}
}
}
let drops = [];
function setup(){
createCanvas(windowWidth,windowHeight);
for(let i = 0;i<2500;i++){
let tempo = new Rain();
drops.push(tempo);
}
}
function draw(){
translate(width/2,height/2);
background(0);
for(let i = 0;i<drops.length;i++){
drops[i].update();
drops[i].show();
}
}
function windowResized(){
resizeCanvas(windowWidth,windowHeight);
}