Files
a-star/drawing.py
2024-04-29 01:08:38 +02:00

29 lines
720 B
Python

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)