Manual
Almnck.
Price: 50ⓐ

Horizon Sphere: Design Document

Author: CONSENSX
Date: 2026-02-17
Status: Implemented — as-built reference (updated 2026-02-17)


1. What We’re Building

Replace the current flat sine-arc celestial system (sun and moon sliding along a parabola above “Almnck.”) with a 3D celestial sphere centred on the frontispiece text. The sphere has two modes:

Ambient mode — always visible, no interaction required. The sun and moon float above the logo at their correct astronomical positions, projected onto an oblate (vertically compressed) dome. Sunrise appears near “A”, sunset near “.”. A faint horizon disc and atmospheric glow are visible. The zodiac constellations ride on the sphere surface instead of a separate canvas.

Armillary mode — activated by any of: clicking on the sun or moon body, clicking on the period “.” of “Almnck.”, or long-pressing (~400ms) anywhere in the masthead except the nav zone. Short clicks on the “Almnck.” link still navigate home normally. The masthead expands vertically, golden armillary rings fade in (celestial equator, meridian, sun’s diurnal path, moon’s diurnal path), and cardinal points appear. Time does NOT auto-sweep on expand. Plain drag rotates the sphere. Cmd+drag (macOS) or Ctrl+drag (other platforms) scrubs time left/right. On release (after 800ms dwell), the time eases back to the real time, the rotation returns to the default south-facing view, and the rings dissolve.

2. Why

The sine arc is decorative but meaningless — the y-position is sin(x × π), which has no astronomical basis. The bodies’ x-positions map altitude/azimuth to a flat strip, losing most of the sky’s geometry.

The 3D sphere makes the masthead a real instrument. The sun’s height, its distance from the moon, the length of daylight, the season — all are legible from the ambient display alone. The armillary mode rewards curiosity by revealing the full mechanics of the sky above the reader.

3. Architecture

3.1 File Structure

assets/js/
  celestial.js          — rewrite (was: sine arc + DOM <img> positioning)
  zodiac.js             — rewrite (was: separate canvas with flat ecliptic mapping)
assets/css/
  almanack.css          — modify (masthead transition, canvas z-index, mobile hide)
src/almnck/templates/
  base.html             — modify (add <canvas> element inside masthead)

Two JS files, not one. celestial.js owns the sphere, the astronomy, the canvas, the bodies, the interaction, the animation, and the HTMX date-change API. zodiac.js becomes a thin rendering pass that celestial.js calls at the right point in its render loop — constellations are drawn onto the same canvas, at the right depth, in the right coordinate system. No separate canvas.

3.2 Module Decomposition

celestial.js is structured as a single IIFE with clear internal sections:

┌─────────────────────────────────────────────────────┐
│  Constants & Configuration                          │
├─────────────────────────────────────────────────────┤
│  Astronomy                                          │
│    sunPosition(hour, doy) → {alt, az}               │
│    moonPosition(hour, doy) → {alt, az, age}         │
│    moonPhaseClass(age) → string                     │
│    dayOfYear(dateStr) → number                      │
├─────────────────────────────────────────────────────┤
│  3D Geometry                                        │
│    altAzToXYZ(alt, az) → {x, y, z}                 │
│    project(x, y, z, cx, cy, r, viewRot) → screen   │
│    drawGreatCircle(ctx, ..., poleVec, ...)           │
│    drawDiurnalPath(ctx, ..., posFn, doy, ...)        │
├─────────────────────────────────────────────────────┤
│  Drawing primitives                                 │
│    drawHorizonDisc(ctx, ...)                         │
│    drawHorizonGlow(ctx, ...)                         │
│    drawBody(ctx, ..., img)                           │
│    drawArmillary(ctx, ..., alpha, hour, doy)        │
│    drawRing(ctx, ...)                                │
├─────────────────────────────────────────────────────┤
│  Scene composition                                  │
│    renderScene(ctx, W, H, cx, cy, radius, state)    │
│      1. Sky wash                                    │
│      2. Horizon glow                                │
│      3. Horizon disc + ring                         │
│      4. Armillary rings (if alpha > 0)              │
│      5. Zodiac constellations (call into zodiac.js) │
│      6. Celestial bodies (sun, moon images)         │
├─────────────────────────────────────────────────────┤
│  State & interaction                                │
│    Canvas sizing, DPR handling                      │
│    Masthead expand/collapse CSS transition           │
│    Drag rotation                                    │
│    Armillary fade (in/out with dwell)               │
│    Time sweep (advance through day on expand)       │
│    Time return (ease back to real time on collapse) │
│    Rotation return (ease back to default view)      │
├─────────────────────────────────────────────────────┤
│  Date resolution & image loading                    │
│    resolvePageDate() → "YYYY-MM-DD"                 │
│    loadCelestialImages(dateStr)                     │
│    hybridDate(dateStr) → {hour, doy}                │
│    preloadCelestialImages(dateStr) → Promise        │
├─────────────────────────────────────────────────────┤
│  Public API                                         │
│    window.__celestialSetDate(dateStr)               │
│    window.__celestialUpdate()                        │
│    window.__celestialAnimating()                     │
│    window.__sunPosition                             │
│    window.__celestialDateStr                         │
│    window.__zodiacRender()                          │
└─────────────────────────────────────────────────────┘

zodiac.js exports a single rendering function that celestial.js calls during renderScene, passing in the projection parameters. Constellations are projected onto the celestial sphere surface using the same project() function, so they move correctly when the user drags.

3.3 Data Flow

                     resolvePageDate()
                           │
                  ┌────────▼─────────┐
                  │  dateStr          │  "2026-02-17"
                  │  → doy, hour     │  hybridDate()
                  └────────┬─────────┘
                           │
              ┌────────────▼────────────┐
              │   sunPosition(hour,doy) │
              │  moonPosition(hour,doy) │
              └────────────┬────────────┘
                           │
                    {alt, az} pairs
                           │
              ┌────────────▼────────────┐
              │    altAzToXYZ(alt, az)   │  → 3D unit sphere
              │    project(xyz, ...)     │  → screen coords
              └────────────┬────────────┘
                           │
              ┌────────────▼────────────┐
              │      renderScene()       │  canvas draw calls
              │  (all drawing happens    │
              │   in one rAF callback)   │
              └──────────────────────────┘

3.4 Coordinate System

World space — right-handed, unit sphere: - Y is up (altitude) - X points west (negative X = east) - Z points north (negative Z = south) - altAzToXYZ(alt, az): - x = -sin(az) × cos(alt) - y = sin(alt) - z = cos(az) × cos(alt) - Azimuth: 0°=North, 90°=East, 180°=South, 270°=West (standard compass)

Projection — oblate perspective: 1. Rotate around Y by viewRot[1] (horizontal spin) 2. Rotate around X by viewRot[0] (vertical tilt) 3. Perspective: scale = 1.8 / (1.8 + z' × 0.3) (mild depth) 4. Screen: sx = cx + x' × radius × scale, sy = cy - y' × radius × scale × yScale 5. yScale < 1 flattens the dome (psychophysical flattened sky dome)

Default view: viewRot = [-0.15, 0] — looking due south, slight downward tilt. East (sunrise, “A”) is screen-left. West (sunset, “.”) is screen-right. Sun arcs left-to-right through the top.

3.5 Astronomy

Carried forward from the existing code, with one critical bug fix applied:

Sun: simplified solar position from day-of-year declination + hour angle. Latitude fixed at 40°N. sunPosition(hour, doy) returns {alt, az}. Hour angle uses sin(ha) > 0 for azimuth sign (not ha > 0).

Moon: synodic offset model. Moon’s hour angle = sun’s + phase offset. Moon age computed from continuous fractional day count (not Date objects) to avoid discontinuities at hour boundaries. Hour angle normalised to [-π, π] before azimuth computation.

Reference epoch: Jan 6 2000 18:14 UTC (new moon). Days from reference to Jan 1 2026 = 9491.24. Synodic period = 29.530588 days.

Moon phase classification: existing 8-phase classifier (new, waxing-crescent, first-quarter, etc.) used for default image fallback.

3.6 Sphere Sizing & Placement

The sphere’s horizontal radius must span the frontispiece text width, so the sun’s diurnal path runs from “A” (east) to “.” (west):

radius = (frontispiece.width / 2) × 1.15

The 1.15 multiplier gives bodies room to clear the text edges.

The sphere centre is placed at the frontispiece’s visual centre:

cx = fpRect.left - mhRect.left + fpWidth / 2
cy = fpRect.top - mhRect.top + fpHeight / 2

Oblate compression (yScale): in ambient mode, the masthead is only ~150px tall, but the radius is ~225px. Without compression, the noon sun would be far above the masthead. yScale is computed dynamically:

headroom = cy                           // pixels above centre to masthead top
yScale = min(1, headroom × 0.85 / radius)
yScale = max(0.3, yScale)              // floor: never a total pancake

In expanded mode, more headroom → yScale increases → more dome visible.

3.7 Canvas Element & Layering

A single <canvas> element is added to the masthead in base.html:

<div class="masthead">
  <canvas class="horizon-canvas" aria-hidden="true"></canvas>
  <!-- existing: meta-left, frontispiece-wrapper, meta-right, masthead-nav -->
</div>

Z-index layering: - Canvas at z-index: 1 (behind text) in ambient mode - Canvas at z-index: 10 with pointer-events: auto in armillary mode - Masthead text at z-index: 2 (always above ambient canvas)

The canvas is sized to the full masthead dimensions and rendered at device pixel ratio for crisp lines.

3.8 Interaction

Five rules govern armillary activation and canvas interaction:

  1. Body hit-test: clicking on the sun or moon (28px hit radius) calls activateArmillary(). The canvas checks body screen positions on each mousedown/touchstart.

  2. Period click: clicking the .fp-period element (the “.” in “Almnck.”) calls activateArmillary().

  3. Long-press: a 400ms timer starts on masthead mousedown / touchstart (except in the nav zone). If the mouse does not move before the timer fires, activateArmillary() is called. A capture-phase click handler prevents link navigation after a long-press fires.

  4. Nav zone exclusion: anything inside .masthead-nav or within 15px proximity never triggers armillary activation.

  5. Canvas drag: once expanded, plain drag rotates viewRot by delta × 0.007 rad/px. Cmd+drag (macOS) or Ctrl+drag (other platforms) scrubs time at 0.05 hr/px. mouseup / touchend triggers an 800ms dwell timer (cancelled if user re-clicks), then collapse begins.

Expand/collapse via CSS transition on masthead padding:

.masthead { transition: padding 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94); }
.masthead.expanded { padding-top: 4em; padding-bottom: 3em; }

During the CSS transition, a requestAnimationFrame loop continuously re-sizes the canvas and re-renders to track the changing masthead height. Stops on transitionend.

Armillary fade: armillaryAlpha eases toward 1 on expand (fast: += diff × 0.08 + 0.003) and toward 0 on collapse (slow: += diff × 0.025 + 0.003). All armillary drawing is multiplied by this alpha.

Time scrub: there is no auto time sweep. The user holds Cmd/Ctrl+drag to scrub time left/right at 0.05 hr/px. On collapse, the display hour eases back to the real time via shortest-path on the 24h clock.

Rotation return: on collapse, viewRot eases back to DEFAULT_ROT at += diff × 0.06 per frame.

Meta-left time display: when expanded, .meta-left shows the current day name and formatted time (e.g. “Wednesday, 1:00 PM”) and a hint line showing the modifier key (“⌘+drag to scrub time” on Mac, “Ctrl+drag to scrub time” elsewhere). The original .meta-left content is restored on collapse.

All three animations (alpha, time, rotation) run in a single rAF loop. The loop self-terminates when all three have converged.

3.9 HTMX Date Navigation

window.__celestialSetDate(dateStr) is called by frontpage-nav.js when the user navigates between dates. This must:

  1. Capture current body screen positions (for animation start)
  2. Determine temporal direction (earlier = -1, later = +1)
  3. Update currentDateStr, doy, load new images
  4. Compute new target positions on the sphere
  5. Animate bodies along their sphere paths from old to new positions
  6. Swap images at mid-animation (when bodies cross the horizon)
  7. Update window.__celestialDateStr for zodiac

The animation uses the sphere projection (not the old flat positionBodyAtX). The sweep interpolates the hour angle, so bodies trace physically correct arcs during the transition.

Reduced motion: skip animation, snap to final positions immediately.

3.10 Zodiac Integration

Currently zodiac.js maps ecliptic longitudes to the flat arc via eclipticLonToX. In the new system, constellations are placed on the celestial sphere at their ecliptic coordinates and projected through the same project() function.

The ecliptic is a great circle tilted ~23.44° from the celestial equator. Each constellation’s position on the ecliptic is converted to RA/Dec, then to alt/az for the current time, then to XYZ. The constellation’s star pattern is drawn as small dots on the sphere surface, properly foreshortened by the projection.

