-
Notifications
You must be signed in to change notification settings - Fork 0
/
coolRain.html
130 lines (115 loc) · 3.4 KB
/
coolRain.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>霓虹雨</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style type="text/css">
.bg {
background: #000;
overflow: hidden;
margin:0px;
}
</style>
<body class="bg">
<canvas id="canvas-club"></canvas>
<script>
var c = document.getElementById("canvas-club");
var ctx = c.getContext("2d");
var w = c.width = window.innerWidth;
var h = c.height = window.innerHeight-125;
var clearColor = 'rgba(0, 0, 0, .1)';
var max = 30;
var drops = [];
function random(min, max) {
return Math.random() * (max - min) + min;
};
function sendNum(arr)
{
return arr[Math.floor(Math.random()*arr.length)];
};
function O() {} ;
O.prototype = {
init: function() {
this.x = random(0, w);
this.y = 0;
this.cr = random(0,240);
this.color = 'hsl('+this.cr+', 100%, 50%)';
this.w = 2;
this.h = 1;
this.vy = random(4, 5);
this.vw = 3;
this.vh = 1;
this.size = 2;
this.hit = random(h * .8, h * .9);
this.a = 1;
this.va = .96;
},
draw: function() {
if (this.y > this.hit) {
ctx.beginPath();
ctx.moveTo(this.x, this.y - this.h / 2);
ctx.bezierCurveTo(
this.x + this.w / 2, this.y - this.h / 2,
this.x + this.w / 2, this.y + this.h / 2,
this.x, this.y + this.h / 2);
ctx.bezierCurveTo(
this.x - this.w / 2, this.y + this.h / 2,
this.x - this.w / 2, this.y - this.h / 2,
this.x, this.y - this.h / 2);
ctx.strokeStyle = 'hsla('+this.cr+', 100%, 50%, '+this.a+')';
ctx.stroke();
ctx.closePath();
} else {
ctx.fillStyle = this.color;
ctx.fillRect(this.x, this.y, this.size, this.size * 5);
}
this.update();
},
update: function() {
if(this.y < this.hit){
this.y += this.vy;
} else {
if(this.a > .03){
this.w += this.vw;
this.h += this.vh;
if(this.w > 100){
this.a *= this.va;
this.vw *= .98;
this.vh *= .98;
}
} else {
this.init();
}
}
}
} ;
function resize(){
w = c.width = window.innerWidth;
h = c.height = window.innerHeight;
} ;
function setup(){
for(var i = 0; i < max; i++){
(function(j){
setTimeout(function(){
var o = new O();
o.init();
drops.push(o);
}, j * 200)
}(i));
}
};
function anim() {
ctx.fillStyle = clearColor;
ctx.fillRect(0,0,w,h);
for(var i in drops){
drops[i].draw();
}
requestAnimationFrame(anim);
};
window.addEventListener("resize", resize);
setup();
anim();
</script>
</body>
</html>