-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
27 lines (23 loc) · 1.03 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
from config import *
def uint_to_rgb(RGBint):
Blue = RGBint & 255
Green = (RGBint >> 8) & 255
Red = (RGBint >> 16) & 255
return (1.0 / 255) * Red, (1.0 / 255) * Green, (1.0 / 255) * Blue
def shape_to_mesh(shape, color):
r, g, b = uint_to_rgb(color)
verts = []
indicies = []
last_index = -1
for row_index, row in enumerate(shape):
for col_index, col in enumerate(row):
if col == 1:
verts += [
(BLOCK_SIZE * col_index), (BLOCK_SIZE * row_index), r, g, b,
(BLOCK_SIZE * col_index) + BLOCK_SIZE, (BLOCK_SIZE * row_index), r, g, b,
(BLOCK_SIZE * col_index) + BLOCK_SIZE, (BLOCK_SIZE * row_index) + BLOCK_SIZE, r, g, b,
(BLOCK_SIZE * col_index), (BLOCK_SIZE * row_index) + BLOCK_SIZE, r, g, b,
]
indicies += [last_index + 1, last_index + 2, last_index + 3, last_index + 3, last_index + 4, last_index + 1]
last_index = last_index + 4
return verts, indicies