@altnovatrail/picture-kit 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/NOTICE +7 -0
- package/README.md +27 -2
- package/lib/emoji.d.ts +16 -0
- package/lib/emoji.js +64 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +10 -0
- package/lib/kind.d.ts +22 -0
- package/lib/kind.js +2 -0
- package/lib/kinds/balance.d.ts +34 -0
- package/lib/kinds/balance.js +217 -0
- package/lib/kinds/branches.d.ts +33 -0
- package/lib/kinds/branches.js +473 -0
- package/lib/kinds/calendar.d.ts +55 -0
- package/lib/kinds/calendar.js +532 -0
- package/lib/kinds/chart.d.ts +48 -0
- package/lib/kinds/chart.js +645 -0
- package/lib/kinds/choices.d.ts +14 -0
- package/lib/kinds/choices.js +53 -0
- package/lib/kinds/clock.d.ts +36 -0
- package/lib/kinds/clock.js +219 -0
- package/lib/kinds/coins.d.ts +37 -0
- package/lib/kinds/coins.js +550 -0
- package/lib/kinds/column.d.ts +37 -0
- package/lib/kinds/column.js +410 -0
- package/lib/kinds/commands-parts.d.ts +12 -0
- package/lib/kinds/commands-parts.js +24 -0
- package/lib/kinds/commands.d.ts +66 -0
- package/lib/kinds/commands.js +789 -0
- package/lib/kinds/containers.d.ts +52 -0
- package/lib/kinds/containers.js +758 -0
- package/lib/kinds/countfig.d.ts +41 -0
- package/lib/kinds/countfig.js +372 -0
- package/lib/kinds/cubes.d.ts +70 -0
- package/lib/kinds/cubes.js +371 -0
- package/lib/kinds/die.d.ts +32 -0
- package/lib/kinds/die.js +301 -0
- package/lib/kinds/domino.d.ts +37 -0
- package/lib/kinds/domino.js +450 -0
- package/lib/kinds/dotgrid.d.ts +38 -0
- package/lib/kinds/dotgrid.js +411 -0
- package/lib/kinds/figure.d.ts +62 -0
- package/lib/kinds/figure.js +687 -0
- package/lib/kinds/fold-parts.d.ts +73 -0
- package/lib/kinds/fold-parts.js +315 -0
- package/lib/kinds/fold.d.ts +52 -0
- package/lib/kinds/fold.js +650 -0
- package/lib/kinds/fraction.d.ts +50 -0
- package/lib/kinds/fraction.js +568 -0
- package/lib/kinds/gauges.d.ts +53 -0
- package/lib/kinds/gauges.js +880 -0
- package/lib/kinds/gears.d.ts +40 -0
- package/lib/kinds/gears.js +787 -0
- package/lib/kinds/grid.d.ts +45 -0
- package/lib/kinds/grid.js +591 -0
- package/lib/kinds/groups.d.ts +23 -0
- package/lib/kinds/groups.js +335 -0
- package/lib/kinds/index.d.ts +3 -0
- package/lib/kinds/index.js +87 -0
- package/lib/kinds/lanes.d.ts +36 -0
- package/lib/kinds/lanes.js +220 -0
- package/lib/kinds/layers.d.ts +31 -0
- package/lib/kinds/layers.js +419 -0
- package/lib/kinds/line.d.ts +38 -0
- package/lib/kinds/line.js +739 -0
- package/lib/kinds/magic-parts.d.ts +72 -0
- package/lib/kinds/magic-parts.js +186 -0
- package/lib/kinds/magic.d.ts +66 -0
- package/lib/kinds/magic.js +664 -0
- package/lib/kinds/map.d.ts +32 -0
- package/lib/kinds/map.js +370 -0
- package/lib/kinds/matchsticks.d.ts +26 -0
- package/lib/kinds/matchsticks.js +434 -0
- package/lib/kinds/necklace.d.ts +27 -0
- package/lib/kinds/necklace.js +342 -0
- package/lib/kinds/net.d.ts +47 -0
- package/lib/kinds/net.js +241 -0
- package/lib/kinds/overlay.d.ts +50 -0
- package/lib/kinds/overlay.js +519 -0
- package/lib/kinds/pieces.d.ts +41 -0
- package/lib/kinds/pieces.js +420 -0
- package/lib/kinds/pipes.d.ts +46 -0
- package/lib/kinds/pipes.js +657 -0
- package/lib/kinds/plane-parts.d.ts +105 -0
- package/lib/kinds/plane-parts.js +372 -0
- package/lib/kinds/plane.d.ts +35 -0
- package/lib/kinds/plane.js +755 -0
- package/lib/kinds/pyramid.d.ts +26 -0
- package/lib/kinds/pyramid.js +228 -0
- package/lib/kinds/ropes.d.ts +30 -0
- package/lib/kinds/ropes.js +571 -0
- package/lib/kinds/shapes.d.ts +59 -0
- package/lib/kinds/shapes.js +490 -0
- package/lib/kinds/solids.d.ts +78 -0
- package/lib/kinds/solids.js +1058 -0
- package/lib/kinds/tangram.d.ts +52 -0
- package/lib/kinds/tangram.js +713 -0
- package/lib/kinds/target.d.ts +39 -0
- package/lib/kinds/target.js +761 -0
- package/lib/kinds/tiles.d.ts +55 -0
- package/lib/kinds/tiles.js +606 -0
- package/lib/kinds/venn.d.ts +38 -0
- package/lib/kinds/venn.js +710 -0
- package/lib/noto.d.ts +2 -0
- package/lib/noto.js +212 -0
- package/lib/objects.d.ts +7 -0
- package/lib/objects.js +226 -0
- package/lib/pen.d.ts +32 -0
- package/lib/pen.js +60 -0
- package/lib/read.d.ts +9 -0
- package/lib/read.js +49 -0
- package/lib/render.d.ts +24 -0
- package/lib/render.js +68 -0
- package/lib/solve/balance.d.ts +46 -0
- package/lib/solve/balance.js +118 -0
- package/lib/style.d.ts +70 -0
- package/lib/style.js +39 -0
- package/lib/svg.d.ts +22 -0
- package/lib/svg.js +48 -0
- package/lib/things.d.ts +40 -0
- package/lib/things.js +269 -0
- package/package.json +28 -4
package/lib/kinds/map.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { margin } from "../kind.js";
|
|
2
|
+
import { textWidth } from "../pen.js";
|
|
3
|
+
import { int, isObj, list, only, text } from "../read.js";
|
|
4
|
+
import { colors, ink, isColor, outline, textOn } from "../style.js";
|
|
5
|
+
import { n, poly } from "../svg.js";
|
|
6
|
+
import { checkThing, drawThing, wordOf } from "../things.js";
|
|
7
|
+
const cols = 8;
|
|
8
|
+
const rows = 6;
|
|
9
|
+
const thingSize = 48;
|
|
10
|
+
function radius(place) {
|
|
11
|
+
const look = place.look ?? "circle";
|
|
12
|
+
return look === "dot" ? 8 : look === "circle" ? 21 : thingSize / 2;
|
|
13
|
+
}
|
|
14
|
+
/** cellOf is the distance between two neighbouring crossings of the grid. */
|
|
15
|
+
function cellOf(scene) {
|
|
16
|
+
const xs = scene.places.map((p) => p.at[0]);
|
|
17
|
+
const ys = scene.places.map((p) => p.at[1]);
|
|
18
|
+
const across = Math.max(...xs) - Math.min(...xs);
|
|
19
|
+
const down = Math.max(...ys) - Math.min(...ys);
|
|
20
|
+
return Math.min(110, 440 / Math.max(1, across), 340 / Math.max(1, down));
|
|
21
|
+
}
|
|
22
|
+
function nameOf(place) {
|
|
23
|
+
return place.label ?? place.id;
|
|
24
|
+
}
|
|
25
|
+
/** labelOutside tells whether a place's name stands under it, not inside. */
|
|
26
|
+
function labelOutside(place) {
|
|
27
|
+
return (place.look ?? "circle") !== "circle";
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* labelSpot is where a place's name stands, from its centre: of eight sides
|
|
31
|
+
* around it, the one farthest from the roads that leave it, below first.
|
|
32
|
+
*/
|
|
33
|
+
function labelSpot(place, roads, byId, grid) {
|
|
34
|
+
if (!labelOutside(place))
|
|
35
|
+
return undefined;
|
|
36
|
+
const w = textWidth(nameOf(place), 16) + 10;
|
|
37
|
+
const r = radius(place);
|
|
38
|
+
const here = grid(place);
|
|
39
|
+
const ways = roads
|
|
40
|
+
.filter((road) => road.from === place.id || road.to === place.id)
|
|
41
|
+
.map((road) => {
|
|
42
|
+
const there = grid(byId.get(road.from === place.id ? road.to : road.from));
|
|
43
|
+
return Math.atan2(there.y - here.y, there.x - here.x);
|
|
44
|
+
});
|
|
45
|
+
const d = r * 0.72;
|
|
46
|
+
const sides = [
|
|
47
|
+
{ x: 0, y: r + 16, w },
|
|
48
|
+
{ x: 0, y: -(r + 16), w },
|
|
49
|
+
{ x: d + w / 2, y: d + 8, w },
|
|
50
|
+
{ x: -(d + w / 2), y: d + 8, w },
|
|
51
|
+
{ x: d + w / 2, y: -(d + 8), w },
|
|
52
|
+
{ x: -(d + w / 2), y: -(d + 8), w },
|
|
53
|
+
{ x: r + w / 2 + 6, y: 0, w },
|
|
54
|
+
{ x: -(r + w / 2 + 6), y: 0, w },
|
|
55
|
+
];
|
|
56
|
+
let best = sides[0];
|
|
57
|
+
let far = -1;
|
|
58
|
+
for (const side of sides) {
|
|
59
|
+
const angle = Math.atan2(side.y, side.x);
|
|
60
|
+
const near = Math.min(Math.PI, ...ways.map((a) => {
|
|
61
|
+
const diff = Math.abs(a - angle) % (2 * Math.PI);
|
|
62
|
+
return Math.min(diff, 2 * Math.PI - diff);
|
|
63
|
+
}));
|
|
64
|
+
if (near > far + 0.05) {
|
|
65
|
+
far = near;
|
|
66
|
+
best = side;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return best;
|
|
70
|
+
}
|
|
71
|
+
function segmentGap(p, a, b) {
|
|
72
|
+
const dx = b.x - a.x;
|
|
73
|
+
const dy = b.y - a.y;
|
|
74
|
+
const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / (dx * dx + dy * dy)));
|
|
75
|
+
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
76
|
+
}
|
|
77
|
+
function same(a, from, to) {
|
|
78
|
+
return (a.from === from && a.to === to) || (a.from === to && a.to === from);
|
|
79
|
+
}
|
|
80
|
+
/** tag writes a label on a white ground; "?" stands in a dashed box. */
|
|
81
|
+
function tag(pen, x, y, label, size = 16) {
|
|
82
|
+
const ask = label === "?";
|
|
83
|
+
const w = Math.max(ask ? 26 : 0, textWidth(label, size) + 10);
|
|
84
|
+
pen.el("rect", {
|
|
85
|
+
x: x - w / 2,
|
|
86
|
+
y: y - 12,
|
|
87
|
+
width: w,
|
|
88
|
+
height: 24,
|
|
89
|
+
rx: 7,
|
|
90
|
+
fill: "#ffffff",
|
|
91
|
+
stroke: ink,
|
|
92
|
+
"stroke-width": ask ? 2 : 1.4,
|
|
93
|
+
"stroke-dasharray": ask ? "4 3" : undefined,
|
|
94
|
+
});
|
|
95
|
+
pen.text(x, y, label, { size });
|
|
96
|
+
}
|
|
97
|
+
export const map = {
|
|
98
|
+
kind: "map",
|
|
99
|
+
members: ["kind", "places", "roads", "route", "sea"],
|
|
100
|
+
check(scene, problems) {
|
|
101
|
+
only(scene, this.members, "scene", problems);
|
|
102
|
+
const ids = new Map();
|
|
103
|
+
const spots = new Set();
|
|
104
|
+
list(scene.places, "places", problems, 2, 12).forEach((p, i) => {
|
|
105
|
+
const path = `places[${i}]`;
|
|
106
|
+
if (!isObj(p)) {
|
|
107
|
+
problems.push(`${path}: must be a place with an id and at`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
only(p, ["id", "at", "look", "label", "color"], path, problems);
|
|
111
|
+
const id = text(p.id, `${path}.id`, problems, 3);
|
|
112
|
+
if (id && ids.has(id))
|
|
113
|
+
problems.push(`${path}.id: "${id}" names another place too`);
|
|
114
|
+
const at = list(p.at, `${path}.at`, problems, 2, 2);
|
|
115
|
+
if (at.length === 2) {
|
|
116
|
+
const before = problems.length;
|
|
117
|
+
int(at[0], `${path}.at[0]`, problems, 0, cols);
|
|
118
|
+
int(at[1], `${path}.at[1]`, problems, 0, rows);
|
|
119
|
+
if (problems.length === before) {
|
|
120
|
+
const key = `${at[0]},${at[1]}`;
|
|
121
|
+
if (spots.has(key))
|
|
122
|
+
problems.push(`${path}.at: another place stands at ${at[0]}, ${at[1]}`);
|
|
123
|
+
spots.add(key);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (p.look !== undefined && p.look !== "dot" && p.look !== "circle")
|
|
127
|
+
checkThing(p.look, `${path}.look`, problems);
|
|
128
|
+
const inside = p.look === undefined || p.look === "circle";
|
|
129
|
+
if (p.label !== undefined)
|
|
130
|
+
text(p.label, `${path}.label`, problems, inside ? 3 : 10);
|
|
131
|
+
else if (inside && typeof p.id === "string" && [...p.id].length > 3)
|
|
132
|
+
problems.push(`${path}.id: a circle shows its id inside, at most 3 characters`);
|
|
133
|
+
if (p.color !== undefined) {
|
|
134
|
+
if (!inside)
|
|
135
|
+
problems.push(`${path}.color: only a circle has a colour`);
|
|
136
|
+
else if (!isColor(p.color))
|
|
137
|
+
problems.push(`${path}.color: must be a colour: ${Object.keys(colors).join(", ")}`);
|
|
138
|
+
}
|
|
139
|
+
if (id)
|
|
140
|
+
ids.set(id, p);
|
|
141
|
+
});
|
|
142
|
+
if (scene.sea !== undefined && typeof scene.sea !== "boolean")
|
|
143
|
+
problems.push("sea: must be true or false");
|
|
144
|
+
const roads = [];
|
|
145
|
+
list(scene.roads, "roads", problems, 1, 20).forEach((r, i) => {
|
|
146
|
+
const path = `roads[${i}]`;
|
|
147
|
+
if (!isObj(r)) {
|
|
148
|
+
problems.push(`${path}: must be a road with from and to`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
only(r, ["from", "to", "label", "arrow"], path, problems);
|
|
152
|
+
let ok = true;
|
|
153
|
+
for (const end of ["from", "to"]) {
|
|
154
|
+
if (typeof r[end] !== "string" || !ids.has(r[end])) {
|
|
155
|
+
problems.push(`${path}.${end}: must name a place: ${[...ids.keys()].join(", ")}`);
|
|
156
|
+
ok = false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (ok && r.from === r.to) {
|
|
160
|
+
problems.push(`${path}.to: a road joins two different places`);
|
|
161
|
+
ok = false;
|
|
162
|
+
}
|
|
163
|
+
if (ok && roads.some((o) => same(o, r.from, r.to))) {
|
|
164
|
+
problems.push(`${path}: another road joins ${r.from} and ${r.to} already`);
|
|
165
|
+
ok = false;
|
|
166
|
+
}
|
|
167
|
+
if (r.label !== undefined)
|
|
168
|
+
text(r.label, `${path}.label`, problems, 6);
|
|
169
|
+
if (r.arrow !== undefined && typeof r.arrow !== "boolean")
|
|
170
|
+
problems.push(`${path}.arrow: must be true or false`);
|
|
171
|
+
if (ok)
|
|
172
|
+
roads.push(r);
|
|
173
|
+
});
|
|
174
|
+
if (problems.length > 0)
|
|
175
|
+
return;
|
|
176
|
+
const typed = scene;
|
|
177
|
+
const cell = cellOf(typed);
|
|
178
|
+
const pos = (p) => ({ x: p.at[0] * cell, y: p.at[1] * cell });
|
|
179
|
+
typed.roads.forEach((r, i) => {
|
|
180
|
+
const a = ids.get(r.from);
|
|
181
|
+
const b = ids.get(r.to);
|
|
182
|
+
for (const p of typed.places) {
|
|
183
|
+
if (p === a || p === b)
|
|
184
|
+
continue;
|
|
185
|
+
if (segmentGap(pos(p), pos(a), pos(b)) < radius(p) + 6)
|
|
186
|
+
problems.push(`roads[${i}]: passes over place ${p.id}; move ${p.id} or join through it with two roads`);
|
|
187
|
+
}
|
|
188
|
+
const gap = Math.hypot(pos(a).x - pos(b).x, pos(a).y - pos(b).y) - radius(a) - radius(b);
|
|
189
|
+
if (gap < (r.label ? 44 : 18))
|
|
190
|
+
problems.push(`roads[${i}]: ${r.from} and ${r.to} stand too close for a road${r.label ? " with a label" : ""}`);
|
|
191
|
+
});
|
|
192
|
+
if (scene.route !== undefined) {
|
|
193
|
+
const route = list(scene.route, "route", problems, 2, 13);
|
|
194
|
+
route.forEach((id, i) => {
|
|
195
|
+
if (typeof id !== "string" || !ids.has(id))
|
|
196
|
+
problems.push(`route[${i}]: must name a place`);
|
|
197
|
+
});
|
|
198
|
+
if (problems.length > 0)
|
|
199
|
+
return;
|
|
200
|
+
for (let i = 0; i + 1 < route.length; i++) {
|
|
201
|
+
const from = route[i];
|
|
202
|
+
const to = route[i + 1];
|
|
203
|
+
const road = typed.roads.find((r) => same(r, from, to));
|
|
204
|
+
if (!road)
|
|
205
|
+
problems.push(`route[${i + 1}]: no road joins ${from} and ${to}`);
|
|
206
|
+
else if (road.arrow && road.from !== from)
|
|
207
|
+
problems.push(`route[${i + 1}]: the road between ${from} and ${to} goes only from ${road.from}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
draw(scene, pen) {
|
|
212
|
+
const s = scene;
|
|
213
|
+
const cell = cellOf(s);
|
|
214
|
+
const byId = new Map(s.places.map((p) => [p.id, p]));
|
|
215
|
+
const grid = (p) => ({ x: p.at[0] * cell, y: p.at[1] * cell });
|
|
216
|
+
const spots = new Map(s.places.map((p) => [p.id, labelSpot(p, s.roads, byId, grid)]));
|
|
217
|
+
// The picture's box holds every place and every label outside one.
|
|
218
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
219
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
220
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
221
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
222
|
+
for (const p of s.places) {
|
|
223
|
+
const { x, y } = grid(p);
|
|
224
|
+
const r = radius(p);
|
|
225
|
+
minX = Math.min(minX, x - r);
|
|
226
|
+
maxX = Math.max(maxX, x + r);
|
|
227
|
+
minY = Math.min(minY, y - r);
|
|
228
|
+
maxY = Math.max(maxY, y + r);
|
|
229
|
+
const spot = spots.get(p.id);
|
|
230
|
+
if (spot) {
|
|
231
|
+
minX = Math.min(minX, x + spot.x - spot.w / 2);
|
|
232
|
+
maxX = Math.max(maxX, x + spot.x + spot.w / 2);
|
|
233
|
+
minY = Math.min(minY, y + spot.y - 12);
|
|
234
|
+
maxY = Math.max(maxY, y + spot.y + 12);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const inset = margin + (s.sea ? 14 : 2);
|
|
238
|
+
const x0 = inset - minX;
|
|
239
|
+
const y0 = inset - minY;
|
|
240
|
+
const width = maxX - minX + 2 * inset;
|
|
241
|
+
const height = maxY - minY + 2 * inset;
|
|
242
|
+
const pos = (p) => ({ x: x0 + p.at[0] * cell, y: y0 + p.at[1] * cell });
|
|
243
|
+
if (s.sea)
|
|
244
|
+
pen.el("rect", {
|
|
245
|
+
x: margin / 2,
|
|
246
|
+
y: margin / 2,
|
|
247
|
+
width: width - margin,
|
|
248
|
+
height: height - margin,
|
|
249
|
+
rx: 18,
|
|
250
|
+
fill: "#cfe9fb",
|
|
251
|
+
stroke: colors.blue.fill,
|
|
252
|
+
"stroke-width": outline,
|
|
253
|
+
});
|
|
254
|
+
const ends = (from, to) => {
|
|
255
|
+
const a = byId.get(from);
|
|
256
|
+
const b = byId.get(to);
|
|
257
|
+
const pa = pos(a);
|
|
258
|
+
const pb = pos(b);
|
|
259
|
+
const l = Math.hypot(pb.x - pa.x, pb.y - pa.y);
|
|
260
|
+
const ux = (pb.x - pa.x) / l;
|
|
261
|
+
const uy = (pb.y - pa.y) / l;
|
|
262
|
+
const ra = radius(a) + 4;
|
|
263
|
+
const rb = radius(b) + 4;
|
|
264
|
+
return {
|
|
265
|
+
a: { x: pa.x + ux * ra, y: pa.y + uy * ra },
|
|
266
|
+
b: { x: pb.x - ux * rb, y: pb.y - uy * rb },
|
|
267
|
+
ux,
|
|
268
|
+
uy,
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
const route = s.route ?? [];
|
|
272
|
+
for (let i = 0; i + 1 < route.length; i++) {
|
|
273
|
+
const e = ends(route[i], route[i + 1]);
|
|
274
|
+
pen.el("path", {
|
|
275
|
+
d: `M${n(e.a.x)} ${n(e.a.y)}L${n(e.b.x)} ${n(e.b.y)}`,
|
|
276
|
+
stroke: colors.orange.fill,
|
|
277
|
+
"stroke-width": 12,
|
|
278
|
+
"stroke-linecap": "round",
|
|
279
|
+
class: "route",
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const way = s.sea ? colors.blue.dark : ink;
|
|
283
|
+
for (const r of s.roads) {
|
|
284
|
+
const e = ends(r.from, r.to);
|
|
285
|
+
pen.add('<g class="road">');
|
|
286
|
+
pen.el("path", {
|
|
287
|
+
d: `M${n(e.a.x)} ${n(e.a.y)}L${n(e.b.x)} ${n(e.b.y)}`,
|
|
288
|
+
stroke: way,
|
|
289
|
+
"stroke-width": 3,
|
|
290
|
+
"stroke-linecap": "round",
|
|
291
|
+
"stroke-dasharray": s.sea ? "9 7" : undefined,
|
|
292
|
+
});
|
|
293
|
+
if (r.arrow) {
|
|
294
|
+
const size = 13;
|
|
295
|
+
const { x, y } = e.b;
|
|
296
|
+
pen.el("path", {
|
|
297
|
+
d: poly([
|
|
298
|
+
{ x, y },
|
|
299
|
+
{ x: x - e.ux * size - e.uy * size * 0.55, y: y - e.uy * size + e.ux * size * 0.55 },
|
|
300
|
+
{ x: x - e.ux * size + e.uy * size * 0.55, y: y - e.uy * size - e.ux * size * 0.55 },
|
|
301
|
+
]),
|
|
302
|
+
fill: way,
|
|
303
|
+
stroke: way,
|
|
304
|
+
"stroke-width": 1.5,
|
|
305
|
+
"stroke-linejoin": "round",
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
pen.add("</g>");
|
|
309
|
+
}
|
|
310
|
+
for (const r of s.roads) {
|
|
311
|
+
if (!r.label)
|
|
312
|
+
continue;
|
|
313
|
+
const e = ends(r.from, r.to);
|
|
314
|
+
tag(pen, (e.a.x + e.b.x) / 2, (e.a.y + e.b.y) / 2, r.label);
|
|
315
|
+
}
|
|
316
|
+
for (const p of s.places) {
|
|
317
|
+
const { x, y } = pos(p);
|
|
318
|
+
const look = p.look ?? "circle";
|
|
319
|
+
pen.add('<g class="place">');
|
|
320
|
+
if (look === "dot") {
|
|
321
|
+
pen.el("circle", { cx: x, cy: y, r: 8, fill: ink });
|
|
322
|
+
}
|
|
323
|
+
else if (look === "circle") {
|
|
324
|
+
const color = p.color ?? "white";
|
|
325
|
+
pen.el("circle", {
|
|
326
|
+
cx: x,
|
|
327
|
+
cy: y,
|
|
328
|
+
r: 21,
|
|
329
|
+
fill: colors[color].fill,
|
|
330
|
+
stroke: ink,
|
|
331
|
+
"stroke-width": outline,
|
|
332
|
+
});
|
|
333
|
+
const name = nameOf(p);
|
|
334
|
+
pen.text(x, y, name, { size: name.length > 2 ? 15 : 19, fill: textOn(color) });
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
drawThing(pen, look, x, y, thingSize);
|
|
338
|
+
}
|
|
339
|
+
const spot = spots.get(p.id);
|
|
340
|
+
if (spot)
|
|
341
|
+
tag(pen, x + spot.x, y + spot.y, nameOf(p));
|
|
342
|
+
pen.add("</g>");
|
|
343
|
+
}
|
|
344
|
+
return { width, height };
|
|
345
|
+
},
|
|
346
|
+
describe(scene) {
|
|
347
|
+
const s = scene;
|
|
348
|
+
const byId = new Map(s.places.map((p) => [p.id, p]));
|
|
349
|
+
const name = (id) => nameOf(byId.get(id));
|
|
350
|
+
const places = s.places
|
|
351
|
+
.map((p) => {
|
|
352
|
+
const look = p.look ?? "circle";
|
|
353
|
+
if (look === "dot" || look === "circle")
|
|
354
|
+
return nameOf(p);
|
|
355
|
+
return `${nameOf(p)} (${wordOf(look)})`;
|
|
356
|
+
})
|
|
357
|
+
.join(", ");
|
|
358
|
+
const way = s.sea ? "sea route" : "road";
|
|
359
|
+
const roads = s.roads
|
|
360
|
+
.map((r) => {
|
|
361
|
+
const what = r.arrow
|
|
362
|
+
? `from ${name(r.from)} to ${name(r.to)}, one way only`
|
|
363
|
+
: `between ${name(r.from)} and ${name(r.to)}`;
|
|
364
|
+
return `${what}${r.label ? ` (${r.label})` : ""}`;
|
|
365
|
+
})
|
|
366
|
+
.join("; ");
|
|
367
|
+
const route = s.route ? ` The highlighted way goes ${s.route.map(name).join(" – ")}.` : "";
|
|
368
|
+
return `A ${s.sea ? "sea " : ""}map with ${s.places.length} places: ${places}. ${s.roads.length} ${way}${s.roads.length === 1 ? "" : "s"}: ${roads}.${route}`;
|
|
369
|
+
},
|
|
370
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Kind } from "../kind.ts";
|
|
2
|
+
import { type ColorName } from "../style.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Matchsticks: matches laid on a table. Either a text — digits as on a digital
|
|
5
|
+
* clock and the signs + − = — that the kind lays out in matches, or sticks
|
|
6
|
+
* between neighbouring points of a square or a triangular grid, for squares and
|
|
7
|
+
* triangles. A match may be coloured, to show the one that moves or goes; an
|
|
8
|
+
* empty place, drawn dashed, shows where a match was or could go.
|
|
9
|
+
*/
|
|
10
|
+
export type Mark = "ghost" | ColorName;
|
|
11
|
+
export type Stick = [number, number, number, number];
|
|
12
|
+
export type MatchsticksScene = {
|
|
13
|
+
kind: "matchsticks";
|
|
14
|
+
text?: string;
|
|
15
|
+
marks?: {
|
|
16
|
+
char: number;
|
|
17
|
+
place: string;
|
|
18
|
+
mark: Mark;
|
|
19
|
+
}[];
|
|
20
|
+
grid?: "square" | "triangle";
|
|
21
|
+
sticks?: (Stick | {
|
|
22
|
+
at: Stick;
|
|
23
|
+
mark?: Mark;
|
|
24
|
+
})[];
|
|
25
|
+
};
|
|
26
|
+
export declare const matchsticks: Kind;
|