Browse Source

Add more parameters and walls

master
Josh Gordon 4 years ago
parent
commit
182381c612
  1. 39
      app/dungeon.py

39
app/dungeon.py

@ -7,10 +7,13 @@ import cv2
CELL_SIZE = 5
RETRY_CELL_PLACEMENT = True
SCALE_FACTOR = 32
WALL_SCALE = 4
MAP_SCALE = 8
SCALE_FACTOR = WALL_SCALE*MAP_SCALE
GRID_SIZE = 10
FLOW_COLOR = np.array([0,255,0]) #red
WALL_COLOR = np.array([255,255,255]) #white
def randomColor():
b = randint(0,255)
@ -137,17 +140,44 @@ class Grid(object):
if not self.spaces[x,y] == 0:
#print(self.cells[self.spaces[x,y]-1].getColor())
imBase[x,y,:] = self.cells[self.spaces[x,y]-1].getColor()/255
imBase = np.kron(imBase,np.ones((SCALE_FACTOR,SCALE_FACTOR,1)))
imBase = np.kron(imBase,np.ones((WALL_SCALE,WALL_SCALE,1)))
return imBase
def getCells(self):
return self.cells
def scaleMap(im):
return np.kron(im,np.ones((MAP_SCALE,MAP_SCALE,1)))
def drawFlow(im,grid):
for cell in grid.getCells():
for (y1,x1,y0,x0) in cell.getFlow():
cv2.arrowedLine(im,(x1*SCALE_FACTOR + SCALE_FACTOR//2,y1*SCALE_FACTOR + SCALE_FACTOR//2),(x0*SCALE_FACTOR + SCALE_FACTOR//2,y0*SCALE_FACTOR + SCALE_FACTOR//2),100)
def drawWalls(im):
newim = im.copy()
w,h,_ = im.shape
for x in range(w):
for y in range(h):
if np.array_equal(im[x,y,:],np.array([0,0,0])):
pass
elif x == 0 or y == 0 or x == w-1 or y == h-1:
newim[x,y,:] = WALL_COLOR
else:
color = im[x,y,:]
floor = True
for i in [-1,0,1]:
for j in [-1,0,1]:
if not np.array_equal(im[x+i,y+j,:],color):
if not np.array_equal(im[x+i,y+j,:],WALL_COLOR):
floor = False
#If this pixel has a neighbor with a different color,
#it is a floor only if that different color is the wall color
#THIS NEEDS TO BE DEBUGGED, START HERE TOMORROW
if not floor:
newim[x,y,:] = WALL_COLOR
return newim
#driver code
@ -161,9 +191,12 @@ print(g)
im = g.exportImage()
#print(im)
print(im.shape)
im = drawWalls(im)
im = scaleMap(im)
drawFlow(im,g)
cv2.imshow("Here",im)
cv2.waitKey(0)
cv2.imwrite("dungeon.png",im)
Loading…
Cancel
Save