celestial.js calls zodiac.renderOnSphere(ctx, cx, cy, radius, viewRot, hour, doy, yScale) at the right Z-order point in renderScene — after the horizon disc, before the bodies. zodiac.js is responsible for the constellation data and star placement; celestial.js provides the projection infrastructure.

3.11 Sun Position for Sundial Lighting

window.__sunPosition must still provide page-space coordinates for the sundial lighting system in sidenotes.js. After rendering, we project the sun’s alt/az to screen coordinates and convert to page space:

var sunScreen = project(sunXYZ.x, sunXYZ.y, sunXYZ.z, cx, cy, radius, viewRot);
window.__sunPosition = {
  x: canvasRect.left + sunScreen.sx + window.scrollX,
  y: canvasRect.top + sunScreen.sy + window.scrollY,
  visible: sunOpacity > 0.1
};

3.12 Mobile

The existing system hides celestial bodies on mobile (display: none !important at the mobile breakpoint). We maintain this — the canvas gets the same treatment. No JS execution cost on mobile.

@media (max-width: 600px) {
  .horizon-canvas { display: none !important; }
}

The canvas init() checks for the computed display: none and exits early.

3.13 Progressive Enhancement

The system is entirely decorative. If JS fails, the canvas never appears. If the canvas doesn’t render, the masthead looks exactly as it does without celestial bodies — text on a cream background with an illuminated rule. The <canvas> element has aria-hidden="true".

4. Rendering Pipeline

Every frame, renderScene() draws in this order:

1. Clear canvas (transparent — masthead CSS background shows through)
2. Sky wash (faint blue-to-transparent gradient, intensity from sun altitude)
3. Horizon glow (saffron for sun, silver for moon — radial gradients at
   the horizon point nearest each body)
4. Horizon disc (filled ellipse at y=0, faint parchment tone)
5. Horizon ring (circle at y=0, golden stroke, thickens with armillary)
6. Armillary rings (if armillaryAlpha > 0):
   a. Celestial equator — great circle with NCP as pole
   b. Meridian — great circle with East as pole
   c. Sun's diurnal path — dashed, warm saffron
   d. Moon's diurnal path — dashed, cool silver
   e. Horizon ring reinforcement
   f. Cardinal point rivets and labels (N, E, S, W)
7. Zodiac constellations — small dots on the sphere surface
8. Sun — image (or fallback disc) with glow halo, faded by altitude
9. Moon — image (or fallback disc) with glow halo, faded by altitude

Drawing order ensures bodies are always on top (they’re the focal point). Armillary rings are underneath bodies but above the horizon disc.

5. State Machine

         ┌──────────────────────────────────────────────────┐
         │                   AMBIENT                        │
         │  armillaryAlpha = 0                              │
         │  timeAnimating = false                           │
         │  canvas z-index: 1 (behind text)                 │
         │  masthead: normal padding                        │
         │  renderScene: glow + disc + bodies               │
         └───────────┬──────────────────────────────────────┘
                     │ body click / period click / long-press
                     ▼
         ┌──────────────────────────────────────────────────┐
         │                  EXPANDING                       │
         │  armillaryAlpha → 1 (fast ease)                  │
         │  time frozen at current clock value              │
         │  canvas z-index: 10 (captures input)             │
         │  masthead: .expanded (CSS transition)             │
         │  rAF loop: resize canvas + render each frame     │
         └───────────┬──────────────────────────────────────┘
                     │ transitionend
                     ▼
         ┌──────────────────────────────────────────────────┐
         │                  EXPANDED                        │
         │  armillaryAlpha ≈ 1                              │
         │  user can rotate freely; ⌘/Ctrl+drag scrubs time│
         │  meta-left shows time + hint                     │
         │  Full armillary visible                          │
         └───────────┬──────────────────────────────────────┘
                     │ mouseup / touchend
                     │ (800ms dwell timer)
                     ▼
         ┌──────────────────────────────────────────────────┐
         │                 COLLAPSING                       │
         │  armillaryAlpha → 0 (slow ease, ~3s)             │
         │  timeAnimating = false                           │
         │  timeReturning = true (ease hour → realHour)     │
         │  rotationReturning = true (ease rot → default)   │
         │  masthead: remove .expanded                      │
         │  rAF loop: resize canvas + render each frame     │
         └───────────┬──────────────────────────────────────┘
                     │ all animations converged
                     ▼
                  AMBIENT (loop)

