@benosjs/pixel 0.0.0-stage → 0.8.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.
Files changed (55) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +62 -2
  3. package/dist/js/index.development.js +2419 -0
  4. package/dist/js/index.development.js.map +1 -0
  5. package/dist/js/index.production.js +2119 -0
  6. package/dist/js/png.development.js +60 -0
  7. package/dist/js/png.development.js.map +1 -0
  8. package/dist/js/png.production.js +46 -0
  9. package/dist/types/ai.d.ts +37 -0
  10. package/dist/types/ai.d.ts.map +1 -0
  11. package/dist/types/character.d.ts +61 -0
  12. package/dist/types/character.d.ts.map +1 -0
  13. package/dist/types/color.d.ts +14 -0
  14. package/dist/types/color.d.ts.map +1 -0
  15. package/dist/types/draw.d.ts +27 -0
  16. package/dist/types/draw.d.ts.map +1 -0
  17. package/dist/types/font.d.ts +5 -0
  18. package/dist/types/font.d.ts.map +1 -0
  19. package/dist/types/format.d.ts +22 -0
  20. package/dist/types/format.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +13 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/library/decor.d.ts +2 -0
  24. package/dist/types/library/decor.d.ts.map +1 -0
  25. package/dist/types/library/furniture.d.ts +2 -0
  26. package/dist/types/library/furniture.d.ts.map +1 -0
  27. package/dist/types/library/index.d.ts +9 -0
  28. package/dist/types/library/index.d.ts.map +1 -0
  29. package/dist/types/library/make.d.ts +6 -0
  30. package/dist/types/library/make.d.ts.map +1 -0
  31. package/dist/types/library/more.d.ts +2 -0
  32. package/dist/types/library/more.d.ts.map +1 -0
  33. package/dist/types/library/people.d.ts +2 -0
  34. package/dist/types/library/people.d.ts.map +1 -0
  35. package/dist/types/library/structure.d.ts +2 -0
  36. package/dist/types/library/structure.d.ts.map +1 -0
  37. package/dist/types/library/tech.d.ts +2 -0
  38. package/dist/types/library/tech.d.ts.map +1 -0
  39. package/dist/types/must.d.ts +6 -0
  40. package/dist/types/must.d.ts.map +1 -0
  41. package/dist/types/palette.d.ts +8 -0
  42. package/dist/types/palette.d.ts.map +1 -0
  43. package/dist/types/pixelate.d.ts +36 -0
  44. package/dist/types/pixelate.d.ts.map +1 -0
  45. package/dist/types/png.d.ts +4 -0
  46. package/dist/types/png.d.ts.map +1 -0
  47. package/dist/types/procedural.d.ts +91 -0
  48. package/dist/types/procedural.d.ts.map +1 -0
  49. package/dist/types/recolor.d.ts +14 -0
  50. package/dist/types/recolor.d.ts.map +1 -0
  51. package/dist/types/render.d.ts +13 -0
  52. package/dist/types/render.d.ts.map +1 -0
  53. package/dist/types/sheet.d.ts +19 -0
  54. package/dist/types/sheet.d.ts.map +1 -0
  55. package/package.json +39 -3
