Advertisement
Guest User

Untitled

a guest
Mar 29th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import vecmath
  2. from operator import truediv
  3.  
  4. class ObjectLocation(vecmath.Vector):
  5.     def __init__(self, token):
  6.         self.token = token
  7.  
  8.  
  9. class OutputBuilder(vecmath.Vector):
  10.     def __init__(self):
  11.         self.pos_height = 7
  12.         self.neg_height = 7
  13.        
  14.         self.pos_width = 7
  15.         self.neg_width = 7
  16.        
  17.         self.locations = []
  18.        
  19.         self.center_char = 'O'
  20.         self.draw_center = True
  21.        
  22.         self.draw_x_center_line = True
  23.        
  24.         self.x_center_line_char = '-'
  25.        
  26.         self.draw_y_center_line = True
  27.         self.y_center_line_char = '|'
  28.        
  29.         self.fill_char = '#'
  30.        
  31.         self.resolution = 100
  32.        
  33.        
  34.        
  35.     def addLocation(self, group):
  36.         if not isinstance(group, Group):
  37.             raise ValueError, 'You can only add Group Objects'
  38.            
  39.         self.locations.append(group)
  40.        
  41.     def generate(self):
  42.         half_res = truediv(self.resolution, 2)
  43.         s = ''
  44.            
  45.         for x in xrange(-abs(self.neg_width), abs(self.pos_width) + 1):
  46.             for y in xrange(-abs(self.neg_height), abs(self.pos_height) + 1):
  47.                
  48.                 if x == 0 and y == 0:
  49.                     if self.draw_center:
  50.                         # CENTER POINT!!
  51.                         s += self.center_char
  52.                         continue
  53.                        
  54.                 xres = x * self.resolution
  55.                 yres = y * self.resolution
  56.                 for l in self.locations:
  57.                     if vecmath.isbetweenRect((l.x, l.y, 0), (xres - half_res, yres - half_res, 0), (xres + half_res, yres + half_res, 0)):
  58.                         s += l.token
  59.                        
  60.                         break
  61.                        
  62.                 if x == 0 and y != 0:
  63.                     if self.draw_x_center_line:
  64.                         s += self.x_center_line_char
  65.                         continue
  66.                        
  67.                 elif x != 0 and y == 0:
  68.                     if self.draw_y_center_line:
  69.                         s += self.y_center_line_char
  70.                         continue
  71.                        
  72.                 s += self.fill_char
  73.                        
  74.             s += '\n'
  75.                        
  76.         return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement