@himmelszelt/sternzeit

sternzeit: German, "star time": sidereal time, the time kept by the stars rather than the Sun. Also the German for Star Trek's stardate.

Astronomy for sky renderers: the Sun and the Moon, accurate, anywhere, any time.

by Daniel Limberger · Last updated 22 November 2026 · Unfamiliar term?Unfamiliar term Like this one: a dotted underline marks a term this site explains. Hover it, or tap it on a touch screen, and its definition opens right where you are reading. The small numbered citations work the same way, with the source they point to.

Contents
  1. Counting time the astronomer’s way
  2. Earth, the platform we observe from
  3. Coordinates on the sky
  4. The Sun
  5. The Moon
  6. Eclipses
  7. A month of Moons
  8. Precise and approximate
  9. The people behind the numbers
  10. References

Before there were clocks, the sky was the clock: the Sun set the day, the Moon the month, the seasons the year. That is why its motions can be predicted so well, forward or back, for any place and any moment. sternzeit computes the Sun’s and the Moon’s part of them and leaves the stars to sternenheer. It answers the way a renderer asks: with the direction to point a light along, the angle to turn a crescent by, how brightly Earth lights the Moon’s night side, and how far an eclipse has come, as a number a shader can use. None of it is guesswork. Jean Meeus wrote the recipes down [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998., and SunCalc, astronomia and Astronomy Engine compute them in JavaScript already; sternzeit is the one made for real-time rendering.

@himmelszelt/sternzeit is written in TypeScript and ships as typed ES modules without a single dependency. It touches neither the DOM nor the GPU, so it runs anywhere JavaScript runs, in a worker or on a server too, and it is cheap enough to call every frame: a few microseconds for the Sun or the Moon, where a frame at 60 Hz lasts more than 16,000. Everything comes twice, precise and approximate. What to do with the numbers is up to you: give a CAD or architecture viewer the right light and shadows for a real site and hour, let a game’s day follow the player’s clock, label what is up right now in augmented reality, or show the sky over a date in history. Four tasks are worked out below, code included: the golden hour for any day and place, a crescent turned the right way, the next eclipse, and a moon calendar of your own.

All of them start from the same three bodies. Earth, tilted and turning, is where we watch from (Figure), and its turning is what sweeps the sky around us once a day. It circles the Sun once a year, and the tilt makes the seasons of that year. The Moon circles Earth about once a month, lit by sunshine and, faintly, by earthshineEarthshine Sunlight reflected by Earth onto the Moon, which lights its night side with a faint, ashen glow, easiest to see on a thin crescent. Strongest around new moon, when the Moon sees a full Earth, and gone at full moon, when the side of Earth facing it is dark..

Drag to rotate. Visualized with Zdog.

observereclipticcelestial equatorvernal equinoxNSecliptic axis
sun-locked: the observer's sky
moon-locked: the observer's sky
An armillary sphereArmillary sphere A model of the sky made of rings around Earth at its center: the celestial equator, the ecliptic, meridians, sometimes the horizon. Used since antiquity to teach the sky and to measure positions in it.: Earth's equator and axis, its north (N) and south (S) pole, the celestial equator (dotted), the ecliptic and its axis, the vernal equinox, the observer's latitude circle and meridian, and the Sun and the Moon in their directions from Earth's center, all in geocentric equatorial coordinates. Distances are schematic, the Sun and the Moon symbols, not to scale. (a, b) The sky as the observer at the chosen place sees it, locked on the Sun and on the Moon: each held at the center while the horizon moves.TryThe June solstice: the Sun at the ecliptic's northernmost, 23.4° above the celestial equator.
Moment and place

Every figure and table on this page is computed live by the library, in your browser, and follows one moment and one place. They are set beside the text, where they stay in view while you read; on a narrow screen, unfold the controls right under the figure, which sit folded up below every figure and every unfolded table, so there is no need to scroll back up here. The pin fills in your location.

In code, it takes one install and two calls:

npm install @himmelszelt/sternzeit
import { fromDate, moon, sun } from "@himmelszelt/sternzeit";

const observer = { latitude: 52.39, longitude: 13.09 };
const now = fromDate(new Date());
// Unit vectors from where you stand: x east, y north, z up.
const toSun = sun.direction(now, observer);
const toMoon = moon.direction(now, observer);

The sections below explain what lies behind these two calls, from the sky down to the code.

Counting time the astronomer’s way

Calendars are a mess. Months have different lengths, leap years come and go, and in 1582 ten days were simply skipped. None of that belongs in orbital mechanics, so astronomers count days instead: the Julian DayJulian Day (JD) A continuous day count starting at noon on January 1, 4713 BCE, Universal Time, in the proleptic Julian calendar. Astronomers use it so calendar irregularities (varying month lengths, leap years, the Julian-to-Gregorian switch) don't have to be handled by the actual position formulas. julianDayUT() converts a date and time to this count. is the number of days since noon on January 1, 4713 BCE. It is a single, continuous number, fractional for the time of day. Today is somewhere around 2.46 million.

Most formulas then don’t count in days but in Julian centuriesJulian century (commonly T) The number of 36,525-day periods since J2000.0. Nearly every formula in this library is a polynomial in T, since century-scale drift terms are numerically nicer to work with in centuries than in raw days. since J2000Standard equinox / J2000.0 The reference epoch, January 1, 2000, 12:00 Terrestrial Time. Mean orbital elements are defined relative to this fixed date rather than now, which is why they need corrections such as nutation and the equation of the center to become an apparent, as-seen-right-now position., noon on January 1, 2000. What changes slowly, such as the tilt of Earth’s axis or the shape of an orbit, is written as a polynomial in time, and counted in centuries its terms stay modest numbers instead of tiny coefficients multiplied by millions of days.

Earth’s rotation makes a fine clock, but not a perfect one. Tidal friction slows it, by an amount that varies over the centuries, so time counted by the turning Earth, universal time or UT, falls behind ephemeris timeEphemeris time The uniform time in which the orbits are computed, kept by atomic clocks rather than by the turning Earth; today it is called Terrestrial Time (TT). It runs ahead of universal time by ΔT, about a minute today, and a Julian Day counted in it is a Julian Ephemeris Day, as julianEphemerisDay returns it., the uniform time in which the orbits are computed. The gap between the two is ΔTDelta T (ΔT) The difference between Terrestrial Time (TT), the uniform time the orbits are computed in, and Universal Time (UT), which follows Earth's actual rotation. Tidal friction slows the rotation, so ΔT grows: about 69 seconds in 2026, some hours two thousand years ago. Known from historical eclipse records and, since the 1950s, atomic clocks; its future is an extrapolation.: about a minute today, and hours in antiquity [2]International Earth Rotation and Reference Systems Service (IERS): Earth Orientation Parameters, C04 series, 1962 to now. hpiers.obspm.fr, 2026. [3]Fred Espenak, Jean Meeus: Five Millennium Canon of Solar Eclipses: -1999 to +3000. NASA Technical Publication TP-2006-214141, 2006. (Figure). In code, one rule covers every function. One that takes a moment, as fromDate returns it, reads it as UT and adds ΔT itself. One that takes a bare Julian Day expects it in ephemeris time already, and julianEphemerisDay gives you that. Mixed up, they misplace the Moon by a fiftieth of its width today, by half in the year 1000.

ΔTDelta T (ΔT) The difference between Terrestrial Time (TT), the uniform time the orbits are computed in, and Universal Time (UT), which follows Earth's actual rotation. Tidal friction slows the rotation, so ΔT grows: about 69 seconds in 2026, some hours two thousand years ago. Known from historical eclipse records and, since the 1950s, atomic clocks; its future is an extrapolation. after Espenak and Meeus, measured by the IERS since 1962, and at the chosen moment, on a logarithmic scale. The years before 1800 are compressed on one too. Before −500 the curve is their long-term parabola, fitted to ancient eclipses, and before −2000 only extrapolated, as are the years after today.TryThe year 1000: ΔT was 26 minutes; without it, an eclipse then lands 6.5° of longitude off.

Then there is sidereal timeSidereal time The hour angle of the vernal equinox, i.e., "what time it is" for pointing a telescope, since it tracks Earth's rotation relative to the stars rather than the Sun: a sidereal day is about 4 minutes shorter than a solar day. siderealTime() gives Greenwich's mean sidereal time, measured from the mean equinox, and apparentSiderealTime() the apparent one, from the true equinox, which apparent right ascensions need., which is Earth’s rotation measured against the stars rather than the Sun. The two differ, because Earth does not only turn, it also moves along its orbit, by almost a degree a day: 360° in a year of 365 days. After one full turn against the stars, the Sun has shifted by that degree, and Earth has to turn a little longer, about four minutes, to face it again. So a day by the stars lasts about 23 hours and 56 minutes, a day by the Sun 24 hours, and over a year the four minutes add up to one whole extra turn: Earth turns 366 times against the stars, but only 365 times from noon to noon. Sidereal time, θ, is that rotation as an angle. It is what connects the sky’s coordinates to your spot on the ground: the dashed meridian through your location rotates with it (Figure), and from one day to the next, at the same clock time, it has gained almost a degree (Table).

In code, a moment is a JavaScript Date or the same moment spelled out, and each of these counts is one call away:

import {
    fromDate, fromJulianDay, julianDayUT, julianEphemerisDay, siderealTime,
    toDate,
} from "@himmelszelt/sternzeit";

// Any JavaScript Date, e.g., new Date() for now. Only the instant
// counts: no position depends on the browser's time zone.
const time = fromDate(new Date("2026-09-21T20:00:00+02:00"));
// Or the same moment spelled out: 20:00 in Berlin (UTC+2).
const same = {
    year: 2026, month: 9, day: 21,
    hour: 20, minute: 0, second: 0, utcOffsetSeconds: 7200,
};

const jd = julianDayUT(same); // 2461305.25, the offset applied
const jde = julianEphemerisDay(time); // ΔT added, for the orbits
const theta = siderealTime(time); // Greenwich mean sidereal, in deg
const date = toDate(fromJulianDay(jd)); // and back to a Date
Moment and place

Earth, the platform we observe from

Summer is not warm because Earth is closer to the Sun: it is closest in early January. Earth’s rotation axis is tilted against the plane of its orbit by about 23.4°, the obliquity of the eclipticObliquity of the ecliptic (ε) The tilt angle, about 23.4°, between Earth's equatorial plane and its orbital plane: the axial tilt responsible for the seasons. Needed to convert between ecliptic and equatorial coordinates. The mean obliquity leaves out nutation; the true obliquity includes it., ε (Figure). In June the northern half leans towards the Sun, which then stands higher and stays up longer there, so its light arrives steeper and for longer; in December it leans away, and the southern half has it the other way round. Where the tilted equator crosses the orbit’s plane lies the vernal equinoxVernal equinox The point on the sky where the Sun crosses the celestial equator northwards, around March 20, and the zero from which both ecliptic longitude and right ascension are counted. Also called the First Point of Aries, after the constellation it lay in some two thousand years ago; precession has since carried it into Pisces. Nutation makes it wobble by up to about 19 arcseconds around its mean position., the point where the Sun crosses the equator northwards in March. Neither is quite fixed: the tilt drifts slowly over millennia, and the Moon’s pull adds a small nod, the nutationNutation (in longitude Δψ, in obliquity Δε) A small, roughly-18.6-year periodic wobble in Earth's axis, caused mainly by the Moon's varying gravitational pull as its orbital plane precesses. Layered on top of the much larger, slow (26,000-year) precession. "In longitude" nutates ecliptic longitude; "in obliquity" nutates the obliquity angle itself., which shifts the tilt and the equinox by under 20 arcsecondsArcsecond A 3600th of a degree, or a 60th of an arcminute, itself a 60th of a degree. A one-euro coin covers about 2° at arm's length, an arcminute from 80 m, and an arcsecond from almost 5 km. Good eyes resolve about an arcminute., 3600ths of a degree. That is a hundredth of the Moon’s width, nothing a sky dome shows, but the Moon covers it in half a minute, and drawn among the stars it would stand that far from its place without it (Table).

Drag to rotate. Visualized with Zdog.

Earth's orbit around the Sun and the Moon's around Earth, seen from above the ecliptic: Earth's orbit over the year in the accent, the Moon's loop around it (dashed, gray) for the coming month and faint for two either way, and fainter still the Moon's own path along the Sun. Arrows point forward in time. Earth turns with the sidereal timeSidereal time The hour angle of the vernal equinox, i.e., "what time it is" for pointing a telescope, since it tracks Earth's rotation relative to the stars rather than the Sun: a sidereal day is about 4 minutes shorter than a solar day. siderealTime() gives Greenwich's mean sidereal time, measured from the mean equinox, and apparentSiderealTime() the apparent one, from the true equinox, which apparent right ascensions need., the chosen place a dot on it with its zenith as a short line. Marked in the accent, the equinoxes and solstices, the perihelion and aphelion, and the dotted ray from the Sun towards the vernal equinox, the direction Earth stands in at the September equinox; in gray, the Lagrange pointsLagrange points The five places where a small body keeps its position relative to two large ones that circle each other, as the Sun and Earth do. L1 and L2 lie about 1.5 million km from Earth, towards the Sun and away from it, where the solar observatories and the Webb telescope sit; L3 is opposite the Sun, L4 and L5 share Earth's orbit, 60° ahead and behind. and the loop's apogeeApogee The point of the Moon's orbit farthest from Earth, up to about 406,700 km away, where the Moon looks smallest: a micromoon when full there. The name is Earth's own form of apoapsis, the farthest point of any orbit; perigee is the nearest. and perigeePerigee The point of the Moon's orbit nearest to Earth, down to about 356,400 km, where the Moon looks largest, 14% wider than at apogee: a supermoon when full there. The name is Earth's own form of periapsis, the nearest point of any orbit.. Orbits to scale; the Sun, Earth and the Moon are not, and grow as the zoom brings them in.TryPerihelion, January 3, 2026: Earth nearest the Sun, 147 million km, in the northern winter.
Moment and place
Moment and place

The table also holds the constants the atmosphere needs: Earth’s radius [4]NASA Space Science Data Coordinated Archive: Planetary Fact Sheets: Earth, Moon, Sun. nssdc.gsfc.nasa.gov, 2024., the thickness of the atmosphere [5]Tomoyuki Nishita, Takao Sirai, Katsumi Tadamura, Eihachiro Nakamae: Display of the Earth Taking into Account Atmospheric Scattering. SIGGRAPH, 1993. [6]Eric Bruneton, Fabrice Neyret: Precomputed Atmospheric Scattering. Computer Graphics Forum 27(4), EGSR, 2008., and the refractionAtmospheric refraction The bending of light by Earth's atmosphere, which lifts everything's apparent altitude above its true geometric one: about 34 arcminutes at the horizon, slightly more than the Sun's own diameter of about 32, so a Sun that seems to touch the horizon has geometrically already set. Falls to 0 at the zenith. that keeps the Sun visible for a few minutes after it has geometrically set [7]Þorsteinn Sæmundsson: Atmospheric Refraction. Sky and Telescope 72, 1986.. Raise the height to 10 km, a jet’s cruising altitude, and the horizon dipsHorizon dip How far the visible horizon lies below the true horizontal, for an observer above the ground: the line of sight to the horizon is a tangent to the curved Earth. About 1° from 1000 m, 2.9° from 8000 m; terrestrial refraction lifts it back by roughly a tenth. by more than 3° (horizonDip).

Coordinates on the sky

To say where something stands on the sky takes two angles, as longitude and latitude do on Earth, and every pair needs a reference: a plane to measure from, and a zero on it. Astronomy has four such systems, and each exists because one step of the computation is simplest in it. Two of them are built on the tilt and the vernal equinox. The equinox makes a natural zero: it is one of the two points where the equator and the ecliptic cross, so it lies on both, and the Sun marks it every March, no star needed. Ecliptic coordinatesEcliptic coordinates (ecliptic longitude l, ecliptic latitude β) Coordinates on the sky with the plane of Earth's orbit, the ecliptic, as their equator. The Sun's ecliptic latitude is about 0 by definition, and the Moon and the planets stay close to the plane, so orbits are computed here before converting to equatorial coordinates. take the plane of Earth’s orbit, the ecliptic (Figure), as their equator. The Sun never leaves it, and the Moon and the planets stay within a few degrees, so orbits are computed here: an ecliptic longitude, l, counted from the vernal equinox, and a small latitude, β, off the plane.

Equatorial coordinatesEquatorial coordinates (right ascension α, declination δ) Coordinates on the celestial sphere using Earth's rotational axis and equator as the reference plane, analogous to longitude/latitude on Earth but for the sky. Right ascension is measured eastward from the vernal equinox; declination is the celestial-equator equivalent of latitude. take Earth’s equator instead, carried out onto the sky as the celestial equator (Figure): right ascension, α, along it, also counted from the vernal equinox, and declination, δ, north or south of it. This is the sky’s own map, the one star catalogs use, since a star keeps both values while Earth turns underneath. The two systems, ecliptic and equatorial, differ only by the obliquity, a tilt about the line towards the vernal equinox.

Both are geocentricGeocentric / topocentric Seen from Earth's center, or from the observer's own place on its surface. Formulas and tables give geocentric positions; for the Moon, the difference, its parallax, reaches about a degree., and nobody stands at Earth’s center. From the surface, a nearby body appears slightly shifted by its parallaxParallax (equatorial horizontal / topocentric position) How far a body's position shifts between Earth's center and the observer on its surface: about a degree for the Moon, some 384,000 km away, 8.8 arcseconds for the Sun, nothing measurable for the stars. equatorialHorizontalParallax is the size of that shift for an observer at Earth's equator with the body on their horizon; topocentricPosition applies the actual correction for a given observer, which horizontalPosition then uses., π: not at all for the stars, by 8.8 arcseconds for the Sun, and by up to a degree for the Moon, two of its own diameters. The topocentric position, α′ and δ′, corrects for it, with the observer on the flattened ellipsoid and at their height above sea level.

Horizontal coordinatesHorizontal coordinates (azimuth A, altitude h) Coordinates relative to one observer's local horizon: altitude is the height above the horizon, azimuth the compass direction along it, from north through east. Unlike the other two systems, this is what you would actually point at, and it depends on the observer's latitude and longitude and the sidereal time., finally, are the observer’s own: an altitude, h, above the horizon and an azimuth, A, from north through east. They follow from the topocentric position through the hour angleHour angle (H) How far a point on the sky has rotated past the local meridian (due south/north), i.e., local sidereal time minus its right ascension. Used to convert equatorial coordinates to horizontal ones., which sidereal time provides. The celestial pole, around which the sky turns, stands above the horizon exactly as high as the place’s latitude, φ (Figure): at the North Pole, latitude 90°, it stands straight overhead, and at the equator, latitude 0°, it lies on the horizon.

Drag to rotate. Visualized with Zdog.

The observer's frame at the chosen place and moment: the horizon, the ENU axes (x east, y north, z up) and the meridian (dotted). The Sun, the Moon (gray) and the direction to one of them (arrow), with its horizontal coordinatesHorizontal coordinates (azimuth A, altitude h) Coordinates relative to one observer's local horizon: altitude is the height above the horizon, azimuth the compass direction along it, from north through east. Unlike the other two systems, this is what you would actually point at, and it depends on the observer's latitude and longitude and the sidereal time. (accent), the azimuth A and the altitude h. The celestial pole at the latitude φ, and the celestial equator, dashed below the horizon. To no scale but the angles.TryBerlin at sunset on June 21: the Sun sets in the northwest, at 312°, 42° past due west.
Moment and place

The rest of this section follows a position through these systems in code. If you came for the sky rather than the code, the figure above holds the gist, and the Sun is next.

Whatever the steps between these systems need comes from just two things, the moment and the place (Figure). The moment gives the sidereal time and jde, the Julian Day in ephemeris time, both first met in counting time. From jde follow the obliquity and the body’s parallax. All of these are the same for everyone on Earth. Only the place is your own: the observer, given by a latitude, a longitude and, if you like, a height.

momentDatefromDatetimeapparentSiderealTimeθjulianEphemerisDayjdejdeearth.trueObliquityεequatorialHorizontalParallaxπ
placeobserver = { latitude, longitude, heightM }
Where the coordinate systems' inputs come from: the moment, through a Date and thetime it becomes, to the sidereal time θ and the ephemeris day jde, and from that to the obliquity ε and the parallax π; the place, as the observer observer. Each function on its arrow.

A position moves through these systems one function at a time (Figure). The ecliptic and the equatorial position are the same wherever you stand; the observer comes in only on the way to the topocentric one. You rarely need to walk them yourself: each position also comes from a single call that covers the whole way there, and a renderer mostly needs the last two, horizontalPosition and direction. The calls follow the one rule from counting time: the first two need only the orbits and take jde, and from the topocentric position on, where Earth’s rotation comes in, they take the moment as fromDate returns it.

in one call
step by step
apparentEclipticalPosition(jde)
eclipticEcliptic coordinates (ecliptic longitude l, ecliptic latitude β) Coordinates on the sky with the plane of Earth's orbit, the ecliptic, as their equator. The Sun's ecliptic latitude is about 0 by definition, and the Moon and the planets stay close to the plane, so orbits are computed here before converting to equatorial coordinates. l, β
eclipticalToEquatorial({l, β}, ε)
apparentPosition(jde)
equatorialEquatorial coordinates (right ascension α, declination δ) Coordinates on the celestial sphere using Earth's rotational axis and equator as the reference plane, analogous to longitude/latitude on Earth but for the sky. Right ascension is measured eastward from the vernal equinox; declination is the celestial-equator equivalent of latitude. α, δ
equatorialToTopocentric({α, δ}, π, θ, observer)
topocentricPosition(time, observer)
topocentricGeocentric / topocentric Seen from Earth's center, or from the observer's own place on its surface. Formulas and tables give geocentric positions; for the Moon, the difference, its parallax, reaches about a degree. α′, δ′
equatorialToHorizontal({α′, δ′}, θ, observer)
horizontalPosition(time, observer)
horizontalHorizontal coordinates (azimuth A, altitude h) Coordinates relative to one observer's local horizon: altitude is the height above the horizon, azimuth the compass direction along it, from north through east. Unlike the other two systems, this is what you would actually point at, and it depends on the observer's latitude and longitude and the sidereal time. A, h
horizontalToDirection({A, h})
direction(time, observer)
ENUENU East-north-up, the observer's own frame for directions: x points east, y north and z up to the zenith, right-handed. Every direction sternzeit returns is a unit vector in it; an engine with y up assigns it as (x, z, -y). x, y, z // x east, y north, and z up
the same for everyone on Earthspecific to the observer
From a body's position to the renderer's vector: the positions (accent), each conversion with its arguments, and to the left, dashed, the call that returns each position directly, highlighted the two a renderer mostly needs.

The last call is the one a renderer places and lights things by: direction returns the horizontalPosition as a unit vector in the observer’s east-north-up frame, ENUENU East-north-up, the observer's own frame for directions: x points east, y north and z up to the zenith, right-handed. Every direction sternzeit returns is a unit vector in it; an engine with y up assigns it as (x, z, -y). for short, with x pointing east, y north and z up; an engine with y up, as most real-time renderers have it, assigns it as (x, z, -y). Refraction is left out on purpose. The altitude is the geometric one, where the body stands, not where the air lifts it for the eye, at the horizon by more than the Sun’s own diameter. Bending the light that way is the job of an atmosphere renderer such as dunstkreis, and earth.atmosphericRefraction gives an estimated lift where you need it.

The Sun

Over a day, the Sun and the Moon cross your sky along a path, and the Sun followed through a year, always at the same hour, traces an analemmaAnalemma The figure the Sun traces in the sky when observed at the same clock time every day for a year: usually a lopsided figure eight. Its height range is twice the obliquity of the ecliptic, about 47°; its width and its eight shape come from the equation of time. (Figure). The Moon’s path, in contrast, never quite closes, as it moves about 13° a day against the stars. The analemma’s height swings with the seasons, from the tilt of Earth’s axis, and its sideways swing comes from the equation of timeEquation of time The difference between apparent solar time, what a sundial shows, and mean solar time, what a clock shows: about 14 minutes one way in February and about 16 the other in November. It has two causes: Earth moves faster along its elliptical orbit near perihelion in early January, and the Sun's motion along the tilted ecliptic projects unevenly onto the equator. Together they shape the analemma's figure eight.: Earth moves faster along its orbit in January than in July, and the tilt adds a second, twice-yearly wobble, so the Sun runs up to about 16 minutes ahead of the clock in November and 14 behind it in February [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998.. Where the analemma’s dots crowd, at the top and the bottom, the Sun lingers before it turns back: the solstices, Latin for the Sun standing still.

analemma: the Sun at this hour, every day of the year, a dot on the 1st of each month

Drag to rotate. Visualized with Zdog.

A sun path diagramSun path diagram A chart of the Sun's track across the sky of one place, over a day, often for several dates at once: flat, as altitude over azimuth, or on a dome. Architects and solar engineers use it to plan shading and daylight.: the Sun's path (a dot per hour) across the sky of the chosen place, in horizontal coordinates, a day around the moment, its ends blending, and the Moon's (gray), a spiral a day either way, fading from the Moon itself. The faint band under it is the Moon's path over the whole lunationLunation One cycle of the Moon's phases, from new moon to new moon: the synodic month, 29.53 days on average. Individual lunations vary by up to about seven hours around the mean., half a month either way. At the center, the observer's ENU axes. Dotted below the horizon, arrows pointing forward in time. Symbols, not to scale. (a) The Sun's analemmaAnalemma The figure the Sun traces in the sky when observed at the same clock time every day for a year: usually a lopsided figure eight. Its height range is twice the obliquity of the ecliptic, about 47°; its width and its eight shape come from the equation of time. at this time of day, a dot on the first of every month.TrySydney: the Sun's path runs through the north, and the analemma stands on its head.
Moment and place

Seen from Earth, the Sun circles the sky once a year along the ecliptic, against stars we cannot see by day. Computing where it stands follows a pattern that most of this library repeats: a rough position, a corrected one, and the one we see, named in the functions’ prefixes mean, true and apparent. The mean one comes from a Sun moving around the sky at a steady pace, just under a degree a day, as if Earth’s orbit were a perfect circle: the mean longitudeMean longitude (L₀) Mean anomaly plus the longitude of perihelion, i.e., the mean anomaly re-expressed as an absolute ecliptic longitude rather than an angle measured from perihelion.. Orbits are ellipses, though, and the equation of the centerEquation of the center (C) The correction added to mean anomaly to get true anomaly, arising because orbits are ellipses, not circles. Usually the single largest correction when approximating orbital motion as uniform circular motion. turns it into the true longitudeTrue anomaly / true longitude The mean anomaly/longitude corrected for orbital eccentricity (see "equation of the center"), giving the body's actual angular position along its real elliptical orbit.. Nutation and aberrationAberration A shift of a body's apparent position towards the direction Earth is moving, by up to about 20.5 arcseconds, because the light arrives at a moving observer at a slant, like rain seen from a running car. Found by James Bradley, who published it in 1729., a small shift caused by Earth’s own orbital speed, then give the apparent positionApparent position Where a body's light seems to come from, as seen from Earth's center: its true orbital position, corrected for nutation and aberration. in right ascension and declination, and from there the conversions between the coordinate systems take it to the observer (Figure).

Aberration hides a subtlety. Sunlight is 8 minutes 20 seconds old, but the delay matters only together with motion: at 30 km/s along its orbit, Earth carries us some 15,000 km sideways while the light is underway, so the Sun appears 20.5 arcseconds behind where it actually stands [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998.. That is a ninetieth of the Sun’s width, invisible to the eye, but it moves the start and end of an eclipse by some 40 seconds. The true longitude leaves it out, the apparent position adds it, and so sun.direction points where the Sun shows. For the Moon, 1.3 light seconds away, the shift is under an arcsecond, and sternzeit leaves it out.

So far, the Sun is a direction: where it stands at any moment, and the paths it takes over a day and over a year. To draw it, a renderer also needs its size, and the analemma’s uneven loops already hinted that it changes: Earth moves faster in January because it is closer to the Sun then (Table). Its orbit is almost a circle, at an eccentricityOrbital eccentricity (e) How elongated an orbit's ellipse is (0 = perfect circle). Directly sets the size of the equation of the center and of orbital-distance variation over one orbit. of about 0.0167 [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998., yet that puts Earth about 3% closer to the Sun in early January than in early July: distance shrinks, and apparentAngularDiameter, the width of the Sun’s disc, grows by as much.

Moment and place

With the Sun’s altitude at hand, the library leaves out the conveniences on purpose: there is no sunrise(), and no dawn() or dusk() either. Each is the moment the altitude crosses a threshold, so walking a day in one-minute steps finds all of them, the start and end of the goldenGolden hour The time around sunrise and sunset when the Sun stands low, its light warm and its shadows long. Photographers count it from about 6° above the horizon down to 4° below, where the blue hour begins. and the blue hourBlue hour / L'heure bleue The stretch of twilight with the Sun about 4° to 6° below the horizon, when the sky goes a deep, saturated blue, colored by ozone rather than by scattering alone. too, or any other threshold you care to render.

import {
    fromDate, fromJulianDay, julianDayUT, sun, toDate,
} from "@himmelszelt/sternzeit";

// Midnight by the Sun at your longitude, not at Greenwich's, so the
// day holds sunrise before sunset wherever you are.
const offset = longitude / 360;
const today = julianDayUT(fromDate(new Date())) + offset;
const midnight = Math.floor(today - 0.5) + 0.5 - offset;
const at = (minute: number) => fromJulianDay(midnight + minute / 1440);
// One altitude a minute, computed once for every threshold below.
const altitudes = Array.from({ length: 1441 }, (_, minute) =>
    sun.horizontalPosition(at(minute), { latitude, longitude }).altitude);

function crossings(deg: number): Date[] {
    const found: Date[] = [];
    for (let minute = 1; minute <= 1440; minute++) {
        if ((altitudes[minute - 1] > deg) !== (altitudes[minute] > deg)) {
            found.push(toDate(at(minute)));
        }
    }
    return found;
}

// The Sun is up once its refracted upper limb clears the horizon,
// the -0.833 degrees every almanac uses. Both stay undefined in the
// midnight sun or the polar night.
const [sunrise, sunset] = crossings(-0.833);
const [dawn, dusk] = crossings(-6); // civil twilight

Run for the chosen day, place and clock:

Computed for every day of a year, the same crossings can be used to visualize the year’s light (Figure): the days lengthening and shortening, summer time shifting them by an hour, and the twilightsTwilight The light before sunrise and after sunset, sunlight scattered down by the air still lit above. Counted by how deep the Sun stands below the horizon: civil twilight to 6°, light enough to read outdoors; nautical to 12°, while sailors can still see the horizon; astronomical to 18°, after which the sky is as dark as it gets. in between. Away from the equator, the days swing more and the twilights last longer, until past the polar circle the Sun stays up all summer and away all winter.

The year at the chosen place, day by day from left to right, midnight to midnight from top to bottom on the chosen clock, its daylight saving time included: day, the golden and the blue hour, then nautical and astronomical twilightTwilight The light before sunrise and after sunset, sunlight scattered down by the air still lit above. Counted by how deep the Sun stands below the horizon: civil twilight to 6°, light enough to read outdoors; nautical to 12°, while sailors can still see the horizon; astronomical to 18°, after which the sky is as dark as it gets., each a shade darker, and night. The line through the golden hour is sunrise and sunset. The slider's ticks are the tropics and the polar circles.TryTromsø: midnight sun from May 18 to July 24, polar night from November 28 to January 14.
Moment and place

The Moon

Seen from Earth, the Moon circles the sky as well, not in a year but in a month: it rises some 50 minutes later every day. It is also the hardest body to follow. It is close, its orbit is tilted against Earth’s by about 5°, and the Sun actually pulls on it about twice as hard as Earth does: a three-body problem, the original one, which has no exact solution. Its position follows the Sun’s pattern, a mean longitude corrected into the apparent one, but where the Sun needs a single equation of the center, the Moon needs dozens of periodic terms, built from four angles, each turning at its own pace. Being close also means a parallax of up to a degree, so the topocentric position matters most here (Table).

Moment and place

Beyond the Moon’s position, the table holds what a renderer needs to draw the Moon. Its size swings far more than the Sun’s: the Moon looks about 14% wider at its closest than at its farthest, the gap between a supermoon and a micromoon. It always shows the same face, almost: its tilted orbit and varying speed let us peek a few degrees around its edges over a month, the optical librationLibration The Moon keeps (nearly) the same face toward Earth, but the tilt of its orbit and axis and its varying speed along the orbit let an observer see a few degrees around its edges over a month, as if it were slowly nodding: the optical libration. The Moon's own slight wobble about its mean rotation adds the physical libration, a few hundredths of a degree. moon.librations gives both, moon.opticalLibrations the first alone. Seen from the observer's own place, an Earth radius off Earth's center, the face turns by up to a degree more over a day, the diurnal libration, which moon.topocentricLibrations adds., so that over time we see 59% of its surface. From your own place it turns a little more, by up to a degree over a day, as Earth’s turning carries you around its center: the diurnal libration, which topocentricLibrations adds.

Then there is its light. Half of the Moon is always in sunshine, and its phase is how much of that half we see. The phase anglePhase angle (i) The angle Sun-Moon-Earth, i.e., how far the Sun is "behind" the Moon as seen from Earth: 0° at full moon, 180° at new moon. illuminatedFraction is (1 + cos i) / 2., the angle Sun-Moon-Earth, measures it, and the illuminated fractionIlluminated fraction (k) How much of the Moon's visible disc is lit, 0 at new moon to 1 at full moon. What the phase looks like, as a single number. turns that into what the phase looks like, from 0 at new moon to 1 at full moon [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998.. It is only a first measure of moonlight, though: a half moon gives about a tenth of the full moon’s light, not half, as the shadows of its craters grow longer away from full moon. For shading the Moon itself, a renderer wants the light direction: sunDirection points from the Moon’s center to the Sun, in ENU like every other direction here. It differs from the Sun’s direction seen from Earth by at most 0.16°, under a third of the Sun’s width, since the Moon stands 384,000 km off to the side.

The night side is not entirely dark, and not a hole either: no star has ever shone through the Moon. Earth reflects sunlight too, and around new moon, when Earth seen from the Moon is almost full, that earthshine gives the unlit part of a thin crescent a faint, ashen glow. How strong it is follows from Earth’s phase as seen from the Moon [8]Hendrik C. van de Hulst: Multiple Light Scattering: Tables, Formulas, and Applications. Academic Press, 1980., scaled by Earth’s albedo [9]Henrik Wann Jensen, Frédo Durand, Michael M. Stark, Simon Premože, Julie Dorsey, Peter Shirley: A Physically-Based Night Sky Model. SIGGRAPH, 2001..

Even a Moon drawn without any shading needs one angle: the tilt of its crescent. Getting it wrong is a classic: games and illustrations like to hang a crescent in the night sky with its lit side up. That cannot happen. The lit side always faces the Sun, and a crescent stands less than 90° from it, so with its lit side up, the Sun would stand above it, and above the horizon too: it would be day. Nor do the horns ever reach around the disc, as they do on a crescent cut out with a smaller circle: the edge of the lit half is a circle on the sphere seen at a slant, a half-ellipse on the disc, so its two tips always lie at the ends of one diameter, however thin the crescent gets.

The exact tilt is the position anglePosition angle The direction from one point on the sky to another, measured from north through east: which side the second lies on, as the separation says how far away it is. from the Moon to the Sun, measured on the sky from north through east, and the parallactic angleParallactic angle The angle between "straight up" (the local zenith direction) and celestial north at a given point on the sky, such as the Moon. Relevant for orienting how a crescent or terminator will actually appear tilted for a specific observer. turns that from the sky’s north to your own up. moon.brightLimbAngle does both; the position angle of the axisPosition angle of axis The angle, on the sky, between celestial north and the Moon's own north pole/rotation axis, needed to draw the Moon's surface features (or a lit crescent) correctly oriented rather than always "upright". turns the Moon’s north pole, and with it its face, the same way. The rest of the Moon’s light is a call each:

import { fromDate, julianEphemerisDay, moon } from "@himmelszelt/sternzeit";

const time = fromDate(new Date());
const observer = { latitude, longitude };
// Functions of a bare Julian Day take ephemeris time.
const jde = julianEphemerisDay(time);
const lit = moon.illuminatedFraction(jde); // 0 new, 1 full
// Half a day on tells waxing from waning without a calendar.
const waxing = moon.illuminatedFraction(jde + 0.5) > lit;
// Counterclockwise from up, as the crescent stands in your sky.
const brightLimb = moon.brightLimbAngle(time, observer);
// For shading: from the Moon's center to the Sun, and Earth's glow.
const light = moon.sunDirection(time, observer);
const glow = moon.earthshine(jde);

The tilt, the libration and the earthshine all come together in the Moon below (Figure).

parallax: geocentric and topocentric, seen square to the Moon's orbit
The Moon, geocentricGeocentric / topocentric Seen from Earth's center, or from the observer's own place on its surface. Formulas and tables give geocentric positions; for the Moon, the difference, its parallax, reaches about a degree. or topocentric, its north pole (N) up: lit by the Sun, its night side in earthshineEarthshine Sunlight reflected by Earth onto the Moon, which lights its night side with a faint, ashen glow, easiest to see on a thin crescent. Strongest around new moon, when the Moon sees a full Earth, and gone at full moon, when the side of Earth facing it is dark., the grid shifted by the librationLibration The Moon keeps (nearly) the same face toward Earth, but the tilt of its orbit and axis and its varying speed along the orbit let an observer see a few degrees around its edges over a month, as if it were slowly nodding: the optical libration. The Moon's own slight wobble about its mean rotation adds the physical libration, a few hundredths of a degree. moon.librations gives both, moon.opticalLibrations the first alone. Seen from the observer's own place, an Earth radius off Earth's center, the face turns by up to a degree more over a day, the diurnal libration, which moon.topocentricLibrations adds., the dashed circles its size at apogeeApogee The point of the Moon's orbit farthest from Earth, up to about 406,700 km away, where the Moon looks smallest: a micromoon when full there. The name is Earth's own form of apoapsis, the farthest point of any orbit; perigee is the nearest. and perigeePerigee The point of the Moon's orbit nearest to Earth, down to about 356,400 km, where the Moon looks largest, 14% wider than at apogee: a supermoon when full there. The name is Earth's own form of periapsis, the nearest point of any orbit.. (a) Seen square to the Moon's orbit, Earth's axis tilts towards the Moon or away from it over the month, and the place circles it over the day, seeing the Moon lower by the parallaxParallax (equatorial horizontal / topocentric position) How far a body's position shifts between Earth's center and the observer on its surface: about a degree for the Moon, some 384,000 km away, 8.8 arcseconds for the Sun, nothing measurable for the stars. equatorialHorizontalParallax is the size of that shift for an observer at Earth's equator with the body on their horizon; topocentricPosition applies the actual correction for a given observer, which horizontalPosition then uses. and, with it high, up to an Earth radius closer; Earth and Moon true to each other, the Moon between perigee and apogee, the distance squeezed. TryA day and a half after new moon: the night side at its bluest, lit by a nearly full Earth.
Moment and place

Eclipses

From the ground, the Sun and the Moon look almost the same size: the Sun is about 400 times wider than the Moon and about 400 times farther away. It is a stroke of luck that will not last. The Moon drifts away by about 3.8 cm a year [10]Jean O. Dickey, Peter L. Bender, James E. Faller et al.: Lunar Laser Ranging: A Continuing Legacy of the Apollo Program. Science 265(5171), 1994., and in some 600 million years it will be too small to ever cover the Sun again. We happen to live in the stretch of Earth’s history in which the sky can go dark in the middle of the day.

With both bodies located, eclipses follow from their positions. A solar eclipse is a matter of perspective: the Moon passing in front of the Sun, which depends on where you stand. On the line the Moon’s shadow sweeps, the Sun goes out (total), or, with the Moon near apogeeApogee The point of the Moon's orbit farthest from Earth, up to about 406,700 km away, where the Moon looks smallest: a micromoon when full there. The name is Earth's own form of apoapsis, the farthest point of any orbit; perigee is the nearest. and too small to cover it, leaves a ring of light around the black disc (annular). A few hundred kilometers to the side, the Moon only takes a bite out of it (partial). A lunar eclipse is the Moon passing through Earth’s shadow, and it looks the same from anywhere the Moon is up: total once the whole disc is inside the umbraUmbra / penumbra The two parts of a shadow cast by a light source that is not a point. In the umbra, the core, the Sun is hidden completely; in the penumbra around it, only partly. Earth's shadow is a pair of cones behind it: at the Moon's distance the umbra is about 4,600 km in radius, the penumbra about 8,200 km, against the Moon's own 1,737 km., partial while only part of it is, and penumbral, barely a dimming, when the Moon misses the umbra altogether (Figure).

solar eclipse, as seen from the chosen place
lunar eclipse, the same from anywhere
Eclipses, both zenith up. (a) The Moon in front of the Sun. (b) The Moon in Earth's umbraUmbra / penumbra The two parts of a shadow cast by a light source that is not a point. In the umbra, the core, the Sun is hidden completely; in the penumbra around it, only partly. Earth's shadow is a pair of cones behind it: at the Moon's distance the umbra is about 4,600 km in radius, the penumbra about 8,200 km, against the Moon's own 1,737 km. and penumbraUmbra / penumbra The two parts of a shadow cast by a light source that is not a point. In the umbra, the core, the Sun is hidden completely; in the penumbra around it, only partly. Earth's shadow is a pair of cones behind it: at the Moon's distance the umbra is about 4,600 km in radius, the penumbra about 8,200 km, against the Moon's own 1,737 km.. Magnified, discs, shadows and horizon true to each other. Corona modified from a photograph by Phil Hart of the total eclipse of April 20, 2023, from Exmouth, Western Australia. The sliders move the moment up to two hours either way under (a), and three under (b).TryBurgos, August 12, 2026, 18:29 UTC: totality in (a), the Sun 8° above the horizon.
Moment and place

For a renderer, both come down to a single phaseEclipse phase How deep an eclipse is, as one number shaped for a lookup texture: 0 with the centers aligned, 0.5 where a total or annular solar eclipse turns partial, 1 as the discs touch, above 1 no eclipse. For a lunar eclipse, 0.5 and 1 are where the Moon's center crosses the edge of the umbra and of the penumbra. A lunar eclipse looks the same from everywhere the Moon is up; a solar one depends on where you stand. [11]Daniel Müller (now Limberger), Juri Engel, Jürgen Döllner: Single-Pass Rendering of Day and Night Sky Phenomena. Vision, Modeling and Visualization (VMV), 2012.: 0 with the centers aligned, 0.5 where a total or annular eclipse of the Sun turns partial, 1 where the discs just touch, and above 1 when there is nothing to see. For the Moon, 0.5 and 1 are where its center crosses the edge of the umbra and of the penumbra. The fixed 0.5 boundary is what makes the phase usable as a texture coordinate for a shader.

Most of the time there is nothing to see, hence the four buttons (Figure): they search the sky forwards or backwards from the moment you are on and jump to the next eclipse’s maximum. Nothing is looked up. NASA’s catalogs list every eclipse over five millennia [3]Fred Espenak, Jean Meeus: Five Millennium Canon of Solar Eclipses: -1999 to +3000. NASA Technical Publication TP-2006-214141, 2006. [12]Fred Espenak, Jean Meeus: Five Millennium Canon of Lunar Eclipses: -1999 to +3000. NASA Technical Publication TP-2009-214172, 2009., but the search finds them from the positions alone: only a full moon can enter Earth’s shadow and only a new moon can cross the Sun, so it needs to look closer only once a lunationLunation One cycle of the Moon's phases, from new moon to new moon: the synodic month, 29.53 days on average. Individual lunations vary by up to about seven hours around the mean.. The solar search answers for the place you chose, which is why it often lands on a modest partial eclipse.

Eclipses also come in pairs. They happen in seasons, while the Sun stands near one of the two points where the Moon’s orbit crosses the ecliptic, and a season lasts longer than the month from one new moon to the next. So every eclipse of the Sun has one of the Moon about two weeks before or after it, if often only a faint penumbral one. The total solar eclipse of August 12, 2026, over Greenland, Iceland and Spain, was followed by a partial lunar eclipse on August 28.

In a total lunar eclipse, the Moon darkens in the penumbra first, barely noticeable, then turns a dark red in the umbra, lit only by sunlight that Earth’s atmosphere bends around the planet, its outer rim tinged blue by the ozone the light passes through. Tracing that light through the atmosphere gives the colors physically [13]Theodore C. Yapo, Barbara Cutler: Rendering Lunar Eclipses. Graphics Interface, 2009., but far from real time. A renderer can approximate them from the eclipse’s phase instead [11]Daniel Müller (now Limberger), Juri Engel, Jürgen Döllner: Single-Pass Rendering of Day and Night Sky Phenomena. Vision, Modeling and Visualization (VMV), 2012., and the panel only hints at them. Next to the phase, the table lists the magnitudeEclipse magnitude How much of the eclipsed body is covered, as a fraction of its diameter: of the Sun's by the Moon in a solar eclipse, of the Moon's by Earth's umbra or penumbra in a lunar one. 1 or more means total. It is the number the eclipse catalogs list, and not the phase, which runs the other way, from 0 at the center to 1 as the discs part., the number the catalogs give (Table).

Moment and place

Rare as they are, eclipses should not cost a renderer anything on every frame, yet they are special enough to be worth a notification when one comes. This example finds the next total lunar eclipse, stepping from full moon to full moon and narrowing each candidate down to the minute by bisectionBisection Finding where something changes by halving: test the middle of a span, keep the half the change lies in, and repeat. Each test halves the span, so a day narrows down to the minute in 11 tests, where walking it minute by minute takes up to 1,440.. The buttons above search much the same way (Figure):

import {
    eclipse, fromDate, fromJulianDay, julianDayUT, julianEphemerisDay, moon,
    toDate,
} from "@himmelszelt/sternzeit";

// Only a full moon can be eclipsed, so step by lunations rather than
// by days. Full moons sit half a lunation after the counted new ones.
const { MEAN_NEW_MOON, MEAN_SYNODIC_MONTH } = moon;
const firstFullMoon = MEAN_NEW_MOON + MEAN_SYNODIC_MONTH / 2;

const MINUTE = 1 / 1440;

// The search runs in UT, the orbits in ephemeris time.
const shadow = (jd: number) => eclipse.lunar(julianEphemerisDay(jd));
const offset = (jd: number) => shadow(jd).axisOffsetKm;
// Totality: the whole disc fits inside the umbra.
const total = (jd: number) => shadow(jd).umbralMagnitude >= 1;

// The first minute between a and b where test turns true, by halving.
function bisect(a: number, b: number, test: (jd: number) => boolean) {
    while (b - a > MINUTE) {
        const mid = (a + b) / 2;
        if (test(mid)) b = mid;
        else a = mid;
    }
    return b;
}

function nextTotalLunarEclipse(from: number): Date | null {
    const gone = (from - firstFullMoon) / MEAN_SYNODIC_MONTH;
    for (let month = Math.floor(gone); month < gone + 250; month++) {
        const full = firstFullMoon + month * MEAN_SYNODIC_MONTH;
        // The true full moon wanders up to 14 hours from the mean one;
        // three-hour steps find the one closest to the shadow's axis.
        let [closest, km] = [full, Infinity];
        for (let jd = full - 0.75; jd <= full + 0.75; jd += 1 / 8) {
            const away = offset(jd);
            if (away < km) [closest, km] = [jd, away];
        }
        // The deepest moment: where the Moon stops closing in on the axis.
        const greatest = bisect(closest - 1 / 8, closest + 1 / 8,
            (jd) => offset(jd + MINUTE) > offset(jd));
        if (!total(greatest)) continue;
        // Totality lasts less than two hours, so it began within the hour.
        const start = bisect(greatest - 1 / 24, greatest, total);
        if (start > from) return toDate(fromJulianDay(start));
    }
    return null;
}

// Up to twenty years ahead; from late 2026 that is totality on
// 2028-12-31, from 16:18 UTC.
const next = nextTotalLunarEclipse(julianDayUT(fromDate(new Date())));

A month of Moons

Put together, the pieces above make a moon calendar that shows more than the phase: which way the Moon is turned where you are, and whether it is up while it is dark. In the calendar below (Figure), the discs are the Moon at the same time of day all month, turned as it stands in the sky there; the lanes say when it is up, and the Sun with it. How to draw them is up to you, so the drawing falls to two functions you bring yourself:

import {
    fromDate, julianEphemerisDay, moon, sun,
} from "@himmelszelt/sternzeit";

const DAY_MS = 86_400_000;
const observer = { latitude, longitude };
// Upper limb on the horizon, refraction included, as for sunrise.
const isUp = (altitude: number) => altitude > -0.833;

// firstDay: the first midnight, timeOfDay: milliseconds after it.
for (let day = 0; day < days; day++) {
    const time = fromDate(new Date(firstDay + day * DAY_MS + timeOfDay));
    const jde = julianEphemerisDay(time);
    // The parallactic angle turns the sky's north into the zenith.
    const q = moon.parallacticAngle(time, observer);
    drawMoonDisc(day, {
        lit: moon.illuminatedFraction(jde),
        earthshine: moon.earthshine(jde),
        libration: moon.librations(jde),
        // Counterclockwise from up, already turned into this sky.
        brightLimb: moon.brightLimbAngle(time, observer),
        north: moon.positionAngleOfAxis(jde) - q,
        up: isUp(moon.horizontalPosition(time, observer).altitude),
    });
}

// The lanes, in ten-minute steps: the altitude picks the color.
for (let minute = 0; minute < days * 1440; minute += 10) {
    const time = fromDate(new Date(firstDay + minute * 60_000));
    drawLane("moon", minute, moon.horizontalPosition(time, observer).altitude);
    drawLane("sun", minute, sun.horizontalPosition(time, observer).altitude);
}

Filled in for the chosen place, that is a whole month at once. Slide the time of day beneath it, and every Moon turns with the sky:

The Moon on every day of a month at the chosen time of day, as it stands in the sky at the chosen place: beside the date its compass point and, after the arrow, its altitude, hatched while it is below the horizon. Under each week, midnight to midnight, when the Moon is up (yellow while low) and the Sun (fading through civil twilight); the ticks mark the time of day, which the slider below sets.TryQuito in December: on the equator, the evening crescents lie on their backs.
Moment and place

The same few functions reach beyond this chapter. Close to the code above: a sun path diagramSun path diagram A chart of the Sun's track across the sky of one place, over a day, often for several dates at once: flat, as altitude over azimuth, or on a dome. Architects and solar engineers use it to plan shading and daylight. with the Sun and the Moon every hour, or a search for the night the Moon rises behind a landmark. A little further: your horizon with the eclipses of the coming years, or a sundial drawn for your latitude. And everything that depends on where sunlight falls, such as a solar panel’s yield over a year.

Precise and approximate

Every quantity comes in two variants. The precise one follows Jean Meeus’ Astronomical Algorithms [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998., the standard reference for this kind of computation. The approximate one follows the night sky model of Jensen et al. [9]Henrik Wann Jensen, Frédo Durand, Michael M. Stark, Simon Premože, Julie Dorsey, Peter Shirley: A Physically-Based Night Sky Model. SIGGRAPH, 2001., with far fewer terms. The tables show the precise values; approx in any table’s heading switches all of them, and hovering an approximate value shows how far off it is.

For most rendering, the approximation is plenty. Over a year, the Sun’s approximate altitude stays within 0.002° of the precise one, invisible next to a disc half a degree wide. The Moon’s can be off by almost a tenth of a degree, a fifth of its diameter: fine for a sky dome, not for an eclipse. That is what the precise variant is for, along with the exact moment of sunset or a telescope view. Both live behind the same names, so switching is a change of import path.

import { sun } from "@himmelszelt/sternzeit"; // precise
import { sun as fast } from "@himmelszelt/sternzeit/approx"; // approximate

Neither costs a frame anything. On a desktop CPU, a Ryzen 7 7800X3D, the precise Sun takes about 2 µs a call, the Moon about 5 µs, and the approximate ones about 1 µs, so the quick start’s two calls fit into a frame at 60 Hz some two thousand times over. Imported alone, the Sun adds about 4 kB to a bundle, minified and compressed, the quick start’s Sun and Moon under 6 kB, and the whole library under 7 kB.

The people behind the numbers

Almost every number in this library goes back to Jean Meeus, a Belgian meteorologist who worked at Brussels Airport until 1993 [14]Royal Astronomical Society of Canada: Honorary Member: Jean Meeus. rasc.ca, 2003. and computed the sky in his spare time. His Astronomical Algorithms [1]Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998. turned the celestial mechanics of the observatories into recipes for a home computer, and it is still the book astronomy libraries are checked against. The asteroid 2213 Meeus carries his name [15]Royal Astronomical Society of Canada: Asteroid (2213) Meeus. rasc.ca, 2003..

Þorsteinn Sæmundsson, astronomer at the University of Iceland, who computed its almanac for sixty years [16]Sigrún Helgadóttir, Örn S. Kaldalóns: Andlát heiðursfélaga: Þorsteinn Sæmundsson, stjörnufræðingur. Stjörnuskoðunarfélag Seltjarnarness, sky.is (Icelandic), 2023., fitted the refraction behind earth.atmosphericRefraction [7]Þorsteinn Sæmundsson: Atmospheric Refraction. Sky and Telescope 72, 1986.. The approximate variants follow the night sky model of Henrik Wann Jensen and his colleagues [9]Henrik Wann Jensen, Frédo Durand, Michael M. Stark, Simon Premože, Julie Dorsey, Peter Shirley: A Physically-Based Night Sky Model. SIGGRAPH, 2001., which renders the Moon, the stars, zodiacal light and airglow together with the atmosphere they shine through.

Hendrik van de Hulst wrote the book on light scattering whose law for a sphere’s phase moon.earthshine applies to Earth seen from the Moon [8]Hendrik C. van de Hulst: Multiple Light Scattering: Tables, Formulas, and Applications. Academic Press, 1980.. As a student in 1944, he predicted the faint 21 cm radio glow of hydrogen between the stars, the signal radio astronomers have mapped the Milky Way with ever since [17]Joop W. Hovenier: Obituary: H. C. van de Hulst. Journal of Quantitative Spectroscopy and Radiative Transfer 68, 2001.. And Fred Espenak, for decades at NASA’s Goddard Space Flight Center and known as Mr. Eclipse [18]Jay Anderson: Fred Espenak (1953-2025). Sky & Telescope, 2025., compiled the eclipse canons with Meeus, along with the polynomials for ΔT [3]Fred Espenak, Jean Meeus: Five Millennium Canon of Solar Eclipses: -1999 to +3000. NASA Technical Publication TP-2006-214141, 2006..

References

  1. Jean Meeus: Astronomical Algorithms. 2nd edition, Willmann-Bell, 1998. The precise variants' main source.
  2. International Earth Rotation and Reference Systems Service (IERS): Earth Orientation Parameters, C04 series, 1962 to now. hpiers.obspm.fr, 2026. ΔT as measured since 1962, from the observed UT1 and the leap seconds.
  3. Fred Espenak, Jean Meeus: Five Millennium Canon of Solar Eclipses: -1999 to +3000. NASA Technical Publication TP-2006-214141, 2006. Every solar eclipse from 2000 BCE to 3000 CE, and the polynomials for ΔT.
  4. NASA Space Science Data Coordinated Archive: Planetary Fact Sheets: Earth, Moon, Sun. nssdc.gsfc.nasa.gov, 2024. Mean radii and similar constants.
  5. Tomoyuki Nishita, Takao Sirai, Katsumi Tadamura, Eihachiro Nakamae: Display of the Earth Taking into Account Atmospheric Scattering. SIGGRAPH, 1993.
  6. Eric Bruneton, Fabrice Neyret: Precomputed Atmospheric Scattering. Computer Graphics Forum 27(4), EGSR, 2008.
  7. Þorsteinn Sæmundsson: Atmospheric Refraction. Sky and Telescope 72, 1986. Atmospheric refraction from the true altitude.
  8. Hendrik C. van de Hulst: Multiple Light Scattering: Tables, Formulas, and Applications. Academic Press, 1980. Earthshine from Earth's phase as seen from the Moon.
  9. Henrik Wann Jensen, Frédo Durand, Michael M. Stark, Simon Premože, Julie Dorsey, Peter Shirley: A Physically-Based Night Sky Model. SIGGRAPH, 2001. The approximate variants' main source.
  10. Jean O. Dickey, Peter L. Bender, James E. Faller et al.: Lunar Laser Ranging: A Continuing Legacy of the Apollo Program. Science 265(5171), 1994. The Moon drifting away by 3.8 cm a year, measured by laser.
  11. Daniel Müller (now Limberger), Juri Engel, Jürgen Döllner: Single-Pass Rendering of Day and Night Sky Phenomena. Vision, Modeling and Visualization (VMV), 2012.
  12. Fred Espenak, Jean Meeus: Five Millennium Canon of Lunar Eclipses: -1999 to +3000. NASA Technical Publication TP-2009-214172, 2009. Every lunar eclipse from 2000 BCE to 3000 CE.
  13. Theodore C. Yapo, Barbara Cutler: Rendering Lunar Eclipses. Graphics Interface, 2009. Traces light through Earth's atmosphere into the umbra: physically based, far from real time.
  14. Royal Astronomical Society of Canada: Honorary Member: Jean Meeus. rasc.ca, 2003. Jean Meeus' life and books.
  15. Royal Astronomical Society of Canada: Asteroid (2213) Meeus. rasc.ca, 2003. The asteroid named for Jean Meeus.
  16. Sigrún Helgadóttir, Örn S. Kaldalóns: Andlát heiðursfélaga: Þorsteinn Sæmundsson, stjörnufræðingur. Stjörnuskoðunarfélag Seltjarnarness, sky.is (Icelandic), 2023. Þorsteinn Sæmundsson's life and his sixty years of the University of Iceland's almanac.
  17. Joop W. Hovenier: Obituary: H. C. van de Hulst. Journal of Quantitative Spectroscopy and Radiative Transfer 68, 2001. Hendrik van de Hulst's life, and his prediction of the 21 cm line.
  18. Jay Anderson: Fred Espenak (1953-2025). Sky & Telescope, 2025. Fred Espenak's life, at NASA and as Mr. Eclipse.