Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Topographer(object):
- def __init__(self, size, **kwargs):
- for key, value in kwargs.iteritems():
- setattr(self, key, value)
- self.size = size
- def boundary(self):
- lx = self.size[0] - 1
- ly = self.size[1] - 1
- hx = 0
- hy = 0
- for x in range(self.size[0]):
- for y in range(self.size[1]):
- c = self.get(x, y)
- if c is None:
- continue
- if lx > x: lx = x
- if ly > y: ly = y
- if hx < x: hx = x
- if hy < y: hy = y
- return ((lx, ly), (hx + 1, hy + 1))
- def render(self):
- low, high = self.boundary()
- x = low[0]
- print '+%s+' % ('-' * (high[1] - low[1]))
- while x < high[0]:
- line, y = '|', low[1]
- while y < high[1]:
- c = self.get(x, y)
- if c is None:
- c = ' '
- line += str(c)
- y += 1
- print line + '|'
- x += 1
- print '+%s+' % ('-' * (high[1] - low[1]))
- def get(self, x, y):
- for z in range(self.height):
- if self.volume[x, y, z] != 0:
- return '@'
Add Comment
Please, Sign In to add comment