-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.html
111 lines (97 loc) · 2.36 KB
/
timer.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
<html>
<head>
<title>Timer</title>
</head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-52655112-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-52655112-4');
</script>
<body>
<canvas id="canvas"></canvas>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
window.onload = function(){
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var W = window.innerWidth-20;
var H = window.innerHeight-20;
canvas.width = W;
canvas.height = H;
var msg="";
var maxParticles = 100;
var particles = [];
for(var i = 0; i < maxParticles; i++)
{
particles.push({
x: Math.random()*W,
y: Math.random()*H,
r: Math.random()*4+1,
d: Math.random()*maxParticles
})
}
function draw()
{
ctx.clearRect(0, 0, W, H);
var countDownDate = new Date("Dec 25, 2019 00:00:00").getTime();
var now = new Date().getTime();
var distance = countDownDate - now;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var day = days+1;
msg = day + " Days to Christmas";
if (distance < 0) {
msg = "Merry Christmas";
}
ctx.font = "44px Trebuchet MS";
ctx.fillStyle = "red"; //Font Color
ctx.textAlign = "center";
ctx.fillText(msg, canvas.width/2, canvas.height/2+10);
ctx.fillStyle = "#9ec9ef"; //Snow Flake Colors
ctx.beginPath();
for(var i = 0; i < maxParticles; i++)
{
var p = particles[i];
ctx.moveTo(p.x, p.y);
ctx.arc(p.x, p.y, p.r, 0, Math.PI*2, true);
}
ctx.fill();
update();
}
var angle = 0;
function update()
{
angle += 0.01;
for(var i = 0; i < maxParticles; i++)
{
var p = particles[i];
p.y += Math.cos(angle+p.d) + 1 + p.r/2;
p.x += Math.sin(angle) * 2;
if(p.x > W+5 || p.x < -5 || p.y > H)
{
if(i%3 > 0)
{
particles[i] = {x: Math.random()*W, y: -10, r: p.r, d: p.d};
}
else
{
if(Math.sin(angle) > 0)
{
particles[i] = {x: -5, y: Math.random()*H, r: p.r, d: p.d};
}
else
{
particles[i] = {x: W+5, y: Math.random()*H, r: p.r, d: p.d};
}
}
}
}
}
setInterval(draw, 33);
}
});</script>
</body>
</html>