import pygame from pygame.locals import * from consts import * def draw_cell(display, position, color): position = (position[0] * CELL_SIZE + PADDING, position[1] * CELL_SIZE + PADDING) rect = pygame.Rect(position, (40, 40)) pygame.draw.rect(display, color, rect) def gridtoscreen(pos): return (pos[0] * CELL_SIZE, pos[1] * CELL_SIZE) def center_line(pos): return (pos[0] + CELL_SIZE / 2, pos[1] + CELL_SIZE / 2) def draw_path(display, color, path): if path is None: return for i in range(0, len(path)-1): n1 = center_line(gridtoscreen(path[i].g_pos())) n2 = center_line(gridtoscreen(path[i + 1].g_pos())) pygame.draw.line(display, color, n1, n2, 4) def draw_grid(display, grid): for row in range(0, ROWS): for column in range(0, COLS): node = grid[row][column] if node.celltype == 0: draw_cell(display, (row, column), CELL_COLOR) elif node.celltype == 1: draw_cell(display, (row, column), WALL_COLOR) elif node.celltype == 2: draw_cell(display, (row, column), START_COLOR) elif node.celltype == 3: draw_cell(display, (row, column), END_COLOR)