-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathklein.py
More file actions
56 lines (44 loc) · 1.92 KB
/
klein.py
File metadata and controls
56 lines (44 loc) · 1.92 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
import numpy as np
import pygame as pg
import random
import settings
from bml import klein_bml, klein_bmlr
def main() -> None:
screen = pg.display.set_mode((settings.DISPLAY_SIZE, settings.DISPLAY_SIZE))
pg.display.set_caption('BML')
base_lattice = np.zeros((settings.LATTICE_SIZE, settings.LATTICE_SIZE, 2))
while np.sum(base_lattice != 0) / np.sum(base_lattice >= 0) < settings.DENSITY:
i = random.randint(0, settings.LATTICE_SIZE - 1)
j = random.randint(0, settings.LATTICE_SIZE - 1)
k = random.randint(0, 1)
base_lattice[i, j, k] = random.choice([1, 2])
if settings.RANDOMIZED:
result = klein_bmlr(base_lattice)
else:
result = klein_bml(base_lattice)
run = True
for step, lattice in result:
for event in pg.event.get():
if event.type == pg.QUIT:
run = False
screen.fill((0, 0, 0))
for i in range(lattice.shape[0]):
for j in range(lattice.shape[1]):
if value := lattice[i, j, 0]:
rect = pg.Rect(int(i * settings.SCALE), int(j * settings.SCALE), int(settings.SCALE), int(settings.SCALE))
if value == 1:
pg.draw.rect(screen, settings.DISPLAY_COLOR_1, rect)
else:
pg.draw.rect(screen, settings.DISPLAY_COLOR_2, rect)
elif value := lattice[i, j, 1]:
rect = pg.Rect(int((settings.LATTICE_SIZE - i) * settings.SCALE), int(j * settings.SCALE), int(settings.SCALE), int(settings.SCALE))
if value == 1:
pg.draw.rect(screen, [c // 3 for c in settings.DISPLAY_COLOR_1], rect)
else:
pg.draw.rect(screen, [c // 3 for c in settings.DISPLAY_COLOR_2], rect)
if not run:
break
pg.display.flip()
pg.quit()
if __name__ == '__main__':
main()