-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
154 lines (120 loc) · 2.83 KB
/
script.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var canvas;
var ctx;
var starttime;
var laststep;
function pad(n, l)
{
var s = ("000" + n);
return s.substr(s.length - l);
}
function getms()
{
return Date.now() - starttime
}
function getTimeString()
{
let v = getms();
//Extract milliseconds
ms = v % 1000;
//Convert to seconds
v -= ms;
v /= 1000;
//Extract seconds
let s = v % 60;
v -= s;
//Convert to minutes
v /= 60;
//extract minutes
let m = v % 60;
v -= m;
//Convert to hours
v /= 60;
//extract hours
let h = v % 60;
v -= h;
//Convert to days
let d = v / 24;
return d.toString() + ":" + pad(h.toString(), 2) + ":" + pad(m.toString(), 2) + ":" + pad(s.toString(), 2) + "." + pad(ms.toString(), 3);
}
var step = 0;
let stepheight = 130;
let msstep = 1000/60;
var last_ms = 0;
var audio;
var last_audio = 0;
var audio_interval = 3000;
function update()
{
let n = Date.now();
let y = ((step * stepheight) % window.innerHeight);
//getms() * 3 % window.innerHeight
let dobeep = n - last_audio > audio_interval;
if(dobeep)
{
last_audio = n;
}
if(dobeep)
{
ctx.fillStyle = "white";
audio.play();
}
else
{
ctx.fillStyle = "black";
}
ctx.fillRect(0, 0, canvas.width, canvas.height);
if(!dobeep)
{
ctx.fillStyle = "white";
}
else
{
ctx.fillStyle = "black";
}
let blocksize = stepheight;
let blocklevel = 0;
let d = audio_interval - (n - last_audio);
ctx.fillRect(window.innerWidth/2 - d - blocksize , blocklevel, blocksize, blocksize);
ctx.fillRect(window.innerWidth/2 + d, blocklevel, blocksize, blocksize);
if(dobeep)
{
ctx.fillStyle = "black";
}
else
{
ctx.fillStyle = "white";
}
ctx.fillRect(0, y, window.innerWidth, stepheight);
let deltastep = n - laststep;
ctx.fillText(deltastep.toString(), 10, window.innerHeight);
if(!dobeep)
{
ctx.fillStyle = "black";
}
else
{
ctx.fillStyle = "white";
}
ctx.fillText(getTimeString(), window.innerWidth/2 - 300, y + 100);
step += 1;
if(step * stepheight > window.innerHeight)
{
step = 1;
}
laststep = n;
//setTimeout(update, msstep);
window.requestAnimationFrame(update);
}
window.onload = (event) => {
canvas = document.getElementById("canvas");
ctx = canvas.getContext('2d');
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
ctx.font = "bold 80px Arial";
starttime = Date.now();
laststep = starttime;
audio = new Audio('beep.wav');
audio.play();
window.requestAnimationFrame(update);
//update();
};