-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclock.html
More file actions
145 lines (144 loc) · 4.32 KB
/
clock.html
File metadata and controls
145 lines (144 loc) · 4.32 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word Clock</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap">
<style>
:root {
--color-bg: #00d000;
--color-dim: #00a000;
--color-active: #ffff00;
}
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: var(--color-bg);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
#clock {
padding: 20px;
}
.row {
display: flex;
}
.letter {
font-family: 'Roboto Mono', monospace;
font-size: clamp(18px, 4vw, 44px);
line-height: 1.2;
color: var(--color-dim);
padding: clamp(8px, 2vw, 20px);
transition: color 0.4s ease;
user-select: none;
}
.letter.on {
color: var(--color-active);
}
</style>
</head>
<body>
<div id="clock"></div>
<script>
const GRID = [
['I','T','L','I','S','A','S','T','I','M','E'],
['A','C','Q','U','A','R','T','E','R','D','C'],
['T','W','E','N','T','Y','F','I','V','E','X'],
['H','A','L','F','B','T','E','N','F','T','O'],
['P','A','S','T','E','R','U','N','I','N','E'],
['O','N','E','S','I','X','T','H','R','E','E'],
['F','O','U','R','F','I','V','E','T','W','O'],
['E','I','G','H','T','E','L','E','V','E','N'],
['S','E','V','E','N','T','W','E','L','V','E'],
['T','E','N','W','E','O','C','L','O','C','K'],
];
const HOURS = [
[[8,5],[8,6],[8,7],[8,8],[8,9],[8,10]],
[[5,0],[5,1],[5,2]],
[[6,8],[6,9],[6,10]],
[[5,6],[5,7],[5,8],[5,9],[5,10]],
[[6,0],[6,1],[6,2],[6,3]],
[[6,4],[6,5],[6,6],[6,7]],
[[5,3],[5,4],[5,5]],
[[8,0],[8,1],[8,2],[8,3],[8,4]],
[[7,0],[7,1],[7,2],[7,3],[7,4]],
[[4,7],[4,8],[4,9],[4,10]],
[[9,0],[9,1],[9,2]],
[[7,5],[7,6],[7,7],[7,8],[7,9],[7,10]],
];
const MINUTES = [
[[9,5],[9,6],[9,7],[9,8],[9,9],[9,10]],
[[2,6],[2,7],[2,8],[2,9]],
[[3,5],[3,6],[3,7]],
[[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8]],
[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5]],
[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9]],
[[3,0],[3,1],[3,2],[3,3]],
[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9]],
[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5]],
[[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8]],
[[3,5],[3,6],[3,7]],
[[2,6],[2,7],[2,8],[2,9]],
];
const PAST = [[4,0],[4,1],[4,2],[4,3]];
const TO = [[3,9],[3,10]];
const IT_IS = [[0,0],[0,1],[0,3],[0,4]];
function buildGrid() {
const clock = document.getElementById('clock');
GRID.forEach((rowData, r) => {
const rowEl = document.createElement('div');
rowEl.className = 'row';
rowData.forEach((char, c) => {
const cell = document.createElement('div');
cell.className = 'letter';
cell.id = `r${r}c${c}`;
cell.textContent = char;
rowEl.appendChild(cell);
});
clock.appendChild(rowEl);
});
}
function allOff() {
document.querySelectorAll('.letter').forEach(el => el.classList.remove('on'));
}
function light(cells) {
cells.forEach(([r, c]) => {
const el = document.getElementById(`r${r}c${c}`);
if (el) el.classList.add('on');
});
}
function update() {
const now = new Date();
const mins = now.getMinutes();
const m = Math.floor(mins / 5); // 0–11
const isPast = m <= 6;
let h = now.getHours() % 12;
if (!isPast) h = (h + 1) % 12;
allOff();
light(IT_IS);
light(HOURS[h]);
light(MINUTES[m]);
if (m === 0) { /* O'CLOCK — no PAST/TO */ }
else if (isPast) { light(PAST); }
else { light(TO); }
}
buildGrid();
update();
function scheduleTick() {
const now = new Date();
const msUntilNextMinute = (60 - now.getSeconds()) * 1000 - now.getMilliseconds();
setTimeout(() => {
update();
setInterval(update, 60_000);
}, msUntilNextMinute);
}
scheduleTick();
</script>
</body>
</html>