Exemple #1
0
 def set_coordinates(self, x, y=None):
     if isinstance(x, Coordinates):
         coord = x
     elif isinstance(x, (list, tuple)):
         coord = Coordinates(*x)
     else:
         coord = Coordinates(x, y)
     self.coord = coord
Exemple #2
0
    def __init__(self, *p, origin=Coordinates(0, 0)):
        if isinstance(p[0], tuple):
            p = Coordinates(*p[0])
        elif isinstance(p[0], Coordinates):
            p = p[0]
        elif isinstance(p[0], numeric):
            p = Coordinates(*p)

        if isinstance(origin, tuple):
            origin = Coordinates(*origin)

        self.p = p
        self.origin = origin
Exemple #3
0
 def add_graph(self, obj, x=0, y=0):
     if isinstance(x, Coordinates):
         coord_other = x
     else:
         coord_other = Coordinates(x, y)
     coord = obj.coord + coord_other
     xi = coord.x
     xf = coord.x + obj.graph.w
     yf = self.flipud(coord.y - 1)
     yi = self.flipud(coord.y - 1 + obj.graph.h)
     x_slice = slice(xi, xf)
     y_slice = slice(yi, yf)
     transparent = obj.transparent
     if transparent:
         new_subgraph = self[y_slice, x_slice].no_background_draw(obj.graph)
     else:
         new_subgraph = obj.graph
     self[y_slice, x_slice] = new_subgraph
Exemple #4
0
 def origin(self):
     x = min([obj.coord.x for obj in self.objects])
     y = min([obj.coord.y for obj in self.objects])
     return Coordinates(x, y)
Exemple #5
0
 def end(self):
     x = self.objects[-1].coord.x
     y = self.objects[-1].coord.y
     self.coord = Coordinates(x, y)
     return self.coord
Exemple #6
0
 def origin(self):
     self.coord = Coordinates(self.x, self.y)
     return self.coord
Exemple #7
0
        target_point = p2
        arrived = current_point == target_point
        self.add_point(current_point)
        while not arrived:
            next_points = [current_point + m for m in movements]
            distances = [calc_distance(p, target_point)
                         for p in next_points]
            idx = distances.index(min(distances))
            current_point += movements[idx]
            self.add_point(current_point)
            arrived = current_point == target_point

    def update(self):
        self.graph = Graph(w=self.w, h=self.h)
        origin = self.origin
        for obj in self.objects:
            obj.coord -= origin
            self.graph.add_graph(obj)


movements = [
    Coordinates(0, 1),
    Coordinates(1, 1),
    Coordinates(1, 0),
    Coordinates(1, -1),
    Coordinates(0, -1),
    Coordinates(-1, -1),
    Coordinates(-1, 0),
    Coordinates(-1, 1),
]
Exemple #8
0
 def __init__(self, w, h, x=0, y=0, framed=True, frame_formatter=None):
     super(Block, self).__init__(w=w, h=h)
     self.framed = framed
     self.set_frame_formatter(frame_formatter)
     self.coord = Coordinates(x, y)