only 60 dots, to match normal clocks; colours change through the day and support dark mode
This commit is contained in:
parent
24758b7758
commit
6eaa95d0f7
3 changed files with 80 additions and 14 deletions
15
index.html
15
index.html
|
@ -3,12 +3,11 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<title>A thing made by CLP</title>
|
<title>Hilbert clock</title>
|
||||||
<script type="module" src="script.js"></script>
|
<script type="module" src="script.js"></script>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
|
||||||
<svg id="board" viewBox="-0.3 -0.3 1.6 1.6" style="max-height: 100svh">
|
<svg id="board" viewBox="-0.3 -0.3 1.6 1.6" style="max-height: 100svh">
|
||||||
<defs>
|
<defs>
|
||||||
<linearGradient id="dots-gradient">
|
<linearGradient id="dots-gradient">
|
||||||
|
@ -16,12 +15,14 @@
|
||||||
<stop offset="100%" stop-color="white" />
|
<stop offset="100%" stop-color="white" />
|
||||||
</linearGradient>
|
</linearGradient>
|
||||||
</defs>
|
</defs>
|
||||||
<rect x="-100" y="-100" width="200" height="200" fill="hsl(140,60%,60%)"/>
|
<path id="big-hand" class="curve" fill="none" stroke-width="-1.01" stroke-linejoin="round" stroke-linecap="square"/>
|
||||||
<path class="curve" fill="none" stroke="hsl(24,50%,10%)" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="square"/>
|
<path id="small-hand" class="curve" fill="none" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="square"/>
|
||||||
<path class="curve" fill="none" stroke="hsl(240,50%,50%)" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="square"/>
|
<path id="dots" fill="none" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="round"/>
|
||||||
<path id="dots" fill="none" stroke="hsl(240,20%,90%)" stroke-width="0.01" stroke-linejoin="round" stroke-linecap="round"/>
|
|
||||||
<text id="debug" fill="white" font-size="0.1"></debug>
|
<text id="debug" fill="white" font-size="0.1"></debug>
|
||||||
</svg>
|
</svg>
|
||||||
</main>
|
|
||||||
|
<footer>
|
||||||
|
<p><a href="https://somethingorotherwhatever.com">made by clp</a></p>
|
||||||
|
</footer.
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
23
script.js
23
script.js
|
@ -26,6 +26,7 @@ const width = 1.5 * 2**-(steps+1);
|
||||||
|
|
||||||
const dots = [];
|
const dots = [];
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
for(let c of s) {
|
for(let c of s) {
|
||||||
const [dx,dy] = dir;
|
const [dx,dy] = dir;
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
@ -36,15 +37,19 @@ for(let c of s) {
|
||||||
dir = [dy,-dx];
|
dir = [dy,-dx];
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
|
i += 1;
|
||||||
x += dx;
|
x += dx;
|
||||||
y += dy;
|
y += dy;
|
||||||
d += `l ${dx} ${dy}`;
|
d += `l ${dx} ${dy}`;
|
||||||
}
|
}
|
||||||
|
if(i==61) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d += 'l 0.000000001 0.000001'; // make sure the final dot is drawn
|
d += 'l 0.000000001 0.000001'; // make sure the final dot is drawn
|
||||||
|
|
||||||
const length = (2**(2*steps)-1) * m;
|
const length = 60 * m;
|
||||||
|
|
||||||
const curves = Array.from(document.querySelectorAll('.curve'));
|
const curves = Array.from(document.querySelectorAll('.curve'));
|
||||||
|
|
||||||
|
@ -67,13 +72,17 @@ function easeLinear(t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function frame() {
|
function frame() {
|
||||||
const segments = 2**(2*steps)-1; // number of segments in the curve
|
const now = new Date();
|
||||||
const period = 1000*60/segments; // One period of the small hand is 60 seconds
|
const midnight = new Date(now.getFullYear(),now.getMonth(),now.getDate());
|
||||||
|
|
||||||
|
const dt = (new Date() - midnight);
|
||||||
|
document.body.style.setProperty('--bg-hue',dt*360/(1000*60*60*24));
|
||||||
|
|
||||||
|
const segments = 60; // number of segments in the curve
|
||||||
|
const period = 1000; // One period of the small hand is 60 seconds
|
||||||
curves.forEach((curve,i) => {
|
curves.forEach((curve,i) => {
|
||||||
const now = new Date();
|
const m = (dt / period / (60**(1-i))) % (2*60); // between 0 and 120
|
||||||
const midnight = new Date(now.getFullYear(),now.getMonth(),now.getDate());
|
//const m = document.getElementById('t').valueAsNumber * 120;
|
||||||
const dt = (new Date() - midnight) / period / (60**(1-i));
|
|
||||||
const m = dt % (2*segments);
|
|
||||||
const t = i == 0 ? m : (Math.floor(m) + easeInOutSine(m % 1)); // linear for big hand, eased for small hand
|
const t = i == 0 ? m : (Math.floor(m) + easeInOutSine(m % 1)); // linear for big hand, eased for small hand
|
||||||
const a = t/segments; // between 0 and 2
|
const a = t/segments; // between 0 and 2
|
||||||
const b = 2*(1-Math.abs(1-a/2));
|
const b = 2*(1-Math.abs(1-a/2));
|
||||||
|
|
56
style.css
56
style.css
|
@ -2,4 +2,60 @@
|
||||||
--spacing: 1em;
|
--spacing: 1em;
|
||||||
|
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
|
|
||||||
|
--bg-hue: 210;
|
||||||
|
--bg-lum: 60%;
|
||||||
|
|
||||||
|
--hand-hue: calc(180 + var(--bg-hue));
|
||||||
|
--big-hand-lum: 15%;
|
||||||
|
--small-hand-lum: 50%;
|
||||||
|
--dots-lum: 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
filter: saturate(0%);
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--bg-lum: 20%;
|
||||||
|
--big-hand-lum: 90%;
|
||||||
|
--small-hand-lum:60%;
|
||||||
|
--dots-lum: 15%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: hsl(var(--bg-hue),60%,var(--bg-lum));
|
||||||
|
display: grid;
|
||||||
|
justify-items: center;
|
||||||
|
grid-template: 1fr auto / 1fr;
|
||||||
|
height: 100svh;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#board {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
main {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
path {
|
||||||
|
stroke: hsl(var(--hand-hue),50%,var(--lum));
|
||||||
|
}
|
||||||
|
|
||||||
|
#big-hand {
|
||||||
|
--lum: var(--big-hand-lum);
|
||||||
|
}
|
||||||
|
|
||||||
|
#small-hand {
|
||||||
|
--lum: var(--small-hand-lum);
|
||||||
|
}
|
||||||
|
|
||||||
|
#dots {
|
||||||
|
--lum: var(--dots-lum);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue