Browse Source

Fix door carving, add canonical coloring

master
Josh Gordon 4 years ago
parent
commit
a2f2d12360
  1. 35
      app/dungeon.py

35
app/dungeon.py

@ -7,13 +7,14 @@ import cv2
CELL_SIZE = 5
RETRY_CELL_PLACEMENT = True
WALL_SCALE = 4
MAP_SCALE = 8
WALL_SCALE = 6
MAP_SCALE = 12
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
FLOOR_COLOR = np.array([40,100,100]) #brown
def randomColor():
b = randint(0,255)
@ -166,7 +167,7 @@ def drawWalls(im,grid):
for dy in range(WALL_SCALE):
x = cx*WALL_SCALE+dx
y = cy*WALL_SCALE+dy
print(x,y)
#print(x,y)
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:
@ -180,11 +181,32 @@ def drawWalls(im,grid):
if not np.array_equal(newim[x+i,y+j,:],WALL_COLOR): #and that color is not a wall
floor = False #become a wall
else:
print("Debug")
pass
#print("Debug")
if not floor:
newim[x,y,:] = WALL_COLOR
return newim
def carveDoors(im,grid):
newim = im.copy()
for cell in grid.getCells():
for (cy1,cx1,cy0,cx0) in cell.getFlow():
p1 = (cx1*WALL_SCALE + WALL_SCALE//2,cy1*WALL_SCALE + WALL_SCALE//2)
p0 = (cx0*WALL_SCALE + WALL_SCALE//2,cy0*WALL_SCALE + WALL_SCALE//2)
cv2.line(newim,p1,p0,cell.getColor()/255,1)
return newim
def canonicalize(im):
w,h,_ = im.shape
newim = im.copy()
for x in range(w):
for y in range(h):
if np.array_equal(im[x,y,:],np.array([0,0,0])) or np.array_equal(im[x,y,:],WALL_COLOR):
pass
else:
newim[x,y,:] = FLOOR_COLOR/255
return newim
#driver code
g = Grid(GRID_SIZE,GRID_SIZE)
@ -194,14 +216,17 @@ g.addCell()
g.addCell()
g.addCell()
g.addCell()
g.addCell()
print(g)
im = g.exportImage()
#print(im)
im = drawWalls(im,g)
im = carveDoors(im,g)
im = scaleMap(im)
drawFlow(im,g)
#drawFlow(im,g)
im = canonicalize(im)
cv2.imshow("Here",im)
cv2.waitKey(0)

Loading…
Cancel
Save