<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
#cavs {
background: black;
}
body {
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="cavs" width="500" height="500"></canvas>
<script>
var cavs = document.getElementById("cavs");
var ctx = cavs.getContext("2d");
var w = (cavs.width = window.innerWidth);
var h = (cavs.height = window.innerHeight);
window.onresize = function () {
var w = (cavs.width = window.innerWidth);
var h = (cavs.height = window.innerHeight);
};
var cont = 30;
var RainArr = [];
function Rain() {
}
Rain.prototype = {
init: function () {
this.x = random(1, w);
this.y = 0;
this.r = 1;
this.ySpeed = random(4, 7);
this.rSpeed = 1;
this.t = 1;
this.ts = 0.96;
this.l = random(h * 0.8, h * 0.9);
this.maxR = 50;
},
draw: function () {
if (this.y > this.l) {
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);
ctx.strokeStyle = "rgba(0,255,255," + this.t + ")";
ctx.closePath();
ctx.stroke();
} else {
ctx.beginPath();
ctx.fillStyle = colorRandom();
ctx.fillRect(this.x, this.y, 2, 10);
ctx.closePath();
}
this.update();
},
update: function () {
if (this.y > this.l) {
if (this.t > 0.03) {
this.r += this.rSpeed;
if (this.r > this.maxR) {
this.t *= this.ts;
}
} else {
this.init();
}
} else {
this.y += this.ySpeed;
}
},
};
function random(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
var one = new Rain();
one.init();
function createRain() {
for (var i = 0; i < cont; i++) {
(function (j) {
setTimeout(function () {
var rain = new Rain();
rain.init();
RainArr.push(rain);
}, j * 200);
})(i);
}
}
createRain();
function move() {
ctx.beginPath();
ctx.fillStyle = "rgba(0,0,0,0.1)";
ctx.fillRect(0, 0, w, h);
ctx.closePath();
for(var i = 0;i<RainArr.length;i++){
RainArr[i].draw();
}
window.requestAnimationFrame(move);
}
move();
function colorRandom(){
var r = Math.floor(Math.random()*255);
var g = Math.floor(Math.random()*255);
var b = Math.floor(Math.random()*255);
return "rgba("+ r +","+ g +","+ b +")";
}
</script>
</body>
</html>