-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpha.html
More file actions
216 lines (185 loc) · 7.84 KB
/
Copy pathalpha.html
File metadata and controls
216 lines (185 loc) · 7.84 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Floating Color Timer</title>
<style>
body {
margin: 0;
padding: 0;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-family: 'Segoe UI', system-ui, sans-serif;
transition: background-color 1s ease;
color: white;
text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.time-display {
font-size: 4rem;
font-weight: 300;
margin-bottom: 1rem;
letter-spacing: 2px;
}
.date-display {
font-size: 1.5rem;
margin-bottom: 2rem;
opacity: 0.9;
}
.color-info {
background: rgba(0, 0, 0, 0.7);
padding: 1.5rem;
border-radius: 15px;
margin-top: 2rem;
text-align: center;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.color-code {
font-family: 'Monaco', 'Courier New', monospace;
font-size: 1.2rem;
margin: 0.5rem 0;
}
.hsl-values {
display: flex;
gap: 1rem;
justify-content: center;
margin-top: 0.5rem;
flex-wrap: wrap;
}
.hsl-value {
background: rgba(255, 255, 255, 0.1);
padding: 0.5rem 1rem;
border-radius: 8px;
}
.description {
max-width: 600px;
text-align: center;
line-height: 1.6;
margin: 2rem;
padding: 1rem;
background: rgba(0, 0, 0, 0.7);
border-radius: 10px;
}
</style>
</head>
<body>
<div class="time-display" id="currentTime">00:00:00</div>
<div class="date-display" id="currentDate">January 1, 2024</div>
<div class="color-info">
<div>Current Color Tone</div>
<div class="color-code" id="colorCode">#FFFFFF</div>
<div class="hsl-values">
<div class="hsl-value">H: <span id="hueValue">0</span>°</div>
<div class="hsl-value">S: <span id="saturationValue">50</span>%</div>
<div class="hsl-value">L: <span id="lightnessValue">50</span>%</div>
</div>
</div>
<div class="description">
<p>The color changes cyclically throughout the day, creating a unique visual timeline. Each second brings a subtle shift in hue, while hours and minutes influence saturation and lightness.</p>
<p>The color progression follows the natural flow of time, creating distinctive visual moments throughout your day.</p>
</div>
<script>
class FloatingColorTimer {
constructor() {
this.timeDisplay = document.getElementById('currentTime');
this.dateDisplay = document.getElementById('currentDate');
this.colorCode = document.getElementById('colorCode');
this.hueValue = document.getElementById('hueValue');
this.saturationValue = document.getElementById('saturationValue');
this.lightnessValue = document.getElementById('lightnessValue');
// Initialize and start the timer
this.updateTime();
this.updateColor();
setInterval(() => {
this.updateTime();
this.updateColor();
}, 1000);
}
updateTime() {
const now = new Date();
// Format time (HH:MM:SS)
const timeString = now.toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
// Format date
const dateString = now.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
this.timeDisplay.textContent = timeString;
this.dateDisplay.textContent = dateString;
}
updateColor() {
const now = new Date();
const totalSeconds = now.getHours() * 3600 +
now.getMinutes() * 60 +
now.getSeconds();
const totalMilliseconds = now.getHours() * 3600000 +
now.getMinutes() * 60000 +
now.getSeconds() * 1000 +
now.getMilliseconds();
// Calculate HSL values based on time
// Hue: Cycles through 0-360 degrees based on milliseconds in the day
const hue = (totalMilliseconds / (24 * 60 * 60 * 1000)) * 360;
// Saturation: Pulses throughout the hour (0-60 minutes)
const minuteProgress = now.getMinutes() / 60;
const saturation = 30 + (Math.sin(minuteProgress * Math.PI * 2) * 20 + 20);
// Lightness: Changes throughout the day
const hourProgress = now.getHours() / 24;
const lightness = 30 + (Math.sin(hourProgress * Math.PI * 2) * 10 + 10);
// Apply color to body
const color = `hsl(${hue}, ${saturation}%, ${lightness}%)`;
document.body.style.backgroundColor = color;
// Update display values
this.colorCode.textContent = this.hslToHex(hue, saturation, lightness);
this.hueValue.textContent = Math.round(hue);
this.saturationValue.textContent = Math.round(saturation);
this.lightnessValue.textContent = Math.round(lightness);
// Adjust text color for better contrast
document.body.style.color = lightness > 50 ? '#333' : '#fff';
}
hslToHex(h, s, l) {
h /= 360;
s /= 100;
l /= 100;
let r, g, b;
if (s === 0) {
r = g = b = l;
} else {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
const toHex = x => {
const hex = Math.round(x * 255).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
}
}
// Initialize the timer when page loads
document.addEventListener('DOMContentLoaded', () => {
new FloatingColorTimer();
});
</script>
</body>
</html>