@@ -0,0 +1,2419 @@
1
+ // packages/pixel/src/format.ts
2
+ /**
3
+ * The shared sprite format: a text map plus a palette.
4
+ *
5
+ * Each string in `rows` is one row of pixels and each character is one pixel. A
6
+ * character is looked up in `palette` to get its colour; '.' is always transparent.
7
+ * Recolouring a sprite is swapping palette values, and nothing else changes.
8
+ */
9
+ var TRANSPARENT = ".";
10
+ var spriteWidth = (sprite) => sprite.rows[0]?.length ?? 0;
11
+ var spriteHeight = (sprite) => sprite.rows.length;
12
+ /** Lists everything wrong with a sprite. An empty list means it is valid. */
13
+ function validateSprite(sprite) {
14
+ const problems = [];
15
+ if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(sprite.id)) problems.push(`id "${sprite.id}" is not lowercase-with-hyphens`);
16
+ if (!sprite.name.trim()) problems.push("name is empty");
17
+ if (sprite.rows.length === 0) problems.push("has no rows");
18
+ const width = spriteWidth(sprite);
19
+ sprite.rows.forEach((row, y) => {
20
+ if (row.length !== width) problems.push(`row ${y} is ${row.length} wide, expected ${width}`);
21
+ for (const char of row) if (char !== "." && !(char in sprite.palette)) problems.push(`row ${y} uses '${char}', which is not in the palette`);
22
+ });
23
+ for (const [char, color] of Object.entries(sprite.palette)) {
24
+ if (char.length !== 1 || char === ".") problems.push(`palette key '${char}' must be one character other than '.'`);
25
+ if (!/^#[0-9a-f]{6}$/.test(color)) problems.push(`palette colour "${color}" is not lowercase #rrggbb`);
26
+ }
27
+ const used = new Set(sprite.rows.join(""));
28
+ for (const char of Object.keys(sprite.palette)) if (!used.has(char)) problems.push(`palette entry '${char}' is never used`);
29
+ if (sprite.rows.every((row) => /^\.*$/.test(row))) problems.push("is completely transparent");
30
+ return problems;
31
+ }
32
+ // packages/pixel/src/must.ts
33
+ /**
34
+ * Returns a value the surrounding code guarantees is present, such as an array item
35
+ * at an index already known to be in range. Throws if that guarantee is ever broken.
36
+ */
37
+ function must(value) {
38
+ if (value === void 0) throw new Error("Internal error: a value that must exist is missing");
39
+ return value;
40
+ }
41
+ // packages/pixel/src/draw.ts
42
+ /**
43
+ * A small drawing board for building a sprite's text map from shapes instead of
44
+ * typing every row. `rows()` returns the finished map.
45
+ */
46
+ var Draw = class {
47
+ width;
48
+ height;
49
+ grid;
50
+ constructor(width, height) {
51
+ this.width = width;
52
+ this.height = height;
53
+ this.grid = Array.from({ length: height }, () => Array(width).fill("."));
54
+ }
55
+ get(x, y) {
56
+ return this.grid[y]?.[x] ?? ".";
57
+ }
58
+ px(x, y, char) {
59
+ if (x >= 0 && y >= 0 && x < this.width && y < this.height) must(this.grid[y])[x] = char;
60
+ return this;
61
+ }
62
+ /** Several single pixels in one colour: [[x, y], ...]. */
63
+ dots(char, points) {
64
+ for (const [x, y] of points) this.px(x, y, char);
65
+ return this;
66
+ }
67
+ rect(x, y, width, height, char) {
68
+ for (let dy = 0; dy < height; dy++) for (let dx = 0; dx < width; dx++) this.px(x + dx, y + dy, char);
69
+ return this;
70
+ }
71
+ /** A one-pixel border just inside the given rectangle. */
72
+ frame(x, y, width, height, char) {
73
+ return this.hline(x, y, width, char).hline(x, y + height - 1, width, char).vline(x, y, height, char).vline(x + width - 1, y, height, char);
74
+ }
75
+ hline(x, y, length, char) {
76
+ return this.rect(x, y, length, 1, char);
77
+ }
78
+ vline(x, y, length, char) {
79
+ return this.rect(x, y, 1, length, char);
80
+ }
81
+ /** A filled circle. Use a centre ending in .5 for an even diameter. */
82
+ disc(cx, cy, radius, char) {
83
+ for (let y = 0; y < this.height; y++) for (let x = 0; x < this.width; x++) if ((x + .5 - cx) ** 2 + (y + .5 - cy) ** 2 <= radius ** 2) this.px(x, y, char);
84
+ return this;
85
+ }
86
+ /** Stamps a text map at a position. '.' leaves what is underneath. */
87
+ stamp(x, y, rows) {
88
+ rows.forEach((row, dy) => {
89
+ [...row].forEach((char, dx) => {
90
+ if (char !== ".") this.px(x + dx, y + dy, char);
91
+ });
92
+ });
93
+ return this;
94
+ }
95
+ /** Outlines the drawing: every empty pixel that touches a filled one is filled. */
96
+ outline(char = "o") {
97
+ const edge = [];
98
+ for (let y = 0; y < this.height; y++) for (let x = 0; x < this.width; x++) {
99
+ if (this.get(x, y) !== ".") continue;
100
+ if ([
101
+ this.get(x - 1, y),
102
+ this.get(x + 1, y),
103
+ this.get(x, y - 1),
104
+ this.get(x, y + 1)
105
+ ].some((neighbour) => neighbour !== ".")) edge.push([x, y]);
106
+ }
107
+ return this.dots(char, edge);
108
+ }
109
+ rows() {
110
+ return this.grid.map((row) => row.join(""));
111
+ }
112
+ };
113
+ // packages/pixel/src/color.ts
114
+ function toRgb(hex) {
115
+ return [
116
+ parseInt(hex.slice(1, 3), 16),
117
+ parseInt(hex.slice(3, 5), 16),
118
+ parseInt(hex.slice(5, 7), 16)
119
+ ];
120
+ }
121
+ function toHex([r, g, b]) {
122
+ const part = (value) => Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0");
123
+ return `#${part(r)}${part(g)}${part(b)}`;
124
+ }
125
+ /** Hue in degrees from 0 to 360; saturation and lightness from 0 to 1. */
126
+ function toHsl(hex) {
127
+ const [red, green, blue] = toRgb(hex);
128
+ const r = red / 255;
129
+ const g = green / 255;
130
+ const b = blue / 255;
131
+ const max = Math.max(r, g, b);
132
+ const min = Math.min(r, g, b);
133
+ const lightness = (max + min) / 2;
134
+ if (max === min) return [
135
+ 0,
136
+ 0,
137
+ lightness
138
+ ];
139
+ const spread = max - min;
140
+ const saturation = spread / (1 - Math.abs(2 * lightness - 1));
141
+ return [
142
+ (max === r ? ((g - b) / spread + 6) % 6 : max === g ? (b - r) / spread + 2 : (r - g) / spread + 4) * 60,
143
+ saturation,
144
+ lightness
145
+ ];
146
+ }
147
+ function fromHsl(hue, saturation, lightness) {
148
+ const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
149
+ const sector = (hue % 360 + 360) % 360 / 60;
150
+ const second = chroma * (1 - Math.abs(sector % 2 - 1));
151
+ const [r, g, b] = sector < 1 ? [
152
+ chroma,
153
+ second,
154
+ 0
155
+ ] : sector < 2 ? [
156
+ second,
157
+ chroma,
158
+ 0
159
+ ] : sector < 3 ? [
160
+ 0,
161
+ chroma,
162
+ second
163
+ ] : sector < 4 ? [
164
+ 0,
165
+ second,
166
+ chroma
167
+ ] : sector < 5 ? [
168
+ second,
169
+ 0,
170
+ chroma
171
+ ] : [
172
+ chroma,
173
+ 0,
174
+ second
175
+ ];
176
+ const lift = lightness - chroma / 2;
177
+ return toHex([
178
+ (r + lift) * 255,
179
+ (g + lift) * 255,
180
+ (b + lift) * 255
181
+ ]);
182
+ }
183
+ /** How bright a colour looks, from 0 (black) to 1 (white). */
184
+ function brightness(hex) {
185
+ const [r, g, b] = toRgb(hex);
186
+ return (.299 * r + .587 * g + .114 * b) / 255;
187
+ }
188
+ /** Scales a colour towards black. 1 leaves it alone, 0 gives black. */
189
+ function darken(hex, amount) {
190
+ return toHex(toRgb(hex).map((value) => value * amount));
191
+ }
192
+ /** Blends two colours. 0 gives the first, 1 the second. */
193
+ function mix(from, to, amount) {
194
+ const a = toRgb(from);
195
+ const b = toRgb(to);
196
+ const blend = (start, end) => start + (end - start) * amount;
197
+ return toHex([
198
+ blend(a[0], b[0]),
199
+ blend(a[1], b[1]),
200
+ blend(a[2], b[2])
201
+ ]);
202
+ }
203
+ // packages/pixel/src/palette.ts
204
+ /**
205
+ * The house palette. Library sprites draw from these colours so that they sit well
206
+ * together. A sprite's own palette holds only the entries it uses.
207
+ */
208
+ var HOUSE_PALETTE = {
209
+ o: "#2b2233",
210
+ x: "#262b3d",
211
+ k: "#663931",
212
+ d: "#8f563b",
213
+ w: "#b97a45",
214
+ W: "#d9a066",
215
+ s: "#eec39a",
216
+ M: "#3b3f52",
217
+ m: "#5a6078",
218
+ K: "#7f8a99",
219
+ q: "#9badb7",
220
+ p: "#b8c4d6",
221
+ l: "#dfe6f0",
222
+ P: "#f4f4f4",
223
+ "1": "#ffffff",
224
+ S: "#1f2f4a",
225
+ J: "#22324f",
226
+ j: "#306082",
227
+ h: "#3f3f74",
228
+ H: "#5b6ee1",
229
+ C: "#639bff",
230
+ c: "#5fcde4",
231
+ L: "#cbdbfc",
232
+ F: "#4b692f",
233
+ f: "#37946e",
234
+ G: "#6abe30",
235
+ g: "#99e550",
236
+ y: "#fbf236",
237
+ Y: "#e8b930",
238
+ O: "#df7126",
239
+ b: "#d95763",
240
+ R: "#ac3232",
241
+ t: "#e4dccf",
242
+ T: "#cfc5b4",
243
+ u: "#a89f8f"
244
+ };
245
+ /** The subset of a palette that a set of rows actually uses. */
246
+ function paletteFor(rows, source = HOUSE_PALETTE) {
247
+ const palette = {};
248
+ for (const char of new Set(rows.join(""))) {
249
+ if (char === ".") continue;
250
+ const colour = source[char];
251
+ if (colour === void 0) throw new Error(`No colour for '${char}'`);
252
+ palette[char] = colour;
253
+ }
254
+ return palette;
255
+ }
256
+ // packages/pixel/src/character.ts
257
+ /**
258
+ * Characters are built by stacking layers on a 16 by 24 grid: body, bottoms, shoes,
259
+ * top, hair, then accessory. Every layer uses the same characters for the same job
260
+ * (h is always hair, t the top), so one palette colours the whole stack.
261
+ */
262
+ var WIDTH = 16;
263
+ var HEIGHT = 24;
264
+ var BLANK = ".".repeat(WIDTH);
265
+ /** A full-height layer from a few rows starting at `top`. */
266
+ function layer(top, rows) {
267
+ rows.forEach((row, index) => {
268
+ if (row.length !== WIDTH) throw new Error(`Layer row ${top + index} "${row}" is ${row.length} wide`);
269
+ });
270
+ return [
271
+ ...Array(top).fill(BLANK),
272
+ ...rows,
273
+ ...Array(HEIGHT - top - rows.length).fill(BLANK)
274
+ ];
275
+ }
276
+ var BODY = layer(1, [
277
+ ".....oooooo.....",
278
+ "....osssssso....",
279
+ "...osssssssso...",
280
+ "...osssssssso...",
281
+ "...osssssssso...",
282
+ "...osesssseso...",
283
+ "...osssssssso...",
284
+ "....ossSSsso....",
285
+ ".....oooooo....."
286
+ ]);
287
+ var SHOES = layer(22, ["...obbboobbbo...", "...oooo..oooo..."]);
288
+ var HAIR_STYLES = [
289
+ {
290
+ id: "short",
291
+ name: "Short",
292
+ rows: layer(1, [
293
+ ".....oooooo.....",
294
+ "....ohhhhhho....",
295
+ "...ohhhhhhhho...",
296
+ "...ohhhhhhhho...",
297
+ "...oh......ho..."
298
+ ])
299
+ },
300
+ {
301
+ id: "fringe",
302
+ name: "Fringe",
303
+ rows: layer(1, [
304
+ ".....oooooo.....",
305
+ "....ohhhhhho....",
306
+ "...ohhhhhhhho...",
307
+ "...ohhhhhhhho...",
308
+ "...ohhhhhhhho..."
309
+ ])
310
+ },
311
+ {
312
+ id: "long",
313
+ name: "Long",
314
+ rows: layer(1, [
315
+ ".....oooooo.....",
316
+ "....ohhhhhho....",
317
+ "...ohhhhhhhho...",
318
+ "...ohhhhhhhho...",
319
+ "..ohh......hho..",
320
+ "..oh........ho..",
321
+ "..oh........ho..",
322
+ "..oh........ho..",
323
+ "..ohh......hho..",
324
+ "...oo......oo..."
325
+ ])
326
+ },
327
+ {
328
+ id: "curly",
329
+ name: "Curly",
330
+ rows: layer(0, [
331
+ ".....oooooo.....",
332
+ "...oohhhhhhoo...",
333
+ "..ohhhhhhhhhho..",
334
+ "..ohhhhhhhhhho..",
335
+ "..ohhhhhhhhhho..",
336
+ "..ohh......hho..",
337
+ "..oo........oo.."
338
+ ])
339
+ },
340
+ {
341
+ id: "bald",
342
+ name: "Bald",
343
+ rows: layer(0, [])
344
+ }
345
+ ];
346
+ var TOPS = [
347
+ {
348
+ id: "hoodie",
349
+ name: "Hoodie",
350
+ rows: layer(10, [
351
+ "...otttttttto...",
352
+ "..otttttttttto..",
353
+ "..otTttttttTto..",
354
+ "..otTttwwttTto..",
355
+ "..osTttttttTso..",
356
+ "..ooTttttttToo.."
357
+ ])
358
+ },
359
+ {
360
+ id: "t-shirt",
361
+ name: "T-shirt",
362
+ rows: layer(10, [
363
+ "...otttttttto...",
364
+ "..otttttttttto..",
365
+ "..otTttwwttTto..",
366
+ "..osTttttttTso..",
367
+ "..osTttttttTso..",
368
+ "..ooTttttttToo.."
369
+ ])
370
+ },
371
+ {
372
+ id: "shirt-and-tie",
373
+ name: "Shirt and tie",
374
+ rows: layer(10, [
375
+ "...otttwwttto...",
376
+ "..ottttwwtttto..",
377
+ "..otTttwwttTto..",
378
+ "..otTttwwttTto..",
379
+ "..osTttttttTso..",
380
+ "..ooTttttttToo.."
381
+ ])
382
+ },
383
+ {
384
+ id: "blazer",
385
+ name: "Blazer",
386
+ rows: layer(10, [
387
+ "...oTtwwwwtTo...",
388
+ "..ottTtwwtTtto..",
389
+ "..otTtTwwTtTto..",
390
+ "..otTttTTttTto..",
391
+ "..osTttttttTso..",
392
+ "..ooTttttttToo.."
393
+ ])
394
+ }
395
+ ];
396
+ var BOTTOMS = [{
397
+ id: "trousers",
398
+ name: "Trousers",
399
+ rows: layer(16, [
400
+ "....ojjjjjjo....",
401
+ "....ojjjjjjo....",
402
+ "....ojjJJjjo....",
403
+ "....ojjoojjo....",
404
+ "....ojjoojjo....",
405
+ "....oJJooJJo...."
406
+ ])
407
+ }, {
408
+ id: "shorts",
409
+ name: "Shorts",
410
+ rows: layer(16, [
411
+ "....ojjjjjjo....",
412
+ "....ojjjjjjo....",
413
+ "....oJJooJJo....",
414
+ "....ossoosso....",
415
+ "....ossoosso....",
416
+ "....oSSooSSo...."
417
+ ])
418
+ }];
419
+ var ACCESSORIES = [
420
+ {
421
+ id: "none",
422
+ name: "None",
423
+ rows: layer(0, [])
424
+ },
425
+ {
426
+ id: "glasses",
427
+ name: "Glasses",
428
+ rows: layer(6, ["....a.a..a.a...."])
429
+ },
430
+ {
431
+ id: "headphones",
432
+ name: "Headphones",
433
+ rows: layer(1, [
434
+ ".....aaaaaa.....",
435
+ "....a......a....",
436
+ "...a........a...",
437
+ "...a........a...",
438
+ "..oao......oao..",
439
+ "..oAo......oAo..",
440
+ "..oao......oao.."
441
+ ])
442
+ },
443
+ {
444
+ id: "cap",
445
+ name: "Cap",
446
+ rows: layer(1, [
447
+ ".....oooooo.....",
448
+ "....occcccco....",
449
+ "...occcccccco...",
450
+ "..oocccccccco...",
451
+ ".oCCCCCCCCCCo...",
452
+ "..oooooooooo...."
453
+ ])
454
+ }
455
+ ];
456
+ var SKIN_TONES = [
457
+ {
458
+ name: "Light",
459
+ colour: "#f6d3b3"
460
+ },
461
+ {
462
+ name: "Fair",
463
+ colour: "#eec39a"
464
+ },
465
+ {
466
+ name: "Tan",
467
+ colour: "#d9a066"
468
+ },
469
+ {
470
+ name: "Brown",
471
+ colour: "#b97a45"
472
+ },
473
+ {
474
+ name: "Deep",
475
+ colour: "#8f563b"
476
+ }
477
+ ];
478
+ var HAIR_COLOURS = [
479
+ {
480
+ name: "Dark brown",
481
+ colour: "#45283c"
482
+ },
483
+ {
484
+ name: "Brown",
485
+ colour: "#8f563b"
486
+ },
487
+ {
488
+ name: "Blonde",
489
+ colour: "#e8b930"
490
+ },
491
+ {
492
+ name: "Ginger",
493
+ colour: "#c2522d"
494
+ },
495
+ {
496
+ name: "Grey",
497
+ colour: "#9badb7"
498
+ },
499
+ {
500
+ name: "Blue",
501
+ colour: "#5b6ee1"
502
+ },
503
+ {
504
+ name: "Pink",
505
+ colour: "#d77bba"
506
+ }
507
+ ];
508
+ var TOP_COLOURS = [
509
+ {
510
+ name: "Blue",
511
+ colour: "#5b6ee1"
512
+ },
513
+ {
514
+ name: "Red",
515
+ colour: "#d95763"
516
+ },
517
+ {
518
+ name: "Green",
519
+ colour: "#37946e"
520
+ },
521
+ {
522
+ name: "Gold",
523
+ colour: "#e8b930"
524
+ },
525
+ {
526
+ name: "Purple",
527
+ colour: "#76428a"
528
+ },
529
+ {
530
+ name: "Grey",
531
+ colour: "#7f8a99"
532
+ },
533
+ {
534
+ name: "White",
535
+ colour: "#f4f4f4"
536
+ },
537
+ {
538
+ name: "Charcoal",
539
+ colour: "#3b3f52"
540
+ }
541
+ ];
542
+ var BOTTOM_COLOURS = [
543
+ {
544
+ name: "Denim",
545
+ colour: "#306082"
546
+ },
547
+ {
548
+ name: "Charcoal",
549
+ colour: "#3b3f52"
550
+ },
551
+ {
552
+ name: "Khaki",
553
+ colour: "#b9a36a"
554
+ },
555
+ {
556
+ name: "Brown",
557
+ colour: "#663931"
558
+ },
559
+ {
560
+ name: "Grey",
561
+ colour: "#7f8a99"
562
+ }
563
+ ];
564
+ var SHOE_COLOURS = [
565
+ {
566
+ name: "Brown",
567
+ colour: "#8f563b"
568
+ },
569
+ {
570
+ name: "Black",
571
+ colour: "#262b3d"
572
+ },
573
+ {
574
+ name: "White",
575
+ colour: "#dfe6f0"
576
+ },
577
+ {
578
+ name: "Red",
579
+ colour: "#d95763"
580
+ }
581
+ ];
582
+ var ACCENT_COLOURS = [
583
+ {
584
+ name: "White",
585
+ colour: "#f4f4f4"
586
+ },
587
+ {
588
+ name: "Red",
589
+ colour: "#d95763"
590
+ },
591
+ {
592
+ name: "Yellow",
593
+ colour: "#fbf236"
594
+ },
595
+ {
596
+ name: "Cyan",
597
+ colour: "#5fcde4"
598
+ },
599
+ {
600
+ name: "Lime",
601
+ colour: "#99e550"
602
+ }
603
+ ];
604
+ var DEFAULT_CHARACTER = {
605
+ skin: must(SKIN_TONES[1]).colour,
606
+ hairStyle: "short",
607
+ hairColour: must(HAIR_COLOURS[0]).colour,
608
+ top: "hoodie",
609
+ topColour: must(TOP_COLOURS[0]).colour,
610
+ bottom: "trousers",
611
+ bottomColour: must(BOTTOM_COLOURS[0]).colour,
612
+ shoeColour: must(SHOE_COLOURS[0]).colour,
613
+ accessory: "none",
614
+ accent: must(ACCENT_COLOURS[0]).colour
615
+ };
616
+ function part(parts, id) {
617
+ const found = parts.find((item) => item.id === id);
618
+ if (!found) throw new Error(`Unknown part "${id}"`);
619
+ return found;
620
+ }
621
+ /** Lays maps on top of each other. Later layers cover earlier ones; dots let them show through. */
622
+ function stack(layers) {
623
+ return must(layers[0]).map((baseRow, y) => [...baseRow].map((_, x) => layers.reduce((seen, rows) => {
624
+ const char = must(rows[y])[x] ?? ".";
625
+ return char === "." ? seen : char;
626
+ }, ".")).join(""));
627
+ }
628
+ /** Builds a character sprite from a set of choices. */
629
+ function buildCharacter(choices) {
630
+ const rows = stack([
631
+ BODY,
632
+ part(BOTTOMS, choices.bottom).rows,
633
+ SHOES,
634
+ part(TOPS, choices.top).rows,
635
+ part(HAIR_STYLES, choices.hairStyle).rows,
636
+ part(ACCESSORIES, choices.accessory).rows
637
+ ]);
638
+ return {
639
+ id: "character",
640
+ name: "Character",
641
+ tags: ["character", "generated"],
642
+ rows,
643
+ palette: paletteFor(rows, {
644
+ o: "#2b2233",
645
+ e: "#222034",
646
+ s: choices.skin,
647
+ S: darken(choices.skin, .82),
648
+ h: choices.hairColour,
649
+ t: choices.topColour,
650
+ T: darken(choices.topColour, .72),
651
+ w: choices.accent,
652
+ j: choices.bottomColour,
653
+ J: darken(choices.bottomColour, .72),
654
+ b: choices.shoeColour,
655
+ a: "#3b3f52",
656
+ A: choices.accent,
657
+ c: choices.accent,
658
+ C: darken(choices.accent, .75)
659
+ })
660
+ };
661
+ }
662
+ /** A random set of choices. Pass a random source to make it repeatable. */
663
+ function randomCharacter(random = Math.random) {
664
+ const pick = (items) => must(items[Math.floor(random() * items.length)]);
665
+ return {
666
+ skin: pick(SKIN_TONES).colour,
667
+ hairStyle: pick(HAIR_STYLES).id,
668
+ hairColour: pick(HAIR_COLOURS).colour,
669
+ top: pick(TOPS).id,
670
+ topColour: pick(TOP_COLOURS).colour,
671
+ bottom: pick(BOTTOMS).id,
672
+ bottomColour: pick(BOTTOM_COLOURS).colour,
673
+ shoeColour: pick(SHOE_COLOURS).colour,
674
+ accessory: pick(ACCESSORIES).id,
675
+ accent: pick(ACCENT_COLOURS).colour
676
+ };
677
+ }
678
+ /** Moves the head and body down one pixel, as on the low point of a step or a breath out. */
679
+ function bob(rows) {
680
+ const legsStart = 16;
681
+ const upper = [BLANK, ...rows.slice(0, legsStart)];
682
+ const legsTop = must(rows[legsStart]);
683
+ const merged = must(upper[legsStart]).split("").map((char, x) => char === "." ? legsTop[x] ?? "." : char).join("");
684
+ return [
685
+ ...upper.slice(0, legsStart),
686
+ merged,
687
+ ...rows.slice(17)
688
+ ];
689
+ }
690
+ /** Lifts one leg a pixel off the ground. Legs occupy rows 19 to 23; the left one is columns 3 to 7. */
691
+ function liftLeg(rows, side) {
692
+ const [from, to] = side === "left" ? [3, 8] : [8, 13];
693
+ return rows.map((row, y) => {
694
+ if (y < 18) return row;
695
+ const below = (rows[y + 1] ?? BLANK).slice(from, to);
696
+ if (y === 18) return row;
697
+ return row.slice(0, from) + below + row.slice(to);
698
+ });
699
+ }
700
+ /** A four-frame walk on the spot: left step, stand, right step, stand. */
701
+ function walkFrames(rows) {
702
+ return [
703
+ liftLeg(rows, "left"),
704
+ bob(rows),
705
+ liftLeg(rows, "right"),
706
+ bob(rows)
707
+ ];
708
+ }
709
+ /** A two-frame idle: standing, then a slight dip as if breathing. */
710
+ function idleFrames(rows) {
711
+ return [rows, bob(rows)];
712
+ }
713
+ /** Walk and idle animations for a character sprite. */
714
+ function animateCharacter(character) {
715
+ const base = {
716
+ palette: character.palette,
717
+ tags: [...character.tags.filter((tag) => tag !== "generated"), "animation"]
718
+ };
719
+ return [{
720
+ ...base,
721
+ id: `${character.id}-walk`,
722
+ name: `${character.name}, walking`,
723
+ frames: walkFrames(character.rows),
724
+ frameMs: 160
725
+ }, {
726
+ ...base,
727
+ id: `${character.id}-idle`,
728
+ name: `${character.name}, idle`,
729
+ frames: idleFrames(character.rows),
730
+ frameMs: 520
731
+ }];
732
+ }
733
+ /** All frames of an animation side by side as one sprite, ready to save as a strip. */
734
+ function animationStrip(animation) {
735
+ const rows = must(animation.frames[0]).map((_, y) => animation.frames.map((frame) => must(frame[y])).join(""));
736
+ return {
737
+ id: animation.id,
738
+ name: animation.name,
739
+ tags: animation.tags,
740
+ palette: animation.palette,
741
+ rows
742
+ };
743
+ }
744
+ /** One frame of an animation as a sprite. */
745
+ function animationFrame(animation, index) {
746
+ return {
747
+ id: animation.id,
748
+ name: animation.name,
749
+ tags: animation.tags,
750
+ palette: animation.palette,
751
+ rows: must(animation.frames[index % animation.frames.length])
752
+ };
753
+ }
754
+ // packages/pixel/src/library/make.ts
755
+ /** Builds a library sprite. Without a palette, colours come from the house palette. */
756
+ function make(id, name, tags, rows, palette) {
757
+ return {
758
+ id,
759
+ name,
760
+ tags,
761
+ rows,
762
+ palette: palette ? paletteFor(rows, palette) : paletteFor(rows)
763
+ };
764
+ }
765
+ /** Checks that hand-typed rows are all `width` wide, so a typo fails loudly. */
766
+ function art(width, rows) {
767
+ rows.forEach((row, y) => {
768
+ if (row.length !== width) throw new Error(`Row ${y} "${row}" is ${row.length} wide, expected ${width}`);
769
+ });
770
+ return rows;
771
+ }
772
+ // packages/pixel/src/library/decor.ts
773
+ var coffeeMug = new Draw(16, 16).rect(4, 5, 7, 8, "b").hline(5, 5, 5, "k").vline(10, 6, 7, "R").hline(4, 12, 7, "R").vline(5, 7, 2, "P").dots("b", [
774
+ [11, 7],
775
+ [12, 7],
776
+ [12, 8],
777
+ [12, 9],
778
+ [12, 10],
779
+ [11, 10]
780
+ ]).outline().dots("p", [
781
+ [6, 2],
782
+ [7, 1],
783
+ [9, 2],
784
+ [10, 1]
785
+ ]).rows();
786
+ var pottedPlant = new Draw(16, 32).disc(8, 10, 4.6, "f").disc(4.5, 14, 3.4, "f").disc(11.5, 14, 3.4, "f").disc(8, 16, 4.2, "f").disc(8, 9, 4.6, "G").disc(4.5, 13, 3.4, "G").disc(11.5, 13, 3.4, "G").disc(8, 15, 4.2, "G").disc(7, 7.5, 2.4, "g").disc(4, 12, 1.6, "g").disc(11, 12, 1.6, "g").dots("g", [
787
+ [7, 14],
788
+ [8, 15],
789
+ [9, 13]
790
+ ]).rect(7, 20, 2, 2, "k").rect(3, 22, 10, 2, "w").hline(3, 22, 10, "W").rect(4, 24, 8, 6, "w").vline(11, 24, 6, "d").hline(4, 29, 8, "d").outline().rows();
791
+ var trashBin = new Draw(16, 16).dots("P", [
792
+ [6, 2],
793
+ [5, 3],
794
+ [6, 3],
795
+ [7, 3],
796
+ [5, 4],
797
+ [6, 4],
798
+ [7, 4],
799
+ [9, 3],
800
+ [10, 3],
801
+ [9, 4],
802
+ [10, 4]
803
+ ]).px(6, 3, "p").rect(3, 5, 10, 2, "q").hline(3, 5, 10, "p").rect(4, 7, 8, 7, "K").vline(6, 8, 5, "m").vline(9, 8, 5, "m").outline().rows();
804
+ var wallClock = new Draw(16, 16).disc(7.5, 7.5, 6.5, "H").disc(7.5, 7.5, 5.3, "P").dots("K", [
805
+ [7, 3],
806
+ [7, 11],
807
+ [3, 7],
808
+ [11, 7]
809
+ ]).vline(7, 4, 4, "M").hline(8, 7, 3, "M").px(7, 7, "b").outline().rows();
810
+ var deskLamp = new Draw(16, 16).hline(9, 2, 4, "b").hline(8, 3, 6, "b").hline(8, 4, 7, "b").dots("R", [
811
+ [13, 3],
812
+ [14, 4],
813
+ [13, 4]
814
+ ]).hline(9, 5, 5, "y").dots("m", [[7, 4], [6, 5]]).vline(6, 6, 6, "m").hline(4, 12, 6, "m").hline(3, 13, 8, "M").outline().rows();
815
+ var duck = art(16, [
816
+ "................",
817
+ "......yyyy......",
818
+ ".....yyyyyy.....",
819
+ ".....yyxyyy.....",
820
+ "...OOyyyyyy.....",
821
+ "....Oyyyyyy.....",
822
+ ".....yyyyy...y..",
823
+ "...yyyyyyyyyyy..",
824
+ "..yyyyyyyyyyyy..",
825
+ "..yyyYYYYyyyyy..",
826
+ "..yyyyYYYyyyy...",
827
+ "...yyyyyyyyy....",
828
+ "....yyyyyyy....."
829
+ ]);
830
+ var rubberDuck = new Draw(16, 16).stamp(0, 1, duck).outline().rows();
831
+ var whiteboard = new Draw(32, 32).rect(2, 3, 28, 19, "p").rect(3, 4, 26, 17, "1").hline(5, 6, 8, "H").hline(5, 8, 11, "H").hline(5, 10, 6, "H").frame(19, 6, 8, 5, "b").hline(21, 8, 4, "b").vline(6, 13, 6, "M").hline(6, 18, 11, "M").rect(8, 16, 2, 2, "c").rect(11, 14, 2, 4, "G").rect(14, 15, 2, 3, "Y").rect(20, 13, 4, 4, "y").rect(24, 15, 4, 4, "g").rect(8, 22, 16, 1, "K").hline(10, 21, 2, "b").hline(13, 21, 2, "H").vline(6, 23, 7, "m").vline(25, 23, 7, "m").hline(4, 30, 5, "m").hline(23, 30, 5, "m").outline().rows();
832
+ var DECOR = [
833
+ make("coffee-mug", "Coffee mug", ["decor", "kitchen"], coffeeMug),
834
+ make("potted-plant", "Potted plant", ["decor"], pottedPlant),
835
+ make("trash-bin", "Trash bin", ["decor"], trashBin),
836
+ make("wall-clock", "Wall clock", ["decor"], wallClock),
837
+ make("desk-lamp", "Desk lamp", ["decor"], deskLamp),
838
+ make("rubber-duck", "Rubber duck", ["decor"], rubberDuck),
839
+ make("whiteboard", "Whiteboard", ["decor", "furniture"], whiteboard)
840
+ ];
841
+ // packages/pixel/src/library/furniture.ts
842
+ var codingDesk = art(32, [
843
+ "................................",
844
+ "................................",
845
+ ".........oooooooooooooo.........",
846
+ ".........oMMMMMMMMMMMMo.........",
847
+ ".........oMSSSSSSSSSSMo.........",
848
+ ".........oMScccSSggSSMo.........",
849
+ ".........oMSSyyyyySSSMo.........",
850
+ ".........oMSccSSccccSMo.........",
851
+ ".........oMSSggggSSSSMo.........",
852
+ ".........oMSSSSSSSSSSMo.........",
853
+ ".........oMMMMMMMMMMMMo.........",
854
+ ".........oooooooooooooo.........",
855
+ ".............ommmmo.............",
856
+ ".oooooooooooooMMMMooooooooooooo.",
857
+ ".oWPPPPPWWWWWWWWWWWWWWWbbbWWWWo.",
858
+ ".oWPppPPWWWWWWWWWWWWWWWbPbbWWWo.",
859
+ ".oWPPPPPWWKKKKKKKKKKKKWWbbbWWWo.",
860
+ ".oWPppPPWWKpKpKpKpKpKKWWdddWWWo.",
861
+ ".oWPPPPPWWKKKKKKKKKKKKWWWWWWWWo.",
862
+ ".oWdddddWWddddddddddddWWWWWWWWo.",
863
+ ".oWWWWWWWWWWWWWWWWWWWWWWWWWWWWo.",
864
+ ".owwwwwwwwwwwwwwwwwwwwwwwwwwwwo.",
865
+ ".oddddddddddddddddddddddddddddo.",
866
+ ".odwwwwwwwwwwwwwwwwdwwwwwwwwwdo.",
867
+ ".odwwwwwwwoooooooooooowwKKwwwdo.",
868
+ ".odwwwwwwwoHHHHHHHHHHowwwwwwwdo.",
869
+ ".odddddddoHHHHHHHHHHHHodddddddo.",
870
+ ".oooooooooHhHHHHHHHHhHooooooooo.",
871
+ "..kk.....oHhHHHHHHHHhHo.....kk..",
872
+ "..kk.....ohhhhhhhhhhhho.....kk..",
873
+ ".........oooooooooooooo.........",
874
+ "............oo....oo............"
875
+ ]);
876
+ var officeChair = new Draw(16, 16).rect(4, 1, 8, 6, "H").hline(4, 1, 8, "C").vline(11, 2, 5, "h").rect(7, 7, 2, 1, "m").rect(3, 8, 10, 3, "H").hline(3, 10, 10, "h").rect(7, 11, 2, 2, "m").hline(4, 13, 8, "M").dots("M", [
877
+ [4, 14],
878
+ [7, 14],
879
+ [8, 14],
880
+ [11, 14]
881
+ ]).outline().rows();
882
+ var sofa = new Draw(32, 24).rect(4, 5, 24, 9, "H").hline(4, 5, 24, "C").vline(16, 6, 8, "h").rect(2, 10, 4, 10, "H").hline(2, 10, 4, "C").rect(26, 10, 4, 10, "H").hline(26, 10, 4, "C").vline(5, 11, 9, "h").vline(26, 11, 9, "h").rect(6, 14, 20, 4, "C").vline(16, 14, 4, "H").hline(6, 17, 20, "H").rect(6, 18, 20, 2, "h").rect(3, 20, 2, 2, "k").rect(27, 20, 2, 2, "k").outline().rows();
883
+ function bookshelf() {
884
+ const board = new Draw(32, 32).rect(2, 2, 28, 28, "w").hline(2, 2, 28, "W").vline(29, 3, 27, "d");
885
+ for (const shelf of [
886
+ {
887
+ bottom: 10,
888
+ books: [
889
+ [
890
+ 2,
891
+ 6,
892
+ "b"
893
+ ],
894
+ [
895
+ 2,
896
+ 5,
897
+ "H"
898
+ ],
899
+ [
900
+ 3,
901
+ 6,
902
+ "G"
903
+ ],
904
+ [
905
+ 2,
906
+ 4,
907
+ "y"
908
+ ],
909
+ [
910
+ 2,
911
+ 6,
912
+ "C"
913
+ ],
914
+ [
915
+ 1,
916
+ 5,
917
+ "P"
918
+ ],
919
+ [
920
+ 3,
921
+ 6,
922
+ "R"
923
+ ],
924
+ [
925
+ 2,
926
+ 5,
927
+ "f"
928
+ ],
929
+ [
930
+ 2,
931
+ 6,
932
+ "O"
933
+ ],
934
+ [
935
+ 2,
936
+ 4,
937
+ "H"
938
+ ],
939
+ 1,
940
+ [
941
+ 2,
942
+ 6,
943
+ "b"
944
+ ]
945
+ ]
946
+ },
947
+ {
948
+ bottom: 19,
949
+ books: [
950
+ [
951
+ 3,
952
+ 6,
953
+ "H"
954
+ ],
955
+ [
956
+ 2,
957
+ 6,
958
+ "Y"
959
+ ],
960
+ [
961
+ 2,
962
+ 5,
963
+ "b"
964
+ ],
965
+ [
966
+ 2,
967
+ 6,
968
+ "f"
969
+ ],
970
+ 3,
971
+ [
972
+ 2,
973
+ 5,
974
+ "C"
975
+ ],
976
+ [
977
+ 3,
978
+ 6,
979
+ "m"
980
+ ],
981
+ [
982
+ 2,
983
+ 4,
984
+ "G"
985
+ ],
986
+ [
987
+ 2,
988
+ 6,
989
+ "b"
990
+ ],
991
+ [
992
+ 1,
993
+ 5,
994
+ "P"
995
+ ],
996
+ [
997
+ 2,
998
+ 6,
999
+ "O"
1000
+ ]
1001
+ ]
1002
+ },
1003
+ {
1004
+ bottom: 28,
1005
+ books: [
1006
+ [
1007
+ 2,
1008
+ 5,
1009
+ "G"
1010
+ ],
1011
+ [
1012
+ 2,
1013
+ 6,
1014
+ "R"
1015
+ ],
1016
+ [
1017
+ 3,
1018
+ 6,
1019
+ "C"
1020
+ ],
1021
+ [
1022
+ 2,
1023
+ 5,
1024
+ "y"
1025
+ ],
1026
+ [
1027
+ 2,
1028
+ 6,
1029
+ "H"
1030
+ ],
1031
+ [
1032
+ 2,
1033
+ 6,
1034
+ "b"
1035
+ ],
1036
+ [
1037
+ 3,
1038
+ 5,
1039
+ "f"
1040
+ ],
1041
+ [
1042
+ 2,
1043
+ 6,
1044
+ "P"
1045
+ ],
1046
+ [
1047
+ 2,
1048
+ 4,
1049
+ "O"
1050
+ ],
1051
+ [
1052
+ 2,
1053
+ 6,
1054
+ "j"
1055
+ ],
1056
+ [
1057
+ 2,
1058
+ 5,
1059
+ "Y"
1060
+ ]
1061
+ ]
1062
+ }
1063
+ ]) {
1064
+ board.rect(4, shelf.bottom - 6, 24, 7, "k");
1065
+ let x = 4;
1066
+ for (const book of shelf.books) {
1067
+ if (typeof book === "number") {
1068
+ x += book;
1069
+ continue;
1070
+ }
1071
+ const [width, height, colour] = book;
1072
+ const top = shelf.bottom - height + 1;
1073
+ board.rect(x, top, width, height, colour);
1074
+ if (width >= 2 && height >= 5) board.hline(x, top + 1, width, "l");
1075
+ x += width;
1076
+ }
1077
+ }
1078
+ return board.outline().rows();
1079
+ }
1080
+ var filingCabinet = (() => {
1081
+ const board = new Draw(16, 32).rect(2, 3, 12, 27, "q").rect(2, 3, 12, 2, "p");
1082
+ for (const y of [
1083
+ 6,
1084
+ 14,
1085
+ 22
1086
+ ]) board.rect(3, y, 10, 7, "p").frame(3, y, 10, 7, "K").rect(6, y + 1, 4, 2, "P").hline(6, y + 4, 4, "M");
1087
+ return board.vline(13, 5, 25, "K").outline().rows();
1088
+ })();
1089
+ var FURNITURE = [
1090
+ make("coding-desk", "Coding desk", ["furniture", "tech"], codingDesk),
1091
+ make("office-chair", "Office chair", ["furniture"], officeChair),
1092
+ make("sofa", "Sofa", ["furniture"], sofa),
1093
+ make("bookshelf", "Bookshelf", ["furniture"], bookshelf()),
1094
+ make("filing-cabinet", "Filing cabinet", ["furniture"], filingCabinet)
1095
+ ];
1096
+ var PEOPLE = [make("developer", "Developer", ["character"], art(16, [
1097
+ "................",
1098
+ ".....oooooo.....",
1099
+ "....ohhhhhho....",
1100
+ "...ohhhhhhhho...",
1101
+ "...ohhhhhhhho...",
1102
+ "...ohssssssho...",
1103
+ "...osesssseso...",
1104
+ "...osssssssso...",
1105
+ "....ossSSsso....",
1106
+ ".....oooooo.....",
1107
+ "...otttttttto...",
1108
+ "..otttttttttto..",
1109
+ "..otTttttttTto..",
1110
+ "..otTttwwttTto..",
1111
+ "..osTttttttTso..",
1112
+ "..ooTttttttToo..",
1113
+ "....ojjjjjjo....",
1114
+ "....ojjjjjjo....",
1115
+ "....ojjJJjjo....",
1116
+ "....ojjoojjo....",
1117
+ "....ojjoojjo....",
1118
+ "....oJJooJJo....",
1119
+ "...obbboobbbo...",
1120
+ "...oooo..oooo..."
1121
+ ]), {
1122
+ o: "#2b2233",
1123
+ h: "#45283c",
1124
+ s: "#eec39a",
1125
+ S: "#d9a066",
1126
+ e: "#222034",
1127
+ t: "#5b6ee1",
1128
+ T: "#3f3f74",
1129
+ w: "#f4f4f4",
1130
+ j: "#306082",
1131
+ J: "#22324f",
1132
+ b: "#8f563b"
1133
+ })];
1134
+ // packages/pixel/src/library/more.ts
1135
+ var standingDesk = new Draw(32, 32).rect(10, 2, 12, 9, "M").rect(11, 3, 10, 7, "S").hline(12, 4, 4, "c").hline(13, 6, 6, "g").hline(12, 8, 3, "y").rect(15, 11, 2, 2, "m").rect(24, 11, 2, 2, "b").rect(5, 12, 4, 1, "P").rect(2, 13, 28, 3, "W").hline(2, 15, 28, "w").rect(4, 16, 2, 13, "m").rect(26, 16, 2, 13, "m").rect(6, 18, 20, 1, "M").rect(2, 29, 6, 1, "M").rect(24, 29, 6, 1, "M").outline().rows();
1136
+ var meetingTable = new Draw(32, 24).rect(5, 7, 22, 1, "W").rect(3, 8, 26, 6, "W").hline(3, 13, 26, "w").rect(5, 14, 22, 1, "w").rect(8, 9, 4, 2, "p").hline(8, 11, 4, "K").rect(17, 9, 3, 3, "P").px(18, 10, "p").rect(23, 9, 2, 2, "b").rect(8, 15, 2, 6, "k").rect(22, 15, 2, 6, "k").outline().rows();
1137
+ var beanBag = new Draw(16, 16).disc(8, 11, 5.6, "R").disc(8, 10, 5.3, "b").disc(8, 7, 3.6, "b").dots("P", [[6, 6], [5, 7]]).hline(5, 11, 6, "R").outline().rows();
1138
+ var coatRack = new Draw(16, 32).rect(7, 2, 2, 2, "W").rect(7, 4, 2, 24, "w").dots("w", [
1139
+ [5, 6],
1140
+ [4, 5],
1141
+ [10, 6],
1142
+ [11, 5],
1143
+ [6, 6],
1144
+ [9, 6]
1145
+ ]).rect(9, 7, 4, 11, "H").vline(12, 7, 11, "h").hline(9, 7, 4, "C").rect(3, 7, 3, 8, "b").vline(3, 7, 8, "R").rect(4, 28, 8, 2, "k").outline().rows();
1146
+ var locker = (() => {
1147
+ const board = new Draw(16, 32).rect(2, 2, 12, 28, "H").hline(2, 2, 12, "C");
1148
+ for (const y of [3, 16]) board.frame(3, y, 10, 13, "h").hline(5, y + 2, 6, "h").hline(5, y + 4, 6, "h").rect(10, y + 7, 1, 3, "p");
1149
+ return board.rect(3, 30, 2, 1, "M").rect(11, 30, 2, 1, "M").outline().rows();
1150
+ })();
1151
+ var receptionDesk = new Draw(32, 24).rect(20, 1, 8, 5, "M").rect(21, 2, 6, 3, "S").hline(22, 3, 3, "c").disc(6, 3.5, 2.2, "G").px(5, 3, "g").rect(5, 5, 2, 1, "w").rect(1, 6, 30, 2, "W").rect(2, 8, 28, 13, "w").frame(4, 10, 24, 9, "d").rect(14, 12, 4, 4, "O").rect(15, 13, 2, 2, "y").hline(2, 20, 28, "d").outline().rows();
1152
+ var stool = new Draw(16, 16).rect(4, 4, 8, 2, "b").hline(4, 5, 8, "R").vline(5, 6, 8, "m").vline(10, 6, 8, "m").hline(6, 10, 4, "m").outline().rows();
1153
+ var rug = (() => {
1154
+ const board = new Draw(32, 16).rect(2, 4, 28, 9, "b").frame(3, 5, 26, 7, "y");
1155
+ for (let x = 7; x <= 24; x += 4) board.dots("y", [
1156
+ [x, 8],
1157
+ [x + 1, 7],
1158
+ [x + 1, 9],
1159
+ [x + 2, 8]
1160
+ ]);
1161
+ for (let x = 3; x <= 28; x += 2) board.px(x, 3, "s").px(x, 13, "s");
1162
+ return board.outline().rows();
1163
+ })();
1164
+ var pingPongTable = new Draw(32, 24).rect(21, 7, 2, 2, "P").rect(15, 5, 2, 5, "P").hline(14, 5, 4, "K").rect(2, 10, 28, 3, "f").hline(2, 10, 28, "G").hline(2, 12, 28, "F").rect(5, 13, 2, 8, "M").rect(25, 13, 2, 8, "M").hline(7, 16, 18, "M").outline().rows();
1165
+ var cardboardBox = new Draw(16, 16).rect(2, 4, 12, 2, "s").rect(2, 6, 12, 8, "W").rect(7, 4, 2, 5, "p").vline(13, 6, 8, "w").hline(2, 13, 12, "w").rect(4, 9, 3, 3, "P").px(5, 10, "b").outline().rows();
1166
+ var tvScreen = new Draw(32, 24).rect(2, 2, 28, 17, "M").rect(3, 3, 26, 15, "S").hline(6, 5, 10, "p").rect(6, 12, 3, 5, "c").rect(11, 9, 3, 8, "g").rect(16, 11, 3, 6, "y").rect(21, 7, 3, 10, "b").rect(14, 19, 4, 2, "m").rect(10, 21, 12, 1, "M").outline().rows();
1167
+ var desktopTower = (() => {
1168
+ const board = new Draw(16, 24).rect(4, 2, 8, 20, "M").rect(5, 3, 6, 18, "m").hline(6, 5, 4, "M").px(8, 8, "c").px(6, 10, "g");
1169
+ for (const y of [
1170
+ 13,
1171
+ 15,
1172
+ 17
1173
+ ]) board.hline(6, y, 4, "M");
1174
+ return board.outline().rows();
1175
+ })();
1176
+ var tablet = new Draw(16, 16).rect(3, 2, 10, 12, "M").rect(4, 3, 8, 10, "C").rect(5, 4, 2, 2, "y").rect(9, 4, 2, 2, "b").rect(5, 7, 2, 2, "g").rect(9, 7, 2, 2, "1").hline(6, 11, 4, "L").outline().rows();
1177
+ var phone = new Draw(16, 16).rect(5, 2, 6, 12, "M").rect(6, 3, 4, 9, "S").hline(6, 4, 3, "c").hline(7, 6, 3, "g").hline(6, 8, 2, "c").hline(7, 10, 3, "g").hline(7, 13, 2, "m").outline().rows();
1178
+ var headphones = (() => {
1179
+ const board = new Draw(16, 16);
1180
+ for (let y = 0; y < 9; y++) for (let x = 0; x < 16; x++) {
1181
+ const distance = Math.hypot(x + .5 - 8, y + .5 - 8.5);
1182
+ if (distance <= 6.2 && distance > 4.6) board.px(x, y, "M");
1183
+ }
1184
+ return board.rect(2, 8, 3, 5, "b").rect(11, 8, 3, 5, "b").vline(4, 9, 3, "R").vline(11, 9, 3, "R").outline().rows();
1185
+ })();
1186
+ var router = new Draw(16, 16).vline(3, 3, 6, "M").vline(12, 3, 6, "M").rect(2, 9, 12, 4, "P").hline(2, 12, 12, "p").dots("g", [[4, 10], [6, 10]]).px(8, 10, "y").dots("M", [[3, 13], [12, 13]]).outline().rows();
1187
+ var gameController = new Draw(16, 16).rect(2, 6, 12, 5, "m").rect(2, 10, 3, 3, "m").rect(11, 10, 3, 3, "m").dots("M", [
1188
+ [4, 7],
1189
+ [3, 8],
1190
+ [4, 8],
1191
+ [5, 8],
1192
+ [4, 9],
1193
+ [7, 8],
1194
+ [8, 8]
1195
+ ]).px(11, 7, "b").px(12, 8, "g").px(10, 8, "y").px(11, 9, "c").outline().rows();
1196
+ var mouse = new Draw(16, 16).vline(8, 1, 3, "K").rect(6, 4, 5, 9, "P").rect(5, 6, 7, 5, "P").vline(8, 4, 3, "p").px(8, 5, "K").hline(5, 7, 7, "p").hline(6, 12, 5, "p").outline().rows();
1197
+ var arcadeCabinet = new Draw(16, 32).rect(2, 3, 12, 27, "h").rect(3, 4, 10, 3, "y").hline(5, 5, 6, "b").rect(3, 8, 10, 8, "S").dots("g", [
1198
+ [6, 10],
1199
+ [9, 10],
1200
+ [7, 11],
1201
+ [8, 11],
1202
+ [6, 12],
1203
+ [9, 12]
1204
+ ]).dots("c", [[7, 14], [8, 14]]).px(8, 13, "y").rect(2, 17, 12, 3, "m").px(5, 16, "b").px(5, 17, "M").px(9, 18, "b").px(11, 18, "y").vline(4, 21, 8, "H").vline(11, 21, 8, "H").rect(7, 23, 2, 3, "M").outline().rows();
1205
+ var fridge = new Draw(16, 32).rect(2, 2, 12, 27, "l").hline(2, 2, 12, "1").hline(2, 11, 12, "q").rect(4, 5, 1, 4, "K").rect(4, 14, 1, 6, "K").vline(13, 3, 26, "p").px(9, 15, "b").px(11, 17, "c").rect(8, 19, 3, 3, "y").rect(3, 29, 2, 1, "M").rect(11, 29, 2, 1, "M").outline().rows();
1206
+ var microwave = new Draw(16, 16).rect(1, 4, 14, 9, "p").hline(1, 4, 14, "l").rect(2, 5, 9, 7, "S").hline(4, 10, 5, "K").rect(5, 8, 3, 2, "y").rect(12, 5, 2, 2, "g").dots("M", [
1207
+ [12, 8],
1208
+ [13, 8],
1209
+ [12, 10],
1210
+ [13, 10],
1211
+ [2, 13],
1212
+ [13, 13]
1213
+ ]).outline().rows();
1214
+ var vendingMachine = (() => {
1215
+ const board = new Draw(16, 32).rect(2, 2, 12, 28, "b").rect(3, 3, 10, 3, "R").hline(4, 4, 8, "y").rect(3, 7, 7, 14, "S");
1216
+ [
1217
+ [
1218
+ "c",
1219
+ "g",
1220
+ "y"
1221
+ ],
1222
+ [
1223
+ "y",
1224
+ "O",
1225
+ "c"
1226
+ ],
1227
+ [
1228
+ "g",
1229
+ "c",
1230
+ "O"
1231
+ ]
1232
+ ].forEach((row, index) => {
1233
+ row.forEach((colour, slot) => board.rect(4 + slot * 2, 8 + index * 4, 1, 2, colour));
1234
+ board.hline(3, 10 + index * 4, 7, "M");
1235
+ });
1236
+ return board.rect(11, 8, 2, 4, "p").hline(11, 14, 2, "M").rect(3, 23, 10, 3, "M").vline(13, 6, 24, "R").rect(3, 30, 2, 1, "x").rect(11, 30, 2, 1, "x").outline().rows();
1237
+ })();
1238
+ var pizzaBox = new Draw(16, 16).rect(2, 2, 12, 6, "w").frame(3, 3, 10, 4, "d").rect(1, 8, 14, 5, "W").rect(3, 9, 10, 3, "Y").hline(3, 11, 10, "w").dots("b", [
1239
+ [5, 10],
1240
+ [8, 9],
1241
+ [10, 10]
1242
+ ]).outline().rows();
1243
+ var donut = new Draw(16, 16).disc(8, 8.5, 5.6, "w").disc(8, 7.5, 5.2, "b").disc(8, 8, 1.7, ".").dots("y", [
1244
+ [5, 6],
1245
+ [10, 9],
1246
+ [8, 4]
1247
+ ]).dots("c", [[10, 5], [5, 9]]).dots("1", [
1248
+ [7, 11],
1249
+ [11, 7],
1250
+ [4, 7]
1251
+ ]).outline().rows();
1252
+ var energyDrink = new Draw(16, 16).rect(5, 3, 6, 11, "G").hline(5, 3, 6, "p").hline(5, 13, 6, "q").vline(10, 4, 9, "F").dots("y", [
1253
+ [8, 5],
1254
+ [7, 6],
1255
+ [7, 7],
1256
+ [8, 7],
1257
+ [8, 8],
1258
+ [8, 9],
1259
+ [7, 10]
1260
+ ]).outline().rows();
1261
+ var cactus = new Draw(16, 16).px(8, 2, "b").rect(7, 3, 3, 9, "G").vline(8, 4, 7, "g").rect(4, 6, 2, 3, "G").px(6, 8, "G").rect(11, 5, 2, 3, "G").px(10, 7, "G").rect(5, 12, 7, 3, "w").hline(5, 12, 7, "W").outline().rows();
1262
+ var pictureFrame = new Draw(16, 16).rect(2, 2, 12, 12, "w").rect(3, 3, 10, 10, "C").rect(10, 4, 2, 2, "y").hline(7, 7, 2, "f").hline(6, 8, 4, "f").hline(5, 9, 6, "f").hline(4, 10, 8, "f").px(7, 7, "1").rect(3, 11, 10, 2, "G").outline().rows();
1263
+ var trophy = new Draw(16, 16).rect(5, 2, 6, 5, "y").hline(6, 7, 4, "y").dots("Y", [
1264
+ [4, 3],
1265
+ [3, 3],
1266
+ [3, 4],
1267
+ [3, 5],
1268
+ [4, 5],
1269
+ [11, 3],
1270
+ [12, 3],
1271
+ [12, 4],
1272
+ [12, 5],
1273
+ [11, 5]
1274
+ ]).vline(6, 3, 3, "1").vline(10, 2, 5, "Y").rect(7, 8, 2, 2, "Y").rect(5, 10, 6, 1, "Y").rect(4, 11, 8, 3, "k").hline(6, 12, 4, "y").outline().rows();
1275
+ var stickyNotes = new Draw(16, 16).rect(2, 3, 7, 7, "y").hline(3, 5, 4, "Y").hline(3, 7, 3, "Y").rect(7, 5, 7, 7, "g").hline(8, 7, 4, "G").hline(8, 9, 3, "G").rect(4, 8, 7, 6, "c").hline(5, 10, 4, "j").hline(5, 12, 3, "j").outline().rows();
1276
+ var calendar = (() => {
1277
+ const board = new Draw(16, 16).rect(2, 3, 12, 11, "P").rect(2, 3, 12, 3, "b").dots("M", [[5, 2], [10, 2]]);
1278
+ for (const y of [
1279
+ 7,
1280
+ 9,
1281
+ 11
1282
+ ]) for (const x of [
1283
+ 4,
1284
+ 6,
1285
+ 8,
1286
+ 10
1287
+ ]) board.px(x, y, "q");
1288
+ return board.rect(8, 9, 2, 2, "b").hline(2, 13, 12, "p").outline().rows();
1289
+ })();
1290
+ var fireExtinguisher = new Draw(16, 24).hline(6, 3, 5, "M").px(6, 4, "M").rect(7, 5, 2, 2, "M").dots("M", [
1291
+ [11, 4],
1292
+ [12, 5],
1293
+ [12, 6],
1294
+ [12, 7],
1295
+ [12, 8],
1296
+ [12, 9]
1297
+ ]).rect(5, 7, 6, 14, "b").vline(10, 7, 14, "R").vline(6, 8, 3, "P").rect(6, 12, 4, 4, "P").hline(7, 13, 2, "b").hline(5, 20, 6, "R").outline().rows();
1298
+ var bookStack = new Draw(16, 16).rect(3, 4, 9, 3, "G").vline(11, 4, 3, "P").hline(3, 5, 2, "l").rect(4, 7, 9, 3, "H").vline(12, 7, 3, "P").hline(4, 8, 2, "l").rect(3, 10, 10, 3, "b").vline(12, 10, 3, "P").hline(3, 11, 2, "l").outline().rows();
1299
+ var elevator = new Draw(32, 32).rect(2, 2, 28, 28, "q").rect(13, 3, 6, 2, "S").dots("g", [[15, 3], [16, 4]]).rect(5, 6, 22, 24, "p").vline(6, 7, 22, "l").vline(17, 7, 22, "l").rect(15, 6, 2, 24, "K").rect(28, 15, 1, 2, "y").hline(2, 29, 28, "K").outline().rows();
1300
+ var tiledFloor = new Draw(16, 16).rect(0, 0, 16, 16, "l").dots("P", [
1301
+ [2, 2],
1302
+ [10, 3],
1303
+ [4, 11],
1304
+ [12, 12]
1305
+ ]).hline(0, 7, 16, "p").hline(0, 15, 16, "p").vline(7, 0, 16, "p").vline(15, 0, 16, "p").rows();
1306
+ var brickWall = (() => {
1307
+ const board = new Draw(16, 16).rect(0, 0, 16, 16, "b");
1308
+ board.rect(8, 0, 7, 3, "R").rect(4, 4, 7, 3, "R").rect(0, 8, 7, 3, "R").rect(12, 12, 3, 3, "R").rect(0, 12, 3, 3, "R");
1309
+ for (const y of [
1310
+ 3,
1311
+ 7,
1312
+ 11,
1313
+ 15
1314
+ ]) board.hline(0, y, 16, "T");
1315
+ [
1316
+ [7, 15],
1317
+ [3, 11],
1318
+ [7, 15],
1319
+ [3, 11]
1320
+ ].forEach((joints, row) => joints.forEach((x) => board.vline(x, row * 4, 3, "T")));
1321
+ return board.rows();
1322
+ })();
1323
+ var MORE_SPRITES = [
1324
+ make("standing-desk", "Standing desk", ["furniture", "tech"], standingDesk),
1325
+ make("meeting-table", "Meeting table", ["furniture"], meetingTable),
1326
+ make("reception-desk", "Reception desk", ["furniture"], receptionDesk),
1327
+ make("bean-bag", "Bean bag", ["furniture"], beanBag),
1328
+ make("stool", "Stool", ["furniture"], stool),
1329
+ make("locker", "Locker", ["furniture"], locker),
1330
+ make("coat-rack", "Coat rack", ["furniture", "decor"], coatRack),
1331
+ make("ping-pong-table", "Ping-pong table", ["furniture", "fun"], pingPongTable),
1332
+ make("rug", "Rug", ["decor"], rug),
1333
+ make("cardboard-box", "Cardboard box", ["decor"], cardboardBox),
1334
+ make("tv-screen", "Wall screen", ["tech"], tvScreen),
1335
+ make("desktop-tower", "Desktop tower", ["tech"], desktopTower),
1336
+ make("tablet", "Tablet", ["tech"], tablet),
1337
+ make("phone", "Phone", ["tech"], phone),
1338
+ make("headphones", "Headphones", ["tech"], headphones),
1339
+ make("router", "Router", ["tech"], router),
1340
+ make("mouse", "Mouse", ["tech"], mouse),
1341
+ make("game-controller", "Game controller", ["tech", "fun"], gameController),
1342
+ make("arcade-cabinet", "Arcade cabinet", ["tech", "fun"], arcadeCabinet),
1343
+ make("fridge", "Fridge", ["kitchen"], fridge),
1344
+ make("microwave", "Microwave", ["kitchen"], microwave),
1345
+ make("vending-machine", "Vending machine", ["kitchen"], vendingMachine),
1346
+ make("pizza-box", "Pizza box", ["kitchen", "fun"], pizzaBox),
1347
+ make("donut", "Donut", ["kitchen"], donut),
1348
+ make("energy-drink", "Energy drink", ["kitchen"], energyDrink),
1349
+ make("cactus", "Cactus", ["decor"], cactus),
1350
+ make("picture-frame", "Picture frame", ["decor"], pictureFrame),
1351
+ make("trophy", "Trophy", ["decor"], trophy),
1352
+ make("sticky-notes", "Sticky notes", ["decor"], stickyNotes),
1353
+ make("calendar", "Calendar", ["decor"], calendar),
1354
+ make("fire-extinguisher", "Fire extinguisher", ["decor", "structure"], fireExtinguisher),
1355
+ make("book-stack", "Stack of books", ["decor"], bookStack),
1356
+ make("elevator", "Elevator", ["structure"], elevator),
1357
+ make("tiled-floor-tile", "Tiled floor tile", ["tile"], tiledFloor),
1358
+ make("brick-wall-tile", "Brick wall tile", ["tile", "structure"], brickWall)
1359
+ ];
1360
+ // packages/pixel/src/library/structure.ts
1361
+ var window = new Draw(32, 32).rect(2, 2, 28, 26, "P").rect(4, 4, 24, 22, "C").rect(4, 12, 24, 14, "L").rect(6, 6, 5, 2, "1").rect(7, 5, 3, 1, "1").rect(20, 9, 5, 2, "1").rect(21, 8, 3, 1, "1").rect(5, 19, 4, 7, "j").rect(9, 16, 5, 10, "h").rect(17, 20, 4, 6, "h").rect(21, 17, 4, 9, "j").rect(25, 21, 3, 5, "h").dots("y", [
1362
+ [10, 18],
1363
+ [12, 20],
1364
+ [22, 19],
1365
+ [23, 22],
1366
+ [6, 21],
1367
+ [18, 22]
1368
+ ]).rect(15, 4, 2, 22, "P").rect(4, 14, 24, 2, "P").hline(2, 27, 28, "p").rect(1, 28, 30, 2, "p").hline(1, 28, 30, "l").outline().rows();
1369
+ var door = new Draw(16, 32).rect(1, 1, 14, 30, "k").rect(2, 2, 12, 29, "w").rect(4, 4, 8, 10, "W").frame(4, 4, 8, 10, "d").rect(4, 17, 8, 11, "W").frame(4, 17, 8, 11, "d").px(11, 15, "y").px(11, 16, "Y").outline().rows();
1370
+ var carpet = art(16, [
1371
+ "aaaaaaaabaaaaaaa",
1372
+ "aacaaaaabaaaaaaa",
1373
+ "aaaaaaaabaaaacaa",
1374
+ "aaaaaaaabaaaaaaa",
1375
+ "aaaaacaabaaaaaaa",
1376
+ "aaaaaaaabaaaaaaa",
1377
+ "aaaaaaaabaacaaaa",
1378
+ "bbbbbbbbbbbbbbbb",
1379
+ "baaaaaaaaaaaaaaa",
1380
+ "baaaaaacaaaaaaaa",
1381
+ "baaaaaaaaaaaaaca",
1382
+ "baacaaaaaaaaaaaa",
1383
+ "baaaaaaaaaacaaaa",
1384
+ "baaaaaaaaaaaaaaa",
1385
+ "baaaaacaaaaaaaaa",
1386
+ "bbbbbbbbbbbbbbbb"
1387
+ ]);
1388
+ var woodFloor = new Draw(16, 16).rect(0, 0, 16, 16, "W").dots("s", [
1389
+ [1, 1],
1390
+ [9, 1],
1391
+ [13, 5],
1392
+ [4, 5],
1393
+ [7, 9],
1394
+ [12, 9],
1395
+ [2, 13],
1396
+ [13, 13]
1397
+ ]).hline(0, 3, 16, "w").hline(0, 7, 16, "w").hline(0, 11, 16, "w").hline(0, 15, 16, "w").vline(5, 0, 3, "w").vline(11, 4, 3, "w").vline(3, 8, 3, "w").vline(9, 12, 3, "w").rows();
1398
+ var wall = new Draw(16, 16).rect(0, 0, 16, 16, "t").dots("T", [
1399
+ [3, 2],
1400
+ [11, 5],
1401
+ [6, 8],
1402
+ [13, 9]
1403
+ ]).hline(0, 11, 16, "T").rect(0, 12, 16, 4, "m").hline(0, 12, 16, "K").hline(0, 15, 16, "M").rows();
1404
+ var STRUCTURE = [
1405
+ make("window", "Window", ["structure"], window),
1406
+ make("door", "Door", ["structure"], door),
1407
+ make("carpet-tile", "Carpet tile", ["tile"], carpet, {
1408
+ a: "#4b5672",
1409
+ b: "#465069",
1410
+ c: "#525e7c"
1411
+ }),
1412
+ make("wood-floor-tile", "Wood floor tile", ["tile"], woodFloor),
1413
+ make("wall-tile", "Wall tile", ["tile", "structure"], wall)
1414
+ ];
1415
+ // packages/pixel/src/library/tech.ts
1416
+ var monitor = new Draw(16, 16).rect(1, 1, 14, 10, "M").rect(2, 2, 12, 8, "S").hline(3, 3, 4, "c").hline(8, 3, 3, "g").hline(4, 5, 6, "y").hline(3, 7, 3, "c").hline(7, 7, 5, "g").px(12, 10, "g").rect(7, 11, 2, 2, "m").rect(4, 13, 8, 1, "M").outline().rows();
1417
+ var laptop = new Draw(16, 16).rect(3, 2, 10, 7, "p").rect(4, 3, 8, 5, "S").hline(5, 4, 3, "c").px(9, 4, "y").hline(5, 6, 5, "g").hline(3, 9, 10, "K").rect(2, 10, 12, 1, "q").rect(1, 11, 14, 1, "p").hline(6, 11, 4, "q").rect(1, 12, 14, 1, "K").outline().rows();
1418
+ var keyboard = new Draw(16, 16).rect(1, 4, 14, 8, "p").dots("K", [
1419
+ 2,
1420
+ 4,
1421
+ 6,
1422
+ 8,
1423
+ 10,
1424
+ 12
1425
+ ].map((x) => [x, 5])).dots("K", [
1426
+ 3,
1427
+ 5,
1428
+ 7,
1429
+ 9,
1430
+ 11,
1431
+ 13
1432
+ ].map((x) => [x, 7])).dots("K", [
1433
+ [2, 9],
1434
+ [4, 9],
1435
+ [12, 9]
1436
+ ]).hline(6, 9, 5, "K").hline(1, 11, 14, "q").outline().rows();
1437
+ var printer = new Draw(16, 16).rect(5, 1, 6, 4, "P").hline(6, 2, 4, "p").rect(2, 5, 12, 6, "p").hline(2, 5, 12, "l").px(12, 7, "g").px(10, 7, "K").hline(4, 8, 8, "M").rect(2, 11, 12, 2, "q").rect(4, 9, 8, 5, "P").hline(5, 10, 5, "q").hline(5, 12, 4, "q").outline().rows();
1438
+ var serverRack = (() => {
1439
+ const board = new Draw(16, 32).rect(2, 2, 12, 28, "M").hline(2, 2, 12, "m");
1440
+ const secondLight = [
1441
+ "g",
1442
+ "y",
1443
+ "g",
1444
+ "b",
1445
+ "g",
1446
+ "g"
1447
+ ];
1448
+ [
1449
+ 4,
1450
+ 8,
1451
+ 12,
1452
+ 16,
1453
+ 20,
1454
+ 24
1455
+ ].forEach((y, index) => {
1456
+ board.rect(3, y, 10, 3, "m").px(4, y + 1, "g").px(6, y + 1, must(secondLight[index])).hline(8, y + 1, 4, "M");
1457
+ });
1458
+ return board.rect(3, 30, 2, 1, "x").rect(11, 30, 2, 1, "x").outline().rows();
1459
+ })();
1460
+ var coffeeMachine = new Draw(16, 24).rect(2, 2, 12, 19, "m").rect(2, 2, 12, 3, "M").rect(4, 6, 5, 3, "S").hline(5, 7, 2, "g").px(11, 6, "b").px(11, 8, "g").rect(4, 11, 8, 8, "M").rect(7, 11, 2, 2, "K").rect(6, 15, 4, 4, "P").hline(6, 15, 4, "k").vline(10, 16, 2, "P").rect(3, 19, 10, 1, "K").rect(2, 20, 12, 2, "M").outline().rows();
1461
+ var waterCooler = new Draw(16, 32).rect(6, 1, 4, 1, "C").rect(5, 2, 6, 9, "c").rect(5, 2, 6, 2, "L").vline(6, 4, 6, "1").vline(10, 4, 7, "C").rect(6, 11, 4, 1, "H").rect(3, 12, 10, 17, "P").hline(3, 12, 10, "1").vline(12, 13, 16, "p").rect(5, 15, 6, 5, "p").px(6, 17, "H").px(9, 17, "b").rect(5, 21, 6, 1, "K").rect(5, 22, 6, 1, "q").rect(3, 29, 2, 1, "m").rect(11, 29, 2, 1, "m").outline().rows();
1462
+ var TECH = [
1463
+ make("monitor", "Monitor", ["tech"], monitor),
1464
+ make("laptop", "Laptop", ["tech"], laptop),
1465
+ make("keyboard", "Keyboard", ["tech"], keyboard),
1466
+ make("printer", "Printer", ["tech"], printer),
1467
+ make("server-rack", "Server rack", ["tech"], serverRack),
1468
+ make("coffee-machine", "Coffee machine", ["tech", "kitchen"], coffeeMachine),
1469
+ make("water-cooler", "Water cooler", ["kitchen"], waterCooler)
1470
+ ];
1471
+ // packages/pixel/src/library/index.ts
1472
+ var designer = {
1473
+ ...buildCharacter({
1474
+ skin: "#d9a066",
1475
+ hairStyle: "long",
1476
+ hairColour: "#d77bba",
1477
+ top: "t-shirt",
1478
+ topColour: "#3b3f52",
1479
+ bottom: "trousers",
1480
+ bottomColour: "#7f8a99",
1481
+ shoeColour: "#dfe6f0",
1482
+ accessory: "glasses",
1483
+ accent: "#5fcde4"
1484
+ }),
1485
+ id: "designer",
1486
+ name: "Designer",
1487
+ tags: ["character"]
1488
+ };
1489
+ var manager = {
1490
+ ...buildCharacter({
1491
+ skin: "#b97a45",
1492
+ hairStyle: "short",
1493
+ hairColour: "#9badb7",
1494
+ top: "shirt-and-tie",
1495
+ topColour: "#f4f4f4",
1496
+ bottom: "trousers",
1497
+ bottomColour: "#3b3f52",
1498
+ shoeColour: "#262b3d",
1499
+ accessory: "none",
1500
+ accent: "#d95763"
1501
+ }),
1502
+ id: "manager",
1503
+ name: "Manager",
1504
+ tags: ["character"]
1505
+ };
1506
+ /** The tech office sprite set: furniture, tech, decor, tiles and characters in one shared palette. */
1507
+ var SPRITES = [
1508
+ ...FURNITURE,
1509
+ ...TECH,
1510
+ ...DECOR,
1511
+ ...STRUCTURE,
1512
+ ...PEOPLE,
1513
+ ...MORE_SPRITES,
1514
+ designer,
1515
+ manager
1516
+ ];
1517
+ /** Walk and idle animations for the designer and the manager. */
1518
+ var SPRITE_ANIMATIONS = [...animateCharacter(designer), ...animateCharacter(manager)];
1519
+ function findSprite(id) {
1520
+ return SPRITES.find((sprite) => sprite.id === id);
1521
+ }
1522
+ function findAnimation(id) {
1523
+ return SPRITE_ANIMATIONS.find((animation) => animation.id === id);
1524
+ }
1525
+ // packages/pixel/src/render.ts
1526
+ function createBitmap(width, height) {
1527
+ return {
1528
+ width,
1529
+ height,
1530
+ data: new Uint8ClampedArray(width * height * 4)
1531
+ };
1532
+ }
1533
+ function parseHex(color) {
1534
+ return [
1535
+ parseInt(color.slice(1, 3), 16),
1536
+ parseInt(color.slice(3, 5), 16),
1537
+ parseInt(color.slice(5, 7), 16)
1538
+ ];
1539
+ }
1540
+ /** Draws a sprite onto a bitmap. Each sprite pixel becomes a `scale` by `scale` block. */
1541
+ function drawSprite(target, sprite, left = 0, top = 0, scale = 1) {
1542
+ const colors = new Map(Object.entries(sprite.palette).map(([char, color]) => [char, parseHex(color)]));
1543
+ sprite.rows.forEach((row, y) => {
1544
+ [...row].forEach((char, x) => {
1545
+ if (char === ".") return;
1546
+ const color = colors.get(char);
1547
+ if (!color) throw new Error(`${sprite.id}: no palette entry for '${char}'`);
1548
+ for (let dy = 0; dy < scale; dy++) for (let dx = 0; dx < scale; dx++) {
1549
+ const px = left + x * scale + dx;
1550
+ const py = top + y * scale + dy;
1551
+ if (px < 0 || py < 0 || px >= target.width || py >= target.height) continue;
1552
+ target.data.set([...color, 255], (py * target.width + px) * 4);
1553
+ }
1554
+ });
1555
+ });
1556
+ }
1557
+ /** A sprite as pixels, enlarged by a whole-number scale. */
1558
+ function renderSprite(sprite, scale = 1) {
1559
+ if (!Number.isInteger(scale) || scale < 1) throw new Error(`Scale must be a whole number of 1 or more, got ${scale}`);
1560
+ const bitmap = createBitmap(spriteWidth(sprite) * scale, spriteHeight(sprite) * scale);
1561
+ drawSprite(bitmap, sprite, 0, 0, scale);
1562
+ return bitmap;
1563
+ }
1564
+ // packages/pixel/src/sheet.ts
1565
+ /**
1566
+ * Packs sprites onto one image, tallest first, in rows no wider than `maxWidth`,
1567
+ * with `gap` clear pixels between them so neighbours never bleed when scaled.
1568
+ */
1569
+ function packSheet(sprites, maxWidth = 128, gap = 1) {
1570
+ const ordered = [...sprites].sort((a, b) => spriteHeight(b) - spriteHeight(a) || spriteWidth(b) - spriteWidth(a) || a.id.localeCompare(b.id));
1571
+ const frames = {};
1572
+ let x = 0;
1573
+ let y = 0;
1574
+ let rowHeight = 0;
1575
+ let sheetWidth = 0;
1576
+ for (const sprite of ordered) {
1577
+ const width = spriteWidth(sprite);
1578
+ const height = spriteHeight(sprite);
1579
+ if (x > 0 && x + width > maxWidth) {
1580
+ x = 0;
1581
+ y += rowHeight + gap;
1582
+ rowHeight = 0;
1583
+ }
1584
+ frames[sprite.id] = {
1585
+ x,
1586
+ y,
1587
+ width,
1588
+ height
1589
+ };
1590
+ x += width + gap;
1591
+ rowHeight = Math.max(rowHeight, height);
1592
+ sheetWidth = Math.max(sheetWidth, x - gap);
1593
+ }
1594
+ const bitmap = createBitmap(sheetWidth, y + rowHeight);
1595
+ for (const sprite of ordered) drawSprite(bitmap, sprite, must(frames[sprite.id]).x, must(frames[sprite.id]).y);
1596
+ return {
1597
+ bitmap,
1598
+ frames
1599
+ };
1600
+ }
1601
+ // packages/pixel/src/recolor.ts
1602
+ /** A copy of the sprite with some palette entries replaced. Unknown characters are ignored. */
1603
+ function recolour(sprite, changes) {
1604
+ const palette = { ...sprite.palette };
1605
+ for (const [char, colour] of Object.entries(changes)) if (char in palette) palette[char] = colour.toLowerCase();
1606
+ return {
1607
+ ...sprite,
1608
+ palette
1609
+ };
1610
+ }
1611
+ /** A copy of the sprite with every colour passed through `change`. */
1612
+ function mapPalette(sprite, change) {
1613
+ return {
1614
+ ...sprite,
1615
+ palette: Object.fromEntries(Object.entries(sprite.palette).map(([char, colour]) => [char, change(colour)]))
1616
+ };
1617
+ }
1618
+ /** Rotates every colour around the colour wheel. Greys stay grey. */
1619
+ function shiftHue(sprite, degrees) {
1620
+ if (degrees % 360 === 0) return sprite;
1621
+ return mapPalette(sprite, (colour) => {
1622
+ const [hue, saturation, lightness] = toHsl(colour);
1623
+ return fromHsl(hue + degrees, saturation, lightness);
1624
+ });
1625
+ }
1626
+ /** Picks the ramp colour that matches a colour's brightness. The ramp runs dark to light. */
1627
+ var onRamp = (ramp) => (colour) => must(ramp[Math.min(ramp.length - 1, Math.floor(brightness(colour) * ramp.length))]);
1628
+ var RECOLOUR_PRESETS = [
1629
+ {
1630
+ id: "greyscale",
1631
+ name: "Greyscale",
1632
+ apply: (colour) => {
1633
+ const level = brightness(colour) * 255;
1634
+ return toHex([
1635
+ level,
1636
+ level,
1637
+ level
1638
+ ]);
1639
+ }
1640
+ },
1641
+ {
1642
+ id: "handheld",
1643
+ name: "Handheld",
1644
+ apply: onRamp([
1645
+ "#0f380f",
1646
+ "#306230",
1647
+ "#8bac0f",
1648
+ "#9bbc0f"
1649
+ ])
1650
+ },
1651
+ {
1652
+ id: "night",
1653
+ name: "Night",
1654
+ apply: (colour) => mix(colour, "#1a1c3a", .45)
1655
+ },
1656
+ {
1657
+ id: "sunset",
1658
+ name: "Sunset",
1659
+ apply: onRamp([
1660
+ "#2d1b3d",
1661
+ "#7a2e4d",
1662
+ "#c8553d",
1663
+ "#f28f3b",
1664
+ "#ffd07b",
1665
+ "#fff4d6"
1666
+ ])
1667
+ },
1668
+ {
1669
+ id: "blueprint",
1670
+ name: "Blueprint",
1671
+ apply: onRamp([
1672
+ "#0b2a5b",
1673
+ "#1d4e9e",
1674
+ "#5b9bea",
1675
+ "#d6e8ff"
1676
+ ])
1677
+ }
1678
+ ];
1679
+ // packages/pixel/src/pixelate.ts
1680
+ /** One character per palette entry. Sixty-two is the most colours a sprite can hold. */
1681
+ var ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1682
+ var MAX_COLOURS = 62;
1683
+ var FIXED_PALETTES = [
1684
+ {
1685
+ id: "house",
1686
+ name: "House palette",
1687
+ colours: [...new Set(Object.values(HOUSE_PALETTE))]
1688
+ },
1689
+ {
1690
+ id: "handheld",
1691
+ name: "Handheld green",
1692
+ colours: [
1693
+ "#0f380f",
1694
+ "#306230",
1695
+ "#8bac0f",
1696
+ "#9bbc0f"
1697
+ ]
1698
+ },
1699
+ {
1700
+ id: "grey",
1701
+ name: "Four greys",
1702
+ colours: [
1703
+ "#1a1a1a",
1704
+ "#6b6b6b",
1705
+ "#b5b5b5",
1706
+ "#f4f4f4"
1707
+ ]
1708
+ },
1709
+ {
1710
+ id: "ink",
1711
+ name: "Black and white",
1712
+ colours: ["#1d1b26", "#faf8f3"]
1713
+ }
1714
+ ];
1715
+ /** The size of the result for a source image, keeping its shape and never rounding a side to zero. */
1716
+ function fitSize(sourceWidth, sourceHeight, size) {
1717
+ const scale = size / Math.max(sourceWidth, sourceHeight);
1718
+ return [Math.max(1, Math.round(sourceWidth * scale)), Math.max(1, Math.round(sourceHeight * scale))];
1719
+ }
1720
+ /** Shrinks a bitmap by averaging each block of source pixels, weighted by how opaque they are. */
1721
+ function shrink(source, width, height) {
1722
+ const cells = [];
1723
+ for (let y = 0; y < height; y++) {
1724
+ const top = Math.floor(y * source.height / height);
1725
+ const bottom = Math.max(top + 1, Math.floor((y + 1) * source.height / height));
1726
+ for (let x = 0; x < width; x++) {
1727
+ const left = Math.floor(x * source.width / width);
1728
+ const right = Math.max(left + 1, Math.floor((x + 1) * source.width / width));
1729
+ let r = 0;
1730
+ let g = 0;
1731
+ let b = 0;
1732
+ let alpha = 0;
1733
+ for (let sy = top; sy < bottom; sy++) for (let sx = left; sx < right; sx++) {
1734
+ const i = (sy * source.width + sx) * 4;
1735
+ const a = must(source.data[i + 3]);
1736
+ r += must(source.data[i]) * a;
1737
+ g += must(source.data[i + 1]) * a;
1738
+ b += must(source.data[i + 2]) * a;
1739
+ alpha += a;
1740
+ }
1741
+ const count = (bottom - top) * (right - left);
1742
+ cells.push(alpha / count < 128 ? null : [
1743
+ r / alpha,
1744
+ g / alpha,
1745
+ b / alpha
1746
+ ]);
1747
+ }
1748
+ }
1749
+ return cells;
1750
+ }
1751
+ /** Finds up to `count` colours that represent the pixels well, by repeatedly splitting the widest group. */
1752
+ function findPalette(pixels, count) {
1753
+ if (pixels.length === 0) return [];
1754
+ let groups = [pixels];
1755
+ while (groups.length < count) {
1756
+ let widest = -1;
1757
+ let channel = 0;
1758
+ let spread = 0;
1759
+ groups.forEach((group, index) => {
1760
+ for (const c of [
1761
+ 0,
1762
+ 1,
1763
+ 2
1764
+ ]) {
1765
+ let min = 255;
1766
+ let max = 0;
1767
+ for (const pixel of group) {
1768
+ if (pixel[c] < min) min = pixel[c];
1769
+ if (pixel[c] > max) max = pixel[c];
1770
+ }
1771
+ if (max - min > spread) {
1772
+ spread = max - min;
1773
+ widest = index;
1774
+ channel = c;
1775
+ }
1776
+ }
1777
+ });
1778
+ if (widest < 0) break;
1779
+ const along = channel;
1780
+ const sorted = [...must(groups[widest])].sort((a, b) => a[along] - b[along]);
1781
+ const value = (index) => must(sorted[index])[along];
1782
+ let cut = Math.floor(sorted.length / 2);
1783
+ while (cut < sorted.length - 1 && value(cut) === value(cut - 1)) cut++;
1784
+ if (value(cut) === value(cut - 1)) {
1785
+ cut = Math.floor(sorted.length / 2);
1786
+ while (cut > 1 && value(cut) === value(cut - 1)) cut--;
1787
+ }
1788
+ groups = [
1789
+ ...groups.slice(0, widest),
1790
+ sorted.slice(0, cut),
1791
+ sorted.slice(cut),
1792
+ ...groups.slice(widest + 1)
1793
+ ];
1794
+ }
1795
+ const colours = groups.map((group) => {
1796
+ const sum = group.reduce((total, pixel) => [
1797
+ total[0] + pixel[0],
1798
+ total[1] + pixel[1],
1799
+ total[2] + pixel[2]
1800
+ ], [
1801
+ 0,
1802
+ 0,
1803
+ 0
1804
+ ]);
1805
+ return toHex([
1806
+ sum[0] / group.length,
1807
+ sum[1] / group.length,
1808
+ sum[2] / group.length
1809
+ ]);
1810
+ });
1811
+ return [...new Set(colours)];
1812
+ }
1813
+ /** Index of the palette colour closest to a colour, weighting channels roughly as the eye does. */
1814
+ function nearest(colour, palette) {
1815
+ let best = 0;
1816
+ let bestDistance = Infinity;
1817
+ palette.forEach((candidate, index) => {
1818
+ const distance = 3 * (colour[0] - candidate[0]) ** 2 + 4 * (colour[1] - candidate[1]) ** 2 + 2 * (colour[2] - candidate[2]) ** 2;
1819
+ if (distance < bestDistance) {
1820
+ bestDistance = distance;
1821
+ best = index;
1822
+ }
1823
+ });
1824
+ return best;
1825
+ }
1826
+ var BAYER = [
1827
+ 0,
1828
+ 8,
1829
+ 2,
1830
+ 10,
1831
+ 12,
1832
+ 4,
1833
+ 14,
1834
+ 6,
1835
+ 3,
1836
+ 11,
1837
+ 1,
1838
+ 9,
1839
+ 15,
1840
+ 7,
1841
+ 13,
1842
+ 5
1843
+ ].map((value) => value / 16 - .5 + 1 / 32);
1844
+ /** Converts a bitmap into a sprite. */
1845
+ function pixelate(source, options) {
1846
+ const [width, height] = fitSize(source.width, source.height, options.size);
1847
+ const cells = shrink(source, width, height);
1848
+ const solid = cells.filter((cell) => cell !== null);
1849
+ const wanted = typeof options.palette === "number" ? findPalette(solid, Math.min(options.palette, 62)) : options.palette;
1850
+ const colours = [...new Set(wanted.map((colour) => colour.toLowerCase()))].slice(0, 62);
1851
+ if (colours.length === 0) colours.push("#000000");
1852
+ const rgb = colours.map(toRgb);
1853
+ const dither = options.dither ?? "none";
1854
+ const strength = 255 / Math.max(2, Math.cbrt(colours.length) * 1.5);
1855
+ const work = cells.map((cell) => cell ? [...cell] : null);
1856
+ const picks = [];
1857
+ for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
1858
+ const cell = work[y * width + x];
1859
+ if (!cell) {
1860
+ picks.push(null);
1861
+ continue;
1862
+ }
1863
+ const offset = dither === "ordered" ? must(BAYER[y % 4 * 4 + x % 4]) * strength : 0;
1864
+ const index = nearest([
1865
+ cell[0] + offset,
1866
+ cell[1] + offset,
1867
+ cell[2] + offset
1868
+ ], rgb);
1869
+ picks.push(index);
1870
+ if (dither === "diffusion") {
1871
+ const chosen = must(rgb[index]);
1872
+ const error = [
1873
+ cell[0] - chosen[0],
1874
+ cell[1] - chosen[1],
1875
+ cell[2] - chosen[2]
1876
+ ];
1877
+ for (const [dx, dy, share] of [
1878
+ [
1879
+ 1,
1880
+ 0,
1881
+ 7 / 16
1882
+ ],
1883
+ [
1884
+ -1,
1885
+ 1,
1886
+ 3 / 16
1887
+ ],
1888
+ [
1889
+ 0,
1890
+ 1,
1891
+ 5 / 16
1892
+ ],
1893
+ [
1894
+ 1,
1895
+ 1,
1896
+ 1 / 16
1897
+ ]
1898
+ ]) {
1899
+ const nx = x + dx;
1900
+ const ny = y + dy;
1901
+ if (nx < 0 || nx >= width || ny >= height) continue;
1902
+ const neighbour = work[ny * width + nx];
1903
+ if (neighbour) for (const c of [
1904
+ 0,
1905
+ 1,
1906
+ 2
1907
+ ]) neighbour[c] += error[c] * share;
1908
+ }
1909
+ }
1910
+ }
1911
+ const used = [...new Set(picks.filter((pick) => pick !== null))].sort((a, b) => a - b);
1912
+ const charFor = new Map(used.map((index, position) => [index, must(ALPHABET[position])]));
1913
+ const rows = Array.from({ length: height }, (_, y) => picks.slice(y * width, (y + 1) * width).map((pick) => pick === null ? "." : must(charFor.get(pick))).join(""));
1914
+ return {
1915
+ id: "pixel-art",
1916
+ name: "Pixel art",
1917
+ tags: ["generated"],
1918
+ palette: Object.fromEntries(used.map((index) => [must(charFor.get(index)), must(colours[index])])),
1919
+ rows
1920
+ };
1921
+ }
1922
+ // packages/pixel/src/procedural.ts
1923
+ /**
1924
+ * Rule-based generators. Each takes a seed and always returns the same sprite for
1925
+ * the same seed, so a result can be found again from its number.
1926
+ */
1927
+ /** A repeatable source of random numbers from 0 up to, but not including, 1. */
1928
+ function createRandom(seed) {
1929
+ let state = seed >>> 0;
1930
+ return () => {
1931
+ state = state + 1831565813 >>> 0;
1932
+ let t = state;
1933
+ t = Math.imul(t ^ t >>> 15, t | 1);
1934
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
1935
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
1936
+ };
1937
+ }
1938
+ /** Combines a seed with a second number so different generators never share a sequence. */
1939
+ var mixSeed = (seed, salt) => (Math.imul(seed >>> 0, 2654435761) ^ Math.imul(salt + 1, 40503)) >>> 0;
1940
+ var SIZE = 16;
1941
+ var OUTLINE = "#2b2233";
1942
+ var pickFrom = (random, items) => must(items[Math.floor(random() * items.length)]);
1943
+ var between = (random, low, high) => low + random() * (high - low);
1944
+ var whole = (random, low, high) => low + Math.floor(random() * (high - low + 1));
1945
+ function finish(id, name, tags, rows, colours) {
1946
+ return {
1947
+ id,
1948
+ name,
1949
+ tags: [...tags, "generated"],
1950
+ rows,
1951
+ palette: paletteFor(rows, colours)
1952
+ };
1953
+ }
1954
+ var emptyCells = () => Array.from({ length: SIZE }, () => Array(SIZE).fill(false));
1955
+ /** Whether a cell is filled. Anything outside the grid counts as empty. */
1956
+ var filled = (cells, x, y) => cells[y]?.[x] ?? false;
1957
+ function fill(cells, x, y, value) {
1958
+ const row = cells[y];
1959
+ if (row && x >= 0 && x < SIZE) row[x] = value;
1960
+ }
1961
+ /** One attempt at a creature. Returns null when the shape came out too small to read. */
1962
+ function tryCreature(random) {
1963
+ const alive = emptyCells();
1964
+ for (let y = 1; y <= 14; y++) for (let x = 1; x <= 7; x++) {
1965
+ const towardsCentre = (x - 1) / 6;
1966
+ const towardsMiddle = 1 - ((y - 7.5) / 7) ** 2;
1967
+ fill(alive, x, y, random() < .12 + .6 * towardsCentre * towardsMiddle + .15 * towardsMiddle);
1968
+ }
1969
+ const at = (x, y) => y < 1 || y > 14 || x < 1 ? false : filled(alive, Math.min(x, 15 - x), y);
1970
+ const smooth = alive.map((row, y) => row.map((cell, x) => {
1971
+ if (y < 1 || y > 14 || x < 1 || x > 7) return false;
1972
+ let neighbours = 0;
1973
+ for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++) if ((dx || dy) && at(x + dx, y + dy)) neighbours++;
1974
+ return neighbours >= 5 || cell && neighbours >= 2;
1975
+ }));
1976
+ const eyeRow = whole(random, 5, 7);
1977
+ for (let y = eyeRow - 1; y <= eyeRow + 1; y++) for (let x = 4; x <= 7; x++) fill(smooth, x, y, true);
1978
+ for (let y = 0; y < SIZE; y++) for (let x = 8; x < SIZE; x++) fill(smooth, x, y, filled(smooth, 15 - x, y));
1979
+ const body = emptyCells();
1980
+ const queue = [[7, eyeRow]];
1981
+ let cells = 0;
1982
+ while (queue.length) {
1983
+ const next = queue.pop();
1984
+ if (!next) break;
1985
+ const [x, y] = next;
1986
+ if (x < 0 || y < 0 || x >= SIZE || y >= SIZE) continue;
1987
+ if (filled(body, x, y) || !filled(smooth, x, y)) continue;
1988
+ fill(body, x, y, true);
1989
+ cells++;
1990
+ queue.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
1991
+ }
1992
+ if (cells < 44) return null;
1993
+ const board = new Draw(SIZE, SIZE);
1994
+ for (let y = 0; y < SIZE; y++) for (let x = 0; x < SIZE; x++) {
1995
+ if (!filled(body, x, y)) continue;
1996
+ const openBelow = !filled(body, x, y + 1);
1997
+ const openAbove = !filled(body, x, y - 1);
1998
+ board.px(x, y, openBelow ? "s" : openAbove && y < 8 ? "h" : "b");
1999
+ }
2000
+ board.dots("w", [[5, eyeRow], [10, eyeRow]]).dots("p", [[6, eyeRow], [9, eyeRow]]);
2001
+ if (random() < .5 && body[eyeRow + 2]?.[7]) board.dots("p", [[7, eyeRow + 2], [8, eyeRow + 2]]);
2002
+ return board.outline().rows();
2003
+ }
2004
+ /** A symmetric little monster. */
2005
+ function generateCreature(seed) {
2006
+ for (let attempt = 0; attempt < 50; attempt++) {
2007
+ const random = createRandom(mixSeed(seed, 100 + attempt));
2008
+ const rows = tryCreature(random);
2009
+ if (!rows) continue;
2010
+ const hue = random() * 360;
2011
+ const saturation = between(random, .45, .75);
2012
+ return finish("creature", "Creature", ["creature"], rows, {
2013
+ o: OUTLINE,
2014
+ b: fromHsl(hue, saturation, .55),
2015
+ s: fromHsl(hue - 20, saturation, .38),
2016
+ h: fromHsl(hue + 20, saturation, .72),
2017
+ w: "#ffffff",
2018
+ p: "#222034"
2019
+ });
2020
+ }
2021
+ return finish("creature", "Creature", ["creature"], new Draw(SIZE, SIZE).disc(8, 8, 5, "b").outline().rows(), {
2022
+ o: OUTLINE,
2023
+ b: "#5b6ee1"
2024
+ });
2025
+ }
2026
+ /** True where a pixel of the drawing touches empty space, counting only up, down, left and right. */
2027
+ var onEdge = (board, x, y) => [
2028
+ board.get(x - 1, y),
2029
+ board.get(x + 1, y),
2030
+ board.get(x, y - 1),
2031
+ board.get(x, y + 1)
2032
+ ].includes(".");
2033
+ function potion(random) {
2034
+ const board = new Draw(SIZE, SIZE);
2035
+ const shape = pickFrom(random, [
2036
+ "round",
2037
+ "square",
2038
+ "flask"
2039
+ ]);
2040
+ if (shape === "round") board.disc(8, 10, 4.6, "g");
2041
+ if (shape === "square") board.rect(4, 6, 8, 9, "g");
2042
+ if (shape === "flask") for (let y = 6; y <= 14; y++) board.hline(7 - Math.floor((y - 6) / 2), y, 2 + Math.floor((y - 6) / 2) * 2, "g");
2043
+ const level = whole(random, 8, 10);
2044
+ const liquid = [];
2045
+ for (let y = level; y < SIZE; y++) for (let x = 0; x < SIZE; x++) if (board.get(x, y) === "g" && !onEdge(board, x, y)) liquid.push([x, y]);
2046
+ board.dots("l", liquid);
2047
+ board.dots("d", liquid.filter(([x, y]) => board.get(x, y + 1) !== "l"));
2048
+ board.dots("t", liquid.filter(([, y]) => y === level));
2049
+ board.rect(7, 3, 2, 4, "g").rect(6, 3, 4, 1, "g").rect(7, 1, 2, 2, "c").px(6, 9, "1");
2050
+ const hue = random() * 360;
2051
+ return {
2052
+ rows: board.outline().rows(),
2053
+ colours: {
2054
+ o: OUTLINE,
2055
+ g: "#dfe6f0",
2056
+ c: "#b97a45",
2057
+ "1": "#ffffff",
2058
+ l: fromHsl(hue, .7, .55),
2059
+ d: fromHsl(hue, .7, .4),
2060
+ t: fromHsl(hue, .8, .75)
2061
+ }
2062
+ };
2063
+ }
2064
+ function gem(random) {
2065
+ const board = new Draw(SIZE, SIZE);
2066
+ const shape = pickFrom(random, [
2067
+ "diamond",
2068
+ "cut",
2069
+ "round"
2070
+ ]);
2071
+ for (let y = 0; y < SIZE; y++) for (let x = 0; x < SIZE; x++) {
2072
+ const dx = Math.abs(x + .5 - 8);
2073
+ const dy = Math.abs(y + .5 - 8);
2074
+ if (!(shape === "diamond" ? dx + dy <= 6.5 : shape === "cut" ? dx <= 5 && dy <= 6 && dx + dy <= 8.5 : dx * dx + dy * dy <= 5.6 * 5.6)) continue;
2075
+ const band = x + y - 15;
2076
+ board.px(x, y, band < -4 ? "h" : band > 3 ? "s" : "b");
2077
+ }
2078
+ board.px(6, 5, "1").px(5, 6, "1");
2079
+ const hue = random() * 360;
2080
+ return {
2081
+ rows: board.outline().rows(),
2082
+ colours: {
2083
+ o: OUTLINE,
2084
+ "1": "#ffffff",
2085
+ h: fromHsl(hue, .75, .75),
2086
+ b: fromHsl(hue, .75, .55),
2087
+ s: fromHsl(hue - 15, .75, .38)
2088
+ }
2089
+ };
2090
+ }
2091
+ function sword(random) {
2092
+ const board = new Draw(SIZE, SIZE);
2093
+ const length = whole(random, 7, 9);
2094
+ for (let i = 0; i < length; i++) board.px(13 - i, 2 + i, "h").px(12 - i, 2 + i, "b").px(13 - i, 3 + i, "b");
2095
+ board.px(13, 2, "h");
2096
+ const gx = 12 - length;
2097
+ const gy = 2 + length;
2098
+ const guard = whole(random, 1, 2);
2099
+ for (let k = -guard; k <= guard; k++) board.px(gx + k, gy + k, "g").px(gx + k + 1, gy + k, "g");
2100
+ for (let j = 1; j <= 2; j++) board.px(gx - j, gy + j, "k");
2101
+ board.px(gx - 3, gy + 3, "g");
2102
+ const tinted = random() < .45;
2103
+ const hue = random() * 360;
2104
+ const metal = pickFrom(random, [
2105
+ ["#fbf236", "#e8b930"],
2106
+ ["#dfe6f0", "#9badb7"],
2107
+ ["#d9a066", "#b97a45"]
2108
+ ]);
2109
+ return {
2110
+ rows: board.outline().rows(),
2111
+ colours: {
2112
+ o: OUTLINE,
2113
+ h: tinted ? fromHsl(hue, .6, .85) : "#ffffff",
2114
+ b: tinted ? fromHsl(hue, .6, .65) : "#b8c4d6",
2115
+ g: metal[1],
2116
+ k: pickFrom(random, [
2117
+ "#663931",
2118
+ "#ac3232",
2119
+ "#3f3f74",
2120
+ "#37946e"
2121
+ ])
2122
+ }
2123
+ };
2124
+ }
2125
+ function shield(random) {
2126
+ const board = new Draw(SIZE, SIZE);
2127
+ [
2128
+ 5,
2129
+ 5,
2130
+ 5,
2131
+ 5,
2132
+ 5,
2133
+ 5,
2134
+ 5,
2135
+ 4,
2136
+ 4,
2137
+ 3,
2138
+ 2,
2139
+ 1
2140
+ ].forEach((half, index) => board.hline(8 - half, 2 + index, half * 2, "a"));
2141
+ const emblem = pickFrom(random, [
2142
+ "stripe",
2143
+ "cross",
2144
+ "halves",
2145
+ "dot",
2146
+ "chevron",
2147
+ "band"
2148
+ ]);
2149
+ for (let y = 0; y < SIZE; y++) for (let x = 0; x < SIZE; x++) {
2150
+ if (board.get(x, y) !== "a") continue;
2151
+ const mirrored = Math.min(x, 15 - x);
2152
+ if (emblem === "stripe" ? mirrored === 7 : emblem === "cross" ? mirrored === 7 || y === 6 || y === 7 : emblem === "halves" ? x >= 8 : emblem === "dot" ? (x + .5 - 8) ** 2 + (y + .5 - 7) ** 2 <= 5 : emblem === "chevron" ? y - (7 - mirrored) === 4 || y - (7 - mirrored) === 5 : y >= 6 && y <= 8) board.px(x, y, "e");
2153
+ }
2154
+ const rim = [];
2155
+ for (let y = 0; y < SIZE; y++) for (let x = 0; x < SIZE; x++) if (board.get(x, y) !== "." && onEdge(board, x, y)) rim.push([x, y]);
2156
+ board.dots("m", rim);
2157
+ const hue = random() * 360;
2158
+ return {
2159
+ rows: board.outline().rows(),
2160
+ colours: {
2161
+ o: OUTLINE,
2162
+ m: "#9badb7",
2163
+ a: fromHsl(hue, .6, .5),
2164
+ e: pickFrom(random, [
2165
+ "#f4f4f4",
2166
+ "#fbf236",
2167
+ fromHsl(hue + 180, .6, .6)
2168
+ ])
2169
+ }
2170
+ };
2171
+ }
2172
+ function key(random) {
2173
+ const board = new Draw(SIZE, SIZE);
2174
+ if (random() < .5) board.disc(4.5, 8, 3.1, "g");
2175
+ else board.rect(2, 5, 5, 6, "g");
2176
+ board.rect(7, 7, 7, 2, "g").hline(7, 8, 7, "s");
2177
+ const teeth = whole(random, 2, 3);
2178
+ for (let i = 0; i < teeth; i++) board.vline(13 - i * 2, 9, whole(random, 1, 2), "s");
2179
+ const hue = random() * 360;
2180
+ const metal = random() < .5 ? pickFrom(random, [
2181
+ ["#fbf236", "#e8b930"],
2182
+ ["#dfe6f0", "#9badb7"],
2183
+ ["#d9a066", "#b97a45"]
2184
+ ]) : [fromHsl(hue, .7, .65), fromHsl(hue, .7, .45)];
2185
+ const rows = board.outline().rows();
2186
+ return {
2187
+ rows: new Draw(SIZE, SIZE).stamp(0, 0, rows).rect(4, 7, 1, 2, "o").rows(),
2188
+ colours: {
2189
+ o: OUTLINE,
2190
+ g: metal[0],
2191
+ s: metal[1]
2192
+ }
2193
+ };
2194
+ }
2195
+ var ITEM_MAKERS = {
2196
+ potion,
2197
+ gem,
2198
+ sword,
2199
+ shield,
2200
+ key
2201
+ };
2202
+ var ITEM_KINDS = [
2203
+ {
2204
+ id: "potion",
2205
+ name: "Potion"
2206
+ },
2207
+ {
2208
+ id: "gem",
2209
+ name: "Gem"
2210
+ },
2211
+ {
2212
+ id: "sword",
2213
+ name: "Sword"
2214
+ },
2215
+ {
2216
+ id: "shield",
2217
+ name: "Shield"
2218
+ },
2219
+ {
2220
+ id: "key",
2221
+ name: "Key"
2222
+ }
2223
+ ];
2224
+ /** A 16 by 16 inventory icon. */
2225
+ function generateItem(seed, kind) {
2226
+ const index = ITEM_KINDS.findIndex((item) => item.id === kind);
2227
+ if (index < 0) throw new Error(`Unknown item kind "${kind}"`);
2228
+ const made = ITEM_MAKERS[kind](createRandom(mixSeed(seed, 200 + index)));
2229
+ return finish(kind, must(ITEM_KINDS[index]).name, ["item"], made.rows, made.colours);
2230
+ }
2231
+ /** Rows of bricks, each row offset by half a brick. */
2232
+ var bricks = (random) => {
2233
+ const shades = Array.from({ length: 8 }, () => pickFrom(random, [
2234
+ "a",
2235
+ "a",
2236
+ "b",
2237
+ "c"
2238
+ ]));
2239
+ return (x, y) => {
2240
+ const row = Math.floor(y / 4);
2241
+ const along = (x + row % 2 * 4) % 16;
2242
+ if (y % 4 === 3 || along % 8 === 7) return "m";
2243
+ return must(shades[row * 2 + Math.floor(along / 8)]);
2244
+ };
2245
+ };
2246
+ /** Four long planks, each with one joint in a random place and a few streaks of grain. */
2247
+ var planks = (random) => {
2248
+ const joints = Array.from({ length: 4 }, () => whole(random, 0, 15));
2249
+ const shades = Array.from({ length: 4 }, () => pickFrom(random, [
2250
+ "a",
2251
+ "a",
2252
+ "c"
2253
+ ]));
2254
+ const grain = /* @__PURE__ */ new Set();
2255
+ for (let i = 0; i < 6; i++) {
2256
+ const start = whole(random, 0, 15);
2257
+ const y = whole(random, 0, 3) * 4 + whole(random, 0, 2);
2258
+ const length = whole(random, 2, 4);
2259
+ for (let k = 0; k < length; k++) grain.add(`${(start + k) % 16},${y}`);
2260
+ }
2261
+ return (x, y) => {
2262
+ const row = Math.floor(y / 4);
2263
+ if (y % 4 === 3 || x === joints[row]) return "m";
2264
+ return grain.has(`${x},${y}`) ? "b" : must(shades[row]);
2265
+ };
2266
+ };
2267
+ /** Two colours in a checkerboard, with a few scuffs. */
2268
+ var checker = (random) => {
2269
+ const scuffs = new Set(Array.from({ length: 12 }, () => `${whole(random, 0, 15)},${whole(random, 0, 15)}`));
2270
+ return (x, y) => {
2271
+ const dark = (Math.floor(x / 8) + Math.floor(y / 8)) % 2 === 1;
2272
+ if (scuffs.has(`${x},${y}`)) return dark ? "m" : "b";
2273
+ return dark ? "c" : "a";
2274
+ };
2275
+ };
2276
+ /** Irregular stones: each pixel belongs to its nearest stone centre, measured around the edges. */
2277
+ var cobbles = (random) => {
2278
+ const centres = Array.from({ length: 7 }, () => [
2279
+ random() * 16,
2280
+ random() * 16,
2281
+ pickFrom(random, [
2282
+ "a",
2283
+ "a",
2284
+ "b",
2285
+ "c"
2286
+ ])
2287
+ ]);
2288
+ const stoneAt = (x, y) => {
2289
+ let best = 0;
2290
+ let bestDistance = Infinity;
2291
+ centres.forEach(([cx, cy], index) => {
2292
+ const dx = Math.min(Math.abs(x - cx), 16 - Math.abs(x - cx));
2293
+ const dy = Math.min(Math.abs(y - cy), 16 - Math.abs(y - cy));
2294
+ if (dx * dx + dy * dy < bestDistance) {
2295
+ bestDistance = dx * dx + dy * dy;
2296
+ best = index;
2297
+ }
2298
+ });
2299
+ return best;
2300
+ };
2301
+ return (x, y) => {
2302
+ const stone = stoneAt(x + .5, y + .5);
2303
+ return stone !== stoneAt((x + 1) % 16 + .5, y + .5) || stone !== stoneAt(x + .5, (y + 1) % 16 + .5) ? "m" : must(centres[stone])[2];
2304
+ };
2305
+ };
2306
+ /** A plain ground with scattered light and dark specks: grass, gravel or carpet. */
2307
+ var speckle = (random) => {
2308
+ const specks = /* @__PURE__ */ new Map();
2309
+ for (let i = 0; i < 44; i++) specks.set(`${whole(random, 0, 15)},${whole(random, 0, 15)}`, pickFrom(random, [
2310
+ "b",
2311
+ "c",
2312
+ "c"
2313
+ ]));
2314
+ return (x, y) => specks.get(`${x},${y}`) ?? "a";
2315
+ };
2316
+ var TILE_PAINTERS = {
2317
+ bricks,
2318
+ planks,
2319
+ checker,
2320
+ cobbles,
2321
+ speckle
2322
+ };
2323
+ var TILE_STYLES = [
2324
+ {
2325
+ id: "bricks",
2326
+ name: "Bricks"
2327
+ },
2328
+ {
2329
+ id: "planks",
2330
+ name: "Planks"
2331
+ },
2332
+ {
2333
+ id: "checker",
2334
+ name: "Checker"
2335
+ },
2336
+ {
2337
+ id: "cobbles",
2338
+ name: "Cobbles"
2339
+ },
2340
+ {
2341
+ id: "speckle",
2342
+ name: "Speckle"
2343
+ }
2344
+ ];
2345
+ /** A 16 by 16 floor tile that repeats without visible seams. */
2346
+ function generateTile(seed, style) {
2347
+ const index = TILE_STYLES.findIndex((tile) => tile.id === style);
2348
+ if (index < 0) throw new Error(`Unknown tile style "${style}"`);
2349
+ const random = createRandom(mixSeed(seed, 300 + index));
2350
+ const paint = TILE_PAINTERS[style](random);
2351
+ const rows = Array.from({ length: SIZE }, (_, y) => Array.from({ length: SIZE }, (_, x) => paint(x, y)).join(""));
2352
+ const hue = random() * 360;
2353
+ const saturation = between(random, .15, .5);
2354
+ const lightness = between(random, .4, .62);
2355
+ return finish(`${style}-tile`, `${must(TILE_STYLES[index]).name} tile`, ["tile"], rows, {
2356
+ a: fromHsl(hue, saturation, lightness),
2357
+ b: fromHsl(hue, saturation, lightness + .07),
2358
+ c: fromHsl(hue, saturation, lightness - .07),
2359
+ m: fromHsl(hue, saturation * .8, lightness - .2)
2360
+ });
2361
+ }
2362
+ /** A sprite repeated across and down, for checking that a tile joins up with itself. */
2363
+ function repeatSprite(sprite, across, down) {
2364
+ const rows = Array.from({ length: down }, () => sprite.rows.map((row) => row.repeat(across))).flat();
2365
+ return {
2366
+ ...sprite,
2367
+ rows
2368
+ };
2369
+ }
2370
+ // packages/pixel/src/font.ts
2371
+ /**
2372
+ * A small capital-letter pixel font, five pixels wide and seven tall, for drawing
2373
+ * a few words into an image without loading a font file.
2374
+ */
2375
+ var GLYPHS = {
2376
+ A: ".###. #...# #...# ##### #...# #...# #...#",
2377
+ B: "####. #...# #...# ####. #...# #...# ####.",
2378
+ C: ".#### #.... #.... #.... #.... #.... .####",
2379
+ D: "####. #...# #...# #...# #...# #...# ####.",
2380
+ E: "##### #.... #.... ####. #.... #.... #####",
2381
+ F: "##### #.... #.... ####. #.... #.... #....",
2382
+ G: ".#### #.... #.... #.### #...# #...# .####",
2383
+ H: "#...# #...# #...# ##### #...# #...# #...#",
2384
+ I: "##### ..#.. ..#.. ..#.. ..#.. ..#.. #####",
2385
+ J: "..### ...#. ...#. ...#. ...#. #..#. .##..",
2386
+ K: "#...# #..#. #.#.. ##... #.#.. #..#. #...#",
2387
+ L: "#.... #.... #.... #.... #.... #.... #####",
2388
+ M: "#...# ##.## #.#.# #.#.# #...# #...# #...#",
2389
+ N: "#...# ##..# #.#.# #..## #...# #...# #...#",
2390
+ O: ".###. #...# #...# #...# #...# #...# .###.",
2391
+ P: "####. #...# #...# ####. #.... #.... #....",
2392
+ Q: ".###. #...# #...# #...# #.#.# #..#. .##.#",
2393
+ R: "####. #...# #...# ####. #.#.. #..#. #...#",
2394
+ S: ".#### #.... #.... .###. ....# ....# ####.",
2395
+ T: "##### ..#.. ..#.. ..#.. ..#.. ..#.. ..#..",
2396
+ U: "#...# #...# #...# #...# #...# #...# .###.",
2397
+ V: "#...# #...# #...# #...# #...# .#.#. ..#..",
2398
+ W: "#...# #...# #...# #.#.# #.#.# ##.## #...#",
2399
+ X: "#...# #...# .#.#. ..#.. .#.#. #...# #...#",
2400
+ Y: "#...# #...# .#.#. ..#.. ..#.. ..#.. ..#..",
2401
+ Z: "##### ....# ...#. ..#.. .#... #.... #####",
2402
+ " ": "..... ..... ..... ..... ..... ..... ....."
2403
+ };
2404
+ var FONT_HEIGHT = 7;
2405
+ /** A line of text as a one-colour sprite. Letters are capitalised; anything else becomes a space. */
2406
+ function textSprite(text, colour) {
2407
+ const letters = [...text.toUpperCase()].map((char) => must(GLYPHS[char] ?? GLYPHS[" "]).split(" "));
2408
+ const rows = Array.from({ length: 7 }, (_, y) => letters.map((glyph) => must(glyph[y]).replaceAll("#", "x")).join("."));
2409
+ return {
2410
+ id: "text",
2411
+ name: text,
2412
+ tags: ["text"],
2413
+ palette: { x: colour },
2414
+ rows
2415
+ };
2416
+ }
2417
+ export { ACCENT_COLOURS, ACCESSORIES, BOTTOMS, BOTTOM_COLOURS, DEFAULT_CHARACTER, Draw, FIXED_PALETTES, FONT_HEIGHT, HAIR_COLOURS, HAIR_STYLES, HOUSE_PALETTE, ITEM_KINDS, MAX_COLOURS, RECOLOUR_PRESETS, SHOE_COLOURS, SKIN_TONES, SPRITES, SPRITE_ANIMATIONS, TILE_STYLES, TOPS, TOP_COLOURS, TRANSPARENT, animateCharacter, animationFrame, animationStrip, brightness, buildCharacter, createBitmap, createRandom, darken, drawSprite, findAnimation, findPalette, findSprite, fitSize, fromHsl, generateCreature, generateItem, generateTile, idleFrames, mapPalette, mix, nearest, packSheet, paletteFor, pixelate, randomCharacter, recolour, renderSprite, repeatSprite, shiftHue, shrink, spriteHeight, spriteWidth, stack, textSprite, toHex, toHsl, toRgb, validateSprite, walkFrames };
2418
+
2419
+ //# sourceMappingURL=index.development.js.map