@johnmorrisdotca/wakusei-planets 0.74.2 → 0.75.1
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.
- package/CHANGELOG.md +28 -1
- package/NOTICE.md +4 -3
- package/README.md +7 -7
- package/dist/bodies/dwarfs.js +1 -1
- package/dist/bodies/earth-look.js +1 -1
- package/dist/bodies/jupiter.js +1 -1
- package/dist/bodies/mars.js +1 -1
- package/dist/bodies/moons-neptune.js +1 -1
- package/dist/bodies/moons-pluto.js +2 -0
- package/dist/bodies/moons-saturn.js +1 -1
- package/dist/bodies/neptune.js +1 -1
- package/dist/bodies/pluto.js +1 -0
- package/dist/bodies/saturn.js +1 -1
- package/dist/bodies/uranus.js +1 -1
- package/dist/bodies/venus.js +1 -1
- package/dist/data/discovery.js +30 -0
- package/dist/data/estimated-moons.js +354 -354
- package/dist/data/moon-catalogue.d.ts +1 -1
- package/dist/data/moon-catalogue.js +368 -368
- package/dist/data/orbits.js +3 -0
- package/dist/element.d.ts +1 -1
- package/dist/element.js +19 -2
- package/dist/facts.d.ts +1 -1
- package/dist/facts.js +4 -1
- package/dist/flat/bodies.d.ts +11 -10
- package/dist/flat/bodies.js +62 -28
- package/dist/flat/element.d.ts +55 -16
- package/dist/flat/element.js +746 -86
- package/dist/flat/index.d.ts +4 -2
- package/dist/flat/index.js +5 -3
- package/dist/flat/look.d.ts +206 -0
- package/dist/flat/look.js +305 -0
- package/dist/flat/marks.d.ts +122 -0
- package/dist/flat/marks.js +60 -0
- package/dist/flat/scene.d.ts +119 -2
- package/dist/flat/scene.js +130 -2
- package/dist/flat/words.d.ts +16 -0
- package/dist/flat/words.js +74 -1
- package/dist/moon-catalogue.d.ts +9 -9
- package/dist/moon-catalogue.js +11 -10
- package/dist/moon-pages/element.js +0 -2
- package/dist/moon-pages/hero.d.ts +1 -4
- package/dist/moon-pages/hero.js +5 -10
- package/dist/portrait/model.js +3 -3
- package/dist/scene/body.d.ts +1 -0
- package/dist/scene/body.js +8 -4
- package/dist/scene/glsl.js +3 -1
- package/dist/scene/look.d.ts +15 -0
- package/dist/scene/look.js +19 -0
- package/dist/scene/name-label.d.ts +10 -0
- package/dist/scene/name-label.js +93 -1
- package/dist/scene/painter.d.ts +2 -1
- package/dist/scene/painter.js +8 -4
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +15 -1
- package/dist/space/element.js +23 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/flat/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { FLAT_BODIES, ORBITER_COLOURS, flatBody, isFlatBody, orbiterColour, orbiterName, type FlatBodyId, type FlatBodyInfo } from "./bodies.ts";
|
|
2
2
|
export { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout, type FlatView } from "./geometry.ts";
|
|
3
3
|
export { MERCATOR_LIMIT, PROJECTIONS, fitMap, graticule, isProjection, mapExtent, mapOutline, mapPixels, mapSun, projectMap, resampleMap, unprojectMap, type GraticuleLine, type MapCentre, type MapFit, type MapLine, type MapPixels, type ProjectionId } from "./projections.ts";
|
|
4
|
-
export { circleOutline, flatOrbiter, flatSun, flatTrack, hasPath, shadeNight, trackPieces, type FlatOrbiter } from "./scene.ts";
|
|
5
|
-
export {
|
|
4
|
+
export { circleOutline, flatMoonTrackHalf, flatMoonTracks, flatMoons, flatOrbiter, flatSun, flatSunRate, flatTrack, hasPath, moonsOfBody, shadeNight, sunriseLine, trackPieces, type FlatMoon, type FlatOrbiter } from "./scene.ts";
|
|
5
|
+
export { FLAT_LOOKS, MAP_LAND, MAP_LINE, MAP_SEA, MAP_TONES, bandEdges, creditLicence, creditWho, pictureWidth, pictureWidths, readLook, toneMap, toneRamp, type FlatLook, type Tone } from "./look.ts";
|
|
6
|
+
export { MARK_SHAPES, markName, readMarks, type FlatMark, type HeldMark, type MarkShape, type MarkText } from "./marks.ts";
|
|
7
|
+
export { FLAT_WORDS, coordinateText, gridText, say, type FlatLang } from "./words.ts";
|
|
6
8
|
export type { FlatPick, WakuseiFlat } from "./element.ts";
|
package/dist/flat/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
// The flat map's pure parts and the element's types (`@johnmorrisdotca/wakusei-planets/flat`): the map's geometry, the bodies it draws, the Sun, the orbiters over the ground, the night's shading, coverage circles and ground tracks, and the words. They import on a server and need no browser.
|
|
1
|
+
// The flat map's pure parts and the element's types (`@johnmorrisdotca/wakusei-planets/flat`): the map's geometry, the bodies it draws, the Sun and the sunrise line, the orbiters over the ground, the night's shading, coverage circles and ground tracks, the two looks (the photo and the line map's tones), the marks a page adds, and the words. They import on a server and need no browser.
|
|
2
2
|
// The element itself is in `@johnmorrisdotca/wakusei-planets/flat/define`, which registers `<wakusei-flat>`.
|
|
3
3
|
export { FLAT_BODIES, ORBITER_COLOURS, flatBody, isFlatBody, orbiterColour, orbiterName } from "./bodies.js";
|
|
4
4
|
export { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, unprojectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
|
|
5
5
|
export { MERCATOR_LIMIT, PROJECTIONS, fitMap, graticule, isProjection, mapExtent, mapOutline, mapPixels, mapSun, projectMap, resampleMap, unprojectMap } from "./projections.js";
|
|
6
|
-
export { circleOutline, flatOrbiter, flatSun, flatTrack, hasPath, shadeNight, trackPieces } from "./scene.js";
|
|
7
|
-
export {
|
|
6
|
+
export { circleOutline, flatMoonTrackHalf, flatMoonTracks, flatMoons, flatOrbiter, flatSun, flatSunRate, flatTrack, hasPath, moonsOfBody, shadeNight, sunriseLine, trackPieces } from "./scene.js";
|
|
7
|
+
export { FLAT_LOOKS, MAP_LAND, MAP_LINE, MAP_SEA, MAP_TONES, bandEdges, creditLicence, creditWho, pictureWidth, pictureWidths, readLook, toneMap, toneRamp } from "./look.js";
|
|
8
|
+
export { MARK_SHAPES, markName, readMarks } from "./marks.js";
|
|
9
|
+
export { FLAT_WORDS, coordinateText, gridText, say } from "./words.js";
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { FlatBodyId } from "./bodies.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The two looks of the flat map: `photo`, the real surface picture the package already holds for the body, and `map`, a line map drawn from that same picture (dark tones, a line where one tone meets the next, a grid, the names).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { FLAT_LOOKS } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
8
|
+
*
|
|
9
|
+
* console.log(FLAT_LOOKS.join(" / "));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const FLAT_LOOKS: readonly ["map", "photo"];
|
|
13
|
+
/**
|
|
14
|
+
* A look of the flat map.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { FlatLook } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
19
|
+
*
|
|
20
|
+
* const look: FlatLook = "map";
|
|
21
|
+
* console.log(look);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type FlatLook = (typeof FLAT_LOOKS)[number];
|
|
25
|
+
/**
|
|
26
|
+
* Read a `look` attribute. `map` and `photo` (any case) are themselves; anything else, and no attribute, is `photo`, the picture the element has always drawn.
|
|
27
|
+
* (chikyu-earth's `<chikyu-flat>` starts on `map`: there the picture is new. Here it is the existing look, and a page that does not ask for the map changes in nothing.)
|
|
28
|
+
*
|
|
29
|
+
* @param value - The attribute's text, or null.
|
|
30
|
+
* @returns The look.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { readLook } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
35
|
+
*
|
|
36
|
+
* console.log(readLook("Map"), readLook(null), readLook("sepia"));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function readLook(value: string | null | undefined): FlatLook;
|
|
40
|
+
/**
|
|
41
|
+
* The widths of the pictures the package holds for a body, smallest first: 1024 and 2048 pixels, and for Europa 1024 only.
|
|
42
|
+
*
|
|
43
|
+
* @param body - The body.
|
|
44
|
+
* @returns The widths.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { pictureWidths } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
49
|
+
*
|
|
50
|
+
* console.log(pictureWidths("mars"), pictureWidths("europa"));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const pictureWidths: (body: FlatBodyId) => readonly number[];
|
|
54
|
+
/**
|
|
55
|
+
* The picture a view needs: the narrowest width that has a pixel for each one the world is across on the screen, or the widest the body has.
|
|
56
|
+
*
|
|
57
|
+
* @param body - The body.
|
|
58
|
+
* @param pixelsAcross - How many device pixels 360 degrees of longitude is across.
|
|
59
|
+
* @returns The width in pixels.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { pictureWidth } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
64
|
+
*
|
|
65
|
+
* console.log(pictureWidth("mars", 900), pictureWidth("mars", 3000), pictureWidth("europa", 3000));
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function pictureWidth(body: FlatBodyId, pixelsAcross: number): number;
|
|
69
|
+
/**
|
|
70
|
+
* Whose picture a body's map is, in a few words for one small line: `NASA / USGS` for Mars, `Nestaeric` for Jupiter. The whole credit is `picturesCredit`.
|
|
71
|
+
*
|
|
72
|
+
* @param body - The body.
|
|
73
|
+
* @returns The names.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { creditWho } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
78
|
+
*
|
|
79
|
+
* console.log(creditWho("mars"), "|", creditWho("jupiter"));
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const creditWho: (body: FlatBodyId) => string;
|
|
83
|
+
/**
|
|
84
|
+
* The licence of a body's picture, in a language, for the credit line: `public domain` or `CC BY 4.0`.
|
|
85
|
+
*
|
|
86
|
+
* @param body - The body.
|
|
87
|
+
* @param lang - `en` or `ja`.
|
|
88
|
+
* @returns The licence's name.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { creditLicence } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
93
|
+
*
|
|
94
|
+
* console.log(creditLicence("mars", "en"), "|", creditLicence("mars", "ja"), "|", creditLicence("jupiter", "en"));
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function creditLicence(body: FlatBodyId, lang: "en" | "ja"): string;
|
|
98
|
+
/**
|
|
99
|
+
* A tone of the line map as red, green and blue, each 0 to 255.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import type { Tone } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
104
|
+
*
|
|
105
|
+
* const night: Tone = [4, 8, 20];
|
|
106
|
+
* console.log(night.join(","));
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export type Tone = readonly [number, number, number];
|
|
110
|
+
/**
|
|
111
|
+
* The darkest tone of the line map: the dark sea and ground tone the lines and the marks lie on. A page changes it with `--wakusei-flat-sea`.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { MAP_SEA } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
116
|
+
*
|
|
117
|
+
* console.log(MAP_SEA.join(","));
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare const MAP_SEA: Tone;
|
|
121
|
+
/**
|
|
122
|
+
* The lightest tone of the line map. A page changes it with `--wakusei-flat-land`.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { MAP_LAND } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
127
|
+
*
|
|
128
|
+
* console.log(MAP_LAND.join(","));
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare const MAP_LAND: Tone;
|
|
132
|
+
/**
|
|
133
|
+
* The colour of the line where one tone meets the next, as red, green, blue and how opaque it is (0 to 1). A page changes the colour with `--wakusei-flat-line`.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { MAP_LINE } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
138
|
+
*
|
|
139
|
+
* console.log(MAP_LINE.join(","));
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare const MAP_LINE: readonly [number, number, number, number];
|
|
143
|
+
/**
|
|
144
|
+
* How many tones the line map has.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { MAP_TONES } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
149
|
+
*
|
|
150
|
+
* console.log(MAP_TONES);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare const MAP_TONES = 5;
|
|
154
|
+
/**
|
|
155
|
+
* The tones of the line map: `count` colours from `sea` (the darkest ground of the picture) to `land` (the lightest), evenly between.
|
|
156
|
+
*
|
|
157
|
+
* @param sea - The darkest tone.
|
|
158
|
+
* @param land - The lightest tone.
|
|
159
|
+
* @param count - How many tones.
|
|
160
|
+
* @returns The tones, darkest first.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { MAP_LAND, MAP_SEA, toneRamp } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
165
|
+
*
|
|
166
|
+
* console.log(toneRamp(MAP_SEA, MAP_LAND, 3).map((tone) => tone.join(",")).join(" | "));
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function toneRamp(sea: Tone, land: Tone, count?: number): Tone[];
|
|
170
|
+
/**
|
|
171
|
+
* Where one tone ends and the next begins: the brightnesses (0 to 255) that cut a picture's pixels into `bands` groups of the same number of pixels each, so the darkest fifth of a body is the darkest tone whatever its colour.
|
|
172
|
+
*
|
|
173
|
+
* @param brightness - Each pixel's brightness, 0 to 255.
|
|
174
|
+
* @param bands - How many tones.
|
|
175
|
+
* @returns `bands - 1` brightnesses, lowest first.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { bandEdges } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
180
|
+
*
|
|
181
|
+
* console.log(bandEdges([0, 10, 20, 30, 40, 50, 60, 70, 80, 90], 5));
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export declare function bandEdges(brightness: ArrayLike<number>, bands: number): number[];
|
|
185
|
+
/**
|
|
186
|
+
* The line map of a picture: the picture's brightness, smoothed, cut into tones of equal area (`ramp`, darkest first), with a line in `line` along every place a tone meets the next. The same picture, so the map has the same shapes, and nothing new is fetched.
|
|
187
|
+
* Darkness is the picture's own, so on Mars the dark regions are the darkest tone and on the Moon the maria; on a gas giant the bands.
|
|
188
|
+
*
|
|
189
|
+
* @param pixels - The picture's pixels, 4 bytes each (red, green, blue, alpha), a row at a time, as `ImageData` has them.
|
|
190
|
+
* @param width - The picture's width.
|
|
191
|
+
* @param height - The picture's height.
|
|
192
|
+
* @param ramp - The tones, darkest first; five by default (`toneRamp(MAP_SEA, MAP_LAND)`).
|
|
193
|
+
* @param line - The line's colour and how opaque it is.
|
|
194
|
+
* @returns The new picture in the same layout, every pixel opaque.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* import { toneMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
199
|
+
*
|
|
200
|
+
* const grey = new Uint8ClampedArray(8 * 2 * 4);
|
|
201
|
+
* for (let i = 0; i < 16; i += 1) grey.set([i * 16, i * 16, i * 16, 255], i * 4);
|
|
202
|
+
* const out = toneMap(grey, 8, 2);
|
|
203
|
+
* console.log(out.length, out[3]);
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export declare function toneMap(pixels: ArrayLike<number>, width: number, height: number, ramp?: readonly Tone[], line?: readonly [number, number, number, number]): Uint8ClampedArray<ArrayBuffer>;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two looks of the flat map: `photo`, the real surface picture the package already holds for the body, and `map`, a line map drawn from that same picture (dark tones, a line where one tone meets the next, a grid, the names).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { FLAT_LOOKS } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
7
|
+
*
|
|
8
|
+
* console.log(FLAT_LOOKS.join(" / "));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const FLAT_LOOKS = ["map", "photo"];
|
|
12
|
+
/**
|
|
13
|
+
* Read a `look` attribute. `map` and `photo` (any case) are themselves; anything else, and no attribute, is `photo`, the picture the element has always drawn.
|
|
14
|
+
* (chikyu-earth's `<chikyu-flat>` starts on `map`: there the picture is new. Here it is the existing look, and a page that does not ask for the map changes in nothing.)
|
|
15
|
+
*
|
|
16
|
+
* @param value - The attribute's text, or null.
|
|
17
|
+
* @returns The look.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { readLook } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
22
|
+
*
|
|
23
|
+
* console.log(readLook("Map"), readLook(null), readLook("sepia"));
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function readLook(value) {
|
|
27
|
+
return value !== null && value !== undefined && value.trim().toLowerCase() === "map" ? "map" : "photo";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The widths of the pictures the package holds for a body, smallest first: 1024 and 2048 pixels, and for Europa 1024 only.
|
|
31
|
+
*
|
|
32
|
+
* @param body - The body.
|
|
33
|
+
* @returns The widths.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { pictureWidths } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
38
|
+
*
|
|
39
|
+
* console.log(pictureWidths("mars"), pictureWidths("europa"));
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const pictureWidths = (body) => (body === "europa" ? [1024] : [1024, 2048]);
|
|
43
|
+
/**
|
|
44
|
+
* The picture a view needs: the narrowest width that has a pixel for each one the world is across on the screen, or the widest the body has.
|
|
45
|
+
*
|
|
46
|
+
* @param body - The body.
|
|
47
|
+
* @param pixelsAcross - How many device pixels 360 degrees of longitude is across.
|
|
48
|
+
* @returns The width in pixels.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { pictureWidth } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
53
|
+
*
|
|
54
|
+
* console.log(pictureWidth("mars", 900), pictureWidth("mars", 3000), pictureWidth("europa", 3000));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function pictureWidth(body, pixelsAcross) {
|
|
58
|
+
const widths = pictureWidths(body);
|
|
59
|
+
return widths.find((one) => one >= pixelsAcross) ?? widths[widths.length - 1];
|
|
60
|
+
}
|
|
61
|
+
/** The names the short credit gives, by body: a part of what `NOTICE.md` names, short enough for one small line. */
|
|
62
|
+
const WHO = {
|
|
63
|
+
mercury: "Shady Tex",
|
|
64
|
+
venus: "Solar System Scope",
|
|
65
|
+
earth: "NASA",
|
|
66
|
+
moon: "NASA",
|
|
67
|
+
mars: "NASA / USGS",
|
|
68
|
+
phobos: "USGS",
|
|
69
|
+
deimos: "USGS",
|
|
70
|
+
ceres: "NASA",
|
|
71
|
+
vesta: "NASA",
|
|
72
|
+
jupiter: "Nestaeric",
|
|
73
|
+
io: "NASA",
|
|
74
|
+
europa: "U.S. Geological Survey",
|
|
75
|
+
ganymede: "USGS",
|
|
76
|
+
callisto: "USGS",
|
|
77
|
+
saturn: "Solar System Scope",
|
|
78
|
+
mimas: "NASA",
|
|
79
|
+
enceladus: "NASA",
|
|
80
|
+
tethys: "NASA",
|
|
81
|
+
dione: "NASA",
|
|
82
|
+
rhea: "NASA",
|
|
83
|
+
titan: "NASA",
|
|
84
|
+
iapetus: "NASA",
|
|
85
|
+
phoebe: "NASA",
|
|
86
|
+
uranus: "NestaEric",
|
|
87
|
+
neptune: "Solar System Scope",
|
|
88
|
+
triton: "NASA",
|
|
89
|
+
pluto: "NASA",
|
|
90
|
+
charon: "NASA",
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Whose picture a body's map is, in a few words for one small line: `NASA / USGS` for Mars, `Nestaeric` for Jupiter. The whole credit is `picturesCredit`.
|
|
94
|
+
*
|
|
95
|
+
* @param body - The body.
|
|
96
|
+
* @returns The names.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { creditWho } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
101
|
+
*
|
|
102
|
+
* console.log(creditWho("mars"), "|", creditWho("jupiter"));
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export const creditWho = (body) => WHO[body];
|
|
106
|
+
/** The bodies whose picture is CC BY 4.0, as `NOTICE.md` has it (the unit tests hold this to `PICTURE_CREDITS`); every other picture is public domain. */
|
|
107
|
+
const CC_BY = ["mercury", "venus", "jupiter", "saturn", "uranus", "neptune"];
|
|
108
|
+
/**
|
|
109
|
+
* The licence of a body's picture, in a language, for the credit line: `public domain` or `CC BY 4.0`.
|
|
110
|
+
*
|
|
111
|
+
* @param body - The body.
|
|
112
|
+
* @param lang - `en` or `ja`.
|
|
113
|
+
* @returns The licence's name.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { creditLicence } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
118
|
+
*
|
|
119
|
+
* console.log(creditLicence("mars", "en"), "|", creditLicence("mars", "ja"), "|", creditLicence("jupiter", "en"));
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function creditLicence(body, lang) {
|
|
123
|
+
return CC_BY.includes(body) ? "CC BY 4.0" : lang === "ja" ? "パブリックドメイン" : "public domain";
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The darkest tone of the line map: the dark sea and ground tone the lines and the marks lie on. A page changes it with `--wakusei-flat-sea`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { MAP_SEA } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
131
|
+
*
|
|
132
|
+
* console.log(MAP_SEA.join(","));
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export const MAP_SEA = [27, 51, 88];
|
|
136
|
+
/**
|
|
137
|
+
* The lightest tone of the line map. A page changes it with `--wakusei-flat-land`.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { MAP_LAND } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
142
|
+
*
|
|
143
|
+
* console.log(MAP_LAND.join(","));
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export const MAP_LAND = [118, 158, 198];
|
|
147
|
+
/**
|
|
148
|
+
* The colour of the line where one tone meets the next, as red, green, blue and how opaque it is (0 to 1). A page changes the colour with `--wakusei-flat-line`.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { MAP_LINE } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
153
|
+
*
|
|
154
|
+
* console.log(MAP_LINE.join(","));
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export const MAP_LINE = [214, 230, 248, 0.5];
|
|
158
|
+
/**
|
|
159
|
+
* How many tones the line map has.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { MAP_TONES } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
164
|
+
*
|
|
165
|
+
* console.log(MAP_TONES);
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export const MAP_TONES = 5;
|
|
169
|
+
/**
|
|
170
|
+
* The tones of the line map: `count` colours from `sea` (the darkest ground of the picture) to `land` (the lightest), evenly between.
|
|
171
|
+
*
|
|
172
|
+
* @param sea - The darkest tone.
|
|
173
|
+
* @param land - The lightest tone.
|
|
174
|
+
* @param count - How many tones.
|
|
175
|
+
* @returns The tones, darkest first.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { MAP_LAND, MAP_SEA, toneRamp } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
180
|
+
*
|
|
181
|
+
* console.log(toneRamp(MAP_SEA, MAP_LAND, 3).map((tone) => tone.join(",")).join(" | "));
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export function toneRamp(sea, land, count = MAP_TONES) {
|
|
185
|
+
const n = Math.max(1, Math.floor(count));
|
|
186
|
+
return Array.from({ length: n }, (_, i) => {
|
|
187
|
+
const t = n === 1 ? 0 : i / (n - 1);
|
|
188
|
+
return [Math.round(sea[0] + (land[0] - sea[0]) * t), Math.round(sea[1] + (land[1] - sea[1]) * t), Math.round(sea[2] + (land[2] - sea[2]) * t)];
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/** A box blur of a picture's brightness: round a row (it wraps at the seam, as longitude does) and down a column (it stops at the poles), twice, which is close to a Gaussian. */
|
|
192
|
+
function blur(values, width, height, radius) {
|
|
193
|
+
const size = 2 * radius + 1;
|
|
194
|
+
let from = values;
|
|
195
|
+
let to = new Float32Array(values.length);
|
|
196
|
+
for (let pass = 0; pass < 2; pass += 1) {
|
|
197
|
+
for (let y = 0; y < height; y += 1) {
|
|
198
|
+
const row = y * width;
|
|
199
|
+
let sum = 0;
|
|
200
|
+
for (let k = -radius; k <= radius; k += 1)
|
|
201
|
+
sum += from[row + ((k + width) % width)];
|
|
202
|
+
for (let x = 0; x < width; x += 1) {
|
|
203
|
+
to[row + x] = sum / size;
|
|
204
|
+
sum += from[row + ((x + radius + 1) % width)] - from[row + ((x - radius + width * 2) % width)];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const next = new Float32Array(values.length);
|
|
208
|
+
for (let x = 0; x < width; x += 1) {
|
|
209
|
+
let sum = 0;
|
|
210
|
+
for (let k = -radius; k <= radius; k += 1)
|
|
211
|
+
sum += to[Math.min(height - 1, Math.max(0, k)) * width + x];
|
|
212
|
+
for (let y = 0; y < height; y += 1) {
|
|
213
|
+
next[y * width + x] = sum / size;
|
|
214
|
+
sum += to[Math.min(height - 1, y + radius + 1) * width + x] - to[Math.max(0, y - radius) * width + x];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
from = next;
|
|
218
|
+
to = new Float32Array(values.length);
|
|
219
|
+
}
|
|
220
|
+
return from;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Where one tone ends and the next begins: the brightnesses (0 to 255) that cut a picture's pixels into `bands` groups of the same number of pixels each, so the darkest fifth of a body is the darkest tone whatever its colour.
|
|
224
|
+
*
|
|
225
|
+
* @param brightness - Each pixel's brightness, 0 to 255.
|
|
226
|
+
* @param bands - How many tones.
|
|
227
|
+
* @returns `bands - 1` brightnesses, lowest first.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* import { bandEdges } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
232
|
+
*
|
|
233
|
+
* console.log(bandEdges([0, 10, 20, 30, 40, 50, 60, 70, 80, 90], 5));
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export function bandEdges(brightness, bands) {
|
|
237
|
+
const bins = new Uint32Array(256);
|
|
238
|
+
for (let i = 0; i < brightness.length; i += 1)
|
|
239
|
+
bins[Math.max(0, Math.min(255, Math.round(brightness[i])))] += 1;
|
|
240
|
+
const edges = [];
|
|
241
|
+
let seen = 0;
|
|
242
|
+
let bin = 0;
|
|
243
|
+
for (let b = 1; b < bands; b += 1) {
|
|
244
|
+
const target = (brightness.length * b) / bands;
|
|
245
|
+
while (bin < 255 && seen + bins[bin] < target) {
|
|
246
|
+
seen += bins[bin];
|
|
247
|
+
bin += 1;
|
|
248
|
+
}
|
|
249
|
+
edges.push(bin);
|
|
250
|
+
}
|
|
251
|
+
return edges;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The line map of a picture: the picture's brightness, smoothed, cut into tones of equal area (`ramp`, darkest first), with a line in `line` along every place a tone meets the next. The same picture, so the map has the same shapes, and nothing new is fetched.
|
|
255
|
+
* Darkness is the picture's own, so on Mars the dark regions are the darkest tone and on the Moon the maria; on a gas giant the bands.
|
|
256
|
+
*
|
|
257
|
+
* @param pixels - The picture's pixels, 4 bytes each (red, green, blue, alpha), a row at a time, as `ImageData` has them.
|
|
258
|
+
* @param width - The picture's width.
|
|
259
|
+
* @param height - The picture's height.
|
|
260
|
+
* @param ramp - The tones, darkest first; five by default (`toneRamp(MAP_SEA, MAP_LAND)`).
|
|
261
|
+
* @param line - The line's colour and how opaque it is.
|
|
262
|
+
* @returns The new picture in the same layout, every pixel opaque.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* import { toneMap } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
267
|
+
*
|
|
268
|
+
* const grey = new Uint8ClampedArray(8 * 2 * 4);
|
|
269
|
+
* for (let i = 0; i < 16; i += 1) grey.set([i * 16, i * 16, i * 16, 255], i * 4);
|
|
270
|
+
* const out = toneMap(grey, 8, 2);
|
|
271
|
+
* console.log(out.length, out[3]);
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export function toneMap(pixels, width, height, ramp = toneRamp(MAP_SEA, MAP_LAND), line = MAP_LINE) {
|
|
275
|
+
const n = width * height;
|
|
276
|
+
const brightness = new Float32Array(n);
|
|
277
|
+
for (let i = 0; i < n; i += 1)
|
|
278
|
+
brightness[i] = 0.299 * pixels[i * 4] + 0.587 * pixels[i * 4 + 1] + 0.114 * pixels[i * 4 + 2];
|
|
279
|
+
const smooth = blur(brightness, width, height, Math.max(1, Math.round(width / 512)));
|
|
280
|
+
const edges = bandEdges(smooth, ramp.length);
|
|
281
|
+
const band = new Uint8Array(n);
|
|
282
|
+
for (let i = 0; i < n; i += 1) {
|
|
283
|
+
const value = Math.round(smooth[i]);
|
|
284
|
+
let b = 0;
|
|
285
|
+
while (b < edges.length && value >= edges[b])
|
|
286
|
+
b += 1;
|
|
287
|
+
band[i] = b;
|
|
288
|
+
}
|
|
289
|
+
const out = new Uint8ClampedArray(n * 4);
|
|
290
|
+
const [lr, lg, lb, la] = line;
|
|
291
|
+
for (let y = 0; y < height; y += 1) {
|
|
292
|
+
for (let x = 0; x < width; x += 1) {
|
|
293
|
+
const i = y * width + x;
|
|
294
|
+
const tone = ramp[band[i]];
|
|
295
|
+
// a line where the next pixel to the right (round the seam) or below is another tone
|
|
296
|
+
const edge = band[y * width + ((x + 1) % width)] !== band[i] || (y + 1 < height && band[i + width] !== band[i]);
|
|
297
|
+
const o = i * 4;
|
|
298
|
+
out[o] = edge ? Math.round(tone[0] + (lr - tone[0]) * la) : tone[0];
|
|
299
|
+
out[o + 1] = edge ? Math.round(tone[1] + (lg - tone[1]) * la) : tone[1];
|
|
300
|
+
out[o + 2] = edge ? Math.round(tone[2] + (lb - tone[2]) * la) : tone[2];
|
|
301
|
+
out[o + 3] = 255;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { FlatLang } from "./words.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The shapes a mark can have.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { MARK_SHAPES } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
8
|
+
*
|
|
9
|
+
* console.log(MARK_SHAPES.join(", "));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const MARK_SHAPES: readonly ["dot", "ring", "diamond", "square", "cross", "star"];
|
|
13
|
+
/**
|
|
14
|
+
* A mark's shape.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { MarkShape } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
19
|
+
*
|
|
20
|
+
* const shape: MarkShape = "star";
|
|
21
|
+
* console.log(shape);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type MarkShape = (typeof MARK_SHAPES)[number];
|
|
25
|
+
/**
|
|
26
|
+
* A name in one language or in both.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import type { MarkText } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
31
|
+
*
|
|
32
|
+
* const name: MarkText = { en: "Io", ja: "イオ" };
|
|
33
|
+
* console.log(name.en);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type MarkText = string | {
|
|
37
|
+
readonly en: string;
|
|
38
|
+
readonly ja?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* One mark on the flat map: a place on the ground. The page names it; the map draws it, names it when it is pointed at, pressed or reached by the keyboard, and sends `wakusei-flat-pick` (`kind: "mark"`) when it is chosen.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import type { FlatMark } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
46
|
+
*
|
|
47
|
+
* const olympus: FlatMark = { id: "olympus", lat: 18.65, lon: -133.8, name: { en: "Olympus Mons", ja: "オリンポス山" }, shape: "diamond", colour: "#ffd23f" };
|
|
48
|
+
* console.log(olympus.name);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface FlatMark {
|
|
52
|
+
/** Names the mark, and no other mark of the element has the same (a later one with the same id replaces the earlier). */
|
|
53
|
+
id: string;
|
|
54
|
+
/** Degrees north (negative south), -90 to 90. */
|
|
55
|
+
lat: number;
|
|
56
|
+
/** Degrees east (negative west). The map wraps, so 190 and -170 are the same place. */
|
|
57
|
+
lon: number;
|
|
58
|
+
/** What it is called: one text for every language, or `{ en, ja }` (a missing `ja` is said in English). */
|
|
59
|
+
name: MarkText;
|
|
60
|
+
/** The group it belongs to, which the key names (`setMarks`'s group is used when this is left out). */
|
|
61
|
+
group?: string;
|
|
62
|
+
/** The shape: `dot` by default. */
|
|
63
|
+
shape?: MarkShape;
|
|
64
|
+
/** A CSS colour: white by default. */
|
|
65
|
+
colour?: string;
|
|
66
|
+
/** The size, as the radius in pixels: 4 by default, between 2 and 12. */
|
|
67
|
+
size?: number;
|
|
68
|
+
/** True to write the name beside the mark, where there is room. The name is always read to a screen reader and shown when the mark is pointed at. */
|
|
69
|
+
labelled?: boolean;
|
|
70
|
+
/** Anything the page wants back in the pick event. */
|
|
71
|
+
data?: unknown;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A mark the map holds: the page's record with its group, shape and size filled in, and the position wrapped.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { readMarks, type HeldMark } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
79
|
+
*
|
|
80
|
+
* const held: HeldMark = readMarks("moons", [{ id: "io", lat: 0, lon: 190, name: "Io" }])[0]!;
|
|
81
|
+
* console.log(held.lon, held.shape, held.group);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export interface HeldMark extends FlatMark {
|
|
85
|
+
group: string;
|
|
86
|
+
shape: MarkShape;
|
|
87
|
+
size: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check a list of marks and fill in what is left out: a mark with no finite place or no id or name is dropped, a longitude is wrapped to -180 up to 180, a latitude is held to the poles, a shape the map does not know is a dot, the size is held between 2 and 12 and a later mark with the same id replaces the earlier.
|
|
91
|
+
*
|
|
92
|
+
* @param group - The group a mark with none of its own belongs to.
|
|
93
|
+
* @param marks - The page's marks.
|
|
94
|
+
* @returns The marks the map holds, in the order given.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { readMarks } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
99
|
+
*
|
|
100
|
+
* const held = readMarks("favourites", [
|
|
101
|
+
* { id: "a", lat: 95, lon: 200, name: "A" },
|
|
102
|
+
* { id: "b", lat: Number.NaN, lon: 0, name: "B" },
|
|
103
|
+
* ]);
|
|
104
|
+
* console.log(held.length, held[0]!.lat, held[0]!.lon);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function readMarks(group: string, marks: readonly FlatMark[]): HeldMark[];
|
|
108
|
+
/**
|
|
109
|
+
* A mark's name in a language: the text itself, or the language's own and else the English.
|
|
110
|
+
*
|
|
111
|
+
* @param name - A mark's `name`.
|
|
112
|
+
* @param lang - `en` or `ja`.
|
|
113
|
+
* @returns The name.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { markName } from "@johnmorrisdotca/wakusei-planets/flat";
|
|
118
|
+
*
|
|
119
|
+
* console.log(markName({ en: "Io", ja: "イオ" }, "ja"), markName("Io", "ja"), markName({ en: "Io" }, "ja"));
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare const markName: (name: MarkText | undefined, lang: FlatLang) => string;
|