def draw_event(self, event): coords = event.coords stddraw.setPenRadius(0.0055) stddraw.setPenColor(c=stddraw.RED) stddraw.point(coords[0], coords[1]) stddraw.setPenColor() self.__reset_pen()
def __borders_plot(self): stddraw.setPenColor(c=stddraw.RED) stddraw.setPenRadius(0.0025) stddraw.line(0, 0, 0, self.width) stddraw.line(0, 0, self.height, 0) stddraw.line(0, self.width, self.height, self.width) stddraw.line(self.height, 0, self.height, self.width) self.__reset_pen()
def __draw_drone_info(self, drone, cur_step): stddraw.setPenRadius(0.0125) stddraw.setPenColor(c=stddraw.BLACK) # index stddraw.text(drone.coords[0], drone.coords[1] + (drone.com_range / 2.0), "id: " + str(drone.identifier))
def __draw_next_target(self, drone_coo, target): stddraw.setPenRadius(0.0055) stddraw.setPenColor(c=stddraw.BLUE) stddraw.point(target[0], target[1]) stddraw.setPenColor() self.__reset_pen() stddraw.setPenColor(c=stddraw.BLUE) stddraw.setPenRadius(0.0025) stddraw.line(drone_coo[0], drone_coo[1], target[0], target[1]) self.__reset_pen()
def draw_obstacles(self): """ Spawns random obstacle segments in the map. """ stddraw.setPenColor(c=stddraw.RED) stddraw.setPenRadius(0.002) for i in range(self.simulator.n_obstacles): # generation is done only at the beginning startx, starty, endx, endy = self.simulator.environment.obstacles[ i] stddraw.line(startx, starty, endx, endy) self.__reset_pen()
def draw_depot(self, depot): coords = depot.coords stddraw.setPenRadius(0.0100) stddraw.setPenColor(c=stddraw.BLUE) stddraw.point(coords[0], coords[1]) self.__draw_communication_range(depot) self.__reset_pen() # draw the buffer size stddraw.setPenRadius(0.0125) stddraw.setPenColor(c=stddraw.BLACK) stddraw.text(depot.coords[0], depot.coords[1] + 100, "pk: " + str(len(depot.buffer)))
def draw_drone(self, drone, cur_step): coords = drone.coords if drone.buffer_length() > 0: # change color when find a packet stddraw.setPenColor(c=stddraw.GREEN) else: stddraw.setPenColor(c=stddraw.BLACK) stddraw.setPenRadius(0.0055) stddraw.point(coords[0], coords[1]) self.__draw_drone_info(drone, cur_step) self.__draw_communication_range(drone) self.__draw_sensing_range(drone) self.__reset_pen() if config.IS_SHOW_NEXT_TARGET_VEC: self.__draw_next_target(drone.coords, drone.next_target())
def draw_depot(self, depot): coords = depot.coords stddraw.setPenRadius(0.0100) stddraw.setPenColor(c=stddraw.DARK_RED) size_depot = 50 stddraw.filledPolygon([ coords[0] - (size_depot / 2), coords[0], coords[0] + (size_depot / 2) ], [coords[1], coords[1] + size_depot, coords[1]]) self.__draw_communication_range(depot) self.__reset_pen() # draw the buffer size stddraw.setPenRadius(0.0125) stddraw.setPenColor(c=stddraw.BLACK) stddraw.text(depot.coords[0], depot.coords[1] + 100, "pk: " + str(len(depot.all_packets())))
def grid_plot(self): """ Plots the tassellation of the area.""" if not self.simulator.grid_cell_size > 0: return # stddraw.setPenColor(c=stddraw.RED) # stddraw.setPenRadius(0.0025) stddraw.setPenColor(c=stddraw.VERY_LIGHT_GRAY) stddraw.setPenRadius(0.002) for i in range(self.simulator.grid_cell_size, self.width, self.simulator.grid_cell_size): stddraw.line(i, 0, i, self.height) for j in range(self.simulator.grid_cell_size, self.height, self.simulator.grid_cell_size): stddraw.line(0, j, self.width, j) self.__reset_pen()
def __grid_plot(self): for i in range(0, self.width, self.simulator.prob_size_cell): stddraw.setPenColor(c=stddraw.GRAY) stddraw.setPenRadius(0.0025) # x1, y1, x2, y2 stddraw.line(i, 0, i, self.height) self.__reset_pen() for j in range(0, self.height, self.simulator.prob_size_cell): stddraw.setPenColor(c=stddraw.GRAY) stddraw.setPenRadius(0.0025) # x1, y1, x2, y2 stddraw.line(0, j, self.width, j) self.__reset_pen() for cell, cell_center in utilities.TraversedCells.all_centers( self.width, self.height, self.simulator.prob_size_cell): index_cell = int(cell[0]) pr = self.simulator.cell_prob_map[index_cell][2] stddraw.text(cell_center[0], cell_center[1], "pr-c: " + str(round(pr, 4)))
def draw_drone(self, drone, cur_step): coords = drone.coords if drone.buffer_length() > 0: # change color when find a packet stddraw.setPenColor(c=stddraw.GREEN) else: stddraw.setPenColor(c=stddraw.BLACK) stddraw.setPenRadius(0.0055) stddraw.point(coords[0], coords[1]) self.__draw_drone_info(drone, cur_step) self.__draw_communication_range(drone) self.__draw_sensing_range(drone) # the radar distance self.__draw_distance_radar(coords[0], coords[1], drone.radar_range) self.__reset_pen() if config.PLOT_TRAJECTORY_NEXT_TARGET and not self.simulator.is_free_movement( ): self.__draw_next_target(drone.coords, drone.next_target())
def __draw_drone_info(self, drone, cur_step): stddraw.setPenRadius(0.0125) stddraw.setPenColor(c=stddraw.BLACK) # life time and speed stddraw.text(drone.coords[0] - 50, drone.coords[1], "buf: " + str(drone.buffer_length())) # index stddraw.text(drone.coords[0], drone.coords[1] + (drone.communication_range / 2.0), "id: " + str(drone.identifier)) if drone.buffer_length() > 0: stddraw.text( drone.coords[0], drone.coords[1] - (drone.communication_range / 2.0), "retr: " + str(drone.routing_algorithm.current_n_transmission)) # If the buffer is empty, do not show the retransmission counters since they are not updated else: stddraw.text(drone.coords[0], drone.coords[1] - (drone.communication_range / 2.0), "retr: -- \\ --")
def __draw_sensing_range(self, body): stddraw.setPenRadius(0.0015) stddraw.setPenColor(c=stddraw.RED) stddraw.circle(body.coords[0], body.coords[1], body.sensing_range) stddraw.setPenColor(c=stddraw.BLACK)
def __reset_pen(self): stddraw.setPenColor(c=stddraw.BLACK) stddraw.setPenRadius(0.0055)
def __channel_to_depot(self): stddraw.setPenColor(c=stddraw.LIGHT_GRAY) stddraw.setPenRadius(0.0025) #x1, y1, x2, y2 stddraw.line(self.width / 2, self.height, self.width / 2, 0) self.__reset_pen()
def __draw_communication_range(self, body): stddraw.setPenRadius(0.0015) stddraw.setPenColor(c=stddraw.BLUE) stddraw.circle(body.coords[0], body.coords[1], body.communication_range) stddraw.setPenColor(c=stddraw.BLACK)
def __draw_distance_radar(self, x, y, radar_radius): stddraw.setPenRadius(0.0015) stddraw.setPenColor(c=stddraw.RED) stddraw.circle(x, y, radar_radius) stddraw.setPenColor(c=stddraw.BLACK)
def draw_vector(self, pos, vector): stddraw.setPenRadius(0.0500) stddraw.line(pos[0], pos[1], vector[0], vector[1])