Guest User

Untitled

a guest
Oct 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class Topographer(object):
  2. def __init__(self, size, **kwargs):
  3. for key, value in kwargs.iteritems():
  4. setattr(self, key, value)
  5.  
  6. self.size = size
  7.  
  8. def boundary(self):
  9. lx = self.size[0] - 1
  10. ly = self.size[1] - 1
  11. hx = 0
  12. hy = 0
  13.  
  14. for x in range(self.size[0]):
  15. for y in range(self.size[1]):
  16. c = self.get(x, y)
  17.  
  18. if c is None:
  19. continue
  20.  
  21. if lx > x: lx = x
  22. if ly > y: ly = y
  23. if hx < x: hx = x
  24. if hy < y: hy = y
  25.  
  26. return ((lx, ly), (hx + 1, hy + 1))
  27.  
  28. def render(self):
  29. low, high = self.boundary()
  30. x = low[0]
  31.  
  32. print '+%s+' % ('-' * (high[1] - low[1]))
  33.  
  34. while x < high[0]:
  35. line, y = '|', low[1]
  36. while y < high[1]:
  37. c = self.get(x, y)
  38. if c is None:
  39. c = ' '
  40. line += str(c)
  41. y += 1
  42. print line + '|'
  43. x += 1
  44.  
  45. print '+%s+' % ('-' * (high[1] - low[1]))
  46.  
  47. def get(self, x, y):
  48. for z in range(self.height):
  49. if self.volume[x, y, z] != 0:
  50. return '@'
Add Comment
Please, Sign In to add comment