// ── Almanac: the Earth up close ── // Tap the glow around the Earth in the orrery and the view drops to the // Earth's own scale: a 3D Earth lit by the real Sun (day, night and the // terminator where they are), the Moon where it is, lit and shadowed, and the // ISS and the GPS constellation on their orbits. Eclipses are not special // cases: the shading asks, for every point on the Earth and the Moon, how much // of the Sun's disc the other body covers from there, so the Moon's shadow // crosses the Earth and the Earth's shadow reddens the Moon on their own. // // Offline and honest: // - The Sun, the Moon, the Earth's turning and the eclipses are pure maths, // exact offline for any date (Meeus, "Astronomical Algorithms", 2nd ed.). // - Satellites come from orbital elements (CelesTrak's OMM records): // a snapshot ships with each release, the server fetches fresher ones as // "Satellite data from the internet" allows (/almanac-satellites: Ask // first, the default, fetches only when an admin presses Get fresh data; // Automatically; Never; ZIMI_OFFLINE forces Never), and SGP4/SDP4 // (satellite.js, MIT) propagates them. The ISS's place along its orbit // drifts once its data is a few days old, so its dot fades and says so, // and past two weeks only its orbit is drawn. // Nothing is drawn that the data does not support. // // Loaded with the other almanac modules (they share one global scope); the // heavy parts (three.js, the textures, the propagator) load only when the // view is first opened. window.openAlmanacEarth() is the entry point: the // orrery's Earth glow calls it. // // Frames and units: the scene is geocentric, in Earth equatorial radii, on // the true equator and equinox of date (x toward the equinox, z toward the // north celestial pole). The Earth turns in it by Greenwich apparent sidereal // time. The pure functions below take and return plain numbers so the tests // (tests/test_almanac_earth.cjs) can check them against published values. // ── Physical constants ── // The AU, the speed of light and the day in seconds are the orrery's // (almanac-orrery.js AU_KM, SPEED_OF_LIGHT_KM_S, SECONDS_PER_DAY); the // Julian Day is almanac.js's _dateToJD. They share this global scope. var AE_EARTH_RADIUS_KM = 6378.137; // WGS84 equatorial radius var AE_EARTH_FLATTENING = 1 / 298.257223563; // WGS84 var AE_EARTH_E2 = AE_EARTH_FLATTENING * (2 - AE_EARTH_FLATTENING); // first eccentricity squared var AE_MOON_RADIUS_KM = 1737.4; // IAU mean radius var AE_SUN_RADIUS_KM = 695700; // IAU 2015 nominal solar radius var AE_GM_EARTH = 398600.4418; // km^3/s^2, WGS84 / IERS // L_G: the rate by which a clock on the geoid (Earth's rotation included) // runs slow against one far from the Earth, W0/c^2 (IAU 2000 Resolution B1.9). var AE_L_G = 6.969290134e-10; var AE_MICRO = 1e6; var AE_NANO = 1e9; // The Earth's shadow is wider than the solid Earth: the atmosphere blocks // sunlight too. Chauvenet's rule enlarges it by 1/50 (Meeus ch. 54). var AE_SHADOW_ENLARGE = 1.02; // Everything the view draws for one instant, in scene units (Earth radii). // ms is a JS time (UTC). function _aeSceneAt(ms) { var jd = _dateToJD(ms); var jde = jd + _aeDeltaTDays(jd); var sun = _aeSun(jde), moon = _aeMoon(jde); return { ms: ms, jd: jd, jde: jde, sun: _aeEqVec(sun.ra, sun.dec, sun.distKm / AE_EARTH_RADIUS_KM), moon: _aeEqVec(moon.ra, moon.dec, moon.distKm / AE_EARTH_RADIUS_KM), sunEq: sun, moonEq: moon, gast: _aeGast(jd, sun.nut) }; } // Where the Sun is drawn (AE_SUN_SHOW_DIST): its true direction, nearer. function _aeSunShown(scene) { return _aeScale(_aeNorm(scene.sun), AE_SUN_SHOW_DIST); } // ── Geodesy (WGS84): Earth-fixed position <-> latitude and longitude ── // Earth-fixed position (Earth radii) of a surface point, geodetic degrees. function _aeGeodeticToFixed(latDeg, lonDeg) { var la = _aeRad(latDeg), lo = _aeRad(lonDeg); var N = 1 / Math.sqrt(1 - AE_EARTH_E2 * Math.sin(la) * Math.sin(la)); return [N * Math.cos(la) * Math.cos(lo), N * Math.cos(la) * Math.sin(lo), N * (1 - AE_EARTH_E2) * Math.sin(la)]; } // Geodetic latitude/longitude (degrees) of a point on the ellipsoid surface. function _aeFixedToGeodetic(p) { var lon = _aeDeg(Math.atan2(p[1], p[0])); var lat = _aeDeg(Math.atan2(p[2], (1 - AE_EARTH_E2) * Math.sqrt(p[0] * p[0] + p[1] * p[1]))); return { lat: lat, lon: lon }; } // Scene position -> Earth-fixed, and back, for an instant's sidereal angle. function _aeSceneToFixed(v, gast) { return _aeRotZ(v, -gast); } function _aeFixedToScene(v, gast) { return _aeRotZ(v, gast); } // Where a ray first meets the ellipsoid, or null. Scaling z by 1/(1-f) turns // the ellipsoid into the unit sphere. function _aeRayEllipsoid(origin, dir) { var k = 1 / (1 - AE_EARTH_FLATTENING); var o = [origin[0], origin[1], origin[2] * k], d = [dir[0], dir[1], dir[2] * k]; var a = _aeDot(d, d), b = 2 * _aeDot(o, d), c = _aeDot(o, o) - 1; var disc = b * b - 4 * a * c; if (disc < 0) return null; var t = (-b - Math.sqrt(disc)) / (2 * a); if (t < 0) return null; return [origin[0] + t * dir[0], origin[1] + t * dir[1], origin[2] + t * dir[2]]; } // (These two are the orbit view's own: the info corner reads the place under the picture's centre before the ground's code is in.) // The orbit view's body now: its frame (body-fixed to scene) from what the view has drawn. function _aeStBodyNow(key) { var S = _ae.gl, e; if (key === 'moon') e = S.moon.matrix.elements; else if (key === 'earth') { var c = Math.cos(S.earth.rotation.z), sn = Math.sin(S.earth.rotation.z); return { f: { x: [c, sn, 0], y: [-sn, c, 0], z: [0, 0, 1] } }; } else if (S.planets[key] && S.planets[key].pos) e = S.planets[key].mesh.matrix.elements; if (!e) return null; return { f: { x: _aeNorm([e[0], e[1], e[2]]), y: _aeNorm([e[4], e[5], e[6]]), z: _aeNorm([e[8], e[9], e[10]]) } }; } // Where the ray through a point of the screen meets the body: latitude and longitude, or null. function _aeStHit(body, x, y) { var S = _ae.gl, cam = S.camera, V = S.THREE.Vector3, frame = _aeStBodyNow(body), centre = _aeBodyPos(body); if (!frame || !centre) return null; var o = _aeXyz(cam.position); var p = new V((x / _ae.w) * 2 - 1, -(y / _ae.h) * 2 + 1, 0.5).unproject(cam); var d = _aeNorm([p.x - o[0], p.y - o[1], p.z - o[2]]); var toFixed = function (v) { var f = frame.f; return [_aeDot(f.x, v), _aeDot(f.y, v), _aeDot(f.z, v)]; }; var oc = _aeSub(o, centre); if (body === 'earth') { var h = _aeRayEllipsoid(toFixed(oc), toFixed(d)); return h ? _aeFixedToGeodetic(h) : null; } var r = AE_TARGETS[body].surface, b = _aeDot(oc, d), c = _aeDot(oc, oc) - r * r, D = b * b - c; if (D < 0) return null; var t = -b - Math.sqrt(D); if (t < 0) return null; var q = _aeNorm(toFixed(_aeAdd(oc, _aeScale(d, t)))); return _aeLatLonOf(q); } // The point on the Earth with the Sun overhead: latitude = the Sun's // declination, longitude from the Earth's turning. function _aeSubsolarPoint(scene) { return _aeFixedToGeodeticDirection(_aeSceneToFixed(scene.sun, scene.gast)); } // Latitude/longitude of the surface point straight below a direction (the // geodetic point whose normal points along it). function _aeFixedToGeodeticDirection(v) { var n = _aeNorm(v); return { lat: _aeDeg(Math.asin(n[2])), lon: _aeDeg(Math.atan2(n[1], n[0])) }; } // ── Eclipses: how much of the Sun's disc a body covers ── // Fraction of a disc of angular radius r1 covered by a disc of radius r2 // whose centre is d away (all in the same angular unit). Flat-disc geometry, // fine at half a degree; the Sun's limb darkening is ignored. The GLSL twin // in the view's shaders (AE_GLSL_OVERLAP) is this same formula. function _aeDiscOverlap(r1, r2, d) { if (d >= r1 + r2) return 0; if (d <= Math.abs(r1 - r2)) return r2 >= r1 ? 1 : (r2 * r2) / (r1 * r1); var a1 = r1 * r1 * Math.acos(_aeClamp((d * d + r1 * r1 - r2 * r2) / (2 * d * r1), -1, 1)); var a2 = r2 * r2 * Math.acos(_aeClamp((d * d + r2 * r2 - r1 * r1) / (2 * d * r2), -1, 1)); var tri = 0.5 * Math.sqrt(Math.max(0, (-d + r1 + r2) * (d + r1 - r2) * (d - r1 + r2) * (d + r1 + r2))); return (a1 + a2 - tri) / (Math.PI * r1 * r1); } // Fraction of the Sun's light reaching `point` (scene units) with a body of // radius `occR` at `occ` in the way. 1 = full sunlight, 0 = inside the umbra. function _aeSunlightAt(point, sun, occ, occR) { var toSun = _aeSub(sun, point), toOcc = _aeSub(occ, point); var dSun = _aeLen(toSun), dOcc = _aeLen(toOcc); var rSun = Math.asin(Math.min(1, AE_SUN_RADIUS_KM / AE_EARTH_RADIUS_KM / dSun)); var rOcc = Math.asin(Math.min(1, occR / dOcc)); if (_aeDot(toSun, toOcc) <= 0) return 1; // the body is behind the point return 1 - _aeDiscOverlap(rSun, rOcc, _aeAngle(toSun, toOcc)); } var AE_MOON_RADIUS_RE = AE_MOON_RADIUS_KM / AE_EARTH_RADIUS_KM; var AE_SUN_RADIUS_RE = AE_SUN_RADIUS_KM / AE_EARTH_RADIUS_KM; // The Moon's shadow on the Earth. gamma: the shadow axis's least distance // from the Earth's centre in Earth radii (Besselian gamma, signed north // positive); hit: where the axis meets the ground (geodetic), or null when it // passes the Earth by. umbra: the axis carries the umbra (total) rather than // the antumbra (annular) at the Earth. function _aeSolarShadow(scene) { var axis = _aeNorm(_aeSub(scene.moon, scene.sun)); // Sun -> Moon, the shadow's way var along = _aeDot(_aeScale(scene.moon, -1), axis); // Earth centre's distance down the axis var closest = [scene.moon[0] + axis[0] * along, scene.moon[1] + axis[1] * along, scene.moon[2] + axis[2] * along]; var gamma = _aeLen(closest) * (closest[2] >= 0 ? 1 : -1); var hitScene = _aeRayEllipsoid(scene.moon, axis); var hit = hitScene ? _aeFixedToGeodetic(_aeSceneToFixed(hitScene, scene.gast)) : null; // Umbra length: the cone of the Sun's and Moon's radii converges this far // behind the Moon (similar triangles). var sunMoon = _aeLen(_aeSub(scene.moon, scene.sun)); var umbraLen = sunMoon * AE_MOON_RADIUS_RE / (AE_SUN_RADIUS_RE - AE_MOON_RADIUS_RE); var toGround = hitScene ? _aeLen(_aeSub(hitScene, scene.moon)) : along; return { gamma: gamma, hit: hit, umbra: toGround < umbraLen, axis: axis }; } // The Earth's shadow on the Moon, in the classical geocentric angles (Meeus // ch. 54, Chauvenet's 1/50 enlargement). gamma: the Moon centre's distance // from the shadow axis in Earth radii; magnitudes: the fraction of the Moon's // diameter inside the umbra and the penumbra (negative = clear of it). function _aeLunarShadow(scene) { var dMoon = _aeLen(scene.moon), dSun = _aeLen(scene.sun); var piMoon = Math.asin(1 / dMoon); // Moon's horizontal parallax var piSun = Math.asin(1 / dSun); // Sun's horizontal parallax var sSun = Math.asin(AE_SUN_RADIUS_RE / dSun); // Sun's semi-diameter var sMoon = Math.asin(AE_MOON_RADIUS_RE / dMoon); // Moon's semi-diameter var umbraR = AE_SHADOW_ENLARGE * (piMoon + piSun - sSun); var penumbraR = AE_SHADOW_ENLARGE * (piMoon + piSun + sSun); var anti = _aeScale(_aeNorm(scene.sun), -1); var sep = _aeAngle(anti, scene.moon); // Moon centre from the shadow axis var axisDist = dMoon * Math.sin(sep); var north = _aeDot(_aeSub(_aeNorm(scene.moon), anti), [0, 0, 1]) >= 0 ? 1 : -1; return { gamma: axisDist * north, umbralMag: (umbraR + sMoon - sep) / (2 * sMoon), penumbralMag: (penumbraR + sMoon - sep) / (2 * sMoon), umbraR: umbraR, penumbraR: penumbraR, sMoon: sMoon, sep: sep }; } // The instant (ms) near `ms` where f(ms) is least, by golden-section search // over +/- spanMs. f must be unimodal there (an eclipse's axis distance is). var AE_GOLDEN = (Math.sqrt(5) - 1) / 2; var AE_MIN_SEARCH_TOL_MS = 1000; function _aeMinimize(f, ms, spanMs) { var a = ms - spanMs, b = ms + spanMs; var c = b - AE_GOLDEN * (b - a), d = a + AE_GOLDEN * (b - a); var fc = f(c), fd = f(d); while (b - a > AE_MIN_SEARCH_TOL_MS) { if (fc < fd) { b = d; d = c; fd = fc; c = b - AE_GOLDEN * (b - a); fc = f(c); } else { a = c; c = d; fc = fd; d = a + AE_GOLDEN * (b - a); fd = f(d); } } return (a + b) / 2; } // Greatest eclipse near `ms`: the instant the shadow axis passes closest to // the Earth's centre (solar) or the Moon's centre is closest to the Earth's // shadow axis (lunar). Search +/- a day and a half, enough to cover the // local-date slack of the Almanac's eclipse list. var AE_ECLIPSE_SEARCH_MS = 1.5 * MS_PER_DAY; function _aeGreatestEclipse(ms, solar) { var f = solar ? function (t) { return Math.abs(_aeSolarShadow(_aeSceneAt(t)).gamma); } : function (t) { return Math.abs(_aeLunarShadow(_aeSceneAt(t)).gamma); }; // Coarse hourly scan first, then the golden section inside the best hour: // the guess can sit a day off the eclipse, and over three days the distance // need not fall steadily toward it from both ends. var best = ms, bestV = Infinity, step = MS_PER_DAY / 24; for (var t = ms - AE_ECLIPSE_SEARCH_MS; t <= ms + AE_ECLIPSE_SEARCH_MS; t += step) { var v = f(t); if (v < bestV) { bestV = v; best = t; } } return _aeMinimize(f, best, step); } // ── Satellites: the GPS clock's relativity ── // A GPS satellite's clock against a clock on the ground, as fractional // rates: gravity is weaker up there, so it runs fast by (W0 - GM/r)/c^2; it // moves, so it runs slow by v^2/(2 c^2). r in km, v in km/s (inertial). function _aeGpsClockRates(rKm, vKmS) { var c2 = SPEED_OF_LIGHT_KM_S * SPEED_OF_LIGHT_KM_S; var grav = AE_L_G - AE_GM_EARTH / (rKm * c2); var speed = -(vKmS * vKmS) / (2 * c2); return { grav: grav, speed: speed, net: grav + speed }; } // Microseconds a day for a fractional rate, and the ranging error it becomes // in a day if ignored (the clock error times the speed of light), km. function _aeMicrosPerDay(rate) { return rate * SECONDS_PER_DAY * AE_MICRO; } function _aeKmPerDay(rate) { return rate * SECONDS_PER_DAY * SPEED_OF_LIGHT_KM_S; } // ── Satellites: what the data supports ── // Elements are drawn only near the instant they describe. GPS orbits hold // their shape for months at this scale. The ISS's orbit does too (SGP4 keeps // its plane well), but drag and reboosts move its place along the orbit: // past AE_ISS_EXACT_DAYS its dot fades and is labelled approximate, and past // AE_ISS_DOT_DAYS, when that place could be anywhere round the orbit (2-3 // weeks of unmodelled reboosts), only the orbit is drawn, with a dated note. var AE_SAT_WINDOW_DAYS = 180; // Past that a GPS satellite keeps its dot, faded and marked approximate, rather than vanishing, out to AE_SAT_APPROX_DAYS. The window is SGP4's error growth: with no drag at 20,000 km // what grows is the along-track error of the mean motion, about 1.5 km a day (the unmodelled slot changes of a constellation that keeps station add to it), so 1,100 days is about // 1,650 km, a hundredth of the orbit's circumference, 0.26 Earth radii on the screen: still where the constellation was, to a dot's eye. Past it the planes have changed more than that // (satellites retired, others launched) and nothing is drawn. The dot's strength falls in a straight line between the two. var AE_SAT_APPROX_DAYS = 1100, AE_SAT_APPROX_ALPHA_FROM = 0.6, AE_SAT_APPROX_ALPHA_TO = 0.12; function _aeSatApproxAlpha(ageDays) { return AE_SAT_APPROX_ALPHA_FROM + (AE_SAT_APPROX_ALPHA_TO - AE_SAT_APPROX_ALPHA_FROM) * _aeClamp((Math.abs(ageDays) - AE_SAT_WINDOW_DAYS) / (AE_SAT_APPROX_DAYS - AE_SAT_WINDOW_DAYS), 0, 1); } var AE_ISS_EXACT_DAYS = 3; var AE_ISS_DOT_DAYS = 14; var AE_MINUTES_PER_DAY = 1440; var AE_MS_PER_MINUTE = 60000; // JS time of an element set's epoch, from satellite.js's Julian date. function _aeSatEpochMs(satrec) { return (satrec.jdsatepoch - JD_UNIX_EPOCH) * MS_PER_DAY; } // How an element set this many days from the displayed instant (either // direction) is drawn: 'exact', 'approximate' (a faded dot), 'orbit' (the // ISS's ring alone) or 'none'. // `watched`: time running fast, or the view on the station. Then the ISS keeps its (approximate) dot past // AE_ISS_DOT_DAYS: at an hour a second a fortnight passes in six minutes and the station went out like a light, and a // flight to it had nothing to follow. Where along its orbit is the guess the faded dot and its label already own. function _aeSatStanding(ageDays, isIss, watched) { var a = Math.abs(ageDays); if (!isIss) return a <= AE_SAT_WINDOW_DAYS ? 'exact' : a <= AE_SAT_APPROX_DAYS ? 'approximate' : 'none'; if (a > AE_SAT_WINDOW_DAYS) return 'none'; if (a <= AE_ISS_EXACT_DAYS) return 'exact'; return a <= AE_ISS_DOT_DAYS || watched ? 'approximate' : 'orbit'; } // SGP4 answers in TEME (true equator, mean equinox); the scene is on the // true equinox, a turn of the equation of the equinoxes away. km -> Earth radii. function _aeTemeToScene(pKm, eqeq) { return _aeScale(_aeRotZ(_aeXyz(pKm), eqeq), 1 / AE_EARTH_RADIUS_KM); } // The equation of the equinoxes (radians) for a scene. function _aeEqEq(scene) { return _aeRad(scene.sunEq.nut.dpsi * Math.cos(_aeRad(scene.sunEq.nut.eps))); } // What is being eclipsed right now, for the status line: a solar eclipse // while the Moon's penumbra touches the Earth, a lunar one while the Moon is // in the Earth's penumbra. The penumbra's half-width at the Earth: the cone // through the Sun's and Moon's limbs, crossed, widening past the Moon. function _aeEclipseNow(scene) { var facing = _aeDot(scene.moon, scene.sun) > 0; if (facing) { var sol = _aeSolarShadow(scene); var sunMoon = _aeLen(_aeSub(scene.moon, scene.sun)); var penHalf = AE_MOON_RADIUS_RE + (AE_SUN_RADIUS_RE + AE_MOON_RADIUS_RE) * _aeLen(scene.moon) / sunMoon; if (Math.abs(sol.gamma) < 1 + penHalf) return { solar: true, central: !!sol.hit, total: sol.umbra, hit: sol.hit }; return null; } var lun = _aeLunarShadow(scene); if (lun.penumbralMag > 0) return { solar: false, total: lun.umbralMag >= 1, partial: lun.umbralMag > 0, umbralMag: lun.umbralMag }; return null; } // ═══════════════════════════════════════════════════════════════════════ // The view // ═══════════════════════════════════════════════════════════════════════ // Assets. Static files are served immutable for a year, so each name carries // its version: replacing one means a new name here, never new bytes under // the old one. var AE_THREE_URL = _almAsset('/static/earth/three-r186.min.js'); var AE_SGP4_URL = _almAsset('/static/earth/satellite-7.1.0.min.js'); var AE_TEX_DAY = _almAsset('/static/earth/earth-day-v1.webp'); var AE_TEX_NIGHT = _almAsset('/static/earth/earth-night-v1.webp'); var AE_TEX_MOON = _MOON_MAP_URL; // app.js: the 2D Moons' maps, the 1024 one first var AE_TEX_MOON_HI = _MOON_MAP_HI_URL; // The 4096 map goes to the GPU as one channel (8 MB, not 32): three's // RedFormat, which the tree-shaken build does not export by name. var AE_THREE_RED_FORMAT = 1028; // Light added without touching the canvas's alpha (_aeAddLight): three's // CustomBlending, ZeroFactor and OneFactor, not exported by name either. var AE_THREE_CUSTOM_BLENDING = 5, AE_THREE_ZERO_FACTOR = 200, AE_THREE_ONE_FACTOR = 201; var AE_SATS_URL = '/almanac-satellites'; // When the server says it is fetching fresher elements, ask again after this: // its refresh is two CelesTrak requests of up to 20 s each (satellites.py // FETCH_TIMEOUT_S), and a little over. var AE_SATS_REFETCH_MS = 45 * 1000; // "Satellite data from the internet" (satellites.py): the setting, and the // admin's one fetch under Ask first. Both are /manage writes, admin-gated. var AE_SATS_SETTING_URL = '/manage/satellites'; var AE_SATS_REFRESH_URL = '/manage/satellites/refresh'; // Each choice is labelled alm_earth_sat_, and described by _hint // (Server settings in app.js reads the same labels). var AE_SAT_MODES = ['ask', 'auto', 'never']; var AE_SAT_MODE_KEY = 'alm_earth_sat_'; var AE_SAT_ENV = 'ZIMI_SATELLITE_UPDATES'; var AE_HTTP_UNAUTHORIZED = 401, AE_HTTP_FORBIDDEN = 403; // Camera. var AE_FOV_DEG = 35; var AE_NEAR_FRACTION = 0.05; // near plane, as a share of the distance to the nearest surface var AE_NEAR_MIN = 2e-6; // 13 m: over an Apollo site the camera comes within a kilometre of the ground var AE_FAR = 40000; // Earth radii: past Neptune and the near probes as shown (_aeShownDist) var AE_STAR_RADIUS = 25000; // the star sphere, carried with the camera: behind every planet var AE_MIN_DIST_EARTH = 1.12; // closest approach, from the Earth's centre (~770 km up) var AE_MIN_DIST_MOON = AE_MOON_RADIUS_RE * 1.25; var AE_MAX_DIST = 420; // wide enough to hold the Moon's whole orbit var AE_MAX_ELEVATION = _aeRad(85); // north stays up; never flip over a pole var AE_START_MAX_LAT = _aeRad(50); // the opening view leans no further toward a pole var AE_DRAG_RAD_PER_PX = 0.02; // the fastest a drag turns (a disc too small to follow the finger) var AE_WHEEL_ZOOM = 0.0015; // log-distance per wheel unit var AE_KEY_TURN = _aeRad(5); var AE_KEY_ARROWS = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, 1], ArrowDown: [0, -1] }; // as a one-pixel drag var AE_KEY_ZOOM = 1.15; // A flight's length grows with how far it goes, as a multiple of the scale // it leaves or arrives at (log, so the Moon is not ten times the trip to the // GPS shell): a nudge between framings is quick, a crossing to the Sun is // the longest, and nothing takes longer than AE_FLY_FAR_MS. var AE_FLY_MIN_MS = 500; // A flight between two bodies is one continuous move through an over-the-shoulder view: the camera eases back behind // the body it leaves, off to one side so that body stands large in the foreground (its diameter this fraction of the // narrower side of the frame, its centre this far out toward that side, in half-frames), turned to the destination, // which is framed on the open side (centred this far out the other way), and carries on in without a stop. var AE_FLY_APPROACH_MS = 1500, AE_FLY_TAIL_MS = 900; // the leg to the shoulder, and what the leg in adds to the flight's own length // The camera crawls through the shoulder view: its apparent speed (how fast the picture changes, a share of the // nearer body's distance per second) holds at a small share of the pace either leg cruises at for AE_FLY_CRAWL_MS // either side of it, and rises smoothly from there over AE_FLY_CRAWL_RAMP_MS. The leg to the shoulder eases in from rest // over AE_FLY_EASE_IN_MS, and the leg in eases out to rest over AE_FLY_EASE_OUT_MS. var AE_FLY_CRAWL_MS = 350, AE_FLY_CRAWL_RAMP_MS = 600, AE_FLY_CRAWL_SHARE = 0.04; var AE_FLY_EASE_IN_MS = 500, AE_FLY_EASE_OUT_MS = 800, AE_FLY_TABLE_N = 240; var AE_FLY_BEND_MS = 200, AE_FLY_BEND_REACH = 0.5; // half the span over which the camera rounds the corner at the shoulder var AE_SHOULDER_FILL = 1 / 3, AE_SHOULDER_OLD_AT = 0.55, AE_SHOULDER_DEST_AT = -0.3; var AE_FLY_CLEAR = 1.6, AE_FLY_CLEAR_STEPS = 400; // the nearest a planned flight's camera comes to any body, in its radii (planned to this; the test holds it to 1.35), and the steps the flight is checked at var AE_FLY_MS_PER_LOG = 300; // No flight turns the picture faster than this, in degrees a frame at 60 fps: a flight that would is stretched. var AE_FLY_MAX_TURN_DEG = 4, AE_FLY_MAX_STRETCH = 4, AE_FRAME_MS = 1000 / 60, AE_FLY_PLAN_STEPS = 60; // A body drawn smaller than this across is marked with a ring and its name; the mark fades out by the second size. var AE_MARK_SMALL_PX = 24, AE_MARK_GONE_PX = 64, AE_MARK_SAME_PX = 6; // marks closer than this: only the first // Through a flight between bodies both ends wear a ring the size of the body as drawn (the Sun from the Moon's night // side is nearly black, and a ring is all that outlines it): its radius plus this margin, never under the minimum, // gone by the time the camera has arrived (the last share of the arrival). var AE_RING_MARGIN_PX = 5, AE_RING_MIN_R_PX = 11, AE_RING_FADE_FROM = 0.7; // A flight's ring eases toward shown or not with this time constant (it popped on and off while the camera swung round the // corner of the approach), and the dot and name take over from it over AE_RING_HANDOFF_MS (they popped in at arrival). var AE_RING_EASE_MS = 90, AE_RING_HANDOFF_MS = 350; function _aeRingEase(el, want) { var now = performance.now(), gap = now - (el._aeEaseAt || 0), dt = gap < 250 ? gap : 16, op = el._aeRingOp || 0; // (a ring begun after a pause starts from nothing) if (gap >= 250) op = 0; el._aeEaseAt = now; op += (want - op) * (1 - Math.exp(-dt / AE_RING_EASE_MS)); if (Math.abs(want - op) < 0.01) op = want; else _ae.dirty = true; return (el._aeRingOp = op); } // A name hangs toward the middle of the screen; the mark it hangs from sits on the middle itself when the camera is on it, so // the side it chose holds until the mark is this far over the middle the other way (it flapped left and right on arrival). var AE_NAME_SIDE_HOLD_PX = 40; // How much of a mark's dot and name shows after a flight's ring lets go of it: 0 as the ring goes, 1 once AE_RING_HANDOFF_MS has passed. function _aeRingHandoff(el, ringed) { var now = performance.now(); if (ringed) { el._aeRinged = true; el._aeHandAt = 0; return 1; } if (el._aeRinged) { el._aeRinged = false; el._aeHandAt = now; } if (!el._aeHandAt) return 1; var k = _smoothstep(0, AE_RING_HANDOFF_MS, now - el._aeHandAt); if (k >= 1) el._aeHandAt = 0; else _ae.dirty = true; return k; } function _aeNameOutLeft(el, x) { var half = _ae.w / 2, was = el._aeOutLeft; if (was === undefined || (was && x < half - AE_NAME_SIDE_HOLD_PX) || (!was && x > half + AE_NAME_SIDE_HOLD_PX)) was = x > half; return (el._aeOutLeft = was); } var AE_MARKED = [ { body: 'earth', name: function () { return _tp('Earth'); } }, { body: 'moon', name: function () { return _aeT('alm_moon'); } }, { body: 'sun', name: function () { return _aeT('alm_sun'); } } ]; var AE_FLY_START_DIST = 40; // the zoom in from the orrery starts this far out var AE_STICK_R_PX = 56, AE_STICK_ZONE = 0.5; // the thumb stick every vehicle shares: its reach, and the share of the picture (from the left, from the bottom) that is its var AE_TAP_SLOP_PX = 6; // a pointer that moved less than this was a tap var AE_TAP_RADIUS_PX = 22; // how near a tap must land to pick something var AE_NAME_DIAG = 0.75; // a mark's corner name stands off its ring this share of the radius each way var AE_LABEL_DX = 8; // labels sit this far right of their point (CSS px) var AE_YOU_GAP_PX = 8; // You's ringed marker is wider than a dot: its word stands this much further off, clear of the ring // Presets: the radius (Earth radii) each view must hold, and how full. var AE_FIT_EARTH = 1.12; // the Earth and the ISS's orbit var AE_FIT_SATS = 4.35; // the GPS shell (AE_GPS_SHELL_RE) and a margin var AE_FIT_MOON = AE_MOON_RADIUS_RE * 1.35; var AE_FIT_FILL = 0.92; // Rendering. var AE_MAX_DPR = 2; // a 3x phone fills 2.25x the pixels for little gain // Multisampling smooths edges only below this pixel ratio: at 2x a pixel is // too small for the jaggies to show, and it would hold four more colour // samples a pixel (~16 MB more on a phone screen). var AE_MSAA_BELOW_DPR = 2; // It is chosen once, with the context, and the governor (capability.js) may later step the ratio well under where the // view began: a limb drawn at 1x on a 3x screen with no multisampling is a staircase. An Apple GPU resolves the samples // inside each tile, at little cost, so there a view that begins at up to this ratio is multisampled all along. var AE_MSAA_APPLE_DPR = 2, AE_APPLE_GPU_RE = /apple/i; function _aeMsaa(dpr) { if (dpr < AE_MSAA_BELOW_DPR) return true; return dpr <= AE_MSAA_APPLE_DPR && typeof ZimiCap !== 'undefined' && AE_APPLE_GPU_RE.test(ZimiCap.signals().renderer || ''); } var AE_EARTH_SEGMENTS = [128, 64]; var AE_ATMO_SEGMENTS = [96, 48]; var AE_MOON_SEGMENTS = [64, 32]; var AE_ATMOSPHERE_SCALE = 1.018; // the glow's shell, ~115 km above the surface var AE_ANISOTROPY = 8; var AE_TEXT_TICK_MS = 100; // readouts and the GPS counter, while frames are drawn // Nothing moving, the view asks for no frames: a timer this often (no animation frame) keeps the readouts on time and // asks for a picture only when something changed or the clock has moved something on screen by AE_IDLE_MOVE_PX. var AE_IDLE_TICK_MS = 1000; var AE_IDLE_MOVE_PX = 0.5; // The fastest thing the view draws near a body at real time, in Earth radii a second: Jupiter's equator (12.6 km/s; // the ISS, 7.7 km/s, is next). Seen from `dist` it crosses this many px a second; the clock at a faster pace, faster. var AE_IDLE_FASTEST_RE_S = 12.6 / 6371; var AE_IDLE_SKY_RAD_S = 7.292e-5; // on the ground (Stand here, side by side), the sky's turn: the Earth's rate var AE_IDLE_NEAR_RE = 1e-4; // the nearest a surface is taken to be (Earth radii), so a close-up is not infinite var AE_IDLE_SMOOTH_PX_S = 4; // the clock moving the picture this fast is drawn every frame, as any motion is var AE_SAT_CAPACITY = 80; var AE_GPS_RING_POINTS = 72; var AE_ISS_RING_POINTS = 180; // finest at the station (0.02 degrees apart), 4 degrees at the far side: a chord stands 4 km off its arc at most (the station is the middle vertex) // Riding the station: the Earth turns under the camera as fast as the clock runs, the station standing still in the frame. An hour a // second is 235 degrees of its orbit a second and is still a ride (the model still, the Earth turning under it); past // AE_ISS_FAR_DEG_S of the orbit a second (a day a second flickers) the view eases out to the whole orbit (the ring in view, the // station moving along it, the camera still) in AE_ISS_FAR_MS; it comes back under AE_ISS_NEAR_DEG_S. var AE_FLY_STRAIGHT_FRAME = 0.85; // (the station stays inside this share of the frame's narrower half-width on the way in) var AE_FLY_STRAIGHT_KEEP = 2; // (a flight in to the station: its look has gone over to it by the time the camera is this many gaps from the Earth) var AE_ISS_FAR_DEG_S = 600, AE_ISS_NEAR_DEG_S = 450, AE_ISS_FAR_MS = 1500, AE_ISS_FAR_STEP_MAX_MS = 100, AE_ISS_FAR_FIT = 1.15, AE_ISS_FAR_SLIDE_FROM = 0.8, AE_ISS_FAR_CLEAR_RE = 1.02; var AE_ORBIT_E_MIN = 1e-7; // below this an orbit is round: no perigee to start from var AE_RING_REFRESH_MS = 6 * 3600 * 1000; // GPS orbits barely turn in six hours var AE_MOON_PATH_HALF_DAYS = 13.66; // half a sidereal month either side var AE_MOON_PATH_STEP_HOURS = 6; // Near the Moon the path is drawn in short steps: a 6-hour chord is about 3.5 Earth radii, thirteen times the Moon's // radius, and up close it showed as corners. 10 minutes (0.09 degrees of its orbit) within half a day either side. var AE_MOON_PATH_FINE_HOURS = 12, AE_MOON_PATH_FINE_STEP_MIN = 10; var AE_MOON_PATH_REFRESH_MS = AE_MOON_PATH_FINE_HOURS * 3600 * 1000 / 2; // the Moon never leaves the fine stretch var AE_SAT_POINT_PX = 4; var AE_SAT_SELECTED_PX = 9; var AE_ISS_POINT_PX = 6; var AE_ISS_FADED_ALPHA = 0.45; // The Sun, drawn where it is but not at its distance or size: a disc 3,000 // Earth radii out along its true direction (the real one is ~23,500), about // three times its true width, so it can be seen, and flown to, from here. // Its light on the Earth and the Moon comes from the real Sun (sunPos). var AE_SUN_SHOW_DIST = 3000; var AE_SUN_SHOW_R = 40; // ~0.76 degrees as seen from the Earth (real: 0.27); the Sun's true radius is 109 Earth radii (AE_SUN_RADIUS_RE): drawn at this size until decided var AE_SUN_SEGMENTS = [48, 24]; var AE_SUN_GLOW_SCALE = 7; // the glow's width, in the disc's radii var AE_GRANULES_PER_RADIUS = 160; // the granulation's cells (real: ~700, too fine to draw) var AE_GRANULE_CONTRAST = 0.24; // bright cells against dark lanes, at the disc's centre var AE_GRANULE_LIFE_S = 600; // a granule lives about ten minutes, on the page's clock var AE_GRANULE_CYCLE = 512; // the pattern's time, wrapped to keep a float's precision var AE_SUN_EXPOSURE = [3.0, 1.9, 0.85]; // the photosphere's exposure per colour: pale gold centre (burnt out, the limb darkening is lost), deep orange limb var AE_FIT_SUN = AE_SUN_SHOW_R * 2.2; // the disc and the glow nearest it var AE_MIN_DIST_SUN = AE_SUN_SHOW_R * 1.3; var AE_MAX_DIST_SUN = 100000; // out from the Sun far enough to hold every planet's orbit as shown, on a phone var AE_FLY_FAR_MS = 1600; // the longest flight: to or from the Sun, 3,000 Earth radii var AE_HINT_MS = 4500; var AE_SHEET_SHUT_MS = 300; // a tap this soon after a sheet closed is the tap that closed it var AE_NORTH_SVG = '', AE_NORTH_MIN_RAD = 0.05; // a way back to north-up after a twist: a white needle (its north end solid) that turns with it var AE_MINI_PX = 96; // the minimap's size (CSS px), as v1.15.7 ships it var AE_ROW_DISC_PX = 40, AE_ROW_RING_PX = 3, AE_ROW_CLIP_PX = 8; // the row's discs (almanac-earth.js _aeRowKeys): every one this size, the room the selected one's ring needs, and how many var AE_RIM_ROOM_PX = 72, AE_RIM_GAP_PX = 16; // what the row leaves at its end for the corner's one disc (12 + 44 + a gap); the controls layer says more (--ah-end) when more stands there var AE_FOOT_PAD_PX = 16, AE_FIND_GAP_PX = 8; var AE_FIND_ROOM_PX = 12 + 44 + AE_FIND_GAP_PX - AE_FOOT_PAD_PX; // what the row leaves at its start for search: the corner's 12 px inset, its 44 px disc and a gap, less the foot's own padding var AE_TRACK_RING_PX = 4; // room at the track's start for the ring round the world in view var AE_TRACK_FADE_PX = 28; // a world passing either end of the track fades out over this, so none is cut by a hard edge var AE_DRAWER_MAX = '40%'; // the drawer reaches this far down the view, and scrolls beyond var AE_GO_STRIP_PX = 80; // the search sheet on a portrait phone opens tall: this much of the 3D view stays under the band, above the sheet's top edge ("open that view way more") var AE_HIT_PX = 44, AE_BAR_PX = 56; // a finger's reach: every control of the 3D screen is at least this var AE_TOPBAR_PX = 56; // the page header's own height (app.css --under-topbar, less the notch) var AE_BODY_CLASS = 'ae-3d'; // on the page's body while the view is open: the header floats over the picture var AE_BARE_CLASS = 'ae-bare', AE_BARE_ANIM_CLASS = 'ae-bare-anim', AE_BARE_FADE_MS = 220; // Show where I am: a crosshair, the mark every map uses for "locate me". var AE_LOCATE_SVG = typeof ALM_LOCATE_SVG === 'string' ? ALM_LOCATE_SVG : ''; // almanac.js // The info i as a type designer draws it: a dot, a flag to the left at the top of the stem, and a foot (a bare stroke // read as a tick, Eric 2026-11-08: "the I button still doesn't feel right"). var AE_INFO_SVG = ''; // The view's two switches, as round buttons: a pin for the names of places, a ringed circle for the orbits. var AE_PIN_SVG = ''; // Orbits as a gyroscope: the body, its ring, and the axis straight up through them (Eric 2026-11-08). var AE_ORBIT_SVG = ''; // Every active satellite (almanac-sats.js, loaded on the button's first press): a ring with dots on it. var AE_SATS_SVG = ''; var AE_SATS_JS = _almAsset('/static/almanac-sats.js'); // What the all-satellites layer decides by (almanac-sats.js), kept here so the Almanac's constants pages can show it. var AE_SATS_REF = { ageFreshDays: 3, ageGoneDays: 45, // elements this young are drawn in full; past the second the satellite is not drawn leoMaxKm: 2000, geoMinKm: 35000, // the orbit classes, by mean altitude passMinEl: 10, passSunAlt: -6, // a pass counts above this elevation (degrees), with the Sun below this (civil twilight) passMag: 4.0, // and is listed to this estimated magnitude skyMag: 4.5, // a scene drawing the whole sky (almanac-sats.js _asSkyAsk) shows what a dark sky shows, to this magnitude albedo: 0.25, sunMag: -26.74, // the brightness estimate: a diffuse sphere's reflectance, and the Sun's apparent magnitude areaM2: { iss: 6400, starlink: 3, oneweb: 2, iridium: 4 }, // the size assumed where SATCAT gives no radar cross-section; the ISS's is fitted: -1.8 at 1,000 km, half lit (McCants), about -3.8 overhead at dusk passMax: 16, loneStarlinks: 3, // the list is cut to the most noticeable: single Starlinks to the brightest few, the rest by brightness and height minRcsM2: 1, // a satellite whose radar cross-section is below this is not offered as a pass trainGapS: 150, trainRaanDeg: 3, // Starlinks this close in time and orbital plane (RAAN) are one train gpsMinEl: 5, // a GPS satellite is "overhead" above this elevation leoGoneDays: 14 // a low-orbit satellite's elements run back to a date older than this are not drawn (drag and manoeuvres), well before the 45 days }; // Fly (almanac-fly.js, loaded on the button's first press): a ship you steer through the solar system. // The corner glyphs are one family: a 24 box, a stroke of 2 with round ends, the ink centred on the box (AH_CSS draws them at one size). var AE_FLY_SVG = ''; // the UFO: a lens with its dome, on two legs var AE_FLY_JS = _almAsset('/static/almanac-fly.js'); // What the ship flies by (almanac-fly.js), kept here so the Almanac's constants pages can show it. var AE_FLY_REF = { tauS: 0.5, // full throttle: seconds from the nearest surface (its speed is its height over that, a second): the time to contact, the same at every scale hugPitchDeg: 10, hugEps: 0.05, // throttling forward at the lowest height over a world, the craft circles it unless its nose is up past this many degrees (or it is over the floor by this share) hoverM: 2, // the craft's underside over a ground that is drawn (almanac-standhost.js) bandShare: 0.0063, // the ground starts to show under a craft no higher than this share of the body's radius (40 km over the Earth) skimKm: 5, // the lowest it goes over a surface (the sphere is drawn without relief) deckShare: 0.01, // over a world of gas: the share of its radius it stops over the cloud tops, where the horizon and the bands still read arriveSpan: 2 / 3, // the autopilot stops where the world spans this share of the picture's shorter side arriveEase: 0.05, // its last approach is never slower than this share of the goal's radius in tauS (a pace that only halved would never arrive) clearRadii: 1.5, // it goes round a world in its way no nearer than this many of that world's radii from its middle craftM: 12.756, // the craft's width at its smallest (two millionths of the Earth's radius); near a drawn ground its speed is never figured from less height than this detent: 0.14, // the throttle within this share of its travel of the middle is at stop flareFrom: 0.5, flareLevel: 0.05, // the lever's attitude: from the first height (body radii) the nose may point less and less down, level by the second; the craft rides a world's spin over the same heights flareDegS: 60, // and turns no faster than this reanchorM: 300, reanchorHeights: 4 // flown on low, the ground is built again under the craft once it is this far, and this many of its own heights, from where the last was built }; // What the ground under a craft is drawn by (almanac-stand.js, almanac-standgl.js, almanac-standhost.js), kept here for the same pages. var AE_GROUND_REF = { prep: 3, keep: 2, // built once the craft is within this many times the height it starts to show at, and let go this many times farther again lateMs: 700, // a ground built late (the craft already in the band) comes in over this long mapTexels: [0.5, 2], // the horizon this many of the map's texels away: the map is gone from the ground's picture, and it is all there snowLineM: 5000, snowLinePow: 1.5, // the Earth's snow line: this high at the equator, times the latitude's cosine to this power (2,900 m at 46 degrees: the Alps' is 2,700 to 3,100 m) treeBelowM: 600, // and its trees end this far below it gamma: 2.2, // the ground's tone curve: shown = (1 - exp(-L k))^(1 / gamma) exposureTarget: 0.5, // 1 - exp(-L k) of the reference ground: about 0.65 on screen nightFloor: 1.5e-6, // the faintest light the eye is set to (the Sun at the Earth being 1) nightGlow: 9e-7, // the least light the ground has (starlight and airglow): a dark-adapted eye makes out the ground and its horizon matchPx: 8, matchEveryMs: 3000, // the globe's picture of the place and the ground's are each read from a square of this side, again this often while the globe still shows matchFloor: 4 / 255, // added to both before a ratio: night's near-black is not a ratio of noise matchK: [1 / 32, 4], matchHue: 2, // the match changes the exposure by no more than this either way, and the colour left over by no more than this matchWhite: 0.98, // a mean brighter than this is clipped: its true brightness cannot be read from it luma: [0.2126, 0.7152, 0.0722], // Rec. 709 settleDecades: 2, // the ground is at its own exposure and colour this many tenfolds of height below the top of the band (400 m over the Earth) hdPx: 1024, // Almanac HD's tiles round the place, as two pictures of this side hdFar: 1.5, hdNearShare: 1 / 8, // the far one reaches this many times the horizon's angle from the top of the band, the near one this share of that hdEveryMs: 500, hdRecentre: 0.5, // looked at again this often, the near one drawn again once the craft is this share of its half-width from its middle hdMinCos: 0.2, // a picture's width in longitude grows with latitude no further than this cosine's warmPx: 8, warmMs: 4000, // what a ground's first pictures need is made ahead on targets of this side, a step a frame, for no longer than this sliceMs: 8, sliceIdleMs: 40, // building is done in slices of this long beside a flight, and this long once nothing else moves treesMax: 3200, treeChunk: 400, // the Earth's trees round a place: at most, and to a mesh treesRangeM: [60, 4500] // and how near and how far they stand }; // What is being moved, told in one shape whatever moves it (the craft, a walk, a rover), for the view's own readouts: `_ae.move`, null when nothing is. // vehicle 'ufo' | 'walk' | 'rover'; near: the world it is at (and nearM, its height over it); to and toM: where it is going and how far is left (null with no // destination); speedMS, and speedC the same over light's; lightS: light's own time over what is left; place: the latitude and longitude under it; coveredM: // the ground covered since it set out (null in flight). function _aeMoveTell(vehicle, near, speedMS, more) { var m = { vehicle: vehicle, from: null, to: null, near: near, nearM: 0, toM: null, speedMS: speedMS, speedC: speedMS / SPEED_OF_LIGHT_M_S, lightS: null, place: null, coveredM: null }; for (var k in more) m[k] = more[k]; if (m.toM !== null) m.lightS = m.toM / SPEED_OF_LIGHT_M_S; _ae.move = m; } // The mission player's own figures (almanac-missions.js), kept here so the Almanac's constants pages can show them. var AE_MISSION_REF = { coastM: 120, // on a coast the camera stands this far from the craft, so the craft is seen large turnShare: 0.3, // it looks back at where the craft came from for this share of a coast (the Earth is still 4 degrees wide at 183,000 km: big enough to read as leaving), then ahead at where it is going turnS: 2, // and takes this long to turn about the craft stripSagPx: 14, // the strip's line is an arc, curving up: its ends stand this far below the middle timeStrip: true, // the view's own time strip (date, time, slider) stays at the top during a mission; false takes it away stripStepPx: [90, 160], // the mission strip: one event's step along the line, between these, a quarter of the window's width relS: [90, 5400, 129600] // the time to an event reads in seconds under the first of these, minutes under the second, hours under the third, then days }; var AE_LOCATE_TIMEOUT_MS = 15000; var AE_GPS_COLOR = [0.55, 0.85, 1.0]; var AE_ISS_COLOR = [1.0, 0.82, 0.35]; var AE_SELECTED_COLOR = [1.0, 0.62, 0.04]; var AE_GPS_RING_COLOR = 0x6fb8ff, AE_GPS_RING_ALPHA = 0.2; var AE_GPS_SHELL_RE = 4.16; // GPS orbit radius, 26,560 km, in Earth radii // Orbits fade in between the view holding half of one and nearly all of it. var AE_ORBIT_FADE_FROM = 0.5, AE_ORBIT_FADE_TO = 0.85; var AE_ISS_RING_COLOR = 0xffc861, AE_ISS_RING_ALPHA = 0.5, AE_ISS_RING_FADED = 0.25; var AE_MOON_PATH_COLOR = 0xffffff, AE_MOON_PATH_ALPHA = 0.16; // Star dots from magnitude (brighter = bigger, more opaque) and colour index. // The faintest naked-eye stars (magnitude 5 to 6.5) fall to a one-pixel // dust at a low alpha, so they texture the dark rather than read as dots. var AE_STAR_SIZE0 = 3.4, AE_STAR_SIZE_PER_MAG = 0.55, AE_STAR_SIZE_MIN = 1.0; var AE_STAR_ALPHA0 = 1.15, AE_STAR_ALPHA_PER_MAG = 0.14, AE_STAR_ALPHA_MIN = 0.24; var AE_STAR_CI_MIN = -0.3, AE_STAR_CI_SPAN = 1.9; // colour index -0.3 (blue) .. 1.6 (orange) var AE_HOURS_TO_RAD = Math.PI / 12; var _ae = null; // view state, built on first open var _aeFadeU = { value: 1 }; // how far in from the hero the view has come: what is not the Moon fades by it var _aeIsOpen = false; function _aeT(key, vars) { return (typeof t === 'function') ? t(key, vars) : key; } function _aeReduceMotion() { return _ae && _ae.snapFly ? true : (typeof _almReduceMotion === 'function') ? _almReduceMotion() : false; } // snapFly: a preset taken at once, no flight (the orrery's lift sets its end) function _aeLink(key, html) { return window.AlmanacLinks ? window.AlmanacLinks.wrap(key, html) : html; } function _aeLinked(key) { return !!(window.AlmanacLinks && window.AlmanacLinks.linkFor(key)); } function _aeClamp(x, lo, hi) { return Math.max(lo, Math.min(hi, x)); } // A three.js vector as an array; a unit vector's latitude and longitude (degrees). function _aeXyz(v) { return [v.x, v.y, v.z]; } function _aeLatLonOf(q) { return { lat: _aeDeg(Math.asin(_aeClamp(q[2], -1, 1))), lon: _aeDeg(Math.atan2(q[1], q[0])) }; } function _aeEaseOut(p) { return 1 - Math.pow(1 - p, 3); } // A flight speeds up, cruises and slows to arrive: cubic in and out. // Zero speed and zero acceleration at both ends: a turn eased with it starts and stops without a step in its rate. function _aeSmoother(p) { p = _aeClamp(p, 0, 1); return p * p * p * (p * (6 * p - 15) + 10); } // Isolated left-to-right (U+2066 ... U+2069): inside a right-to-left // sentence the bidi algorithm otherwise reorders its runs ("S, 48.5° W 31.3°"). var AE_LTR_ISOLATE = '\u2066', AE_POP_ISOLATE = '\u2069'; function _aeFmtLatLon(p) { var ns = p.lat >= 0 ? 'N' : 'S', ew = p.lon >= 0 ? 'E' : 'W'; return AE_LTR_ISOLATE + _orrNum(Math.abs(p.lat), null, 1) + '° ' + ns + ', ' + _orrNum(Math.abs(p.lon), null, 1) + '° ' + ew + AE_POP_ISOLATE; } // Numbers and dates through the orrery's formatter cache (almanac-orrery.js // _orrNum, _orrFormatter): the readouts run ten times a second, and building // a formatter costs about a millisecond on a phone. var AE_DATE_OPTS = { day: 'numeric', month: 'short', year: 'numeric' }; var AE_WHEN_OPTS = { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }; function _aeDateFormatter(shape, opts) { return _orrFormatter(shape, function (lang) { return new Intl.DateTimeFormat(lang, opts); }); } function _aeFmtDate(ms) { return _aeDateFormatter('ae-date', AE_DATE_OPTS).format(new Date(ms)); } function _aeFmtWhen(ms) { var d = new Date(ms); // A year before 1 needs the era spelled out (almanac.js _almEraOpts). if (d.getFullYear() <= 0 && typeof _almEraOpts === 'function') { return _aeDateFormatter('ae-when-era', _almEraOpts(d, AE_WHEN_OPTS)).format(d); } return _aeDateFormatter('ae-when', AE_WHEN_OPTS).format(d); } function _aeById(id) { return document.getElementById(id); } // A stylesheet put in the page once, by its id. function _aeCss(id, text) { if (_aeById(id)) return; var st = document.createElement('style'); st.id = id; st.textContent = text; document.head.appendChild(st); } // A file of the view's fetched when first needed: one