def draw_ground_truth(self): if self.ground_truth == None or len(self.ground_truth) == 0: return self color = self.colors.frontier width = self.width_line dim = self.dimensions_map for (a, b) in self.ground_truth: if a == b: # null edge continue a = self.rescale(a) a = xy2ij(center2xy(a, dim), dim) b = self.rescale(b) b = xy2ij(center2xy(b, dim), dim) pygame.draw.line(self.surface_map, color, a, b, width) return self
def draw_robots(self): if self.robots == None or len(self.robots) == 0: return self color = self.colors.robot_1 radius = self.radius_robot dim = self.dimensions_map for robot in self.robots: (xy, orientation) = robot (x, y) = xy if x != 0 and (y != 0 or y != 20): if orientation == 0: xy = (x, y + 5) if orientation == 1: xy = (x + 5, y) if orientation == 2: xy = (x, y - 5) if orientation == 3: xy = (x - 5, y) (x, y) = self.rescale(xy) xy = (x + 1, y + 1) ij = xy2ij(center2xy(xy, dim), dim) (i, j) = ij ij = (int(i), int((j))) # print("BUG: " + str(ij)) pygame.draw.circle(self.surface_map, color, ij, radius) base = [(i, j - 3), (i + 3, j), (i, j + 3), (i - 3, j)] tops = [(i, j - 7), (i + 7, j), (i, j + 7), (i - 7, j)] real = [] for i in range(4): if i == orientation: real.append(tops[i]) elif abs(i - orientation) != 2: real.append(base[i]) pygame.draw.polygon(self.surface_map, (50, 50, 50), real) return self
def is_valid_position(self, xy): (x, y) = center2xy(xy, self.dimensions) (x_max, y_max) = self.dimensions if x < 0 or x > x_max - 1: return False if y < 0 or y > y_max - 1: return False return True
def draw_frontiers(self): if self.frontiers == None or len(self.frontiers) == 0: return self color = self.colors.frontier width = self.width_frontier dim = self.dimensions_map for xy in self.frontiers: xy = self.rescale(xy) (i, j) = xy2ij(center2xy(xy, dim), dim) rect = pygame.Rect(i-self.block_size/2, j-self.block_size/2, self.block_size+1, self.block_size+1) pygame.draw.rect(self.surface_map, color, rect) return self
def draw_robots(self): if self.robots == None or len(self.robots) == 0: return self color_1 = self.colors.robot_1 color_2 = self.colors.robot_2 radius = self.radius_robot dim = self.dimensions_map myrobots = self.environment.get_robots() for robot, color in zip(myrobots, [color_1,color_2]): (x, y, orientation) = robot (x,y) = self.rescale((x,y)) xy = (x+1,y+1) ij = xy2ij(center2xy(xy, dim), dim) (i,j) = ij pygame.draw.circle(self.surface_map, color, ij, radius) base = [(i,j-3), (i+3,j), (i,j+3), (i-3,j)] tops = [(i,j-7), (i+7,j), (i,j+7), (i-7,j)] real = [] for i in range(4): if i == orientation: real.append(tops[i]) elif abs(i-orientation) != 2: real.append(base[i]) pygame.draw.polygon(self.surface_map, (50,50,50), real) return self