-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_image.py
57 lines (44 loc) · 1.64 KB
/
generate_image.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
import logging
from PIL import Image, ImageDraw, ImageFont
from random_boolean_networks import RandomBooleanNetwork
logging.basicConfig(format='%(asctime)-15s %(levelname)-8s %(message)s',
filename='rbn.log',
level=logging.DEBUG)
NODES = 20
NODE_NEIGHBOR_COUNT = 3
ITERATIONS = 50
SCALING = 5
FONT_SIZE = 10
def main():
img = Image.new('RGB', (ITERATIONS * SCALING, NODES * SCALING + 20),
color='black')
rbn = RandomBooleanNetwork(node_count=NODES,
neighbor_count=NODE_NEIGHBOR_COUNT,
seed=None)
rbn.setup()
draw = ImageDraw.Draw(img)
for i in range(ITERATIONS):
for j, node in enumerate(rbn.nodes):
if node.state == 1:
rect = (
i * SCALING, # x1
j * SCALING, # y1
i * SCALING + SCALING, # x2
j * SCALING + SCALING # y2
)
draw.rectangle(rect, fill='red', outline='red' if SCALING == 1 else 'black')
rbn.iterate()
fnt = ImageFont.FreeTypeFont(font='fonts/Roboto/Roboto-Regular.ttf',
size=FONT_SIZE)
draw.text(xy=(1, NODES * SCALING - 1),
text=f'S: {rbn.seed}',
fill='red',
font=fnt)
draw.text(xy=(1, NODES * SCALING + FONT_SIZE - 1),
text=f'I: {ITERATIONS} - N: {rbn.node_count} - P: {rbn.neighbor_count}',
fill='red',
font=fnt,
align='right')
img.save('rbn.png')
if __name__ == "__main__":
main()