def __init__(self, graph:sg.Graph, colour, x, width=BAT_SIZE[0], height=BAT_SIZE[1]): self.graph = graph self.id = graph.DrawRectangle((x - width / 2, 200), (x + width / 2, 200 + height), fill_color=colour) self.y = 0 self.x = x self.curx = x self.cury = height/2
def __init__(self, graph: sg.Graph, colour, x, field_height): self.graph = graph self.field_height = field_height self.width = BAT_SIZE[0] self.height = BAT_SIZE[1] self.current_x = x self.current_y = self.field_height / 2 - self.height / 2 self.id = graph.draw_rectangle( (self.current_x, self.current_y), (self.current_x + self.width, self.current_y + self.height), fill_color=colour ) self.vy = 0
def erase_marks(winfo: Struct, graph: sg.Graph, current_tab: str, full_erase: bool = False) -> None: """Erase markers off graph. Delete stored markers if full_erase enabled. Args: winfo: Struct object that holds all GUI information. graph: The selected PSG graph to draw mask points on. current_tab: String denoting the current tab the graph is on in the GUI full_erase: Value for deleting the figures from the graph. Returns: None """ if current_tab == 'bunwarpj_tab': for marks in winfo.buj_mask_markers: for line in marks: graph.DeleteFigure(line) elif current_tab == 'reconstruct_tab': winfo.rec_mask_coords = [] for line in winfo.rec_mask_markers: graph.DeleteFigure(line)
def draw_mask_points(winfo: Struct, graph: sg.Graph, current_tab: str, double_click: bool = False) -> None: """Draw mask markers to appear on graph. Args: winfo: Struct object that holds all GUI information. graph: The selected PSG graph to draw mask points on. current_tab: String denoting the current tab the graph is on in the GUI double_click: Double-click value for terminating the mask drawing. Only necessary for bUnwarpJ masks. Returns: None """ if current_tab == 'bunwarpj_tab': num_coords = len(winfo.buj_mask_coords) for i in range(num_coords): x1, y1 = winfo.buj_mask_coords[i] x2, y2 = winfo.buj_mask_coords[(i + 1) % num_coords] id_horiz = graph.DrawLine((x1 - 7, y1), (x1 + 7, y1), color='red', width=2) id_verti = graph.DrawLine((x1, y1 - 7), (x1, y1 + 7), color='red', width=2) end = (i+1) % num_coords if end or double_click: id_next = graph.DrawLine((x1, y1), (x2, y2), color='red', width=2) else: id_next = graph.DrawLine((x1, y1), (x1, y1), color='red', width=1) winfo.buj_mask_markers.append((id_horiz, id_verti, id_next)) elif current_tab == 'reconstruct_tab': num_coords = len(winfo.rec_mask_coords) for i in range(num_coords): x1, y1 = winfo.rec_mask_coords[i] x2, y2 = winfo.rec_mask_coords[(i + 1) % num_coords] id_num = graph.DrawLine((x1-1, y1), (x2-1, y2), color='red', width=1) winfo.rec_mask_markers.append(id_num)
def draw_square_mask(winfo: Struct, graph: sg.Graph) -> None: """Create the square mask for the REC graph. Args: winfo: Struct object that holds all GUI information. graph: The selected PSG graph to draw mask points on. Returns: None """ # Get the size of the mask and the graph mask_percent = winfo.rec_mask[0] / 100 graph_x, graph_y = graph.get_size() center_x, center_y = winfo.rec_mask_center winfo.rec_mask_coords = [] left_bounds, right_bounds = False, False top_bounds, bottom_bounds = False, False # Specific handling of figuring out the coordinates of the GUI mask. Be careful # not to change this or check how this may change with future PySimpleGUI updates. width, height = round(graph_x * mask_percent), round(graph_x * mask_percent) if width % 2 != 0: width -= 1 if height % 2 != 0: height -= 1 if center_x <= width//2: left_bounds = True if center_x >= graph_x - width//2: right_bounds = True if graph_y - center_y <= height//2: top_bounds = True if graph_y - center_y >= graph_y - height//2: bottom_bounds = True if not left_bounds and not right_bounds: x_left = center_x - width//2 x_right = center_x + width//2 elif left_bounds and right_bounds: x_left = 0 x_right = graph_x elif right_bounds: x_left = graph_x - width x_right = graph_x elif left_bounds: x_left = 0 x_right = width if not top_bounds and not bottom_bounds: y_top = center_y - height//2 y_bottom = center_y + height//2 elif top_bounds and bottom_bounds: y_top = 0 y_bottom = graph_y elif bottom_bounds: y_top = 0 y_bottom = height elif top_bounds: y_top = graph_y - height y_bottom = graph_y winfo.rec_mask_coords = [(x_left, y_top), (x_left, y_bottom), (x_right, y_bottom), (x_right, y_top)]
from opencv.box import Box from opencv.wall import Wall from theme import PRIMARY from opencv.agent.agent import Agent, Pheromone from opencv.forms.borders import get_rect_borders from opencv.forms.color import ColorFilter, Colors from opencv.forms.triangle import distance from opencv.main import EnvProcess main_graph = Graph((600, 450), (0, 450), (600, 0), key='MAIN-GRAPH', enable_events=True, drag_submits=True, metadata={ "a_id": None, "x": 0, "y": 0 }) colors_graph = Graph((600, 450), (0, 450), (600, 0), key='COLORS-GRAPH', enable_events=True, drag_submits=True, metadata={ "color": None, "a_id": None, }) borders_graph = Graph((600, 450), (0, 450), (600, 0),