-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
42 lines (32 loc) · 1.51 KB
/
gui.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
import pygame
def render(drawing):
pygame.init()
grid_size = (len(drawing[0]), len(drawing))
BLOCK_SIZE = 700 // grid_size[1]
WINDOW_WIDTH = BLOCK_SIZE * grid_size[0]
WINDOW_HEIGHT = BLOCK_SIZE * grid_size[1]
# Set up the drawing window
screen = pygame.display.set_mode([WINDOW_WIDTH, WINDOW_HEIGHT])
# Run until the user asks to quit
running = True
while running:
# Did the user click the window close button?
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Fill the background with white
screen.fill((255, 255, 255))
for x in range(0, grid_size[0]): # WINDOW_WIDTH, BLOCK_SIZE):
for y in range(0, grid_size[1]): # WINDOW_HEIGHT, BLOCK_SIZE):
rect = pygame.Rect(x * BLOCK_SIZE, y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE)
pygame.draw.rect(screen, (220, 220, 220), rect, width=1)
if drawing[y][x] == '\\':
pygame.draw.line(screen, (0, 0, 0), (x * BLOCK_SIZE, y * BLOCK_SIZE), (x * BLOCK_SIZE + BLOCK_SIZE, y * BLOCK_SIZE + BLOCK_SIZE),
width=2)
elif drawing[y][x] == '/':
pygame.draw.line(screen, (0, 0, 0), (x * BLOCK_SIZE, y * BLOCK_SIZE + BLOCK_SIZE),
(x * BLOCK_SIZE + BLOCK_SIZE, y * BLOCK_SIZE), width=2)
# Flip the display
pygame.display.flip()
# Done! Time to quit.
pygame.quit()