-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigitalclockRGB.js
More file actions
43 lines (37 loc) · 922 Bytes
/
digitalclockRGB.js
File metadata and controls
43 lines (37 loc) · 922 Bytes
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
function getTimeOfDay() {
var date = new Date();
return [
date.getHours(),
date.getMinutes(),
date.getSeconds()
].map(function(time) {
return time < 10 ? '0' + time : String(time);
}).join('');
}
function getColor(time) {
var color = '#' + time;
document.body.style.backgroundColor = color;
var clock = document.getElementById('clock');
clock.textContent = color;
}
function compose(f, g) {
return function() {
return f(g());
}
}
function stopClick(clear, name) {
document.body.addEventListener('click', function(event) {
clear(name);
});
}
function startClick(callback) {
document.body.addEventListener('dblclick', function(event) {
callback();
});
}
function init() {
var tick = setInterval(compose(getColor, getTimeOfDay), 1000);
stopClick(clearInterval, tick);
startClick(init);
}
window.onload = init;