Replace gauge with latitude-accurate hemicyclium by day and Ctesibius water clock by night

This commit is contained in:
zyphlar committed 2026-10-09 23:42:16 -07:00
1 parent 8a4ddc7811
commit 25f6137bdd
1 file changed
+230 -88
+230 -88
View File
@@ -26,10 +26,18 @@
--muted: #7a6a58;
--accent: #c2410c;
--accent-soft: #f6c99a;
--dial: #fffaf2;
--dial-line: #d8c7ae;
--seg-done: #f1d6b4;
--shadow-hand: rgba(42, 33, 24, .55);
--stone: #e6dac6;
--stone-top: #f4ecdf;
--stone-dark: #cbb898;
--bowl-rim: #c9b899;
--bowl-deep: #f3ebde;
--dial-line: #9c8566;
--band: rgba(194, 65, 12, .22);
--band-done: rgba(122, 106, 88, .10);
--shadow-hand: rgba(42, 33, 24, .6);
--bronze: #a8773a;
--bronze-dark: #6f4c22;
--water: #4f8fd6;
--star: transparent;
}
@media (prefers-color-scheme: dark) {
@@ -43,10 +51,15 @@
--muted: #a8977f;
--accent: #f59e0b;
--accent-soft: #7c4a14;
--dial: #1f1a14;
--dial-line: #4a3e30;
--seg-done: #4a3418;
--shadow-hand: rgba(0, 0, 0, .7);
--stone: #4a4034;
--stone-top: #5b5043;
--stone-dark: #352d24;
--bowl-rim: #2c251d;
--bowl-deep: #5a4e40;
--dial-line: #a08a6c;
--band: rgba(245, 158, 11, .25);
--band-done: rgba(0, 0, 0, .12);
--shadow-hand: rgba(0, 0, 0, .75);
}
}
body.night {
@@ -59,10 +72,18 @@
--muted: #8f9bc2;
--accent: #a5b4fc;
--accent-soft: #3b4785;
--dial: #131a30;
--dial-line: #2f3b68;
--seg-done: #28336a;
--shadow-hand: rgba(205, 215, 255, .5);
--stone: #323c62;
--stone-top: #3d4874;
--stone-dark: #232b4b;
--bowl-rim: #1b2240;
--bowl-deep: #3a4570;
--dial-line: #7d8bc4;
--band: rgba(165, 180, 252, .28);
--band-done: rgba(0, 0, 0, .15);
--shadow-hand: rgba(0, 0, 0, .6);
--bronze: #b98d4e;
--bronze-dark: #7a5728;
--water: #6ea8ff;
--star: #c7d2fe;
}
@@ -117,25 +138,34 @@
.loc-btn svg { flex: none; color: var(--accent); }
.dial-wrap { position: relative; margin: 8px -8px 0; }
#dial { display: block; width: 100%; height: auto; overflow: visible; }
#dial .face { fill: var(--dial); stroke: var(--border); stroke-width: 1; transition: fill .8s; }
#dial .hour-line { stroke: var(--dial-line); stroke-width: 1; }
#dial .seg { fill: var(--surface-2); transition: fill .4s; }
#dial .seg.done { fill: var(--seg-done); }
#dial .seg.now { fill: var(--accent); }
#dial .numeral { font-family: Cinzel, serif; font-size: 15px; font-weight: 500; fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
#dial .numeral.now { fill: var(--accent); font-weight: 700; }
#dial .horizon { stroke: var(--border); stroke-width: 1.5; }
#dial .gnomon { fill: var(--text); }
#dial .star { fill: var(--star); }
#hand {
transform-box: view-box;
transform-origin: 200px 214px;
transition: transform 1s cubic-bezier(.3, .7, .3, 1);
}
#hand.instant { transition: none; }
#hand .shadow { fill: var(--shadow-hand); filter: url(#soft); }
#hand .tip { fill: var(--accent); }
.dial-wrap svg { display: block; width: 100%; height: auto; }
.dial-wrap svg[hidden] { display: none; }
.stone { fill: var(--stone); }
.stone-top { fill: var(--stone-top); }
.stone-dark { fill: var(--stone-dark); }
.g-rim { stop-color: var(--bowl-rim); }
.g-deep { stop-color: var(--bowl-deep); }
.band { fill: transparent; transition: fill .4s; }
.band.done { fill: var(--band-done); }
.band.now { fill: var(--band); }
.hour-line { stroke: var(--dial-line); stroke-width: 1; fill: none; }
.day-curve { stroke: var(--dial-line); stroke-width: .8; fill: none; opacity: .75; }
.today { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; fill: none; opacity: .8; }
.numeral { font-family: Cinzel, serif; font-size: 12px; font-weight: 500; fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
.numeral.now { fill: var(--accent); font-weight: 700; }
.shadow { fill: var(--shadow-hand); filter: url(#soft); }
.tip { fill: var(--accent); }
.bronze { fill: var(--bronze); }
.bronze-dark { fill: var(--bronze-dark); }
.bronze-line { stroke: var(--bronze); fill: none; }
.water { fill: var(--water); opacity: .7; }
.vessel { fill: var(--bg); opacity: .55; }
.stream { stroke: var(--water); stroke-width: 2; stroke-dasharray: 4 4; animation: flow .5s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -8; } }
@media (prefers-reduced-motion: reduce) { .stream { animation: none; } }
.col-line { stroke: var(--dial-line); stroke-width: 1; }
.col-line.vigil { stroke-width: 2; }
.star { fill: var(--star); }
.readout { text-align: center; margin-top: 4px; }
.numeral-big {
@@ -310,24 +340,65 @@
</header>
<div class="dial-wrap">
<svg id="dial" viewBox="0 0 400 236" role="img" aria-labelledby="dialTitle">
<title id="dialTitle">Sundial</title>
<svg id="sundial" viewBox="0 0 400 268" role="img" aria-labelledby="dialTitle">
<title id="dialTitle">Hemicyclium sundial</title>
<defs>
<filter id="soft" x="-20%" y="-20%" width="140%" height="140%">
<feGaussianBlur stdDeviation="1.6"/>
<feGaussianBlur stdDeviation="1.2"/>
</filter>
<radialGradient id="bowlGrad" cx="200" cy="200" r="230" gradientUnits="userSpaceOnUse">
<stop offset="0" class="g-deep"/>
<stop offset="1" class="g-rim"/>
</radialGradient>
</defs>
<g id="stars"></g>
<path class="face" d="M 14 214 A 186 186 0 0 1 386 214 Z"/>
<g id="segs"></g>
<g id="lines"></g>
<path class="stone-top" d="M 14 52 L 40 22 H 360 L 386 52 Z"/>
<rect class="stone" x="14" y="52" width="372" height="196"/>
<rect class="stone-dark" x="6" y="246" width="388" height="16" rx="2"/>
<path class="bowl" fill="url(#bowlGrad)" d="M 30 52 A 170 170 0 0 0 370 52 Z"/>
<g id="bands"></g>
<g id="dialLines"></g>
<path id="todayCurve" class="today"><title>Today's path of the shadow</title></path>
<g id="numerals"></g>
<line class="horizon" x1="6" y1="214" x2="394" y2="214"/>
<g id="hand">
<path class="shadow" d="M 200 210 L 46 214 L 200 218 Z"/>
<circle class="tip" cx="40" cy="214" r="5"/>
<path id="shadow" class="shadow"/>
<circle id="tip" class="tip" r="3.5" cx="200" cy="52"/>
<path class="bronze" d="M 197 30 L 203 30 L 201.5 52 L 198.5 52 Z"/>
<circle class="bronze-dark" cx="200" cy="52" r="2.5"/>
</svg>
<svg id="clepsydra" viewBox="0 0 400 400" role="img" aria-label="Water clock of Ctesibius" hidden>
<g id="stars"></g>
<!-- supply pipe and constant-head tank -->
<path class="bronze-line" stroke-width="5" d="M 64 0 V 104"/>
<line class="stream" x1="64" y1="106" x2="64" y2="134"/>
<rect class="vessel" x="24" y="118" width="84" height="58" rx="3"/>
<rect class="water" x="24" y="132" width="84" height="44"/>
<path class="bronze-line" stroke-width="4" d="M 24 118 V 176 H 108 V 118"/>
<path class="bronze-line" stroke-width="4" d="M 24 132 H 8 V 160"/>
<line class="stream" x1="8" y1="162" x2="8" y2="250"/>
<!-- orifice and feed to the cylinder -->
<path class="bronze-line" stroke-width="4" d="M 92 176 V 192 H 126 V 204"/>
<line id="drip" class="stream" x1="126" y1="206" x2="126" y2="380"/>
<!-- receiving cylinder -->
<rect class="vessel" x="118" y="230" width="84" height="160" rx="3"/>
<rect id="water" class="water" x="118" y="380" width="84" height="10"/>
<path class="bronze-line" stroke-width="4" d="M 118 230 V 392 H 202 V 230"/>
<path class="bronze-line" stroke-width="3" d="M 112 230 H 120 M 132 230 H 152 M 168 230 H 208"/>
<!-- column of hours -->
<rect class="stone-dark" x="252" y="32" width="64" height="12" rx="2"/>
<rect class="stone" x="260" y="44" width="48" height="164"/>
<rect class="stone-dark" x="252" y="206" width="64" height="12" rx="2"/>
<rect class="stone" x="246" y="218" width="76" height="164"/>
<rect class="stone-dark" x="240" y="380" width="88" height="12" rx="2"/>
<g id="column"></g>
<!-- float, rod and figure ride the water -->
<g id="float">
<rect class="bronze-dark" x="134" y="370" width="62" height="10" rx="3"/>
<rect class="bronze" x="158.5" y="214" width="3" height="156"/>
<circle class="bronze" cx="160" cy="184" r="6"/>
<path class="bronze" d="M 154 214 L 156 192 H 164 L 166 214 Z"/>
<path class="bronze-line" stroke-width="2" d="M 162 198 L 258 200"/>
<circle class="tip" cx="258" cy="200" r="3"/>
</g>
<path class="gnomon" d="M 186 214 L 200 194 L 214 214 Z"/>
</svg>
</div>
@@ -366,7 +437,11 @@
Romans split the daylight, from sunrise to sunset, into twelve equal
<a href="https://en.wikipedia.org/wiki/Roman_timekeeping">horae</a>, and the night into twelve more,
grouped into four watches (<i>vigiliae</i>). So an hour stretched in summer and shrank in winter.
This dial works out sunrise and sunset for your location and shows the Roman hour.
By day this page draws a <i>hemicyclium</i>, the hollowed-stone sundial Vitruvius credits to Berosus,
laid out for your latitude: the curves mark the winter solstice, equinox and summer solstice,
and the dashed line is today's path of the shadow. By night, when a sundial is useless, it switches to
the water clock of Ctesibius: water drips at a steady rate into a cylinder, and a float lifts a figure
whose wand points to the hour.
</p>
<footer>romanti.me</footer>
@@ -396,6 +471,8 @@
location.href = location.href.replace("http://", "https://");
}
const $ = id => document.getElementById(id);
// ---- solar math (after SunCalc / NOAA) ----
const rad = Math.PI / 180, dayMs = 864e5, J1970 = 2440588, J2000 = 2451545, J0 = 0.0009;
const obliquity = rad * 23.4397;
@@ -445,55 +522,125 @@
const ENGLISH = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
const VIGILIAE = ["Prima", "Secunda", "Tertia", "Quarta"];
// ---- dial drawing ----
function solarDec(date) {
const d = toDays(date);
const M = rad * (357.5291 + 0.98560028 * d);
const C = rad * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));
return Math.asin(Math.sin(obliquity) * Math.sin(M + C + rad * 102.9372 + Math.PI));
}
// ---- hemicyclium ----
// Front view of an equator-facing spherical dial. The gnomon tip sits at the centre of the
// sphere, so its shadow lands diametrically opposite the sun: x = -east, y (down) = sin(altitude).
const svgNS = "http://www.w3.org/2000/svg";
const CX = 200, CY = 214, R = 186;
const pt = (r, p) => {
const a = Math.PI * (1 - p);
return [CX + r * Math.cos(a), CY - r * Math.sin(a)];
};
const CX = 200, CY = 52, R = 170, SOLSTICE = 23.44 * rad;
const el = (tag, attrs, parent) => {
const e = document.createElementNS(svgNS, tag);
for (const k in attrs) e.setAttribute(k, attrs[k]);
parent.appendChild(e);
return e;
};
const segEls = [], numEls = [];
(function buildDial() {
const segs = document.getElementById('segs');
const lines = document.getElementById('lines');
const nums = document.getElementById('numerals');
const r1 = R - 6, r2 = R - 24;
for (let i = 0; i < 12; i++) {
const p0 = i / 12 + 0.003, p1 = (i + 1) / 12 - 0.003;
const [ax, ay] = pt(r1, p0), [bx, by] = pt(r1, p1);
const [cx, cy] = pt(r2, p1), [dx, dy] = pt(r2, p0);
segEls.push(el('path', {
class: 'seg',
d: `M${ax},${ay} A${r1},${r1} 0 0 1 ${bx},${by} L${cx},${cy} A${r2},${r2} 0 0 0 ${dx},${dy} Z`
}, segs));
const [nx, ny] = pt(R - 44, (i + 0.5) / 12);
const t = el('text', { class: 'numeral', x: nx, y: ny }, nums);
t.textContent = NUMERALS[i];
function dialPoint(lat, dec, f, halfDay) {
const south = lat < 0, phi = Math.abs(lat) * rad, d = south ? -dec : dec;
const H0 = halfDay ?? Math.acos(Math.max(-1, Math.min(1, -Math.tan(phi) * Math.tan(d))));
const H = H0 * (2 * f - 1);
const x = Math.cos(d) * Math.sin(H);
const y = Math.max(0, Math.sin(phi) * Math.sin(d) + Math.cos(phi) * Math.cos(d) * Math.cos(H));
return [CX + (south ? -x : x) * R, CY + y * R];
}
const toPath = pts => 'M' + pts.map(p => p[0].toFixed(1) + ',' + p[1].toFixed(1)).join('L');
const range = (a, b, n) => Array.from({ length: n + 1 }, (_, i) => a + (b - a) * i / n);
const bandEls = [], numEls = [];
let dialLat = null;
function buildDial(lat) {
if (dialLat === lat) return;
dialLat = lat;
const bands = $('bands'), lines = $('dialLines'), nums = $('numerals');
bands.replaceChildren(); lines.replaceChildren(); nums.replaceChildren();
bandEls.length = numEls.length = 0;
const winter = lat < 0 ? SOLSTICE : -SOLSTICE;
const decs = range(-SOLSTICE, SOLSTICE, 16);
const hourLine = f => decs.map(d => dialPoint(lat, d, f));
const dayCurve = (d, f0, f1, n) => range(f0, f1, n).map(f => dialPoint(lat, d, f));
for (let k = 0; k < 12; k++) {
const f0 = k / 12, f1 = (k + 1) / 12;
const pts = [...hourLine(f0), ...dayCurve(SOLSTICE, f0, f1, 6), ...hourLine(f1).reverse(), ...dayCurve(-SOLSTICE, f1, f0, 6)];
bandEls.push(el('path', { class: 'band', d: toPath(pts) + 'Z' }, bands));
// numerals sit just outside the winter-solstice curve, nearest the rim
const [px, py] = dialPoint(lat, winter, (k + .5) / 12);
const vx = px - CX, vy = py - CY, len = Math.hypot(vx, vy) || 1;
const t = el('text', { class: 'numeral', x: px + vx / len * 11, y: py + vy / len * 11 }, nums);
t.textContent = NUMERALS[k];
numEls.push(t);
}
for (let i = 1; i < 12; i++) {
const [x1, y1] = pt(28, i / 12), [x2, y2] = pt(R - 58, i / 12);
el('line', { class: 'hour-line', x1, y1, x2, y2 }, lines);
for (let k = 0; k <= 12; k++) el('path', { class: 'hour-line', d: toPath(hourLine(k / 12)) }, lines);
const curves = [[winter, 'Bruma (winter solstice)'], [0, 'Aequinoctium (equinox)'], [-winter, 'Solstitium (summer solstice)']];
for (const [d, name] of curves) {
const c = el('path', { class: 'day-curve', d: toPath(dayCurve(d, 0, 1, 48)) }, lines);
el('title', {}, c).textContent = name;
}
const stars = document.getElementById('stars');
}
// ---- clepsydra ----
// Water rises at a steady rate through the night; the float carries the figure up the column.
const TRAVEL = 150, POINTER0 = 200;
const colMarks = [], colNums = [], colBands = [];
(function buildClepsydra() {
const col = $('column');
for (let k = 0; k < 12; k++) {
const y1 = POINTER0 - k * TRAVEL / 12, y0 = y1 - TRAVEL / 12;
colBands.push(el('rect', { class: 'band', x: 260, y: y0, width: 48, height: TRAVEL / 12 }, col));
const t = el('text', { class: 'numeral', x: 284, y: (y0 + y1) / 2 }, col);
t.textContent = NUMERALS[k];
colNums.push(t);
}
for (let k = 0; k <= 12; k++) {
const y = POINTER0 - k * TRAVEL / 12;
el('line', { class: 'col-line' + (k % 3 === 0 ? ' vigil' : ''), x1: 260, x2: 308, y1: y, y2: y }, col);
}
const stars = $('stars');
let seed = 7;
const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
for (let i = 0; i < 40; i++) {
el('circle', { class: 'star', cx: rnd() * 400, cy: rnd() * 200, r: rnd() * 1.2 + .3, opacity: rnd() * .6 + .3 }, stars);
for (let i = 0; i < 50; i++) {
el('circle', { class: 'star', cx: rnd() * 400, cy: rnd() * 400, r: rnd() * 1.2 + .3, opacity: rnd() * .6 + .3 }, stars);
}
})();
function drawDay(now, per, frac, idx) {
$('sundial').toggleAttribute('hidden', false);
$('clepsydra').toggleAttribute('hidden', true);
buildDial(place.lat);
const dec = solarDec(now);
$('todayCurve').setAttribute('d', toPath(range(0, 1, 48).map(f => dialPoint(place.lat, dec, f))));
const halfDay = Math.PI * (per.end - per.start) / dayMs;
const [tx, ty] = dialPoint(place.lat, dec, frac, halfDay);
const dx = tx - CX, dy = ty - CY, len = Math.hypot(dx, dy) || 1;
const nx = -dy / len, ny = dx / len;
$('shadow').setAttribute('d', `M${CX + nx * 2.5},${CY + ny * 2.5} L${tx + nx * .8},${ty + ny * .8} L${tx - nx * .8},${ty - ny * .8} L${CX - nx * 2.5},${CY - ny * 2.5}Z`);
$('shadow').style.display = $('tip').style.display = '';
$('tip').setAttribute('cx', tx);
$('tip').setAttribute('cy', ty);
bandEls.forEach((b, i) => b.setAttribute('class', 'band' + (i < idx ? ' done' : i === idx ? ' now' : '')));
numEls.forEach((n, i) => n.setAttribute('class', 'numeral' + (i === idx ? ' now' : '')));
}
function drawNight(frac, idx) {
$('sundial').toggleAttribute('hidden', true);
$('clepsydra').toggleAttribute('hidden', false);
const rise = frac * TRAVEL;
$('float').setAttribute('transform', `translate(0 ${-rise})`);
$('water').setAttribute('y', 380 - rise);
$('water').setAttribute('height', 10 + rise);
$('drip').setAttribute('y2', 380 - rise);
colBands.forEach((b, i) => b.setAttribute('class', 'band' + (i < idx ? ' done' : i === idx ? ' now' : '')));
colNums.forEach((n, i) => n.setAttribute('class', 'numeral' + (i === idx ? ' now' : '')));
}
// ---- state ----
const ROME = { lat: 41.9028, lng: 12.4964, name: 'Roma', tz: 'Europe/Rome' };
let place = loadPlace() || ROME;
let offsetMin = 0;
let lastIsDay = null;
function loadPlace() {
try {
@@ -531,7 +678,6 @@
return h ? `${h}h ${m % 60}m` : `${m} min`;
};
const fmtCoord = p => `${Math.abs(p.lat).toFixed(2)}°${p.lat >= 0 ? 'N' : 'S'}, ${Math.abs(p.lng).toFixed(2)}°${p.lng >= 0 ? 'E' : 'W'}`;
const $ = id => document.getElementById(id);
// ---- render ----
function render() {
@@ -549,16 +695,8 @@
const within = frac * 12 - idx;
document.body.classList.toggle('night', !per.isDay);
const hand = $('hand');
if (lastIsDay !== per.isDay) {
hand.classList.add('instant');
requestAnimationFrame(() => requestAnimationFrame(() => hand.classList.remove('instant')));
lastIsDay = per.isDay;
}
hand.style.transform = `rotate(${frac * 180}deg)`;
segEls.forEach((s, i) => s.setAttribute('class', 'seg' + (i < idx ? ' done' : i === idx ? ' now' : '')));
numEls.forEach((n, i) => n.setAttribute('class', 'numeral' + (i === idx ? ' now' : '')));
if (per.isDay) drawDay(now, per, frac, idx);
else drawNight(frac, idx);
$('bigNumeral').textContent = NUMERALS[idx];
const when = within < 1 / 3 ? 'Early in' : within < 2 / 3 ? 'Midway through' : 'Late in';
@@ -570,7 +708,7 @@
$('latin').textContent = `Hora ${ORDINALS[idx]} Noctis`;
$('phrase').textContent = `${when} the ${ENGLISH[idx]} hour of night · Vigilia ${VIGILIAE[v]}`;
}
$('dialTitle').textContent = `Sundial showing ${$('latin').textContent}`;
$('dialTitle').textContent = `Hemicyclium sundial showing ${$('latin').textContent}`;
const nextAt = new Date(per.start.getTime() + (idx + 1) * hourLen);
$('progLeft').innerHTML = `<b>${Math.round(within * 100)}%</b> through hour ${NUMERALS[idx]}`;
@@ -612,8 +750,12 @@
function renderPolar(kind) {
const day = kind === 'day';
document.body.classList.toggle('night', !day);
$('hand').style.transform = 'rotate(90deg)';
segEls.forEach(s => s.setAttribute('class', 'seg'));
$('sundial').toggleAttribute('hidden', false);
$('clepsydra').toggleAttribute('hidden', true);
buildDial(place.lat);
$('todayCurve').setAttribute('d', '');
$('shadow').style.display = $('tip').style.display = 'none';
bandEls.forEach(b => b.setAttribute('class', 'band'));
numEls.forEach(n => n.setAttribute('class', 'numeral'));
$('bigNumeral').textContent = day ? '☉' : '☾';
$('latin').textContent = day ? 'Sol Perpetuus' : 'Nox Perpetua';