File size: 5,270 Bytes
ddcc3ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Original hero portrait: the ARCHITECT OF THE VOID.

Not a copy of anyone's character design. The figure is a silhouette packed with
bracket glyphs — the void salesman rendered as the thing he sells. Generated from
scratch: masks, glyph fill, chromatic aberration, scanlines.
"""
import random
from PIL import Image, ImageDraw, ImageFont, ImageFilter

random.seed(2024)
W, H = 900, 1100
BG = (5, 6, 10)

BOLD = "/usr/share/fonts/dejavu-sans-fonts/DejaVuSans-Bold.ttf"
MONO = "/usr/share/fonts/google-noto/NotoSansMono-CondensedMedium.ttf"


def F(p, s):
    try:
        return ImageFont.truetype(p, s)
    except Exception:
        return ImageFont.load_default()


def backdrop():
    img = Image.new("RGB", (W, H), BG)
    d = ImageDraw.Draw(img)
    for y in range(H):
        t = y / H
        v = int(4 + 20 * (1 - t) ** 1.4)
        d.line([(0, y), (W, y)], fill=(v // 3, v // 3 + 1, v))
    # distant static
    for _ in range(1400):
        x, y = random.randint(0, W), random.randint(0, H)
        c = random.choice([(16, 18, 28), (24, 8, 20), (8, 24, 28)])
        d.point((x, y), fill=c)
    # faint grid
    for x in range(0, W, 60):
        d.line([(x, 0), (x, H)], fill=(12, 13, 20))
    for y in range(0, H, 60):
        d.line([(0, y), (W, y)], fill=(12, 13, 20))
    return img


def figure_mask():
    """Head + neck + shoulders + tapering torso silhouette."""
    m = Image.new("L", (W, H), 0)
    d = ImageDraw.Draw(m)
    cx = W // 2
    d.ellipse([cx - 134, 146, cx + 134, 462], fill=255)          # head
    d.polygon([(cx - 52, 430), (cx + 52, 430),
               (cx + 62, 556), (cx - 62, 556)], fill=255)        # neck
    d.polygon([(cx - 62, 540), (cx + 62, 540),                    # shoulders
               (cx + 238, 604), (cx + 282, 1099),
               (cx - 282, 1099), (cx - 238, 604)], fill=255)
    return m


def glyph_fill(mask):
    """Pack the silhouette with bracket glyphs."""
    lay = Image.new("RGB", (W, H), (0, 0, 0))
    d = ImageDraw.Draw(lay)
    glyphs = ["[[", "]]", "$$", "[]", "[", "]", "$", "#", "@", "!", "%", "&"]
    sizes = [14, 17, 20, 24, 28, 34, 42]
    y = 140
    while y < H:
        s = random.choice(sizes)
        f = F(MONO, s)
        x = random.randint(-40, 4)
        while x < W:
            g = random.choice(glyphs)
            shade = random.randint(130, 255)
            tint = random.choice([(shade, shade, shade),
                                  (0, shade, shade),
                                  (shade, 0, shade // 2),
                                  (shade, shade // 2, 0)])
            d.text((x, y), g, font=f, fill=tint)
            x += d.textlength(g, font=f) + random.randint(0, 7)
        y += s + random.randint(-2, 4)
    lay = lay.filter(ImageFilter.GaussianBlur(0.4))
    out = Image.new("RGB", (W, H), (0, 0, 0))
    out.paste(lay, (0, 0), mask)
    return out


def chroma(img, dx=5):
    r, g, b = img.split()
    m = Image.new("L", (W, H), 0)
    m = ImageChops_lighter(m, r)
    out = img.copy()
    for col, off in (((0, 235, 245), -dx), ((240, 20, 160), dx)):
        tint = Image.new("RGB", (W, H), col)
        shifted = m.transform((W, H), Image.AFFINE, (1, 0, -off, 0, 1, 0))
        out = Image.composite(tint, out, shifted)
    out = Image.composite(img, out, m)
    return out


def ImageChops_lighter(a, b):
    from PIL import ImageChops
    return ImageChops.lighter(a, b)


def eyes(img):
    d = ImageDraw.Draw(img)
    cx = W // 2
    for ex in (cx - 74, cx + 26):
        d.rectangle([ex, 268, ex + 48, 296], fill=(255, 252, 240))
        d.rectangle([ex - 4, 262, ex + 52, 302], outline=(0, 220, 235))
    d.rectangle([cx - 96, 258, cx + 96, 306], outline=(240, 0, 150))
    # grin
    d.arc([cx - 78, 330, cx + 78, 430], start=20, end=160, fill=(255, 250, 238), width=7)
    return img


def sigils(img):
    d = ImageDraw.Draw(img)
    d.text((40, 40), "[[", font=F(BOLD, 150), fill=(30, 34, 52))
    d.text((W - 200, H - 210), "]]", font=F(BOLD, 150), fill=(30, 34, 52))
    d.text((W - 150, 120), "$$$", font=F(MONO, 42), fill=(190, 30, 105))
    d.text((46, 210), "KROMER", font=F(MONO, 26), fill=(38, 42, 60))
    d.text((46, H - 90), "ARCHITECT OF THE VOID", font=F(MONO, 24), fill=(150, 170, 190))
    return img


def finish(img):
    d = ImageDraw.Draw(img)
    # glitch bands, outside the face
    for _ in range(22):
        y0 = random.choice([random.randint(470, H - 30), random.randint(0, 130)])
        h = random.randint(3, 20)
        band = img.crop((0, y0, W, min(y0 + h, H)))
        img.paste(band, (random.randint(-26, 26), y0))
    for y in range(0, H, 4):
        d.line([(0, y), (W, y)], fill=(0, 0, 0))
    m = Image.new("L", (W, H), 0)
    ImageDraw.Draw(m).ellipse([-W * .3, -H * .25, W * 1.3, H * 1.25], fill=255)
    m = m.filter(ImageFilter.GaussianBlur(150))
    return Image.composite(img, Image.new("RGB", (W, H), (0, 0, 0)), m)


def main():
    img = backdrop()
    mask = figure_mask()
    fig = glyph_fill(mask)
    img.paste(fig, (0, 0), mask)
    img = chroma(img, 6)
    img = eyes(img)
    img = sigils(img)
    img = finish(img)
    out = "/home/ryzen/foryou/spamton-portrait.png"
    img.save(out)
    print("wrote", out, img.size)


if __name__ == "__main__":
    main()