Celestial Sphere (Masthead Armillary)
The Almanack masthead displays a 3D celestial sphere showing the sun and moon at their approximate astronomical positions. The sphere is centred on the “Almnck.” frontispiece and projected onto an oblate (vertically compressed) dome. In ambient mode, the bodies float silently above the logo. In armillary mode, golden rings, diurnal paths, and cardinal points appear, and the user can rotate the sphere and scrub through the hours of the day.
Files
| File | Role |
|---|---|
assets/js/celestial.js |
Astronomy, projection, rendering, interaction, location |
assets/js/zodiac.js |
Zodiac constellation patterns on the sphere |
assets/js/vendor/astronomy-engine.js |
Astronomy Engine (~412KB), lazy-loaded for Tier 2 |
assets/css/almanack.css |
Canvas styles, expand transition, mobile hide |
src/almnck/ephemeris.py |
Build-time JPL ephemeris computation (skyfield + DE440s) |
src/almnck/templates/base.html |
<canvas>, <script id="celestial-ephemeris"> in .masthead |
assets/celestial/ |
Sun and moon images, per-date and default |
assets/reference/de440s.bsp |
JPL DE440s ephemeris (~32MB, not in git, make ephemeris-fetch) |
How It Works
Ambient Mode
On page load, celestial.js resolves the page’s date (from ?fp= query
param, #frontpage-date element, or today), computes the sun and moon
positions for the current clock hour, and draws them on a canvas that
covers the masthead. The canvas sits behind the text (z-index: 1) with
pointer-events: none.
Bodies use photorealistic images from /static/celestial/{YYYY-MM-DD}/.
If date-specific images aren’t available, the system falls back to
phase-accurate defaults (e.g. moon-waning-gibbous.png).
The zodiac constellations are rendered as small saffron dots on the sphere
surface by zodiac.js, which celestial.js calls at the correct Z-order
point in the render pipeline.
Armillary Mode
Armillary mode is activated by any of three gestures:
- Click on a celestial body (sun or moon). A 28px hit radius around each body’s screen position is tested on every masthead mousedown.
- Click on the period “.” of “Almnck.” (the
.fp-periodelement). Cursor changes tograbon hover as a hint. - Long-press (~400ms) anywhere in the masthead except the navigation bar (and a 15px exclusion zone around it).
Short clicks on the “Almnck.” logo navigate home as normal. Navigation links always work without interference.
When activated:
- The masthead expands vertically (CSS transition on padding).
- Golden armillary rings fade in: celestial equator, meridian, sun’s diurnal path (warm saffron, dashed), moon’s diurnal path (cool silver, dashed), cardinal point rivets and labels (N, E, S, W).
- The canvas gains
pointer-events: autoandz-index: 10. - The
.meta-leftelement shows the day name, date, time, and almanack info: sun rise/set times with day length, moon rise/set with phase name and illumination percentage. Below that, a location line and drag hint.
Interaction during armillary mode:
- Plain drag: rotates the sphere (0.007 rad/px). Tilt clamped to ~64° from vertical.
- Cmd/Ctrl + drag: scrubs through the hours of the day (~1 hour per 20px). The meta-left time display updates in real time.
- Time slider (touch devices): where Cmd+drag isn’t available, a range input appears for scrubbing through the hours.
- Release: after 800ms dwell, the sphere collapses. Time eases back to the real clock time. Rotation returns to the default south-facing view. Armillary rings dissolve.
Date Navigation
When the user navigates between dates via the masthead nav links, the
browser performs a normal cross-document navigation. The destination
page renders its own celestial sphere from its own data-date. The
cross-document View Transition cross-fades the canvas pixels — the new
sphere appears in place of the old. Earlier versions animated the
sun/moon along physically-correct arcs between dates; that was dropped
in May 2026 as part of the HTMX → View Transitions migration (gaudy
on repeat viewings, ~120 lines of orchestration to maintain).
Mobile
The canvas is hidden on viewports narrower than 640px via
display: none !important. The init() function checks for this and
exits early, so there is zero JS execution cost on mobile.
Parallactic Moon
The moon image is rotated by the parallactic angle so that its illuminated limb matches the observer’s sky. The angle is computed from the moon’s hour angle and declination at the observer’s latitude. This makes the crescent “tilt” correctly — pointing roughly toward the sun’s position below the horizon.
Astronomical Model
The celestial sphere uses a two-tier progressive enhancement model for astronomical positions.
Tier 1: JPL Ephemeris (Default)
At build time, ephemeris.py uses skyfield with the JPL DE440s
ephemeris to compute geocentric sun and moon positions (RA/Dec), moon
phase and illumination, and the equation of time. These are embedded as
a <script type="application/json" id="celestial-ephemeris"> block in
every page’s HTML.
On the client, celestial.js reads this JSON and converts RA/Dec to
alt/az using the observer’s latitude (default 40°N) and a longitude
estimated from the browser’s timezone offset. The equation of time
corrects for the difference between solar noon and clock noon.
What Tier 1 provides:
- Sun and moon positions accurate to arcsecond-level (JPL DE440s).
- Moon phase and illumination from skyfield’s moon_phase().
- Equation of time correction (~±16 minutes through the year).
- Timezone-estimated longitude for local sidereal time.
- Seasonal daylight and diurnal arcs with correct declination.
- Zodiac positions: twelve constellations at correct ecliptic
longitudes, moving with the sky as time progresses.
What Tier 1 approximates:
- Observer longitude: estimated from getTimezoneOffset(), so
positions within a timezone may be off by up to ~7° in hour angle
(roughly half a timezone width).
- Fixed latitude: defaults to 40°N unless the reader shares their
location or has used the Regolith latitude picker.
What Tier 1 does not model: - Atmospheric refraction: bodies do not float above the horizon at rise/set as they do in reality. - Lunar parallax: the geocentric position can differ from the topocentric position by up to ~1° for the Moon. - Planetary positions: only the sun and moon are shown. - Stellar positions: zodiac dots are decorative, not from a star catalogue. - Eclipses: not predicted or displayed.
Coverage: DE440s covers 1849–2150 CE. Pages with almanac-day
outside this range (e.g. BCE dates) fall back to the simplified model.
Tier 2: Astronomy Engine (On Geolocation)
When the reader shares their location via the armillary UI, celestial.js
lazy-loads Astronomy Engine (~412KB, vendored) and recomputes
positions with full topocentric accuracy.
What Tier 2 adds over Tier 1:
- Atmospheric refraction ("normal" mode in Horizon()).
- Lunar parallax: topocentric position from the observer’s surface
location, not the Earth’s centre.
- Precise observer position: latitude and longitude from the browser
Geolocation API, not estimated.
Astronomy Engine is only loaded when a stored location exists (or the user clicks “⊕ Use my location”). It is never loaded for the default 40°N fallback, keeping the baseline page weight at zero additional JS.
Simplified Fallback
The original simplified model (sunPosition(), moonPosition()) is
retained for:
- Pages with almanac-day outside the DE440s range (BCE dates).
- Environments where the ephemeris JSON is absent (e.g. test pages).
- The preloadCelestialImages() function on initial page load.
Geolocation
The reader’s location is stored in localStorage under the key
almnck-location as a JSON object:
{
"lat": 37.77,
"lon": -122.42,
"ts": 1708300000,
"source": "geolocation"
}
The source field is "geolocation" for browser-prompted locations or
"manual" for locations set via the Regolith latitude picker. The ts
field is a Unix timestamp of when the location was last set.
Three states:
1. No location (almnck-location absent, almnck-location-denied
absent): armillary shows “Sky for 40°N · ⊕ Use my location”.
2. Location stored: armillary shows “Sky for 38°N, 122°W · ⊕ Update”.
On page load, if the Permissions API reports "granted", the
position is silently refreshed without prompting.
3. Location denied (almnck-location-denied = "true"): no prompt
is shown. The user can clear this via browser settings.
Design Rationale
An almanac is not an ephemeris, but it should get the sky right. The two-tier approach achieves this without bloating the default page: Tier 1 embeds a few hundred bytes of JSON that gives JPL-accurate positions at zero JS cost; Tier 2 loads a full astronomical library only when the reader has opted in to location sharing. The simplified fallback ensures BCE articles still render a plausible sky.
Public API
These window.__ globals are used by other scripts and the test suite:
| Global | Consumer | Purpose |
|---|---|---|
__celestialSetDate(str) |
frontpage-nav.js |
Animate to a new date |
__celestialSetHour(h) |
test suite | Set display hour and re-render |
__celestialUpdate() |
interval timer | Refresh positions from clock |
__celestialAnimating() |
test suite | Returns true if animating |
__celestialDateStr |
zodiac.js |
Current date string |
__sunPosition |
sidenotes.js |
{x, y, visible} in page coords |
__moonPosition() |
test suite | {x, y, visible} in page coords |
almnck-location |
localStorage | {lat, lon, ts, source} shared with latitude picker |
almnck-location-denied |
localStorage | "true" if geolocation was denied |
__zodiacRenderOnSphere() |
celestial.js |
Render constellations |
__zodiacRender() |
celestial.js |
Trigger zodiac redraw |
__celestialUpdateTheme(alt) |
test suite | Force theme update for given sun altitude |
Tests
Tests live in src/tests/:
| File | Marker | What It Covers |
|---|---|---|
test_ephemeris.py |
(unit) | Ephemeris computation: RA/Dec ranges, solstice declinations, moon phase, equation of time, date boundaries, caching |
test_celestial_animation.py |
browser | Date-change animation, rapid changes, reduced motion, canvas presence, mobile hide |
test_celestial_interaction.py |
browser | Body click, period click, long-press, nav preservation, logo navigation, meta-left time display |
test_celestial_location.py |
browser | Ephemeris JSON presence, location prompt in armillary, denied-location hiding |
test_single_theme.py |
unit, browser | The page keeps its one palette whatever the hour or the reader’s OS colour scheme |
The body-click tests inject hour 12 (noon) via __celestialSetHour so
that both sun and moon are deterministically above the horizon regardless
of when the test suite runs. At noon on Feb 13 at 40N, the simplified
model gives sun altitude 36 and moon altitude 19.
Colour Palette
All colours are drawn from the illuminated manuscript CSS variables:
| Element | Colour | Notes |
|---|---|---|
| Horizon disc | rgba(184, 157, 106, 0.06-0.11) |
Faint parchment |
| Horizon ring | rgba(160, 135, 85, 0.2-0.7) |
Golden, thickens in armillary |
| Armillary rings | rgba(184, 137, 46, ) |
Saffron gold |
| Sun glow | rgba(230, 165, 40, ) |
Saffron-amber |
| Moon glow | rgba(150, 165, 195, ) |
Silver-lavender |
| Sun path | rgba(210, 150, 40, ) |
Warm saffron, dashed |
| Moon path | rgba(130, 145, 190, ) |
Cool silver, dashed |
| Cardinal labels | rgba(184, 137, 46, ) |
Saffron, bold 10px |
| Sky wash | rgba(160, 180, 210, 0.04-0.10) |
From sun altitude |
| Zodiac dots | rgba(184, 137, 46, 0.3) |
Saffron, muted |
| Meta-left hint | body font, 0.65rem | 60% opacity |