-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
174 lines (145 loc) · 4.41 KB
/
index.html
File metadata and controls
174 lines (145 loc) · 4.41 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
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
<!DOCTYPE html>
<html>
<head>
<title>SVG Animated Clock</title>
<style>
body {
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #f0f0f0;
font-family: Arial, sans-serif;
}
.clock-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
}
.clock {
width: 300px;
height: 300px;
}
.clock-face {
fill: #fff;
stroke: #333;
stroke-width: 2;
}
.marker {
stroke: #333;
stroke-width: 2;
stroke-linecap: round;
}
.minute-marker {
stroke: #666;
stroke-width: 1;
}
.hands {
transform-origin: 150px 150px;
}
.hand {
transform-origin: 150px 150px;
}
.hour-hand {
stroke: #333;
stroke-width: 6;
stroke-linecap: round;
}
.minute-hand {
stroke: #666;
stroke-width: 4;
stroke-linecap: round;
}
.second-hand {
stroke: #f00;
stroke-width: 2;
stroke-linecap: round;
}
.center-dot {
fill: #333;
}
.digital-clock {
font-size: 2.5rem;
font-weight: bold;
color: #333;
background: #fff;
padding: 10px 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="clock-container">
<svg class="clock" viewBox="0 0 300 300">
<!-- Clock face -->
<circle class="clock-face" cx="150" cy="150" r="145" />
<!-- Markers will be added by JavaScript -->
<g class="markers"></g>
<!-- Clock hands -->
<g class="hands">
<line class="hand hour-hand" x1="150" y1="150" x2="150" y2="85" />
<line class="hand minute-hand" x1="150" y1="150" x2="150" y2="65" />
<line class="hand second-hand" x1="150" y1="150" x2="150" y2="55" />
</g>
<!-- Center dot -->
<circle class="center-dot" cx="150" cy="150" r="3" />
</svg>
<div class="digital-clock">00:00:00</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<script>
const markers = document.querySelector('.markers');
const digitalClock = document.querySelector('.digital-clock');
const hourHand = document.querySelector('.hour-hand');
const minuteHand = document.querySelector('.minute-hand');
const secondHand = document.querySelector('.second-hand');
// Create markers
for (let i = 0; i < 60; i++) {
const marker = document.createElementNS("http://www.w3.org/2000/svg", "line");
const isHour = i % 5 === 0;
const angle = i * 6;
const length = isHour ? 15 : 7;
const r1 = isHour ? 135 : 140;
const r2 = r1 - length;
const x1 = 150 + r1 * Math.cos((angle - 90) * Math.PI / 180);
const y1 = 150 + r1 * Math.sin((angle - 90) * Math.PI / 180);
const x2 = 150 + r2 * Math.cos((angle - 90) * Math.PI / 180);
const y2 = 150 + r2 * Math.sin((angle - 90) * Math.PI / 180);
marker.setAttribute("class", isHour ? "marker" : "minute-marker");
marker.setAttribute("x1", x1);
marker.setAttribute("y1", y1);
marker.setAttribute("x2", x2);
marker.setAttribute("y2", y2);
markers.appendChild(marker);
}
function updateClock() {
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
// Update digital clock
const formattedHours = String(hours).padStart(2, '0');
const formattedMinutes = String(minutes).padStart(2, '0');
const formattedSeconds = String(seconds).padStart(2, '0');
digitalClock.textContent = `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
// Calculate angles
const hourAngle = 30 * (hours % 12) + minutes / 2;
const minuteAngle = 6 * minutes + seconds / 10;
const secondAngle = 6 * seconds;
// Update hands with SVG transform attribute
hourHand.style.transform = `rotate(${hourAngle}deg)`;
minuteHand.style.transform = `rotate(${minuteAngle}deg)`;
secondHand.style.transform = `rotate(${secondAngle}deg)`;
// Schedule next update
const msToNextSecond = 1000 - now.getMilliseconds();
setTimeout(updateClock, msToNextSecond);
}
// Start the clock
updateClock();
</script>
</body>
</html>