diff --git a/index.html b/index.html
index d98825d..2456bd8 100644
--- a/index.html
+++ b/index.html
@@ -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 @@
-
@@ -366,7 +437,11 @@
Romans split the daylight, from sunrise to sunset, into twelve equal
horae, and the night into twelve more,
grouped into four watches (vigiliae). 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 hemicyclium, 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.
@@ -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 = `${Math.round(within * 100)}% 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';