@johnmorrisdotca/chikyu-earth 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,337 @@
1
+ import { METEOR_HEIGHT_KM, SPORADIC_HOURLY_RATE, darkness, hourlyRateAt, meteorSky } from "./rate.js";
2
+ const EARTH_KM = 6371;
3
+ /**
4
+ * The most streaks alive at once: the size of the one mesh they are drawn as.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { METEOR_SLOTS } from "@johnmorrisdotca/chikyu-earth/meteors";
9
+ *
10
+ * console.log(METEOR_SLOTS); // 48
11
+ * ```
12
+ */
13
+ export const METEOR_SLOTS = 48;
14
+ /** Streaks a second across a view whose whole face is dark, on a night with no shower. */
15
+ const BASE_PER_SECOND = 2.5;
16
+ /**
17
+ * The most streaks drawn in a second, however strong the shower.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { METEORS_PER_SECOND_MAX } from "@johnmorrisdotca/chikyu-earth/meteors";
22
+ *
23
+ * console.log(METEORS_PER_SECOND_MAX); // 9
24
+ * ```
25
+ */
26
+ export const METEORS_PER_SECOND_MAX = 9;
27
+ /** A streak is lengthened to at least this many CSS pixels, so it can be seen. */
28
+ const MIN_STREAK_PX = 34;
29
+ /** The most a streak is lengthened by. One that comes straight at the eye stays short: it is a flash, as it would be. */
30
+ const MAX_STRETCH = 14;
31
+ /** The longest path drawn, in kilometres (a meteor that comes in low skims a long way). */
32
+ const MAX_PATH_KM = 260;
33
+ /** The sky is worked out again when the moment shown has moved this far, or this much real time has passed. */
34
+ const SKY_GAME_MS = 60_000;
35
+ const SKY_WALL_MS = 1500;
36
+ const SAMPLES = 160;
37
+ /** The Earth's radius on the screen, in CSS pixels, below which no streak is drawn. */
38
+ const MIN_EARTH_PX = 40;
39
+ const FRAME_MS = 33;
40
+ export const newMeteorState = () => ({ on: false, running: () => false, random: Math.random, drawn: { alive: 0, spawned: 0, perSecond: 0, shower: null, zhr: 0 } });
41
+ /**
42
+ * How many streaks a second are drawn for a mean hourly rate over the dark part of the view: 2.5 a second where the whole view is dark on a
43
+ * night with no shower, more with a shower but squeezed (the 0.6th power) and never over nine, none where nothing in view is dark.
44
+ * A streak stands for a great many meteors: the count follows the real rate, it does not equal it.
45
+ *
46
+ * @param meanHourlyRate - The mean over the view of each place's hourly rate times how dark it is there (`hourlyRateAt`, `darkness`).
47
+ * @returns Streaks a second.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { streaksPerSecond } from "@johnmorrisdotca/chikyu-earth/meteors";
52
+ *
53
+ * console.log(streaksPerSecond(8), streaksPerSecond(0), streaksPerSecond(100000)); // 2.5 0 9
54
+ * ```
55
+ */
56
+ export function streaksPerSecond(meanHourlyRate) {
57
+ if (!(meanHourlyRate > 0))
58
+ return 0;
59
+ return Math.min(METEORS_PER_SECOND_MAX, BASE_PER_SECOND * Math.pow(meanHourlyRate / SPORADIC_HOURLY_RATE, 0.6));
60
+ }
61
+ const VERT = /* glsl */ `
62
+ uniform float now;
63
+ uniform float vw;
64
+ uniform float vh;
65
+ uniform float thick;
66
+ attribute vec3 aStart;
67
+ attribute vec3 aEnd;
68
+ attribute vec2 aTime;
69
+ attribute vec2 aCorner;
70
+ attribute float aGlow;
71
+ varying float vAlong;
72
+ varying float vSide;
73
+ varying float vFade;
74
+ void main() {
75
+ float age = (now - aTime.x) / max(aTime.y, 0.001);
76
+ float u = clamp(age, 0.0, 1.0);
77
+ vec3 headAt = mix(aStart, aEnd, u);
78
+ vec3 tailAt = mix(aStart, aEnd, max(0.0, u - 0.75));
79
+ vec4 head = projectionMatrix * modelViewMatrix * vec4(headAt, 1.0);
80
+ vec4 tail = projectionMatrix * modelViewMatrix * vec4(tailAt, 1.0);
81
+ vec2 halfSize = vec2(vw, vh) * 0.5;
82
+ vec2 along = head.xy / head.w * halfSize - tail.xy / tail.w * halfSize;
83
+ float len = length(along);
84
+ along = len > 0.0001 ? along / len : vec2(1.0, 0.0);
85
+ vec2 across = vec2(-along.y, along.x);
86
+ vec4 at = aCorner.x > 0.5 ? head : tail;
87
+ vec2 push = across * aCorner.y * thick + along * (aCorner.x > 0.5 ? thick : -thick);
88
+ at.xy += push / halfSize * at.w;
89
+ // a streak is there from its start to a short afterglow, and nowhere before or after
90
+ float alive = step(0.0, age) * (1.0 - smoothstep(1.0, 1.35, age));
91
+ vFade = alive * aGlow * smoothstep(0.0, 0.12, age);
92
+ vAlong = aCorner.x;
93
+ vSide = aCorner.y;
94
+ gl_Position = alive > 0.0 ? at : vec4(2.0, 2.0, 2.0, 1.0);
95
+ }`;
96
+ const FRAG = /* glsl */ `
97
+ uniform vec3 tint;
98
+ varying float vAlong;
99
+ varying float vSide;
100
+ varying float vFade;
101
+ void main() {
102
+ float core = 1.0 - abs(vSide);
103
+ // a thin tail that brightens towards the head, and the head itself a small bright point
104
+ float tail = pow(vAlong, 1.2) * smoothstep(0.0, 0.6, core);
105
+ float head = smoothstep(0.8, 1.0, vAlong) * smoothstep(0.0, 0.35, core);
106
+ float alpha = vFade * min(1.0, tail + head);
107
+ gl_FragColor = vec4(tint, alpha);
108
+ }`;
109
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
110
+ const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
111
+ const unit = (v) => {
112
+ const l = Math.hypot(v[0], v[1], v[2]) || 1;
113
+ return [v[0] / l, v[1] / l, v[2] / l];
114
+ };
115
+ /**
116
+ * Where one streak runs: from `start` to `end`, in Earth radii from the centre, in the Earth's own axes.
117
+ * It ends `METEOR_HEIGHT_KM.bottom + 5` km up and comes down the line from the radiant; its true length is the drop in height
118
+ * divided by the sine of the radiant's height, at most 260 km, and `stretch` (1 or more) lengthens it for the eye.
119
+ *
120
+ * @param place - The unit vector of the place it ends over.
121
+ * @param radiant - The unit vector towards the radiant (it must stand above that place's horizon).
122
+ * @param stretch - How many times longer than true to draw it; 1 is true.
123
+ * @returns The two ends, and the true length in kilometres.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * import { placeVector, streakPath } from "@johnmorrisdotca/chikyu-earth/meteors";
128
+ *
129
+ * const place = placeVector({ lon: 0, lat: 0 });
130
+ * // Straight down from overhead: it falls 25 km, from 110 km up to 85 km.
131
+ * const path = streakPath(place, place, 1);
132
+ * console.log(path.km.toFixed(0), ((Math.hypot(...path.start) - 1) * 6371).toFixed(0)); // "25" "110"
133
+ * ```
134
+ */
135
+ export function streakPath(place, radiant, stretch = 1) {
136
+ const bottom = METEOR_HEIGHT_KM.bottom + 5;
137
+ const top = METEOR_HEIGHT_KM.top - 10;
138
+ const sine = Math.max(0.05, dot(place, radiant));
139
+ const km = Math.min(MAX_PATH_KM, (top - bottom) / sine);
140
+ const end = [place[0] * (1 + bottom / EARTH_KM), place[1] * (1 + bottom / EARTH_KM), place[2] * (1 + bottom / EARTH_KM)];
141
+ const back = (km * Math.max(1, stretch)) / EARTH_KM;
142
+ return { start: [end[0] + radiant[0] * back, end[1] + radiant[1] * back, end[2] + radiant[2] * back], end, km };
143
+ }
144
+ /** Make the layer inside `parent`, an object that turns with the Earth and has the Earth's own axes and a radius of 1 (a group, or the Earth's own mesh). Nothing is drawn until `step` starts a streak. */
145
+ export function createMeteorLayer(three, parent, state) {
146
+ const corners = [0, -1, 0, 1, 1, -1, 1, 1];
147
+ const count = METEOR_SLOTS * 4;
148
+ const starts = new Float32Array(count * 3);
149
+ const ends = new Float32Array(count * 3);
150
+ const times = new Float32Array(count * 2).fill(-1000);
151
+ const cornerOf = new Float32Array(count * 2);
152
+ const glows = new Float32Array(count);
153
+ const index = [];
154
+ for (let slot = 0; slot < METEOR_SLOTS; slot += 1) {
155
+ for (let v = 0; v < 4; v += 1) {
156
+ cornerOf[(slot * 4 + v) * 2] = corners[v * 2];
157
+ cornerOf[(slot * 4 + v) * 2 + 1] = corners[v * 2 + 1];
158
+ times[(slot * 4 + v) * 2 + 1] = 1;
159
+ }
160
+ const a = slot * 4;
161
+ index.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
162
+ }
163
+ const geometry = new three.BufferGeometry();
164
+ const startAttr = new three.BufferAttribute(starts, 3);
165
+ const endAttr = new three.BufferAttribute(ends, 3);
166
+ const timeAttr = new three.BufferAttribute(times, 2);
167
+ const glowAttr = new three.BufferAttribute(glows, 1);
168
+ // three.js wants a `position`; the shader places every corner itself
169
+ geometry.setAttribute("position", new three.BufferAttribute(new Float32Array(count * 3), 3));
170
+ geometry.setAttribute("aStart", startAttr);
171
+ geometry.setAttribute("aEnd", endAttr);
172
+ geometry.setAttribute("aTime", timeAttr);
173
+ geometry.setAttribute("aCorner", new three.BufferAttribute(cornerOf, 2));
174
+ geometry.setAttribute("aGlow", glowAttr);
175
+ geometry.setIndex(index);
176
+ const uniforms = { now: { value: 0 }, vw: { value: 1 }, vh: { value: 1 }, thick: { value: 1.8 }, tint: { value: new three.Vector3(1, 0.96, 0.86) } };
177
+ const material = new three.ShaderMaterial({ vertexShader: VERT, fragmentShader: FRAG, uniforms, transparent: true, depthWrite: false, side: three.DoubleSide });
178
+ const mesh = new three.Mesh(geometry, material);
179
+ mesh.frustumCulled = false;
180
+ mesh.renderOrder = 3;
181
+ mesh.visible = false;
182
+ parent.add(mesh);
183
+ const origin = performance.now();
184
+ /** The page's clock, in milliseconds, at which each slot's streak is over (afterglow and all). */
185
+ const over = new Float64Array(METEOR_SLOTS);
186
+ let sky = null;
187
+ let skyAt = -Infinity;
188
+ let peak = 0;
189
+ let perSecond = 0;
190
+ let nextAt = 0;
191
+ let last = 0;
192
+ let told;
193
+ /** A random place on the half of the Earth that faces the view. */
194
+ const somewhere = (facing) => {
195
+ const z = state.random() * 2 - 1;
196
+ const angle = state.random() * 2 * Math.PI;
197
+ const r = Math.sqrt(1 - z * z);
198
+ const p = [r * Math.cos(angle), z, r * Math.sin(angle)];
199
+ return dot(p, facing) < 0 ? [-p[0], -p[1], -p[2]] : p;
200
+ };
201
+ function survey(input) {
202
+ sky = meteorSky(input.time);
203
+ skyAt = input.now;
204
+ let sum = 0;
205
+ peak = 0;
206
+ for (let i = 0; i < SAMPLES; i += 1) {
207
+ const p = somewhere(input.facing);
208
+ const weight = hourlyRateAt(sky, p) * darkness(p, input.sun);
209
+ sum += weight;
210
+ if (weight > peak)
211
+ peak = weight;
212
+ }
213
+ perSecond = streaksPerSecond(sum / SAMPLES);
214
+ const top = sky.showers[0];
215
+ state.drawn.perSecond = perSecond;
216
+ state.drawn.shower = top?.shower.code ?? null;
217
+ state.drawn.zhr = top?.zhr ?? 0;
218
+ if (told !== state.drawn.shower) {
219
+ told = state.drawn.shower;
220
+ state.onShower?.(top?.shower ?? null, top?.zhr ?? 0);
221
+ }
222
+ }
223
+ /** Start one streak in a free slot: where the dark sky and the rate say, travelling the way its shower (or, for a sporadic, chance) says. */
224
+ function spawn(input) {
225
+ const slot = over.findIndex((until) => until <= input.now);
226
+ if (slot < 0 || !sky || peak <= 0)
227
+ return;
228
+ let place = null;
229
+ for (let attempt = 0; attempt < 40 && !place; attempt += 1) {
230
+ const p = somewhere(input.facing);
231
+ if (state.random() * peak < hourlyRateAt(sky, p) * darkness(p, input.sun))
232
+ place = p;
233
+ }
234
+ if (!place)
235
+ return;
236
+ // which stream it belongs to, by each one's share of the rate at that place
237
+ let pick = state.random() * hourlyRateAt(sky, place);
238
+ let radiant = null;
239
+ let speed = 20 + state.random() * 45;
240
+ for (const entry of sky.showers) {
241
+ const share = entry.zhr * Math.max(0, dot(place, entry.overhead));
242
+ if (pick < share) {
243
+ radiant = entry.overhead;
244
+ speed = entry.shower.speedKmS;
245
+ break;
246
+ }
247
+ pick -= share;
248
+ }
249
+ if (!radiant) {
250
+ // a sporadic: from any compass point, 15 to 80 degrees above the horizon
251
+ const east = unit(cross([0, 1, 0], place));
252
+ const north = cross(place, east);
253
+ const bearing = state.random() * 2 * Math.PI;
254
+ const height = ((15 + state.random() * 65) * Math.PI) / 180;
255
+ const flat = Math.cos(height);
256
+ radiant = [
257
+ place[0] * Math.sin(height) + flat * (east[0] * Math.sin(bearing) + north[0] * Math.cos(bearing)),
258
+ place[1] * Math.sin(height) + flat * (east[1] * Math.sin(bearing) + north[1] * Math.cos(bearing)),
259
+ place[2] * Math.sin(height) + flat * (east[2] * Math.sin(bearing) + north[2] * Math.cos(bearing)),
260
+ ];
261
+ }
262
+ const truth = streakPath(place, radiant, 1);
263
+ // its length as the view sees it: the part of the path that lies across the line of sight
264
+ const along = dot(radiant, input.facing);
265
+ const pixels = (truth.km / EARTH_KM) * Math.sqrt(Math.max(0, 1 - along * along)) * input.radius;
266
+ const path = pixels < MIN_STREAK_PX ? streakPath(place, radiant, Math.min(MAX_STRETCH, MIN_STREAK_PX / Math.max(pixels, 0.001))) : truth;
267
+ const life = Math.min(1.1, Math.max(0.3, truth.km / speed));
268
+ const born = (input.now - origin) / 1000;
269
+ const glow = 0.7 + 0.3 * state.random() ** 2;
270
+ for (let v = 0; v < 4; v += 1) {
271
+ const i = slot * 4 + v;
272
+ starts.set(path.start, i * 3);
273
+ ends.set(path.end, i * 3);
274
+ times[i * 2] = born;
275
+ times[i * 2 + 1] = life;
276
+ glows[i] = glow;
277
+ }
278
+ startAttr.needsUpdate = true;
279
+ endAttr.needsUpdate = true;
280
+ timeAttr.needsUpdate = true;
281
+ glowAttr.needsUpdate = true;
282
+ over[slot] = input.now + life * 1350;
283
+ state.drawn.spawned += 1;
284
+ }
285
+ return {
286
+ step(input) {
287
+ // on an Earth too small on the screen to show a streak there are none
288
+ const running = state.on && state.running() && input.radius >= MIN_EARTH_PX;
289
+ if (!running) {
290
+ // held, hidden or switched off: every streak goes at once and nothing more is asked for, so a paused picture is a still one
291
+ over.fill(0);
292
+ nextAt = 0;
293
+ last = input.now;
294
+ state.drawn.alive = 0;
295
+ state.drawn.perSecond = 0;
296
+ mesh.visible = false;
297
+ return Infinity;
298
+ }
299
+ if (!sky || Math.abs(input.time - sky.ms) > SKY_GAME_MS || input.now - skyAt > SKY_WALL_MS)
300
+ survey(input);
301
+ if (perSecond > 0) {
302
+ // after a rest the clock starts again from now, so a pause is not made up for with a burst
303
+ if (input.now - last > 1000 || nextAt === 0)
304
+ nextAt = input.now + (-Math.log(1 - state.random()) / perSecond) * 1000;
305
+ let started = 0;
306
+ while (nextAt <= input.now && started < 4) {
307
+ spawn(input);
308
+ started += 1;
309
+ nextAt += (-Math.log(1 - state.random()) / perSecond) * 1000;
310
+ }
311
+ if (nextAt <= input.now)
312
+ nextAt = input.now + FRAME_MS;
313
+ }
314
+ else
315
+ nextAt = 0;
316
+ last = input.now;
317
+ let alive = 0;
318
+ for (let slot = 0; slot < METEOR_SLOTS; slot += 1)
319
+ if (over[slot] > input.now)
320
+ alive += 1;
321
+ state.drawn.alive = alive;
322
+ mesh.visible = alive > 0;
323
+ uniforms.now.value = (input.now - origin) / 1000;
324
+ uniforms.vw.value = input.width;
325
+ uniforms.vh.value = input.height;
326
+ if (alive > 0)
327
+ return FRAME_MS;
328
+ // nothing alive: sleep until the next one is due, or, where nothing in view is dark, look again in a while (the Earth turns)
329
+ return perSecond > 0 ? Math.max(FRAME_MS, nextAt - input.now) : SKY_WALL_MS;
330
+ },
331
+ dispose() {
332
+ parent.remove(mesh);
333
+ geometry.dispose();
334
+ material.dispose();
335
+ },
336
+ };
337
+ }
@@ -0,0 +1,11 @@
1
+ /** The line, in the two languages the family's pages are written in. */
2
+ export declare const METEOR_NOTE: {
3
+ readonly en: "Meteor streaks are an illustration. How often they appear, and where, how high and when, follow real data.";
4
+ readonly ja: "流星の光の筋はイメージです。出やすさ、場所、高さ、時期は実際のデータにもとづいています。";
5
+ };
6
+ /** The styles of the line (`#meteor-note` in an element's shadow root). */
7
+ export declare const METEOR_NOTE_STYLE = "#meteor-note{position:absolute;left:8px;bottom:6px;margin:0;font:11px/1.3 system-ui,sans-serif;color:#dfe6f2;background:#0b0e14b3;padding:2px 6px;border-radius:4px;pointer-events:none}#meteor-note[hidden]{display:none}";
8
+ /** Put the line right: its words in the language of the element or the page, shown only while meteors are on and `meteors-label` is not `off`. */
9
+ export declare function setMeteorNote(note: HTMLElement | undefined, host: HTMLElement, on: boolean): void;
10
+ /** Whether a reader has asked their device for less motion. */
11
+ export declare const prefersLessMotion: () => boolean;
@@ -0,0 +1,19 @@
1
+ // The line an element shows under its picture while meteors are on, so nobody takes a streak for a meteor that was seen.
2
+ /** The line, in the two languages the family's pages are written in. */
3
+ export const METEOR_NOTE = {
4
+ en: "Meteor streaks are an illustration. How often they appear, and where, how high and when, follow real data.",
5
+ ja: "流星の光の筋はイメージです。出やすさ、場所、高さ、時期は実際のデータにもとづいています。",
6
+ };
7
+ /** The styles of the line (`#meteor-note` in an element's shadow root). */
8
+ export const METEOR_NOTE_STYLE = "#meteor-note{position:absolute;left:8px;bottom:6px;margin:0;font:11px/1.3 system-ui,sans-serif;color:#dfe6f2;background:#0b0e14b3;padding:2px 6px;border-radius:4px;pointer-events:none}#meteor-note[hidden]{display:none}";
9
+ /** Put the line right: its words in the language of the element or the page, shown only while meteors are on and `meteors-label` is not `off`. */
10
+ export function setMeteorNote(note, host, on) {
11
+ if (!note)
12
+ return;
13
+ const lang = (host.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
14
+ note.textContent = METEOR_NOTE[lang];
15
+ note.lang = lang;
16
+ note.hidden = !on || host.getAttribute("meteors-label") === "off";
17
+ }
18
+ /** Whether a reader has asked their device for less motion. */
19
+ export const prefersLessMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
@@ -0,0 +1,206 @@
1
+ import type { GeoPoint } from "../types.ts";
2
+ import { type MeteorShower } from "../data/meteor-showers.ts";
3
+ /**
4
+ * The heights between which most meteors shine, in kilometres above the ground: they light up near the top and have burnt out by the bottom.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { METEOR_HEIGHT_KM } from "@johnmorrisdotca/chikyu-earth/meteors";
9
+ *
10
+ * console.log(METEOR_HEIGHT_KM.top, METEOR_HEIGHT_KM.bottom); // 120 80
11
+ * ```
12
+ */
13
+ export declare const METEOR_HEIGHT_KM: {
14
+ readonly top: 120;
15
+ readonly bottom: 80;
16
+ };
17
+ /**
18
+ * The hourly rate taken for the meteors that belong to no shower (the sporadic background), for an ideal watcher under a perfect sky.
19
+ * It is an assumed round figure, not one from the shower list: the real count runs from a few an hour in the evening to over ten before dawn.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { SPORADIC_HOURLY_RATE } from "@johnmorrisdotca/chikyu-earth/meteors";
24
+ *
25
+ * console.log(SPORADIC_HOURLY_RATE); // 8
26
+ * ```
27
+ */
28
+ export declare const SPORADIC_HOURLY_RATE = 8;
29
+ /**
30
+ * The Sun's longitude along the ecliptic for the equinox of 2000.0, in degrees: the measure the shower list times its maxima by.
31
+ * Low precision (Meeus, Astronomical Algorithms, ch. 25, with the precession since 2000 taken off), good to about 0.01 degree from 1900 to 2100.
32
+ *
33
+ * @param ms - The moment, in milliseconds since the epoch.
34
+ * @returns The longitude, 0 up to 360.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { solarLongitude } from "@johnmorrisdotca/chikyu-earth/meteors";
39
+ *
40
+ * // The Perseids' maximum is at 140.0 degrees.
41
+ * console.log(solarLongitude(Date.UTC(2026, 7, 13, 2)).toFixed(1));
42
+ * ```
43
+ */
44
+ export declare function solarLongitude(ms: number): number;
45
+ /**
46
+ * How strong a shower is at a moment: its zenithal hourly rate then, 0 outside its dates.
47
+ * The list gives the rate at the maximum and the first and last days of activity; between them this draws the simplest curve that fits:
48
+ * the rate falls away from the maximum by the same factor for each degree the Earth moves on, down to half a meteor an hour at the start of the first day and the end of the last.
49
+ * A real shower's curve differs (the Quadrantids' maximum lasts hours, the Taurids' weeks). A shower the list calls variable gives 0.
50
+ *
51
+ * @param shower - A shower of `METEOR_SHOWERS`.
52
+ * @param ms - The moment, in milliseconds since the epoch.
53
+ * @returns The zenithal hourly rate, in meteors an hour.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { METEOR_SHOWERS, showerRate } from "@johnmorrisdotca/chikyu-earth/meteors";
58
+ *
59
+ * const geminids = METEOR_SHOWERS.find((shower) => shower.code === "GEM")!;
60
+ * console.log(showerRate(geminids, Date.UTC(2026, 11, 14, 8)).toFixed(0), showerRate(geminids, Date.UTC(2026, 5, 1))); // "150" 0
61
+ * ```
62
+ */
63
+ export declare function showerRate(shower: MeteorShower, ms: number): number;
64
+ /**
65
+ * The showers active at a moment, strongest first, each with its rate then.
66
+ *
67
+ * @param ms - The moment, in milliseconds since the epoch.
68
+ * @returns The active showers and their zenithal hourly rates (see `showerRate`).
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { activeShowers } from "@johnmorrisdotca/chikyu-earth/meteors";
73
+ *
74
+ * for (const { shower, zhr } of activeShowers(Date.UTC(2026, 7, 12))) console.log(shower.name, zhr.toFixed(1));
75
+ * ```
76
+ */
77
+ export declare function activeShowers(ms: number): {
78
+ shower: MeteorShower;
79
+ zhr: number;
80
+ }[];
81
+ /**
82
+ * The place on the Earth where a point of the sky stands overhead at a moment: for a shower's radiant, the middle of the half
83
+ * of the Earth its meteors fall on.
84
+ *
85
+ * @param sky - Right ascension and declination, in degrees.
86
+ * @param ms - The moment, in milliseconds since the epoch.
87
+ * @returns The longitude and latitude of that place, in degrees.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { METEOR_SHOWERS, pointBeneath } from "@johnmorrisdotca/chikyu-earth/meteors";
92
+ *
93
+ * const perseids = METEOR_SHOWERS.find((shower) => shower.code === "PER")!;
94
+ * const place = pointBeneath(perseids.radiant, Date.UTC(2026, 7, 13, 2));
95
+ * console.log(place.lat, place.lon.toFixed(0)); // 58 and the longitude then
96
+ * ```
97
+ */
98
+ export declare function pointBeneath(sky: {
99
+ ra: number;
100
+ dec: number;
101
+ }, ms: number): GeoPoint;
102
+ /**
103
+ * The place on the Earth that faces the way the Earth is travelling round the Sun (the apex of its way): it sits on the morning side,
104
+ * which sweeps up more meteors than the evening side.
105
+ *
106
+ * @param ms - The moment, in milliseconds since the epoch.
107
+ * @returns The longitude and latitude of that place, in degrees.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { apexPoint } from "@johnmorrisdotca/chikyu-earth/meteors";
112
+ *
113
+ * console.log(Math.abs(apexPoint(Date.UTC(2026, 2, 20, 12)).lat) < 24); // true: it stays within the tropics
114
+ * ```
115
+ */
116
+ export declare function apexPoint(ms: number): GeoPoint;
117
+ /**
118
+ * A place as a unit vector: x to longitude 90 east on the equator, y to the north pole, z to longitude 0 on the equator (the realistic Earth's own axes).
119
+ *
120
+ * @param point - Longitude and latitude, in degrees.
121
+ * @returns The unit vector from the Earth's centre to that place.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * import { placeVector } from "@johnmorrisdotca/chikyu-earth/meteors";
126
+ *
127
+ * console.log(placeVector({ lon: 0, lat: 90 }).map((n) => Math.round(n))); // [0, 1, 0]
128
+ * ```
129
+ */
130
+ export declare const placeVector: (point: GeoPoint) => [number, number, number];
131
+ /**
132
+ * What decides the meteors over the whole Earth at one moment, worked out once: the active showers with the places their radiants
133
+ * stand over, and the apex. `hourlyRateAt` reads it for each place, so a caller that asks about many places does the astronomy once.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { meteorSky, type MeteorSky } from "@johnmorrisdotca/chikyu-earth/meteors";
138
+ *
139
+ * const sky: MeteorSky = meteorSky(Date.UTC(2026, 11, 14, 8));
140
+ * console.log(sky.showers[0]?.shower.name); // "Geminids"
141
+ * ```
142
+ */
143
+ export interface MeteorSky {
144
+ ms: number;
145
+ /** The active showers, strongest first: the rate then, and the unit vector of the place the radiant is overhead. */
146
+ showers: {
147
+ shower: MeteorShower;
148
+ zhr: number;
149
+ overhead: [number, number, number];
150
+ }[];
151
+ /** The unit vector of the place that faces the Earth's way. */
152
+ apex: [number, number, number];
153
+ }
154
+ /**
155
+ * The meteor sky of a moment (see `MeteorSky`).
156
+ *
157
+ * @param ms - The moment, in milliseconds since the epoch.
158
+ * @returns The active showers with their rates and radiant places, and the apex.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * import { hourlyRateAt, meteorSky } from "@johnmorrisdotca/chikyu-earth/meteors";
163
+ *
164
+ * const sky = meteorSky(Date.UTC(2026, 7, 13, 2));
165
+ * console.log(hourlyRateAt(sky, { lon: 139.7, lat: 35.7 }).toFixed(1));
166
+ * ```
167
+ */
168
+ export declare function meteorSky(ms: number): MeteorSky;
169
+ /**
170
+ * How many meteors an ideal watcher at a place would count in an hour under a perfect dark sky, whether or not it is dark there:
171
+ * the sporadic background, a little more on the side that faces the Earth's way and a little less on the other, plus each active
172
+ * shower's rate times the sine of its radiant's height (none where the radiant is below the horizon).
173
+ * The lean towards the morning side (from 0.4 to 1.6 times `SPORADIC_HOURLY_RATE`) is a simple stand-in for the real daily swing.
174
+ *
175
+ * @param sky - The meteor sky of the moment (`meteorSky`).
176
+ * @param place - The place, or its unit vector (`placeVector`).
177
+ * @returns Meteors an hour.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * import { hourlyRateAt, meteorSky, pointBeneath } from "@johnmorrisdotca/chikyu-earth/meteors";
182
+ *
183
+ * const moment = Date.UTC(2026, 11, 14, 8);
184
+ * const sky = meteorSky(moment);
185
+ * // Under the Geminids' radiant the rate is the shower's whole rate and the background on top.
186
+ * console.log(hourlyRateAt(sky, pointBeneath(sky.showers[0]!.shower.radiant, moment)) > 150);
187
+ * ```
188
+ */
189
+ export declare function hourlyRateAt(sky: MeteorSky, place: GeoPoint | readonly [number, number, number]): number;
190
+ /**
191
+ * How dark the sky is at a place, from 0 (the Sun is up) to 1 (the Sun is 6 degrees or more below the horizon, the end of civil twilight),
192
+ * rising evenly between: meteors are counted as seen only where it is dark.
193
+ *
194
+ * @param place - The place's unit vector (`placeVector`).
195
+ * @param sun - The unit vector of the place the Sun is overhead.
196
+ * @returns 0 to 1.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * import { darkness, placeVector } from "@johnmorrisdotca/chikyu-earth/meteors";
201
+ *
202
+ * const sun = placeVector({ lon: 0, lat: 0 });
203
+ * console.log(darkness(placeVector({ lon: 0, lat: 0 }), sun), darkness(placeVector({ lon: 180, lat: 0 }), sun)); // 0 1
204
+ * ```
205
+ */
206
+ export declare function darkness(place: readonly [number, number, number], sun: readonly [number, number, number]): number;