-
Notifications
You must be signed in to change notification settings - Fork 0
/
master-clock.html
183 lines (159 loc) · 5.5 KB
/
master-clock.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LED Masterclock with NTP Sync</title>
<style>
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: black;
height: 100vh;
font-family: 'Courier New', Courier, monospace;
overflow: hidden;
}
.clock-container {
position: relative;
width: 100vmin;
height: 100vmin;
}
.segments, .hour-marker {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.segment {
position: absolute;
width: 2.5%;
height: 2.5%;
background-color: rgba(255, 0, 0, 0.2);
border-radius: 50%;
top: 50%;
left: 50%;
transform-origin: 50% 50%;
transition: background-color 0.2s;
}
.segment.active {
background-color: red;
}
.hour-marker {
width: 2.5%;
height: 2.4%;
background-color: #450000;
border-radius: 50%;
top: 50%;
left: 50%;
transform-origin: 50% 50%;
}
.time-display {
position: absolute;
top: 55%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
font-family: monospace;
color: red;
}
.time-display .time {
font-size: 17vmin;
letter-spacing: 0.5vmin;
}
.time-display .seconds {
font-size: 15vmin;
}
.custom-text {
position: absolute;
top: 75%;
left: 50%;
transform: translate(-50%, 0);
text-align: center;
color: red;
font-size: 6vmin;
font-family: monospace;
}
.sync-info {
position: absolute;
top: 1%;
left: 1%;
color: rgb(94, 0, 0);
padding: 10px;
border-radius: 5px;
font-size: 2vmin;
}
</style>
</head>
<body>
<div class="clock-container">
<div class="segments"></div>
<div class="time-display">
<div class="time">00:00</div>
<div class="seconds">00</div>
</div>
<div class="custom-text" id="customText">Your Custom Text</div>
<div class="sync-info" id="syncInfo">NTP Sync: Checking...</div>
</div>
<script>
const segmentsContainer = document.querySelector('.segments');
const timeDisplay = document.querySelector('.time');
const secondsDisplay = document.querySelector('.seconds');
const customTextDisplay = document.getElementById('customText');
const syncInfoDisplay = document.getElementById('syncInfo');
let customText = "CUSTOM TEXT";
// Generate segments and hour markers
for (let i = 0; i < 60; i++) {
const segment = document.createElement('div');
segment.classList.add('segment');
segment.style.transform = `rotate(${i * 6}deg) translate(0, -45vmin)`;
segmentsContainer.appendChild(segment);
}
for (let i = 0; i < 12; i++) {
const hourMarker = document.createElement('div');
hourMarker.classList.add('hour-marker');
hourMarker.style.transform = `rotate(${i * 30 - 90}deg) translate(0, -42vmin)`;
segmentsContainer.appendChild(hourMarker);
}
const segments = document.querySelectorAll('.segment');
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = now.getSeconds();
// Update time display
timeDisplay.textContent = `${hours}:${minutes}`;
secondsDisplay.textContent = String(seconds).padStart(2, '0');
// Update segments
segments.forEach((segment, index) => {
segment.classList.toggle('active', index <= seconds);
});
// Update custom text
customTextDisplay.textContent = customText;
// Synchronize updates with system clock
const nextUpdate = 1000 - now.getMilliseconds();
setTimeout(updateClock, nextUpdate);
}
async function fetchNtpTime() {
try {
const response = await fetch('https://worldtimeapi.org/api/ip');
const data = await response.json();
// Parse NTP time
const ntpTime = new Date(data.utc_datetime);
const localTime = new Date();
const timeDiff = Math.abs(localTime - ntpTime);
// Update sync info
syncInfoDisplay.textContent = `NTP Sync: Success\nDiff: ${timeDiff}ms\nLocal Timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`;
} catch (error) {
syncInfoDisplay.textContent = 'NTP Sync: Failed';
}
}
// Start the clock and fetch NTP time every 30 seconds
updateClock();
fetchNtpTime();
setInterval(fetchNtpTime, 30000);
</script>
</body>
</html>