-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid_utility.py
More file actions
39 lines (31 loc) · 864 Bytes
/
grid_utility.py
File metadata and controls
39 lines (31 loc) · 864 Bytes
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
from node import Node
import pygame as pg
from colors import GREY,WHITE
def make_grid(rows,width):
grid=[]
gap=width//rows
for i in range(rows):
grid.append([])
for j in range(rows):
node=Node(i,j,gap,rows)
grid[i].append(node)
return grid
def draw_grid(win,rows,width):
gap=width//rows
for i in range(rows):
pg.draw.line(win,GREY,(0,i*gap),(width,i*gap))
for j in range(rows):
pg.draw.line(win,GREY,(j*gap,0),(j*gap,width))
def draw(win,grid,rows,width):
win.fill(WHITE)
for row in grid:
for node in row:
node.draw(win)
draw_grid(win,rows,width)
pg.display.update()
def get_clicked_pos(pos,rows,width):
gap = width // rows
y,x=pos
row=y//gap
col=x//gap
return row,col