-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathart.py
More file actions
798 lines (682 loc) · 27.4 KB
/
Copy pathart.py
File metadata and controls
798 lines (682 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
"""Pixel art: palette, drawing primitives and scene illustrations.
Everything is drawn in code on a tiny LOW_W x LOW_H surface and then scaled up
without smoothing — that yields honest pixel art with no external image files.
"""
import math
import random
import pygame
# Resolution of the "real" image. Everything else is just magnification.
LOW_W, LOW_H = 192, 84
# Limited palette in the spirit of 16-color consoles.
PAL = {
"0": (5, 7, 13), # void
"1": (13, 20, 36), # very dark blue
"2": (24, 34, 56), # dark blue
"3": (39, 54, 79), # dark steel
"4": (61, 82, 115), # steel
"5": (95, 123, 163), # light steel
"6": (143, 168, 200), # gray-blue
"7": (207, 224, 242), # near white
"8": (242, 248, 255), # white
"c": (47, 212, 200), # teal
"C": (127, 245, 234), # bright teal
"d": (20, 131, 126), # dark teal
"a": (255, 179, 71), # amber
"A": (255, 217, 138), # bright amber
"b": (176, 106, 18), # dark amber
"r": (255, 77, 94), # red
"R": (255, 160, 168), # bright red
"e": (140, 31, 44), # dark red
"g": (109, 226, 109), # green
"G": (182, 245, 168), # bright green
"h": (47, 143, 74), # dark green
"p": (155, 93, 229), # purple
"m": (255, 110, 199), # magenta
"y": (247, 240, 106), # yellow
}
SKIP = " ." # characters a sprite leaves undrawn (transparency)
# --------------------------------------------------------------------------
# Primitives
# --------------------------------------------------------------------------
def new_surface():
return pygame.Surface((LOW_W, LOW_H))
def fill(s, c):
s.fill(PAL[c])
def px(s, x, y, c):
"""Sets one pixel, silently skipping anything off-surface or clipped out."""
# get_clip() matches the surface size until a clip is set, so a single
# check rejects both out-of-bounds pixels and ones outside the clip.
x, y = int(x), int(y)
if s.get_clip().collidepoint(x, y):
s.set_at((x, y), PAL[c])
def rect(s, x, y, w, h, c):
pygame.draw.rect(s, PAL[c], (int(x), int(y), int(w), int(h)))
def box(s, x, y, w, h, c):
pygame.draw.rect(s, PAL[c], (int(x), int(y), int(w), int(h)), 1)
def hline(s, x, y, w, c):
rect(s, x, y, w, 1, c)
def vline(s, x, y, h, c):
rect(s, x, y, 1, h, c)
def line(s, x1, y1, x2, y2, c):
pygame.draw.line(s, PAL[c], (int(x1), int(y1)), (int(x2), int(y2)))
def circle(s, x, y, r, c, width=0):
pygame.draw.circle(s, PAL[c], (int(x), int(y)), int(r), width)
def ellipse(s, x, y, w, h, c, width=0):
pygame.draw.ellipse(s, PAL[c], (int(x), int(y), int(w), int(h)), width)
def dither(s, x, y, w, h, c, density=0.5, seed=1):
"""Noise fill — fakes texture and half-tones."""
rnd = random.Random(seed)
for yy in range(int(y), int(y + h)):
for xx in range(int(x), int(x + w)):
if rnd.random() < density:
px(s, xx, yy, c)
def checker(s, x, y, w, h, c, step=2, phase=0):
"""Regular half-tone — a checkerboard every `step` pixels."""
for yy in range(int(y), int(y + h)):
for xx in range(int(x), int(x + w)):
if (xx + yy + phase) % step == 0:
px(s, xx, yy, c)
def vgrad(s, x, y, w, h, colors):
"""Vertical gradient in bands, top to bottom, over the list of colors."""
n = len(colors)
band = max(1, h // n)
for i, c in enumerate(colors):
top = y + i * band
bot = y + h if i == n - 1 else top + band
rect(s, x, top, w, bot - top, c)
# soft seam: dilute the border with pixels of the next color
if i + 1 < n:
dither(s, x, bot - 2, w, 2, colors[i + 1], 0.45, seed=100 + i)
def stars(s, x, y, w, h, count, seed=7, colors="678"):
"""Scatters single-pixel stars over a rectangle."""
rnd = random.Random(seed)
for _ in range(count):
px(s, rnd.randrange(int(x), int(x + w)), rnd.randrange(int(y), int(y + h)),
rnd.choice(colors))
def sprite(s, art, x, y):
"""Draws a sprite from a list of rows where each character is a palette key."""
for dy, row in enumerate(art):
for dx, ch in enumerate(row):
if ch not in SKIP:
px(s, x + dx, y + dy, ch)
def sprite_size(art):
return (max(len(r) for r in art), len(art))
# --------------------------------------------------------------------------
# Larger building blocks reused across several scenes
# --------------------------------------------------------------------------
def metal_wall(s, x, y, w, h, base="2", panel="3", seed=3):
"""Wall made of riveted panels."""
rect(s, x, y, w, h, base)
for py_ in range(int(y), int(y + h), 12):
for px_ in range(int(x), int(x + w), 16):
box(s, px_, py_, 16, 12, panel)
px(s, px_ + 2, py_ + 2, "4")
px(s, px_ + 13, py_ + 9, "1")
dither(s, x, y, w, h, "1", 0.06, seed)
def floor_grate(s, x, y, w, h, seed=5):
"""Grated floor with perspective lines."""
vgrad(s, x, y, w, h, ["2", "3", "3", "4"])
step = 4
for i, yy in enumerate(range(int(y), int(y + h), 2)):
hline(s, x, yy, w, "1" if i % 2 else "2")
cx = LOW_W // 2
for k in range(-6, 7):
line(s, cx + k * step, y, cx + k * step * 3, y + h, "1")
dither(s, x, y, w, h, "4", 0.05, seed)
def corridor_perspective(s, cx, horizon, color_far="1", color_near="3"):
"""Lines converging to a vanishing point — the illusion of a long corridor."""
for k in range(1, 9):
w = k * 22
h = k * 9
x = cx - w // 2
yy = horizon - h // 2
box(s, x, yy, w, h, color_far if k < 5 else color_near)
def door(s, x, y, w, h, frame="4", leaf="3", light="c", opened=False):
"""A bulkhead door, open or closed, with a status light above it."""
rect(s, x, y, w, h, frame)
inner_x, inner_y = x + 2, y + 2
inner_w, inner_h = w - 4, h - 2
if opened:
rect(s, inner_x, inner_y, inner_w, inner_h, "0")
dither(s, inner_x, inner_y, inner_w, inner_h, "1", 0.3, seed=11)
else:
rect(s, inner_x, inner_y, inner_w, inner_h, leaf)
vline(s, x + w // 2, inner_y, inner_h, "2")
vline(s, x + w // 2 - 1, inner_y, inner_h, "4")
checker(s, inner_x, inner_y + inner_h - 8, inner_w, 6, "2", 3)
hline(s, x, y, w, "5")
px(s, x + w // 2, y + 1, light)
def console(s, x, y, w, h, screen="c", dark="1", seed=13):
"""Terminal with a small screen and buttons."""
rect(s, x, y, w, h, "3")
box(s, x, y, w, h, "4")
sw, sh = w - 6, h - 8
rect(s, x + 3, y + 2, sw, sh, dark)
box(s, x + 3, y + 2, sw, sh, "2")
rnd = random.Random(seed)
for i in range(2, sh - 1, 2):
hline(s, x + 5, y + 2 + i, rnd.randrange(3, max(4, sw - 4)), screen)
for i in range(3):
px(s, x + 4 + i * 3, y + h - 3, "ary"[i])
def pipes(s, x, y, w, count=3, seed=17, color="4"):
"""A run of parallel pipes with brackets along them."""
rnd = random.Random(seed)
for i in range(count):
yy = y + i * 4
hline(s, x, yy, w, color)
hline(s, x, yy + 1, w, "2")
for j in range(int(x), int(x + w), rnd.randrange(9, 15)):
rect(s, j, yy - 1, 2, 4, "5")
def planet(s, cx, cy, r, bands, seed=29, dark_limb=True):
"""Gas giant: horizontal bands clipped to a circle."""
rnd = random.Random(seed)
n = len(bands)
for dy in range(-r, r + 1):
half = int((r * r - dy * dy) ** 0.5)
if half <= 0:
continue
y = cy + dy
idx = min(n - 1, int((dy + r) / (2 * r) * n))
c = bands[idx]
hline(s, cx - half, y, half * 2, c)
# ragged boundary between bands
nxt = bands[min(n - 1, idx + 1)]
if rnd.random() < 0.5:
for xx in range(cx - half, cx + half):
if rnd.random() < 0.25:
px(s, xx, y, nxt)
if dark_limb: # darkening towards the limb of the disc
edge = max(1, half // 6)
dither(s, cx - half, y, edge, 1, "e", 0.6, seed + y)
dither(s, cx + half - edge, y, edge, 1, "e", 0.6, seed + y + 1)
def light_cone(s, x, y, w, h, c="a", density=0.12, seed=19):
"""Light cone from a lamp — sparse dither that thickens near the source."""
rnd = random.Random(seed)
for row in range(int(h)):
t = row / max(1, h)
half = int(w * (0.15 + 0.85 * t) / 2)
d = density * (1.0 - 0.7 * t)
for xx in range(x - half, x + half):
if rnd.random() < d:
px(s, xx, y + row, c)
def biomass(s, x, y, w, h, seed=23, c1="e", c2="p", c3="2", hi="r"):
"""Organic growth: dark bulges of flesh with occasional highlights."""
rnd = random.Random(seed)
rect(s, x, y, w, h, c3)
for _ in range(int(w * h / 7)):
bx = rnd.randrange(int(x), int(x + w))
by = rnd.randrange(int(y), int(y + h))
r = rnd.choice([1, 1, 2, 2, 3, 4])
circle(s, bx, by, r, rnd.choice([c1, c1, c1, c2, c3]))
for _ in range(int(w * h / 90)): # wet highlights
px(s, rnd.randrange(int(x), int(x + w)), rnd.randrange(int(y), int(y + h)), hi)
dither(s, x, y, w, h, "1", 0.12, seed + 1)
# --------------------------------------------------------------------------
# Small sprites where the exact shape matters
# --------------------------------------------------------------------------
SPR_SKULL = [
"..7777..",
".766667.",
"76066067",
"76000067",
".7600067",
"..70007.",
"...707..",
]
SPR_PLANT = [
"....g.g....",
"...gGgGg...",
"..ggGGGgg..",
".hggGGGggh.",
"..hggGggh..",
"...hgGgh...",
"....hgh....",
"....bhb....",
"...bbbbb...",
]
SPR_CREATURE_EYES = [
"..y....y..",
".yry..yry.",
"..y....y..",
]
SPR_KEYCARD = [
"aaaaaaaa",
"a1111c1a",
"a1cc11ca",
"a1111c1a",
"aaaaaaaa",
]
SPR_SUIT = [
"..6666..",
".677776.",
"67c88c76",
"6788887 ",
".677776.",
"..6446..",
".64 46.",
]
# --------------------------------------------------------------------------
# Scenes
# --------------------------------------------------------------------------
def scene_title(s):
"""Title screen: the station in silhouette against Typhon."""
fill(s, "0")
stars(s, 0, 0, LOW_W, LOW_H, 130, seed=42)
# gas giant in the bottom-right corner
planet(s, 152, 84, 46, ["e", "b", "a", "b", "e", "b", "A", "a", "b", "e"], seed=43)
# silhouette of the station
rect(s, 20, 26, 46, 8, "3")
box(s, 20, 26, 46, 8, "4")
rect(s, 12, 28, 8, 4, "4")
rect(s, 66, 24, 6, 12, "4")
for x in range(24, 62, 6):
px(s, x, 29, "c")
px(s, x + 2, 31, "a")
line(s, 43, 34, 43, 46, "3")
rect(s, 36, 46, 14, 6, "3")
def scene_cryo(s):
"""Cryo bay: three pods, the middle one still sealed and frosted."""
metal_wall(s, 0, 0, LOW_W, 58, "2", "3", seed=31)
floor_grate(s, 0, 58, LOW_W, LOW_H - 58)
pipes(s, 0, 4, LOW_W, 2, seed=32)
# standby ceiling lamp and its dim light
rect(s, 90, 8, 14, 3, "6")
rect(s, 92, 11, 10, 1, "A")
light_cone(s, 97, 12, 54, 46, "6", 0.07, seed=61)
# three cryo pods: the outer ones are open, the middle one sealed and frosted
for i, x in enumerate((16, 82, 148)):
opened = i != 1
rect(s, x, 18, 30, 44, "3") # housing
box(s, x, 18, 30, 44, "5")
rect(s, x + 2, 20, 26, 4, "4") # headboard with tubing
for t in range(3):
vline(s, x + 8 + t * 6, 14, 6, "4")
px(s, x + 8 + t * 6, 13, "5")
gx, gy, gw, gh = x + 5, 25, 20, 31
if opened:
rect(s, gx, gy, gw, gh, "1") # empty dark niche
dither(s, gx, gy, gw, gh, "2", 0.3, seed=50 + i)
vline(s, x + 3, 25, 31, "4") # lid swung open
vline(s, x + 2, 26, 29, "5")
if i == 2: # streaks in the third pod
dither(s, gx, gy + 14, gw, gh - 14, "e", 0.35, seed=57)
dither(s, gx + 2, gy + 22, gw - 4, 6, "e", 0.6, seed=58)
else:
rect(s, gx, gy, gw, gh, "d") # backlit ice
checker(s, gx, gy, gw, gh, "c", 4, phase=1)
# silhouette of the sleeper over the ice: shoulders, head, folded arms
rect(s, gx + 6, gy + 13, 8, 18, "2")
rect(s, gx + 4, gy + 16, 12, 9, "2")
rect(s, gx + 5, gy + 19, 10, 3, "3")
circle(s, gx + 10, gy + 10, 4, "2")
circle(s, gx + 10, gy + 9, 3, "4")
px(s, gx + 8, gy + 9, "1")
px(s, gx + 12, gy + 9, "1")
# frost patterns along the edges of the glass
dither(s, gx, gy, gw, 7, "C", 0.2, seed=41)
dither(s, gx, gy + gh - 7, gw, 7, "C", 0.16, seed=42)
dither(s, gx, gy, 3, gh, "C", 0.25, seed=43)
dither(s, gx + gw - 3, gy, 3, gh, "C", 0.25, seed=44)
box(s, gx, gy, gw, gh, "4")
# name plate and status indicator
rect(s, x + 6, 58, 18, 3, "2")
hline(s, x + 8, 59, 14, "5")
rect(s, x + 11, 63, 8, 3, "2")
px(s, x + 15, 64, "e" if opened else "c")
def scene_dark(s):
"""An unlit compartment: barely a corridor, and a pair of eyes."""
fill(s, "0")
dither(s, 0, 0, LOW_W, LOW_H, "1", 0.18, seed=71)
# barely discernible corridor outlines
corridor_perspective(s, LOW_W // 2, 40, "1", "1")
px(s, 60, 30, "2")
px(s, 130, 52, "2")
sprite(s, SPR_CREATURE_EYES, 88, 36)
def scene_corridor(s):
"""The ring corridor, receding to a lit door at the far end."""
fill(s, "1")
metal_wall(s, 0, 0, LOW_W, LOW_H, "2", "3", seed=81)
floor_grate(s, 0, 58, LOW_W, LOW_H - 58)
cx = LOW_W // 2
# receding sections: frame plus darkening towards the inside
for k, (w, h) in enumerate([(150, 68), (112, 54), (80, 42), (54, 32)]):
x, y = cx - w // 2, 42 - h // 2
box(s, x, y, w, h, "4" if k < 2 else "3")
box(s, x + 1, y + 1, w - 2, h - 2, "2")
dither(s, x + 2, y + 2, w - 4, h - 4, "1", 0.05 + k * 0.06, seed=86 + k)
# ceiling lamps above each section
for k, (x, w) in enumerate([(cx - 22, 44), (cx - 14, 28), (cx - 8, 16)]):
y = 16 + k * 4
rect(s, x, y, w, 2, "6")
rect(s, x + 2, y + 2, w - 4, 1, "A")
light_cone(s, x + w // 2, y + 3, w + 10, 30 - k * 6, "a", 0.1 - k * 0.025,
seed=90 + k)
# door at the end of the corridor
door(s, cx - 11, 30, 22, 24, "4", "3", "r")
pipes(s, 0, 6, 40, 3, seed=83)
pipes(s, 152, 6, 40, 3, seed=84)
# side doors in perspective
for sx in (10, 158):
rect(s, sx, 34, 6, 24, "3")
box(s, sx, 34, 6, 24, "4")
px(s, sx + 3, 40, "c")
def scene_medbay(s):
"""Medbay: a body under a sheet and a cabinet of medkits."""
metal_wall(s, 0, 0, LOW_W, 60, "2", "3", seed=101)
rect(s, 0, 60, LOW_W, LOW_H - 60, "2")
checker(s, 0, 60, LOW_W, LOW_H - 60, "3", 4)
hline(s, 0, 60, LOW_W, "4")
# medical bed with a body under a sheet
rect(s, 30, 52, 70, 6, "6")
rect(s, 30, 46, 70, 6, "7")
dither(s, 30, 46, 70, 6, "6", 0.3, seed=103)
rect(s, 34, 42, 16, 5, "7")
rect(s, 60, 43, 30, 4, "7")
rect(s, 36, 58, 4, 12, "4")
rect(s, 90, 58, 4, 12, "4")
sprite(s, SPR_SKULL, 38, 36)
# cabinet with medkits
rect(s, 120, 20, 56, 40, "3")
box(s, 120, 20, 56, 40, "5")
for i in range(3):
for j in range(2):
x, y = 124 + j * 26, 24 + i * 12
rect(s, x, y, 22, 9, "2")
box(s, x, y, 22, 9, "4")
if (i + j) % 2 == 0:
rect(s, x + 8, y + 2, 6, 5, "r")
px(s, x + 11, y + 3, "8")
hline(s, x + 9, y + 4, 4, "8")
console(s, 4, 24, 26, 22, "g", "1", seed=107)
# surgical lamp above the bed
rect(s, 56, 4, 22, 3, "5")
rect(s, 58, 7, 18, 1, "7")
light_cone(s, 67, 8, 46, 34, "6", 0.05, seed=109)
def scene_quarters(s):
"""Crew quarters: bunks, forced lockers, a suit on the floor."""
metal_wall(s, 0, 0, LOW_W, 62, "1", "2", seed=121)
rect(s, 0, 62, LOW_W, LOW_H - 62, "2")
checker(s, 0, 62, LOW_W, LOW_H - 62, "3", 3)
# bunk beds
for i, y in enumerate((26, 48)):
rect(s, 10, y, 62, 4, "4")
rect(s, 12, y - 6, 58, 6, "5")
dither(s, 12, y - 6, 58, 6, "6", 0.25, seed=123 + i)
rect(s, 12, y - 9, 14, 4, "7") # pillow
rect(s, 10, y, 3, 14, "3")
rect(s, 69, y, 3, 14, "3")
# personal lockers and scattered belongings
for i in range(3):
x = 96 + i * 30
rect(s, x, 40, 26, 22, "3")
box(s, x, 40, 26, 22, "4")
hline(s, x + 4, 50, 18, "5")
px(s, x + 20, 45, "a")
if i == 1:
rect(s, x + 4, 34, 18, 6, "2") # half-open locker
sprite(s, SPR_KEYCARD, x + 8, 35)
sprite(s, SPR_SUIT, 78, 54)
dither(s, 0, 0, LOW_W, LOW_H, "0", 0.12, seed=127)
rect(s, 34, 6, 16, 2, "5")
light_cone(s, 42, 8, 40, 32, "b", 0.06, seed=129)
def scene_hydro(s):
"""Hydroponics: tiered racks with the growth taking the right half."""
fill(s, "1")
metal_wall(s, 0, 0, LOW_W, LOW_H, "1", "2", seed=141)
# tiered racks of plants under violet lamps
for tier, y in enumerate((28, 54, 80)):
rect(s, 0, y, LOW_W, 3, "3") # shelf
hline(s, 0, y, LOW_W, "5")
rect(s, 0, y - 21, LOW_W, 1, "p") # lamp above the tier
dither(s, 0, y - 20, LOW_W, 8, "p", 0.1, seed=143 + tier)
for i in range(0, LOW_W, 20):
x = i + 2 + (tier * 5) % 9
rect(s, x, y - 4, 13, 4, "b") # tray
box(s, x, y - 4, 13, 4, "3")
sprite(s, SPR_PLANT, x + 1, y - 13)
# the infected patch on the right creeps over the racks
biomass(s, 126, 0, 66, LOW_H, seed=147)
for y in range(0, LOW_H, 3): # ragged edge of the growth
dither(s, 108 + (y * 7) % 14, y, 22, 3, "e", 0.35, seed=148 + y)
sprite(s, SPR_CREATURE_EYES, 150, 34)
def scene_engine(s):
"""Engineering: three distribution panels, the central one dead."""
metal_wall(s, 0, 0, LOW_W, 64, "1", "2", seed=161)
floor_grate(s, 0, 64, LOW_W, LOW_H - 64, seed=162)
pipes(s, 0, 8, LOW_W, 4, seed=163, color="3")
# distribution panels
for i, x in enumerate((14, 74, 134)):
rect(s, x, 26, 44, 34, "3")
box(s, x, 26, 44, 34, "5")
for j in range(4):
for k in range(3):
bx, by = x + 4 + j * 10, 30 + k * 10
rect(s, bx, by, 8, 7, "2")
box(s, bx, by, 8, 7, "4")
lit = (i + j + k) % 4
px(s, bx + 4, by + 3, ["g", "a", "e", "c"][lit])
# knife switch
rect(s, x + 18, 55, 8, 4, "4")
px(s, x + 22, 56, "r" if i == 1 else "g")
console(s, 78, 4, 36, 20, "a", "1", seed=167)
dither(s, 0, 0, LOW_W, LOW_H, "0", 0.1, seed=169)
def scene_reactor(s):
"""Reactor hall: the core glowing red at the bottom of its shaft."""
fill(s, "0")
metal_wall(s, 0, 0, LOW_W, LOW_H, "1", "2", seed=181)
# reactor shaft: concentric rings
cx, cy = LOW_W // 2, 42
for r, c in [(38, "3"), (34, "4"), (30, "3"), (26, "5")]:
circle(s, cx, cy, r, c, 1)
circle(s, cx, cy, 24, "e")
dither(s, cx - 24, cy - 24, 48, 48, "r", 0.4, seed=183)
circle(s, cx, cy, 16, "r")
circle(s, cx, cy, 10, "a")
circle(s, cx, cy, 5, "A")
for k in range(8): # mounting spokes
ang = k * math.pi / 4
dx, dy = math.cos(ang), math.sin(ang)
line(s, cx + 26 * dx, cy + 26 * dy, cx + 40 * dx, cy + 40 * dy, "4")
pipes(s, 0, 68, LOW_W, 3, seed=185, color="4")
console(s, 4, 58, 30, 22, "r", "1", seed=187)
console(s, 158, 58, 30, 22, "a", "1", seed=189)
light_cone(s, cx, cy, 90, 40, "a", 0.12, seed=191)
def scene_ai_core(s):
"""PILOT core: server racks around a floating lens-eye."""
fill(s, "0")
dither(s, 0, 0, LOW_W, LOW_H, "1", 0.25, seed=201)
# server racks receding into the depth
for k, (x, w, h) in enumerate([(6, 22, 66), (30, 18, 58), (150, 18, 58), (166, 22, 66)]):
y = LOW_H - h - 4
rect(s, x, y, w, h, "2")
box(s, x, y, w, h, "3")
for i in range(y + 3, y + h - 3, 5):
hline(s, x + 3, i, w - 6, "c" if (i + k) % 3 else "d")
# AI core: a floating lens-eye
cx, cy = LOW_W // 2, 36
for r, c in [(26, "d"), (22, "c"), (16, "C")]:
circle(s, cx, cy, r, c, 1)
circle(s, cx, cy, 14, "d")
dither(s, cx - 14, cy - 14, 28, 28, "c", 0.5, seed=203)
circle(s, cx, cy, 8, "C")
circle(s, cx, cy, 4, "8")
circle(s, cx, cy, 2, "1")
# beam cast onto the floor
light_cone(s, cx, cy + 14, 70, 34, "c", 0.2, seed=205)
hline(s, 0, LOW_H - 4, LOW_W, "2")
checker(s, 0, LOW_H - 4, LOW_W, 4, "3", 3)
def scene_comms(s):
"""Comms post: consoles and the antenna dish beyond the viewport."""
metal_wall(s, 0, 0, LOW_W, 66, "1", "2", seed=221)
rect(s, 0, 66, LOW_W, LOW_H - 66, "2")
# large antenna dish beyond the viewport
rect(s, 108, 8, 76, 46, "0")
box(s, 108, 8, 76, 46, "4")
stars(s, 110, 10, 72, 42, 40, seed=223)
ellipse(s, 122, 14, 48, 34, "3")
ellipse(s, 126, 18, 40, 26, "2")
line(s, 146, 31, 146, 50, "5")
rect(s, 142, 48, 9, 5, "4")
# comms console
console(s, 6, 20, 46, 34, "c", "1", seed=225)
console(s, 56, 30, 40, 24, "a", "1", seed=227)
for i in range(6): # toggle switches
x = 12 + i * 7
rect(s, x, 58, 5, 6, "3")
px(s, x + 2, 59 + (i % 2) * 3, ["g", "a", "r"][i % 3])
dither(s, 0, 0, LOW_W, LOW_H, "0", 0.1, seed=229)
def scene_shuttle(s):
"""Shuttle airlock: the craft in profile against open space."""
fill(s, "0")
metal_wall(s, 0, 0, LOW_W, 30, "1", "2", seed=241)
floor_grate(s, 0, 62, LOW_W, LOW_H - 62, seed=242)
# airlock doors with a view of the planet
rect(s, 20, 24, 152, 40, "0")
stars(s, 22, 26, 148, 36, 60, seed=243)
s.set_clip((21, 25, 150, 38))
planet(s, 152, 74, 38, ["b", "a", "b", "e", "b", "A", "a", "b"], seed=244)
s.set_clip(None)
box(s, 20, 24, 152, 40, "4")
# shuttle in profile
rect(s, 50, 40, 70, 16, "5")
rect(s, 44, 44, 8, 8, "6")
rect(s, 118, 42, 12, 12, "4")
rect(s, 60, 34, 24, 6, "4")
rect(s, 68, 46, 40, 4, "3")
for i in range(4):
rect(s, 58 + i * 14, 43, 6, 5, "c")
rect(s, 128, 46, 8, 4, "a")
dither(s, 136, 44, 24, 8, "a", 0.3, seed=245)
# floor markings
for x in range(0, LOW_W, 16):
rect(s, x, 66, 8, 3, "y")
light_cone(s, 84, 20, 80, 44, "7", 0.08, seed=247)
def scene_creature(s):
"""The growth filling the frame: flesh, eyes and tendrils."""
fill(s, "0")
dither(s, 0, 0, LOW_W, LOW_H, "1", 0.3, seed=261)
# the creature filling the screen: a mass of flesh, eyes, tendrils
for k in range(7): # strands spreading towards the edges of the frame
line(s, 96, 46, 4 + k * 31, LOW_H + 4, "e")
line(s, 97, 46, 6 + k * 31, LOW_H + 4, "1")
line(s, 96, 46, 4 + k * 31, -4, "e")
biomass(s, 26, 6, 140, 78, seed=263)
biomass(s, 58, 14, 76, 52, seed=265, c1="p", c2="e", c3="e", hi="m")
for x, y in [(70, 30), (110, 26), (84, 46), (122, 48)]:
circle(s, x, y, 5, "1")
circle(s, x, y, 4, "y")
circle(s, x, y, 2, "e")
px(s, x, y, "0")
px(s, x - 1, y - 1, "8")
dither(s, 0, 0, LOW_W, LOW_H, "0", 0.16, seed=267)
def scene_space(s):
"""Open space: Typhon up close, the station and a departing shuttle."""
fill(s, "0")
stars(s, 0, 0, LOW_W, LOW_H, 190, seed=281)
# gas giant large on the left, the station far away
planet(s, 38, 46, 42, ["e", "b", "a", "A", "a", "b", "e", "b", "a", "b", "e"],
seed=282)
rect(s, 130, 30, 30, 5, "4")
rect(s, 126, 31, 4, 3, "5")
rect(s, 160, 28, 4, 9, "5")
px(s, 140, 32, "c")
px(s, 150, 33, "r")
# engine plume of the departing shuttle
rect(s, 96, 60, 10, 4, "6")
rect(s, 92, 61, 4, 2, "a")
dither(s, 70, 59, 24, 6, "a", 0.35, seed=285)
def scene_static(s):
"""Static — used for "bad" endings and malfunctions."""
fill(s, "1")
rnd = random.Random(301)
for y in range(LOW_H):
w = rnd.randrange(10, LOW_W)
x = rnd.randrange(0, LOW_W - 10)
c = rnd.choice("2334561")
hline(s, x, y, w, c)
dither(s, 0, 0, LOW_W, LOW_H, "7", 0.05, seed=303)
dither(s, 0, 0, LOW_W, LOW_H, "0", 0.3, seed=305)
# --------------------------------------------------------------------------
# Animation: drawn on top of the cached frame
# --------------------------------------------------------------------------
def anim_blink(x, y, colors, period=30):
"""Blinking indicator light."""
def fn(s, frame):
px(s, x, y, colors[(frame // period) % len(colors)])
return fn
def anim_cryo(s, frame):
"""Blinking pod indicators and creeping frost."""
px(s, 31, 64, "e" if (frame // 20) % 2 else "1")
px(s, 97, 64, "c" if (frame // 30) % 4 else "d")
px(s, 163, 64, "e" if (frame // 13) % 2 else "1")
d = (frame // 6) % 3
dither(s, 87, 25, 20, 31, "C", 0.05, seed=400 + d)
def anim_dark(s, frame):
"""The eyes in the dark, appearing and vanishing again."""
if (frame // 24) % 4 == 0:
sprite(s, SPR_CREATURE_EYES, 88, 36)
else:
rect(s, 88, 36, 10, 3, "0")
dither(s, 88, 36, 10, 3, "1", 0.2, seed=401)
def anim_reactor(s, frame):
"""A pulse expanding out of the reactor core."""
cx, cy = LOW_W // 2, 42
r = 4 + (frame // 5) % 4
circle(s, cx, cy, r, "A", 1)
circle(s, cx, cy, 2, "8")
def anim_ai(s, frame):
"""The lens flickering while data scrolls down the racks."""
cx, cy = LOW_W // 2, 36
r = 2 + (frame // 8) % 3
circle(s, cx, cy, r, "8", 1)
ph = (frame // 4) % 6
for k in range(4):
x = [9, 33, 153, 169][k]
w = [22, 18, 18, 22][k]
y = LOW_H - 4 - [66, 58, 58, 66][k] + 3 + ((ph + k * 2) % 12) * 5
if y < LOW_H - 8:
hline(s, x, y, w - 6, "C")
def anim_static(s, frame):
"""Fresh interference lines on every frame."""
rnd = random.Random(frame // 2)
for _ in range(14):
y = rnd.randrange(LOW_H)
hline(s, rnd.randrange(0, LOW_W - 20), y, rnd.randrange(10, 40), rnd.choice("1567"))
def anim_creature(s, frame):
"""The creature narrowing its eyes, and a spreading ripple."""
if (frame // 18) % 3 == 0: # the creature narrows its eyes
for x, y in [(70, 30), (110, 26), (84, 46), (122, 48)]:
circle(s, x, y, 5, "e")
r = (frame // 4) % 7
circle(s, 96, 46, 6 + r, "p", 1)
SCENES = {
"title": (scene_title, None),
"cryo": (scene_cryo, anim_cryo),
"dark": (scene_dark, anim_dark),
"corridor": (scene_corridor, anim_blink(96, 31, ["r", "e", "e", "e"], 18)),
"medbay": (scene_medbay, anim_blink(10, 30, ["g", "h"], 25)),
"quarters": (scene_quarters, anim_blink(122, 45, ["a", "b"], 40)),
"hydro": (scene_hydro, None),
"engine": (scene_engine, anim_blink(96, 56, ["r", "e"], 15)),
"reactor": (scene_reactor, anim_reactor),
"ai_core": (scene_ai_core, anim_ai),
"comms": (scene_comms, anim_blink(14, 59, ["g", "h", "y"], 20)),
"shuttle": (scene_shuttle, anim_blink(132, 47, ["a", "A"], 12)),
"creature": (scene_creature, anim_creature),
"space": (scene_space, None),
"static": (scene_static, anim_static),
}
_cache = {}
def render(name, frame=0):
"""Returns the low-resolution scene frame with the animation applied."""
draw, anim = SCENES.get(name, SCENES["static"])
base = _cache.get(name)
if base is None:
base = new_surface()
draw(base)
_cache[name] = base
if anim is None:
return base
s = base.copy()
anim(s, frame)
return s