-
Notifications
You must be signed in to change notification settings - Fork 43
/
love.html
86 lines (86 loc) · 2.83 KB
/
love.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
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body style="background-color: black">
<canvas id='cavs' style='position:fixed; z-index:-1;'></canvas>
</body>
</html>
<script type="text/javascript">
var canvas = document.getElementById("cavs");
const WIDTH = window.innerWidth;
const HEIGHT = window.innerHeight;
canvas.setAttribute("width", WIDTH);
canvas.setAttribute("height", HEIGHT);
var context = canvas.getContext("2d");
var start =
{
loves: [],
DURATION: 30,
begin: function()
{
this.createLove();
},
createLove: function()
{
for (var i = 0; i < WIDTH / 59; i++)
{
var love = new Love();
this.loves.push(love);
}
setInterval(this.drawLove.bind(this), this.DURATION);
},
drawLove: function()
{
context.clearRect(0, 0, WIDTH, HEIGHT);
for (var key in this.loves)
{
this.loves[key].draw();
}
}
}
function Love()
{
var me = this;
function rand()
{
me.maxScale = (Math.random() * 3.2 + 1.2) * WIDTH / 521;
me.curScale = 1.2 * WIDTH / 521;
me.x = Math.floor(Math.random() * WIDTH - 40);
me.y = Math.floor(HEIGHT - Math.random() * 200);
me.ColR = Math.floor(Math.random() * 255);
me.ColG = Math.floor(Math.random() * 255);
me.ColB = Math.floor(Math.random() * 255);
me.alpha = Math.random() * 0.2 + 0.8;
me.vector = Math.random() * 5 + 0.4;
}
(function(){rand();} ());
me.draw = function()
{
if (me.alpha < 0.01) rand();
if(me.curScale < me.maxScale) me.curScale += 0.3;
x = me.x;
y = me.y;
scale = me.curScale;
context.fillStyle = "rgba(" + me.ColR + "," + me.ColG + "," + me.ColB + "," + me.alpha + ")";
context.shadowBlur = 10;
context.shadowColor = "rgb(" + me.ColR + "," + me.ColG + "," + me.ColB + ")";
context.beginPath();
context.bezierCurveTo( x + 2.5*scale, y + 2.5*scale, x + 2.0*scale, y, x, y );
context.bezierCurveTo( x - 3.0*scale, y, x - 3.0*scale, y + 3.5*scale,x - 3.0*scale,y + 3.5*scale );
context.bezierCurveTo( x - 3.0*scale, y + 5.5*scale, x - 1.0*scale, y + 7.7*scale, x + 2.5*scale, y + 9.5*scale );
context.bezierCurveTo( x + 6.0*scale, y + 7.7*scale, x + 8.0*scale, y + 5.5*scale, x + 8.0*scale, y + 3.5*scale );
context.bezierCurveTo( x + 8.0*scale, y + 3.5*scale, x + 8.0*scale, y, x + 5.0*scale, y );
context.bezierCurveTo( x + 3.5*scale, y, x + 2.5*scale, y + 2.5*scale, x + 2.5*scale, y + 2.5*scale );
context.fill();
context.closePath();
me.y -= me.vector;
me.alpha -= (me.vector / 2.9 * 3.5 / HEIGHT);
}
}
window.onload = function()
{
start.begin();
}
</script>