@johnmorrisdotca/wakusei-planets 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.
- package/CHANGELOG.md +6 -0
- package/README.md +36 -8
- package/dist/blackbody.d.ts +2 -0
- package/dist/blackbody.js +10 -0
- package/dist/element.d.ts +8 -0
- package/dist/element.js +102 -16
- package/dist/embed.d.ts +3 -0
- package/dist/embed.js +30 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kids/data.d.ts +109 -0
- package/dist/kids/data.js +164 -0
- package/dist/kids/index.d.ts +4 -0
- package/dist/kids/index.js +5 -0
- package/dist/kids/land.d.ts +3 -0
- package/dist/kids/land.js +29 -0
- package/dist/kids/picture.d.ts +39 -0
- package/dist/kids/picture.js +255 -0
- package/dist/kids/sheet.d.ts +60 -0
- package/dist/kids/sheet.js +79 -0
- package/dist/kids/svg.d.ts +46 -0
- package/dist/kids/svg.js +193 -0
- package/dist/line.d.ts +9 -1
- package/dist/line.js +3 -4
- package/dist/scene/body.d.ts +8 -1
- package/dist/scene/body.js +33 -9
- package/dist/scene/glsl.d.ts +7 -2
- package/dist/scene/glsl.js +49 -3
- package/dist/scene/look.d.ts +43 -0
- package/dist/scene/look.js +39 -1
- package/dist/scene/store.d.ts +3 -0
- package/dist/scene/store.js +3 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/star-line.d.ts +20 -0
- package/dist/star-line.js +59 -0
- package/dist/star.d.ts +193 -0
- package/dist/star.js +261 -0
- package/dist/stars.js +3 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type BodyId, type HostId } from "../facts.ts";
|
|
2
|
+
export type Lang = "en" | "ja";
|
|
3
|
+
/**
|
|
4
|
+
* The bodies that have a colouring sheet of their own: the Sun, the planets and Pluto, and the big moons.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { KIDS_BODIES } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
9
|
+
*
|
|
10
|
+
* console.log(KIDS_BODIES.length, KIDS_BODIES[0]);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const KIDS_BODIES: readonly ["sun", "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "moon", "io", "europa", "ganymede", "callisto", "titan", "triton", "charon"];
|
|
14
|
+
/**
|
|
15
|
+
* The name of a body that has a colouring sheet: `sun`, a planet, `pluto`, `moon`, `io`, `europa`, `ganymede`, `callisto`, `titan`, `triton` or `charon`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { KIDS_BODIES, type KidsBody } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
20
|
+
*
|
|
21
|
+
* const body: KidsBody = KIDS_BODIES[5];
|
|
22
|
+
* console.log(body);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type KidsBody = (typeof KIDS_BODIES)[number];
|
|
26
|
+
/**
|
|
27
|
+
* Every sheet: a colouring page for each of `KIDS_BODIES`, then `lineup`, all the planets in a row at their true relative size.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { KIDS_SHEETS } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
32
|
+
*
|
|
33
|
+
* console.log(KIDS_SHEETS.at(-1));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const KIDS_SHEETS: readonly ["sun", "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "moon", "io", "europa", "ganymede", "callisto", "titan", "triton", "charon", "lineup"];
|
|
37
|
+
/**
|
|
38
|
+
* The name of a sheet: a `KidsBody` or `lineup`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { type KidsSheet } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
43
|
+
*
|
|
44
|
+
* const sheet: KidsSheet = "lineup";
|
|
45
|
+
* console.log(sheet);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type KidsSheet = (typeof KIDS_SHEETS)[number];
|
|
49
|
+
/** A body's name for a child: in Japanese the reading in hiragana, then the kanji in brackets. */
|
|
50
|
+
export declare function kidsName(id: BodyId, lang: Lang): string;
|
|
51
|
+
/** The name alone, as a child says it. */
|
|
52
|
+
export declare const kidsSay: (id: BodyId, lang: Lang) => string;
|
|
53
|
+
/** A colour to colour with: the real colour as `#rrggbb` and its name. */
|
|
54
|
+
export interface Swatch {
|
|
55
|
+
hex: string;
|
|
56
|
+
en: string;
|
|
57
|
+
ja: string;
|
|
58
|
+
}
|
|
59
|
+
/** The real colours of each body, a few words each. The first is the colour the package draws the body in. */
|
|
60
|
+
export declare const SWATCHES: Readonly<Record<KidsBody, readonly Swatch[]>>;
|
|
61
|
+
/** A body's width across the middle, in kilometres, to three figures. */
|
|
62
|
+
export declare const widthKm: (id: BodyId) => number;
|
|
63
|
+
/** How many Earths wide a body is. */
|
|
64
|
+
export declare const earthsWide: (id: BodyId) => number;
|
|
65
|
+
/** How long a planet takes to go once round the Sun, in days, from the size of its orbit (Kepler's third law). */
|
|
66
|
+
export declare const yearDays: (id: HostId) => number;
|
|
67
|
+
/** How long a moon takes to go once round its planet, in days, from its mean motion. */
|
|
68
|
+
export declare const moonPeriodDays: (id: BodyId) => number;
|
|
69
|
+
/**
|
|
70
|
+
* The three facts on a body's sheet, in plain words, worked out from the package's numbers: its width and how it compares with Earth, how long it takes to spin and to go round, and for a moon the face it shows.
|
|
71
|
+
* @param id - A body with a sheet.
|
|
72
|
+
* @param lang - `en` or `ja`.
|
|
73
|
+
* @returns Three short sentences.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { kidsFacts } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
78
|
+
*
|
|
79
|
+
* console.log(kidsFacts("jupiter", "en"));
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function kidsFacts(id: KidsBody, lang?: Lang): string[];
|
|
83
|
+
/** The planets of the lineup sheet, nearest the Sun first. */
|
|
84
|
+
export declare const LINEUP_IDS: readonly ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune"];
|
|
85
|
+
/** The words on the sheets that are not a body's own. */
|
|
86
|
+
export declare const SAY: {
|
|
87
|
+
readonly en: {
|
|
88
|
+
readonly colour: "Colour me!";
|
|
89
|
+
readonly brand: "Space Program X";
|
|
90
|
+
readonly pack: "Wakusei Planets";
|
|
91
|
+
readonly credits: "Sizes and spins: IAU and NASA. Drawn from numbers, not copied.";
|
|
92
|
+
readonly lineup: "All the planets";
|
|
93
|
+
readonly lineupLine: "The planets in a row, drawn to the same scale.";
|
|
94
|
+
readonly rings: "Rings";
|
|
95
|
+
readonly info: "Colouring sheet";
|
|
96
|
+
};
|
|
97
|
+
readonly ja: {
|
|
98
|
+
readonly colour: "ぬってね!";
|
|
99
|
+
readonly brand: "Space Program X";
|
|
100
|
+
readonly pack: "Wakusei Planets 惑星";
|
|
101
|
+
readonly credits: "おおきさや まわりかた: IAU と NASA。すうじから かいた え です。";
|
|
102
|
+
readonly lineup: "わくせいの ならびかた";
|
|
103
|
+
readonly lineupLine: "おなじ ものさしで ならべた わくせい。";
|
|
104
|
+
readonly rings: "リング";
|
|
105
|
+
readonly info: "ぬりえ";
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/** The three facts of the lineup sheet: the biggest, the smallest and the Sun, at this sheet's scale (`mmPerKm`). */
|
|
109
|
+
export declare function lineupFacts(lang: Lang, mmPerKm: number): string[];
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// What the kids' colouring sheets say: the names (with the Japanese readings), the colours to colour with and the three facts, all worked out from the package's own numbers.
|
|
2
|
+
import { BODIES, PLANET_IDS } from "../facts.js";
|
|
3
|
+
import { meanSunAu } from "../ephemeris.js";
|
|
4
|
+
import { ORBITS } from "../data/orbits.js";
|
|
5
|
+
/**
|
|
6
|
+
* The bodies that have a colouring sheet of their own: the Sun, the planets and Pluto, and the big moons.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { KIDS_BODIES } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
11
|
+
*
|
|
12
|
+
* console.log(KIDS_BODIES.length, KIDS_BODIES[0]);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const KIDS_BODIES = ["sun", ...PLANET_IDS, "moon", "io", "europa", "ganymede", "callisto", "titan", "triton", "charon"];
|
|
16
|
+
/**
|
|
17
|
+
* Every sheet: a colouring page for each of `KIDS_BODIES`, then `lineup`, all the planets in a row at their true relative size.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { KIDS_SHEETS } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
22
|
+
*
|
|
23
|
+
* console.log(KIDS_SHEETS.at(-1));
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const KIDS_SHEETS = [...KIDS_BODIES, "lineup"];
|
|
27
|
+
const READING = {
|
|
28
|
+
sun: "たいよう", mercury: "すいせい", venus: "きんせい", earth: "ちきゅう", mars: "かせい", jupiter: "もくせい", saturn: "どせい", uranus: "てんのうせい", neptune: "かいおうせい", pluto: "めいおうせい", moon: "つき",
|
|
29
|
+
};
|
|
30
|
+
/** A body's name for a child: in Japanese the reading in hiragana, then the kanji in brackets. */
|
|
31
|
+
export function kidsName(id, lang) {
|
|
32
|
+
const name = BODIES[id].name;
|
|
33
|
+
if (lang === "en")
|
|
34
|
+
return name.en;
|
|
35
|
+
const reading = READING[id];
|
|
36
|
+
return reading === undefined ? name.ja : `${reading}(${name.ja})`;
|
|
37
|
+
}
|
|
38
|
+
/** The name alone, as a child says it. */
|
|
39
|
+
export const kidsSay = (id, lang) => (lang === "ja" ? (READING[id] ?? BODIES[id].name.ja) : BODIES[id].name.en);
|
|
40
|
+
const s = (hex, en, ja) => ({ hex, en, ja });
|
|
41
|
+
/** The real colours of each body, a few words each. The first is the colour the package draws the body in. */
|
|
42
|
+
export const SWATCHES = {
|
|
43
|
+
sun: [s("#ffcf4d", "Yellow", "きいろ"), s("#f28c28", "Orange", "オレンジ"), s("#5b3a29", "Dark brown", "こいちゃいろ")],
|
|
44
|
+
mercury: [s("#a39b92", "Grey", "はいいろ"), s("#6f6a65", "Dark grey", "こいはいいろ"), s("#cfc7bb", "Light grey", "うすいはい")],
|
|
45
|
+
venus: [s("#e8cf94", "Cream", "クリーム"), s("#e0b45a", "Gold", "きんいろ"), s("#c98a4b", "Orange", "オレンジ")],
|
|
46
|
+
earth: [s("#3b78c4", "Blue", "あお"), s("#4f9a52", "Green", "みどり"), s("#9b7b4f", "Brown", "ちゃいろ"), s("#ffffff", "White", "しろ")],
|
|
47
|
+
mars: [s("#c76a3f", "Rust", "さびいろ"), s("#7a4a35", "Brown", "ちゃいろ"), s("#d9a77a", "Sand", "すないろ"), s("#ffffff", "White", "しろ")],
|
|
48
|
+
jupiter: [s("#e8d9bd", "Cream", "クリーム"), s("#c78b55", "Orange", "オレンジ"), s("#b9503a", "Red", "あか"), s("#ffffff", "White", "しろ")],
|
|
49
|
+
saturn: [s("#e4d09c", "Gold", "きんいろ"), s("#efe3c2", "Cream", "クリーム"), s("#b39b73", "Brown", "ちゃいろ")],
|
|
50
|
+
uranus: [s("#a9e0e5", "Light blue", "みずいろ"), s("#6fc2cb", "Teal", "あおみどり"), s("#7d868c", "Grey", "はいいろ")],
|
|
51
|
+
neptune: [s("#4a6ee0", "Blue", "あお"), s("#2f46a8", "Dark blue", "こいあお"), s("#ffffff", "White", "しろ")],
|
|
52
|
+
pluto: [s("#c9a98a", "Tan", "うすちゃいろ"), s("#8c6a50", "Brown", "ちゃいろ"), s("#ecdcc8", "Cream", "クリーム")],
|
|
53
|
+
moon: [s("#b8b5ae", "Grey", "はいいろ"), s("#7c7a76", "Dark grey", "こいはいいろ"), s("#eeeeea", "White", "しろ")],
|
|
54
|
+
io: [s("#e5d26a", "Yellow", "きいろ"), s("#d98b3a", "Orange", "オレンジ"), s("#3a3530", "Black", "くろ")],
|
|
55
|
+
europa: [s("#dcd2c0", "Cream", "クリーム"), s("#a0664a", "Brown", "ちゃいろ"), s("#ffffff", "White", "しろ")],
|
|
56
|
+
ganymede: [s("#a09484", "Tan", "うすちゃいろ"), s("#6f6458", "Dark brown", "こいちゃいろ"), s("#d7cdbd", "Light", "うすいいろ")],
|
|
57
|
+
callisto: [s("#70675d", "Dark brown", "こいちゃいろ"), s("#a89c8c", "Tan", "うすちゃいろ"), s("#ffffff", "White", "しろ")],
|
|
58
|
+
titan: [s("#dba84a", "Orange", "オレンジ"), s("#a8743a", "Brown", "ちゃいろ"), s("#f0d58a", "Yellow", "きいろ")],
|
|
59
|
+
triton: [s("#cdbbac", "Cream", "クリーム"), s("#d9a9a0", "Pink", "ピンク"), s("#8d9aa6", "Blue-grey", "あおぐろ")],
|
|
60
|
+
charon: [s("#9c9189", "Grey", "はいいろ"), s("#8b4a3a", "Red-brown", "あかちゃ"), s("#d8d2cc", "Light grey", "うすいはい")],
|
|
61
|
+
};
|
|
62
|
+
/** Round to three significant figures. */
|
|
63
|
+
const three = (n) => {
|
|
64
|
+
const digits = Math.floor(Math.log10(Math.abs(n))) + 1;
|
|
65
|
+
const step = 10 ** (digits - 3);
|
|
66
|
+
return Math.round(n / step) * step;
|
|
67
|
+
};
|
|
68
|
+
const group = (n) => Math.round(n).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
69
|
+
const one = (n) => (Math.round(n * 10) / 10).toString();
|
|
70
|
+
/** 1 decimal below 100 (the "0" is dropped), whole above. */
|
|
71
|
+
const short = (n) => (n < 100 ? one(n) : group(n));
|
|
72
|
+
const times = (n) => (n >= 10 ? Math.round(n).toString() : one(n));
|
|
73
|
+
const EARTH_KM = BODIES.earth.radiusKm;
|
|
74
|
+
/** A body's width across the middle, in kilometres, to three figures. */
|
|
75
|
+
export const widthKm = (id) => three(BODIES[id].radiusKm * 2);
|
|
76
|
+
/** How many Earths wide a body is. */
|
|
77
|
+
export const earthsWide = (id) => BODIES[id].radiusKm / EARTH_KM;
|
|
78
|
+
const sizeFact = (id, lang) => {
|
|
79
|
+
const w = group(widthKm(id));
|
|
80
|
+
const ratio = earthsWide(id);
|
|
81
|
+
if (id === "earth")
|
|
82
|
+
return lang === "ja" ? `よこはば ${w}km。わたしたちの おうち!` : `${w} km across. Our home!`;
|
|
83
|
+
if (ratio > 0.9 && ratio < 1.1)
|
|
84
|
+
return lang === "ja" ? `よこはば ${w}km。ちきゅうと ほとんど おなじ おおきさ。` : `${w} km across, almost as wide as Earth.`;
|
|
85
|
+
if (ratio >= 1.1)
|
|
86
|
+
return lang === "ja" ? `よこはば ${w}km。ちきゅうの ${times(ratio)}ばい。` : `${w} km across: ${times(ratio)} times as wide as Earth.`;
|
|
87
|
+
return lang === "ja" ? `よこはば ${w}km。ちきゅうの ほうが ${times(1 / ratio)}ばい おおきい。` : `${w} km across. Earth is ${times(1 / ratio)} times wider.`;
|
|
88
|
+
};
|
|
89
|
+
const daysOrHours = (hours, lang) => {
|
|
90
|
+
if (hours < 48)
|
|
91
|
+
return lang === "ja" ? `${one(hours)}じかん` : `${one(hours)} hours`;
|
|
92
|
+
return lang === "ja" ? `${short(hours / 24)}にち` : `${short(hours / 24)} days`;
|
|
93
|
+
};
|
|
94
|
+
const spinFact = (id, lang) => {
|
|
95
|
+
const hours = Math.abs(BODIES[id].rotationHours);
|
|
96
|
+
const time = daysOrHours(hours, lang);
|
|
97
|
+
const back = BODIES[id].rotationHours < 0;
|
|
98
|
+
if (lang === "ja")
|
|
99
|
+
return `${back ? "ぎゃくむきに " : ""}${time}で 1かい まわる。`;
|
|
100
|
+
return back ? `It spins backwards, once in ${time}.` : `It spins once in ${time}.`;
|
|
101
|
+
};
|
|
102
|
+
/** How long a planet takes to go once round the Sun, in days, from the size of its orbit (Kepler's third law). */
|
|
103
|
+
export const yearDays = (id) => meanSunAu(id) ** 1.5 * 365.25;
|
|
104
|
+
const yearFact = (id, lang) => {
|
|
105
|
+
const days = yearDays(id);
|
|
106
|
+
const years = days / 365.25;
|
|
107
|
+
const time = years < 1.2 ? (lang === "ja" ? `${Math.round(days)}にち` : `${Math.round(days)} days`) : lang === "ja" ? `${times(years)}ねん` : `${times(years)} years`;
|
|
108
|
+
return lang === "ja" ? `たいように 1しゅうするのに ${time}。` : `It goes around the Sun in ${time}.`;
|
|
109
|
+
};
|
|
110
|
+
/** How long a moon takes to go once round its planet, in days, from its mean motion. */
|
|
111
|
+
export const moonPeriodDays = (id) => 360 / Math.abs(ORBITS[id].sid);
|
|
112
|
+
const hostOf = (id) => BODIES[id].parent;
|
|
113
|
+
const hostName = (id, lang) => kidsSay(hostOf(id), lang);
|
|
114
|
+
const orbitFact = (id, lang) => {
|
|
115
|
+
const days = short(moonPeriodDays(id));
|
|
116
|
+
const back = BODIES[id].rotationHours < 0;
|
|
117
|
+
if (lang === "ja")
|
|
118
|
+
return `${hostName(id, lang)}を ${back ? "ぎゃくむきに " : ""}1しゅうするのに ${days}にち。`;
|
|
119
|
+
return `It goes around ${hostName(id, lang)} in ${days} days${back ? ", backwards!" : "."}`;
|
|
120
|
+
};
|
|
121
|
+
const faceFact = (id, lang) => (lang === "ja" ? `いつも おなじ めんを ${hostName(id, lang)}に むけている。` : `It always shows the same face to ${hostName(id, lang)}.`);
|
|
122
|
+
const sunFacts = (lang) => [
|
|
123
|
+
sizeFact("sun", lang),
|
|
124
|
+
lang === "ja" ? `${one(BODIES.sun.rotationHours / 24)}にちで 1かい まわる。` : `It spins once in ${one(BODIES.sun.rotationHours / 24)} days.`,
|
|
125
|
+
lang === "ja" ? "ちきゅうから やく 1おく5000まんkm。" : "It is about 150 million km from Earth.",
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* The three facts on a body's sheet, in plain words, worked out from the package's numbers: its width and how it compares with Earth, how long it takes to spin and to go round, and for a moon the face it shows.
|
|
129
|
+
* @param id - A body with a sheet.
|
|
130
|
+
* @param lang - `en` or `ja`.
|
|
131
|
+
* @returns Three short sentences.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { kidsFacts } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
136
|
+
*
|
|
137
|
+
* console.log(kidsFacts("jupiter", "en"));
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export function kidsFacts(id, lang = "en") {
|
|
141
|
+
if (id === "sun")
|
|
142
|
+
return sunFacts(lang);
|
|
143
|
+
if (BODIES[id].kind === "moon")
|
|
144
|
+
return [sizeFact(id, lang), orbitFact(id, lang), faceFact(id, lang)];
|
|
145
|
+
return [sizeFact(id, lang), spinFact(id, lang), yearFact(id, lang)];
|
|
146
|
+
}
|
|
147
|
+
/** The planets of the lineup sheet, nearest the Sun first. */
|
|
148
|
+
export const LINEUP_IDS = ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune"];
|
|
149
|
+
/** The words on the sheets that are not a body's own. */
|
|
150
|
+
export const SAY = {
|
|
151
|
+
en: { colour: "Colour me!", brand: "Space Program X", pack: "Wakusei Planets", credits: "Sizes and spins: IAU and NASA. Drawn from numbers, not copied.", lineup: "All the planets", lineupLine: "The planets in a row, drawn to the same scale.", rings: "Rings", info: "Colouring sheet" },
|
|
152
|
+
ja: { colour: "ぬってね!", brand: "Space Program X", pack: "Wakusei Planets 惑星", credits: "おおきさや まわりかた: IAU と NASA。すうじから かいた え です。", lineup: "わくせいの ならびかた", lineupLine: "おなじ ものさしで ならべた わくせい。", rings: "リング", info: "ぬりえ" },
|
|
153
|
+
};
|
|
154
|
+
/** The three facts of the lineup sheet: the biggest, the smallest and the Sun, at this sheet's scale (`mmPerKm`). */
|
|
155
|
+
export function lineupFacts(lang, mmPerKm) {
|
|
156
|
+
const radii = LINEUP_IDS.map((id) => [id, BODIES[id].radiusKm]);
|
|
157
|
+
const biggest = radii.reduce((a, b) => (b[1] > a[1] ? b : a))[0];
|
|
158
|
+
const smallest = radii.reduce((a, b) => (b[1] < a[1] ? b : a))[0];
|
|
159
|
+
const sun = Math.round((BODIES.sun.radiusKm * 2 * mmPerKm) / 10);
|
|
160
|
+
const x = times(earthsWide(biggest));
|
|
161
|
+
return lang === "ja"
|
|
162
|
+
? [`いちばん おおきい: ${kidsSay(biggest, lang)}。ちきゅうの ${x}ばい。`, `いちばん ちいさい: ${kidsSay(smallest, lang)}。`, `ここでは たいようは ${sun}cm にも なる!`]
|
|
163
|
+
: [`Biggest: ${kidsSay(biggest, lang)}, ${x} times as wide as Earth.`, `Smallest: ${kidsSay(smallest, lang)}.`, `The Sun would be ${sun} cm wide here!`];
|
|
164
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The kids' colouring sheets: thick-line pictures of the Sun, the planets and the big moons, to print and colour, with the real colours to use and three facts, in English and Japanese.
|
|
2
|
+
export { KIDS_BODIES, KIDS_SHEETS, kidsFacts } from "./data.js";
|
|
3
|
+
export { colouringArt } from "./picture.js";
|
|
4
|
+
export { kidsRoom, kidsSvg } from "./svg.js";
|
|
5
|
+
export { kidsLayout, kidsSheet } from "./sheet.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BodyId, Feature } from "../facts.ts";
|
|
2
|
+
/** The shapes a sheet draws instead of a body's own features: the Earth's lands, Pluto's heart (a bright plain) with a few craters, Mars's dark regions and its polar cap, and Saturn's bands without the hexagon, none of them crossing another. */
|
|
3
|
+
export declare const OWN_FEATURES: Partial<Record<BodyId, readonly Feature[]>>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The Earth's big lands as a few corner points each (longitude, latitude in degrees), rough on purpose: a child colours a continent, not a coastline.
|
|
2
|
+
const LAND = [
|
|
3
|
+
[[-165, 64], [-150, 70], [-125, 70], [-95, 70], [-82, 68], [-62, 58], [-55, 50], [-67, 45], [-76, 38], [-81, 30], [-80, 25], [-84, 30], [-90, 29], [-97, 26], [-97, 20], [-92, 18], [-87, 21], [-83, 15], [-78, 8], [-83, 8], [-92, 14], [-105, 20], [-110, 24], [-115, 30], [-118, 34], [-124, 40], [-124, 48], [-132, 54], [-140, 60], [-152, 59], [-165, 55]],
|
|
4
|
+
[[-72, 78], [-55, 83], [-25, 82], [-20, 72], [-40, 62], [-52, 66], [-58, 75]],
|
|
5
|
+
[[-78, 8], [-72, 12], [-62, 10], [-52, 5], [-50, 0], [-35, -6], [-39, -14], [-41, -22], [-48, -26], [-58, -35], [-63, -41], [-66, -47], [-69, -52], [-72, -52], [-74, -45], [-72, -30], [-70, -18], [-76, -14], [-81, -5], [-80, 0], [-77, 3]],
|
|
6
|
+
[[-17, 21], [-10, 30], [-6, 36], [10, 37], [22, 33], [32, 31], [34, 28], [43, 12], [51, 12], [44, -2], [40, -15], [35, -24], [32, -29], [20, -35], [18, -32], [12, -18], [13, -8], [9, 4], [-8, 4], [-15, 11], [-17, 15]],
|
|
7
|
+
[[-9, 37], [-9, 43], [-2, 44], [-4, 48], [5, 52], [8, 55], [10, 58], [5, 62], [15, 69], [28, 71], [45, 68], [60, 70], [80, 73], [105, 77], [130, 72], [160, 70], [180, 68], [170, 60], [160, 55], [160, 52], [142, 53], [140, 45], [135, 43], [128, 40], [129, 35], [121, 38], [122, 31], [120, 23], [108, 21], [106, 10], [100, 13], [104, 1], [98, 8], [98, 16], [92, 22], [80, 15], [77, 8], [73, 20], [67, 25], [57, 25], [56, 27], [50, 30], [43, 13], [35, 28], [34, 31], [27, 37], [26, 40], [20, 40], [14, 45], [18, 40], [15, 38], [8, 44], [3, 43], [-1, 37]],
|
|
8
|
+
[[114, -22], [122, -18], [130, -12], [137, -12], [142, -11], [146, -19], [153, -26], [150, -37], [141, -38], [130, -32], [115, -34]],
|
|
9
|
+
[[130.8, 33.8], [135, 34.5], [139.8, 35], [141, 38], [141.5, 41.5], [139.5, 40], [136, 36.5], [132.5, 35.5]],
|
|
10
|
+
];
|
|
11
|
+
/** The shapes a sheet draws instead of a body's own features: the Earth's lands, Pluto's heart (a bright plain) with a few craters, Mars's dark regions and its polar cap, and Saturn's bands without the hexagon, none of them crossing another. */
|
|
12
|
+
export const OWN_FEATURES = {
|
|
13
|
+
earth: LAND.map((points) => ({ kind: "line", points, close: true })),
|
|
14
|
+
pluto: [
|
|
15
|
+
{ kind: "line", points: [[190, -10], [178, 0], [170, 12], [172, 24], [182, 30], [190, 24], [198, 30], [208, 24], [210, 12], [202, 0]], close: true },
|
|
16
|
+
{ kind: "circle", lon: 145, lat: 25, radius: 8 },
|
|
17
|
+
{ kind: "circle", lon: 235, lat: -20, radius: 8 },
|
|
18
|
+
{ kind: "circle", lon: 160, lat: -40, radius: 8 },
|
|
19
|
+
],
|
|
20
|
+
mars: [
|
|
21
|
+
{ kind: "band", lat: 72 },
|
|
22
|
+
{ kind: "oval", lon: 70, lat: 8, rx: 14, ry: 10 },
|
|
23
|
+
{ kind: "oval", lon: 20, lat: -28, rx: 20, ry: 8 },
|
|
24
|
+
{ kind: "circle", lon: 75, lat: -45, radius: 9 },
|
|
25
|
+
{ kind: "oval", lon: 30, lat: 40, rx: 16, ry: 9 },
|
|
26
|
+
{ kind: "oval", lon: 115, lat: -8, rx: 12, ry: 9 },
|
|
27
|
+
],
|
|
28
|
+
saturn: [72, 58, 44, 28, 12, -6, -22, -40, -56].map((lat) => ({ kind: "band", lat })),
|
|
29
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type BodyId } from "../facts.ts";
|
|
2
|
+
import type { Pose } from "../ephemeris.ts";
|
|
3
|
+
/** The thickness of the outline of a body and of every line inside it, in millimetres. */
|
|
4
|
+
export declare const OUTLINE_MM = 3;
|
|
5
|
+
export declare const LINE_MM = 2.5;
|
|
6
|
+
export interface Art {
|
|
7
|
+
/** The SVG markup, to put inside an `<svg>` measured in millimetres. */
|
|
8
|
+
markup: string;
|
|
9
|
+
/** How far the picture reaches from its centre: half its width and half its height. */
|
|
10
|
+
halfWidth: number;
|
|
11
|
+
halfHeight: number;
|
|
12
|
+
}
|
|
13
|
+
/** The pose a sheet draws: the body's own tilt, looked at a little from above, full face. */
|
|
14
|
+
export declare function sheetPose(id: BodyId): Pose;
|
|
15
|
+
/** How far a body reaches from its centre, in units of its radius: its outline, its rings and, for the Sun, its rays. */
|
|
16
|
+
export declare function reach(id: BodyId, pose?: Pose): {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A body as a colouring picture: thick black outlines on white (the outline 3 mm, every line inside 2.5 mm), its big features, its rings, and the Sun's rays. The picture is drawn at its centre `(cx, cy)` with `r`
|
|
22
|
+
* millimetres for the body's radius. `outline` is the outline's thickness; the lines inside are 2.5 mm or, for a thinner outline, a little less.
|
|
23
|
+
* @param id - The body's name.
|
|
24
|
+
* @param cx - The centre's place, in millimetres.
|
|
25
|
+
* @param cy - The centre's place, in millimetres.
|
|
26
|
+
* @param r - The body's radius, in millimetres.
|
|
27
|
+
* @param outline - The outline's thickness in millimetres. Default 3.
|
|
28
|
+
* @returns The SVG markup of the body, to put inside an `<svg>` measured in millimetres.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { colouringArt } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
33
|
+
*
|
|
34
|
+
* console.log(colouringArt("mars", 50, 50, 40).startsWith("<g"));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function colouringArt(id: BodyId, cx: number, cy: number, r: number, outline?: number): string;
|
|
38
|
+
/** A body's picture made as large as fits a box `width` by `height` millimetres, in the middle of it. */
|
|
39
|
+
export declare function colouringPicture(id: BodyId, width: number, height: number, top?: number): Art;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// The pictures of the colouring sheets: a body as thick black outlines on white, drawn in millimetres from the package's own numbers (facts, tilt, rings). Big shapes only: a feature too small
|
|
2
|
+
// to colour is made bigger or left out, and two never overlap. Pure: an SVG string, no DOM.
|
|
3
|
+
import { BODIES } from "../facts.js";
|
|
4
|
+
import { cross, RAD, DEG } from "../vec.js";
|
|
5
|
+
import { facing, portrait, silhouette, surfacePoint } from "../pose.js";
|
|
6
|
+
import { OWN_FEATURES } from "./land.js";
|
|
7
|
+
/** The thickness of the outline of a body and of every line inside it, in millimetres. */
|
|
8
|
+
export const OUTLINE_MM = 3;
|
|
9
|
+
export const LINE_MM = 2.5;
|
|
10
|
+
/** The smallest radius of a shape to colour, in millimetres, and the least between two lines. */
|
|
11
|
+
const MIN_SHAPE_MM = 8;
|
|
12
|
+
const MIN_GAP_MM = 12;
|
|
13
|
+
const INK = "#000";
|
|
14
|
+
const n = (v) => (Math.round(v * 100) / 100).toString();
|
|
15
|
+
const polyline = (pts, close = false) => `M${pts.map((p) => `${n(p[0])} ${n(p[1])}`).join("L")}${close ? "Z" : ""}`;
|
|
16
|
+
const stroke = (d, width) => `<path d="${d}" fill="none" stroke="${INK}" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
17
|
+
/** The edges of the rings a child colours, in kilometres from the planet's centre: the main rings of Saturn and the outer and inner rings of Uranus. */
|
|
18
|
+
const RING_EDGES = { saturn: [74658, 136775], uranus: [41800, 51100] };
|
|
19
|
+
/** How far a body is turned to face the viewer, degrees east, where the body's own default is not the best side for a sheet. */
|
|
20
|
+
const PITCH = { saturn: 20, uranus: 35 };
|
|
21
|
+
const TILT = { saturn: 0 };
|
|
22
|
+
const SPIN = { earth: 100 };
|
|
23
|
+
const screen = (frame, p) => [frame.cx + p[0] * frame.r, frame.cy - p[1] * frame.r];
|
|
24
|
+
/** The pose a sheet draws: the body's own tilt, looked at a little from above, full face. */
|
|
25
|
+
export function sheetPose(id) {
|
|
26
|
+
return portrait(id, { pitch: PITCH[id] ?? 18, tilt: TILT[id], phase: 0, spin: SPIN[id] });
|
|
27
|
+
}
|
|
28
|
+
const axesOf = (id) => {
|
|
29
|
+
const km = BODIES[id].axesKm;
|
|
30
|
+
return km === undefined ? undefined : [km[0] / BODIES[id].radiusKm, km[1] / BODIES[id].radiusKm, km[2] / BODIES[id].radiusKm];
|
|
31
|
+
};
|
|
32
|
+
/** The ring's edge as points of the plane of the rings, unit radius ρ, at angle t. */
|
|
33
|
+
const ringPoint = (pose, rho, t) => {
|
|
34
|
+
const e1 = pose.meridian;
|
|
35
|
+
const e2 = cross(pose.pole, pose.meridian);
|
|
36
|
+
return [rho * (Math.cos(t) * e1[0] + Math.sin(t) * e2[0]), rho * (Math.cos(t) * e1[1] + Math.sin(t) * e2[1]), rho * (Math.cos(t) * e1[2] + Math.sin(t) * e2[2])];
|
|
37
|
+
};
|
|
38
|
+
/** How far a body reaches from its centre, in units of its radius: its outline, its rings and, for the Sun, its rays. */
|
|
39
|
+
export function reach(id, pose = sheetPose(id)) {
|
|
40
|
+
const facts = BODIES[id];
|
|
41
|
+
const sil = silhouette(pose, facts.flattening, axesOf(id));
|
|
42
|
+
const a = sil.angle * RAD;
|
|
43
|
+
let x = Math.hypot(sil.a * Math.cos(a), sil.b * Math.sin(a));
|
|
44
|
+
let y = Math.hypot(sil.a * Math.sin(a), sil.b * Math.cos(a));
|
|
45
|
+
const edges = RING_EDGES[id];
|
|
46
|
+
if (edges !== undefined) {
|
|
47
|
+
for (let k = 0; k < 72; k += 1) {
|
|
48
|
+
const p = ringPoint(pose, edges[1] / facts.radiusKm, (k / 72) * 2 * Math.PI);
|
|
49
|
+
x = Math.max(x, Math.abs(p[0]));
|
|
50
|
+
y = Math.max(y, Math.abs(p[1]));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (id === "sun") {
|
|
54
|
+
x = Math.max(x, 1.3);
|
|
55
|
+
y = Math.max(y, 1.3);
|
|
56
|
+
}
|
|
57
|
+
return { x, y };
|
|
58
|
+
}
|
|
59
|
+
/** The longer side of the box round some points. */
|
|
60
|
+
const size = (pts) => {
|
|
61
|
+
const xs = pts.map((p) => p[0]);
|
|
62
|
+
const ys = pts.map((p) => p[1]);
|
|
63
|
+
return Math.max(Math.max(...xs) - Math.min(...xs), Math.max(...ys) - Math.min(...ys));
|
|
64
|
+
};
|
|
65
|
+
/** A circle or oval of angular radii (degrees) round a longitude and latitude, as points on the body. */
|
|
66
|
+
function around(lon, lat, rx, ry) {
|
|
67
|
+
const out = [];
|
|
68
|
+
for (let k = 0; k < 32; k += 1) {
|
|
69
|
+
const t = (k / 32) * 2 * Math.PI;
|
|
70
|
+
const dlat = ry * Math.sin(t);
|
|
71
|
+
out.push([lon + (rx * Math.cos(t)) / Math.max(0.2, Math.cos((lat + dlat) * RAD)), Math.max(-89.9, Math.min(89.9, lat + dlat))]);
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
const between = (a, b) => {
|
|
76
|
+
const cosine = Math.sin(a[1] * RAD) * Math.sin(b[1] * RAD) + Math.cos(a[1] * RAD) * Math.cos(b[1] * RAD) * Math.cos((a[0] - b[0]) * RAD);
|
|
77
|
+
return Math.acos(Math.max(-1, Math.min(1, cosine))) * DEG;
|
|
78
|
+
};
|
|
79
|
+
/** Break a line of samples into the runs that face the viewer. */
|
|
80
|
+
function runs(samples, visible) {
|
|
81
|
+
const out = [];
|
|
82
|
+
let current = [];
|
|
83
|
+
for (const sample of samples) {
|
|
84
|
+
if (visible(sample))
|
|
85
|
+
current.push(sample);
|
|
86
|
+
else if (current.length > 0) {
|
|
87
|
+
out.push(current);
|
|
88
|
+
current = [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (current.length > 0)
|
|
92
|
+
out.push(current);
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/** The lines inside the body: bands, big round shapes, and lines (cracks, lands) that are long enough to colour between. */
|
|
96
|
+
function inside(id, pose, frame, line) {
|
|
97
|
+
const facts = BODIES[id];
|
|
98
|
+
const f = facts.flattening;
|
|
99
|
+
const axes = axesOf(id);
|
|
100
|
+
const spin = SPIN[id] ?? facts.showLon ?? 0;
|
|
101
|
+
const out = [];
|
|
102
|
+
if (frame.r < 18)
|
|
103
|
+
return out;
|
|
104
|
+
const face = (lon, lat) => facing(pose, lon, lat, f, axes);
|
|
105
|
+
const at = (lon, lat) => screen(frame, surfacePoint(pose, lon, lat, f, axes));
|
|
106
|
+
const features = OWN_FEATURES[id] ?? facts.features ?? [];
|
|
107
|
+
// round shapes and ovals: made no smaller than MIN_SHAPE_MM across the radius, kept whole, never overlapping
|
|
108
|
+
const minDeg = (MIN_SHAPE_MM / frame.r) * DEG;
|
|
109
|
+
const shapes = features
|
|
110
|
+
.map((one) => (one.kind === "circle" ? { lon: one.lon, lat: one.lat, rx: one.radius, ry: one.radius } : one.kind === "oval" ? { lon: one.lon, lat: one.lat, rx: one.rx, ry: one.ry } : undefined))
|
|
111
|
+
.filter((one) => one !== undefined)
|
|
112
|
+
.sort((a, b) => b.rx * b.ry - a.rx * a.ry);
|
|
113
|
+
const placed = [];
|
|
114
|
+
const heights = [];
|
|
115
|
+
for (const shape of shapes) {
|
|
116
|
+
if (placed.length >= 6)
|
|
117
|
+
break;
|
|
118
|
+
const rx = Math.min(45, Math.max(shape.rx, minDeg));
|
|
119
|
+
const ry = Math.min(45, Math.max(shape.ry, minDeg));
|
|
120
|
+
const size = Math.max(rx, ry);
|
|
121
|
+
const ring = around(shape.lon, shape.lat, rx, ry);
|
|
122
|
+
if (!ring.every(([lon, lat]) => face(lon, lat) > 0.35))
|
|
123
|
+
continue;
|
|
124
|
+
if (placed.some((p) => between([p.lon, p.lat], [shape.lon, shape.lat]) < (p.size + size) * 1.15))
|
|
125
|
+
continue;
|
|
126
|
+
placed.push({ lon: shape.lon, lat: shape.lat, size });
|
|
127
|
+
heights.push([shape.lat, ry]);
|
|
128
|
+
out.push(stroke(polyline(ring.map(([lon, lat]) => at(lon, lat)), true), line));
|
|
129
|
+
}
|
|
130
|
+
// bands of latitude: each at least MIN_GAP_MM from the last, and not so near the edge that the strip beyond is too thin to colour
|
|
131
|
+
const kept = [];
|
|
132
|
+
const bands = features.filter((one) => one.kind === "band").sort((a, b) => Math.abs(a.lat) - Math.abs(b.lat));
|
|
133
|
+
for (const band of bands) {
|
|
134
|
+
if (kept.length >= 7 || face(spin, band.lat) < 0.5)
|
|
135
|
+
continue;
|
|
136
|
+
if (heights.some(([lat, ry]) => Math.abs(lat - band.lat) < ry + 2))
|
|
137
|
+
continue;
|
|
138
|
+
const here = at(spin, band.lat);
|
|
139
|
+
if (kept.some((p) => Math.hypot(p[0] - here[0], p[1] - here[1]) < MIN_GAP_MM))
|
|
140
|
+
continue;
|
|
141
|
+
const samples = [];
|
|
142
|
+
for (let lon = 0; lon <= 360; lon += 3)
|
|
143
|
+
samples.push([lon, band.lat]);
|
|
144
|
+
const parts = runs(samples, ([lon, lat]) => face(lon, lat) > 0.01).map((part) => part.map(([lon, lat]) => at(lon, lat)));
|
|
145
|
+
if (!parts.some((part) => size(part) >= 2 * MIN_SHAPE_MM))
|
|
146
|
+
continue;
|
|
147
|
+
kept.push(here);
|
|
148
|
+
for (const part of parts)
|
|
149
|
+
out.push(stroke(polyline(part), line));
|
|
150
|
+
}
|
|
151
|
+
// lines: whole (closed) or in the runs that face us, long enough to see
|
|
152
|
+
for (const one of features) {
|
|
153
|
+
if (one.kind !== "line")
|
|
154
|
+
continue;
|
|
155
|
+
const count = one.points.length;
|
|
156
|
+
const samples = [];
|
|
157
|
+
for (let k = 0; k < (one.close === true ? count : count - 1); k += 1) {
|
|
158
|
+
const a = one.points[k];
|
|
159
|
+
const b = one.points[(k + 1) % count];
|
|
160
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1]) / 2));
|
|
161
|
+
for (let s = 0; s < steps; s += 1)
|
|
162
|
+
samples.push([a[0] + ((b[0] - a[0]) * s) / steps, a[1] + ((b[1] - a[1]) * s) / steps]);
|
|
163
|
+
}
|
|
164
|
+
const last = one.points[one.close === true ? 0 : count - 1];
|
|
165
|
+
samples.push([last[0], last[1]]);
|
|
166
|
+
const parts = runs(samples, ([lon, lat]) => face(lon, lat) > 0.01);
|
|
167
|
+
const whole = one.close === true && parts.length === 1 && parts[0].length === samples.length;
|
|
168
|
+
for (const part of parts) {
|
|
169
|
+
if (part.length < 3)
|
|
170
|
+
continue;
|
|
171
|
+
const pts = part.map(([lon, lat]) => at(lon, lat));
|
|
172
|
+
if (size(pts) < 2 * MIN_SHAPE_MM)
|
|
173
|
+
continue;
|
|
174
|
+
out.push(stroke(polyline(pts, whole), line));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
/** The rings as thick edges: the back parts first (the planet will cover them), and the front parts as a white band with its edges, to go over the planet. */
|
|
180
|
+
function ringParts(id, pose, frame, line) {
|
|
181
|
+
const edges = RING_EDGES[id];
|
|
182
|
+
if (edges === undefined)
|
|
183
|
+
return { back: "", front: "" };
|
|
184
|
+
const radius = BODIES[id].radiusKm;
|
|
185
|
+
const e1 = pose.meridian[2];
|
|
186
|
+
const e2 = cross(pose.pole, pose.meridian)[2];
|
|
187
|
+
const phi = Math.atan2(e2, e1);
|
|
188
|
+
const arc = (rho, from, to) => Array.from({ length: 61 }, (_, k) => screen(frame, ringPoint(pose, rho, from + ((to - from) * k) / 60)));
|
|
189
|
+
const front0 = phi - Math.PI / 2;
|
|
190
|
+
const back0 = phi + Math.PI / 2;
|
|
191
|
+
const back = [];
|
|
192
|
+
const outer = edges[1] / radius;
|
|
193
|
+
const inner = edges[0] / radius;
|
|
194
|
+
for (const rho of [inner, outer])
|
|
195
|
+
back.push(stroke(polyline(arc(rho, back0, back0 + Math.PI)), line));
|
|
196
|
+
const band = [...arc(outer, front0, front0 + Math.PI), ...arc(inner, front0 + Math.PI, front0).slice()];
|
|
197
|
+
const front = [`<path d="${polyline(band, true)}" fill="#fff"/>`, ...[inner, outer].map((rho) => stroke(polyline(arc(rho, front0, front0 + Math.PI)), line))];
|
|
198
|
+
return { back: back.join(""), front: front.join("") };
|
|
199
|
+
}
|
|
200
|
+
/** The Sun's rays: short thick strokes all round, long and short in turn. */
|
|
201
|
+
function rays(frame, line) {
|
|
202
|
+
const parts = [];
|
|
203
|
+
for (let k = 0; k < 16; k += 1) {
|
|
204
|
+
const a = (k / 16) * 2 * Math.PI;
|
|
205
|
+
const r1 = 1.1;
|
|
206
|
+
const r2 = k % 2 === 0 ? 1.3 : 1.2;
|
|
207
|
+
parts.push(`M${n(frame.cx + Math.cos(a) * r1 * frame.r)} ${n(frame.cy + Math.sin(a) * r1 * frame.r)}L${n(frame.cx + Math.cos(a) * r2 * frame.r)} ${n(frame.cy + Math.sin(a) * r2 * frame.r)}`);
|
|
208
|
+
}
|
|
209
|
+
return stroke(parts.join(""), line);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A body as a colouring picture: thick black outlines on white (the outline 3 mm, every line inside 2.5 mm), its big features, its rings, and the Sun's rays. The picture is drawn at its centre `(cx, cy)` with `r`
|
|
213
|
+
* millimetres for the body's radius. `outline` is the outline's thickness; the lines inside are 2.5 mm or, for a thinner outline, a little less.
|
|
214
|
+
* @param id - The body's name.
|
|
215
|
+
* @param cx - The centre's place, in millimetres.
|
|
216
|
+
* @param cy - The centre's place, in millimetres.
|
|
217
|
+
* @param r - The body's radius, in millimetres.
|
|
218
|
+
* @param outline - The outline's thickness in millimetres. Default 3.
|
|
219
|
+
* @returns The SVG markup of the body, to put inside an `<svg>` measured in millimetres.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { colouringArt } from "@johnmorrisdotca/wakusei-planets/sheets";
|
|
224
|
+
*
|
|
225
|
+
* console.log(colouringArt("mars", 50, 50, 40).startsWith("<g"));
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function colouringArt(id, cx, cy, r, outline = OUTLINE_MM) {
|
|
229
|
+
const facts = BODIES[id];
|
|
230
|
+
const pose = sheetPose(id);
|
|
231
|
+
const frame = { cx, cy, r };
|
|
232
|
+
const sil = silhouette(pose, facts.flattening, axesOf(id));
|
|
233
|
+
const disc = `<ellipse cx="${n(cx)}" cy="${n(cy)}" rx="${n(r * sil.a)}" ry="${n(r * sil.b)}" transform="rotate(${n(sil.angle)} ${n(cx)} ${n(cy)})"`;
|
|
234
|
+
const line = Math.min(LINE_MM, outline * 0.84);
|
|
235
|
+
const rings = ringParts(id, pose, frame, line);
|
|
236
|
+
const clip = `kids-${id}-clip`;
|
|
237
|
+
return [
|
|
238
|
+
`<g data-body="${id}">`,
|
|
239
|
+
rings.back,
|
|
240
|
+
`${disc} fill="#fff" stroke="${INK}" stroke-width="${outline}"/>`,
|
|
241
|
+
`<clipPath id="${clip}">${disc}/></clipPath>`,
|
|
242
|
+
`<g clip-path="url(#${clip})">${inside(id, pose, frame, line).join("")}</g>`,
|
|
243
|
+
id === "sun" ? rays(frame, line) : "",
|
|
244
|
+
rings.front,
|
|
245
|
+
`</g>`,
|
|
246
|
+
].join("");
|
|
247
|
+
}
|
|
248
|
+
/** A body's picture made as large as fits a box `width` by `height` millimetres, in the middle of it. */
|
|
249
|
+
export function colouringPicture(id, width, height, top = 0) {
|
|
250
|
+
const pose = sheetPose(id);
|
|
251
|
+
const extent = reach(id, pose);
|
|
252
|
+
const pad = OUTLINE_MM;
|
|
253
|
+
const r = Math.min((width - 2 * pad) / (2 * extent.x), (height - 2 * pad) / (2 * extent.y));
|
|
254
|
+
return { markup: colouringArt(id, width / 2, top + height / 2, r), halfWidth: extent.x * r, halfHeight: extent.y * r };
|
|
255
|
+
}
|