-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
46 lines (38 loc) · 1.17 KB
/
utils.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
43
44
45
46
from config import (
CELL_WIDTH,
CELL_HEIGHT,
BOARDER_WIDTH,
SIDEBAR_WIDTH,
BOTTOM_SIDEBAR_HEIGHT,
COLUMN_COUNT,
ROW_COUNT,
)
from layout import layout_manager, LAYOUTS
def mix_color(a, b):
return ((a[0] + b[0]) // 2, (a[1] + b[1]) // 2, (a[2] + b[2] // 2))
def grid_to_central_coordinate(row, column):
x = (
column * (CELL_WIDTH + BOARDER_WIDTH) # column starts from 0
+ CELL_WIDTH / 2
+ BOARDER_WIDTH
+ SIDEBAR_WIDTH
)
y = (
row * (CELL_HEIGHT + BOARDER_WIDTH) # row starts from 0
+ CELL_HEIGHT / 2
+ BOARDER_WIDTH
+ BOTTOM_SIDEBAR_HEIGHT
)
return [x, y]
def coordinate_to_grid(x, y):
if layout_manager.on_layout(LAYOUTS.GRID, x, y):
column = (x - SIDEBAR_WIDTH) // (CELL_WIDTH + BOARDER_WIDTH)
row = (y - BOTTOM_SIDEBAR_HEIGHT) // (CELL_HEIGHT + BOARDER_WIDTH)
if column < COLUMN_COUNT and row < ROW_COUNT:
return [row, column]
else:
return [row - 1, column - 1]
def row_column_on_grid(row, column):
if row < 0 or row >= ROW_COUNT or column < 0 or column >= COLUMN_COUNT:
return False
return True