-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_graphics.py
66 lines (50 loc) · 2.54 KB
/
generate_graphics.py
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
#!/usr/bin/env python3
import os
from PIL import Image, ImageDraw
def define_lines(x: int = 75, y: int = 25) -> list:
""" Line definitions to build symbols """
# Coordinates for lines. 1 Length unit for line is 50.
# +- 1 to make up for offsets caused by line width
center_vertical_line = [(x, y), (x, y + 3*50)]
top_line = [(x, y + 1), (x + 50, y + 1)]
second_top_line = [(x, y + 50), (x + 50, y + 50)]
tilted_down_line = [(x, y + 1), (x + 50 - 1, y + 50)]
tilted_up_line = [(x, y + 50), (x + 50 - 1, y + 1)]
top_vertical_line = [(x + 50, y), (x + 50, y + 50 + 2)]
# Other symbols can be made with combinations
# of lines defined above + rotations.
# Symbols without rotations
symbols = [
[center_vertical_line, top_line],
[center_vertical_line, second_top_line],
[center_vertical_line, tilted_down_line],
[center_vertical_line, tilted_up_line],
[center_vertical_line, top_line, tilted_up_line],
[center_vertical_line, top_vertical_line],
[center_vertical_line, top_line, top_vertical_line],
[center_vertical_line, second_top_line, top_vertical_line],
[center_vertical_line, top_line, second_top_line, top_vertical_line],
]
return symbols
def draw_symbol(symbol_data: list) -> Image.Image:
""" Draw symbol from symbol_data """
image = Image.new("1", (150, 200), "white")
draw = ImageDraw.Draw(image)
for line in symbol_data:
draw.line(line, width=4)
return image
for num in range(1, 10):
symbols = define_lines()
# Generate first instances of symbols without rotations
draw_symbol(symbols[num - 1]).save(f"graphics/{str(num).zfill(4)}.png")
symbols = define_lines(y = 24)
# Generate horizontally rotated symbols
draw_symbol(symbols[num - 1]).transpose(Image.Transpose.FLIP_TOP_BOTTOM).save(f"graphics/{str(num * 100).zfill(4)}.png")
symbols = define_lines(x = 73) # Decrement x by 2 pixels to fix offset of transposing
# Generate vertically rotated symbols
draw_symbol(symbols[num - 1]).transpose(Image.Transpose.FLIP_LEFT_RIGHT).save(f"graphics/{str(num * 10).zfill(4)}.png")
symbols = define_lines(x = 73, y = 24)
# Generate vertically and horizontally rotated symbols
draw_symbol(symbols[num - 1]).transpose(Image.Transpose.FLIP_LEFT_RIGHT).transpose(Image.Transpose.FLIP_TOP_BOTTOM).save(f"graphics/{str(num * 1000).zfill(4)}.png")
# Generate 1 blank image
Image.new("1", (150, 200), "white").save("graphics/blank.png")