If the user clicks during COLLAPSING, the state jumps directly to EXPANDING — all return animations are cancelled, the armillary begins fading back in, time sweep restarts from the current display hour.

6. Colour Palette

All colours from the existing illuminated manuscript CSS variables:

Element Colour Opacity
Horizon disc rgba(184, 157, 106, 0.06–0.11) ambient–armillary
Horizon ring rgba(160, 135, 85, 0.2–0.7) ambient–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 stars rgba(184, 137, 46, 0.3) saffron, muted

7. Preserved Contracts

These window.__ globals must continue to work for other scripts:

Global Consumer Contract
__celestialSetDate(str) frontpage-nav.js Animate to new date
__celestialUpdate() interval timer Refresh positions
__celestialAnimating() test suite Returns bool
__celestialDateStr zodiac.js Current date string
__sunPosition sidenotes.js {x, y, visible} in page coords
__zodiacRender() celestial.js Trigger zodiac redraw
__celestialSetHour(h) test suite Set display hour and re-render
__moonPosition() test suite {x, y, visible} in page coords

8. What Changes for Existing Tests

test_celestial.py (unit tests for directory structure and image files): No changes needed. These test the asset directory, not the JS.

test_celestial_animation.py (Playwright browser tests): Updated. - Bodies are no longer positioned via <img> elements with .style.left and .style.opacity. They’re drawn on a canvas. - Tests query the window.__celestialAnimating() API and the window.__sunPosition / window.__moonPosition() globals. - The rapid-date-change test still validates that bodies settle correctly. - The reduced-motion test still validates instant snap. - Helpers getSunPosition(page) and getMoonPosition(page) read from the exposed window globals.

test_celestial_interaction.py (Playwright browser tests): Written. Covers the full interaction model: - Body clicks (sun and moon hit-test → armillary activation) - Period click (.fp-period → armillary activation) - Long-press (~400ms anywhere in masthead except nav → armillary activation) - Nav zone preservation (nav links remain clickable, not intercepted) - Logo navigation (short click on “Almnck.” still navigates home) - Meta-left time display (day name + formatted time shown when expanded)

9. What Gets Deleted

  • celestial.js lines that create <img> DOM elements (createCelestialImg, positionBodyAtX, positionBody) — bodies are now canvas-drawn.
  • skyToMasthead() — replaced by altAzToXYZ + project.
  • sweepDistance, sweepX — the flat-arc animation helpers. The new animation interpolates hour values, not x-positions.
  • The animateArc() function’s flat horizon-fade logic.
  • zodiac.js canvas creation — zodiac draws on celestial’s canvas.
  • zodiac.js eclipticLonToX() — constellations projected in 3D.
  • .celestial-body CSS class.

10. Resolved Questions

  1. Zodiac depth sorting: constellation dots on the far side of the sphere (z’ > 0 after view rotation) are drawn dimmer — multiply their opacity by max(0.15, 1 - z'). This gives a natural “through the glass” effect in armillary mode without fully hiding them.

  2. Date animation path: date changes via __celestialSetDate animate bodies in ambient mode only — no armillary expansion. The animation interpolates the hour value and lets the sphere projection trace the correct arc. The armillary is reserved for deliberate user interaction.

  3. Activation model: three-tier activation (body click, period click, long-press) replaces the original click-and-drag anywhere. This prevents interference between armillary activation and normal masthead navigation (logo click → home, nav links → pages).

  4. Time control: Cmd/Ctrl+drag replaces auto time sweep. This gives the user explicit control and avoids the disorienting auto-advance.

  5. Moon reference epoch: MOON_REF_DAYS_TO_2026 was corrected from 9126.24 to 9491.24 (off by 365 days). The Jan 3 2026 Full Supermoon was rendering as new moon.

11. Remaining Questions

  1. ~~Touch interaction~~: RESOLVED — touch events are handled (touchstart/touchmove/touchend with passive: false to prevent scroll while dragging the sphere).

  2. Performance: renderScene redraws the entire canvas every frame. On a 2× Retina display with a 900px-wide masthead, that’s a 1800×300 canvas. With 120-step great circles × 4 rings + 96-step diurnal paths × 2, that’s ~720 lineTo calls per frame during armillary mode. Should be fine at 60fps but worth profiling.


As-built reference. Implementation complete on the feat/horizon-sphere branch.