Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vecmath
- from operator import truediv
- class ObjectLocation(vecmath.Vector):
- def __init__(self, token):
- self.token = token
- class OutputBuilder(vecmath.Vector):
- def __init__(self):
- self.pos_height = 7
- self.neg_height = 7
- self.pos_width = 7
- self.neg_width = 7
- self.locations = []
- self.center_char = 'O'
- self.draw_center = True
- self.draw_x_center_line = True
- self.x_center_line_char = '-'
- self.draw_y_center_line = True
- self.y_center_line_char = '|'
- self.fill_char = '#'
- self.resolution = 100
- def addLocation(self, group):
- if not isinstance(group, Group):
- raise ValueError, 'You can only add Group Objects'
- self.locations.append(group)
- def generate(self):
- half_res = truediv(self.resolution, 2)
- s = ''
- for x in xrange(-abs(self.neg_width), abs(self.pos_width) + 1):
- for y in xrange(-abs(self.neg_height), abs(self.pos_height) + 1):
- if x == 0 and y == 0:
- if self.draw_center:
- # CENTER POINT!!
- s += self.center_char
- continue
- xres = x * self.resolution
- yres = y * self.resolution
- for l in self.locations:
- if vecmath.isbetweenRect((l.x, l.y, 0), (xres - half_res, yres - half_res, 0), (xres + half_res, yres + half_res, 0)):
- s += l.token
- break
- if x == 0 and y != 0:
- if self.draw_x_center_line:
- s += self.x_center_line_char
- continue
- elif x != 0 and y == 0:
- if self.draw_y_center_line:
- s += self.y_center_line_char
- continue
- s += self.fill_char
- s += '\n'
- return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement