Skip to content

Instantly share code, notes, and snippets.

@luan
Forked from luizdepra/spiralflood.py
Created June 20, 2012 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luan/2960994 to your computer and use it in GitHub Desktop.
Save luan/2960994 to your computer and use it in GitHub Desktop.
Spiral Water Flood
# Dont work =(
class SpiralFlood:
def __init__(self):
self.tiles = []
def spiralFlood(self, sx, sy, K, m):
x = y = 0
dx = 0
dy = -1
i = 0
while i < m and i < K*K:
if (-K/2 < x <= K/2) and (-K/2 < y <= K/2):
if 0 <= x + sx < 32 and 0 <= y + sy < 32:
# print (x + sx, y + sy)
self.tiles[x + sx][y + sy] = "#"
i += 1
if x == y or (x < 0 and x == -y) or (x > 0 and x == 1-y):
dx, dy = -dy, dx
x, y = x+dx, y+dy
flood = SpiralFlood()
for i in range(32):
r = []
for j in range(32):
r.append(".")
flood.tiles.append(r)
flood.spiralFlood(15,15,32,15)
for k in range(32):
print flood.tiles[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment