-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrain.js
42 lines (34 loc) · 841 Bytes
/
rain.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
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function rainDrop(){
this.x=getRandomInt(0, window.innerWidth);
this.y=getRandomInt(-200,-100);
this.yspeed=getRandomInt(4,10);
}
rainDrop.prototype.fall = function(){
this.y = this.y + this.yspeed;
if(this.y > window.innerHeight){
this.y = getRandomInt(-200,100);
}
}
rainDrop.prototype.show = function(){
stroke(138,43,226);
line(this.x,this.y,this.x,this.y+10);
}
var Drops = [];
function setup(){
createCanvas(window.innerWidth, window.innerHeight);
for(var i=0;i<200;i++){
Drops[i] = new rainDrop();
}
}
function draw(){
background(2, 0, 36);
for(var i=0;i<200;i++){
Drops[i].fall();
Drops[i].show();
}
}