46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import numpy as np
|
|
from Shelf import Shelf
|
|
from Grid import Grid
|
|
WINDOW_X = 1400
|
|
WINDOW_Y = 750
|
|
RECT_SIZE = 50
|
|
|
|
|
|
class Environment:
|
|
def __init__(self, window):
|
|
self.window = window
|
|
self.grid = Grid(self.window)
|
|
self.list_of_coordinates = self.compute_coordinates_of_shelves()
|
|
self.shelves = self.create_shelves()
|
|
|
|
# fills surface with color, draws grid&shelves
|
|
def draw_itself(self):
|
|
self.window.fill((70, 77, 87))
|
|
self.draw_shelves()
|
|
self.grid.draw_grid()
|
|
|
|
# computes shelves coordinates according to window size, might change later
|
|
def compute_coordinates_of_shelves(self):
|
|
y = 0
|
|
y1 = WINDOW_Y - 6*RECT_SIZE
|
|
arr = []
|
|
for x in range(2*RECT_SIZE, WINDOW_X - 2*RECT_SIZE, 3*RECT_SIZE):
|
|
arr.append(x)
|
|
arr.append(y)
|
|
arr.append(x)
|
|
arr.append(y1)
|
|
list_of_coordinates = np.array(arr).reshape(int(len(arr)/2), 2)
|
|
return list_of_coordinates
|
|
|
|
# creating list of shelves
|
|
def create_shelves(self):
|
|
shelves = []
|
|
for row in self.list_of_coordinates:
|
|
shelf = Shelf(self.window, row[0], row[1])
|
|
shelves.append(shelf)
|
|
return shelves
|
|
|
|
def draw_shelves(self):
|
|
for shelf in self.shelves:
|
|
shelf.draw()
|