2d grid python pygame

Solutions on MaxInterview for 2d grid python pygame by the best coders in the world

showing results for - "2d grid python pygame"
Angela
12 Jun 2019
1import pygame
2
3BLACK = (0, 0, 0)
4WHITE = (200, 200, 200)
5WINDOW_HEIGHT = 400
6WINDOW_WIDTH = 400
7
8
9pygame.init()
10SCREEN = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH))
11CLOCK = pygame.time.Clock()
12SCREEN.fill(BLACK)
13
14
15def draw_grid():
16    block_size = 20
17    for x in range(WINDOW_WIDTH):
18        for y in range(WINDOW_HEIGHT):
19            rect = pygame.Rect(x*block_size, y*block_size,
20                               block_size, block_size)
21            pygame.draw.rect(SCREEN, WHITE, rect, 1)
22
23
24while True:
25    draw_grid()
26    pygame.display.flip()
27    for event in pygame.event.get():
28        if event.type == pygame.QUIT:
29            pygame.quit()