예제 #1
0
    def draw(self):
        if self.pulsing:
            color = 'red'
        else:
            color = 'black'

        target = self.target
        source = self.source
        line = Line(source.location, target.location)
        line.setWidth(1)
        line.setFill(color)
        line.setOutline(color)
        line.draw(self.brain.win)

        dx = target.location.x - source.location.x
        dy = target.location.y - source.location.y
        k = dy / dx if dx != 0 else dy
        k = abs(k)
        dd = 20
        sign_dx = -1 if dx < 0 else 1
        sign_dy = -1 if dy < 0 else 1
        dx = -sign_dx * dd / sqrt(k**2 + 1)
        dy = -sign_dy * k * dd / sqrt(k**2 + 1)
        # sleep(1)

        dp = Point(target.location.x + dx, target.location.y + dy)
        line = Line(dp, target.location)
        line.setWidth(3)
        line.setFill(color)
        line.draw(self.brain.win)
예제 #2
0
 def create_line(p0, p1, width):
     line = Line(p0, p1)
     line.setWidth(width)
     color = color_rgb(200, 200, 200)
     line.setOutline(color)
     line.setArrow("last")
     return line
예제 #3
0
    def draw_route(self, car, show_route):
        # TODO optimize to not have to redraw entire route each time
        self.clear_route(self.route)
        self.route = {}

        if not show_route:
            return

        line_width = 3
        line_color = color_rgb(20, 200, 20)
        p0 = Point(car.x, car.y)
        route = car.route[:]
        route.append(car.next_dest_id)
        for vertex_id in route[::-1]:
            intersection = self.intersections[vertex_id]
            p1 = Point(intersection.x, intersection.y)
            line = Line(p0, p1)
            line.setWidth(line_width)
            line.setOutline(line_color)
            self.route[vertex_id] = line
            p0 = p1

        old_route = {
            key: val
            for key, val in self.route.items() if key not in route
        }
        self.route = {
            key: val
            for key, val in self.route.items() if key in route
        }
        self.clear_route(old_route)

        for line in self.route.values():
            line.draw(self.canvas)
예제 #4
0
    def draw_mark(self, move: tuple) -> None:
        """ Draw a mark as specified by a move 
        :param move: a legal move: (selected_tile.x_pos, selected_tile.y_pos, player.mark)
        :return: none
        """

        if self.window is None:
            raise ValueError('Board has no open window!')

        tile_x, tile_y, mark = move

        grid_x, grid_y = self.coord_tile_to_grid(tile_x, tile_y)

        rad = self.tile_size * 0.3

        if mark == 'O':
            cir = Circle(Point(grid_x, grid_y), rad)
            cir.setOutline('blue')
            cir.setWidth(3)
            cir.draw(self.window)
        else:
            downstroke = Line(Point(grid_x - rad, grid_y - rad),
                              Point(grid_x + rad, grid_y + rad))
            upstroke = Line(Point(grid_x - rad, grid_y + rad),
                            Point(grid_x + rad, grid_y - rad))
            downstroke.setOutline('red')
            downstroke.setWidth(3)
            upstroke.setOutline('red')
            upstroke.setWidth(3)
            upstroke.draw(self.window)
            downstroke.draw(self.window)
예제 #5
0
def drawFieldPanel():

    # Create Field panel
    field = GraphWin("The Field", 400, 400)

    # Create vertical and horizontal lines on Field panel
    for i in range(9):
        v_field_line = Line(Point(40 * (i + 1), 0), Point(40 * (i + 1), 400))
        v_field_line.setOutline("light gray")
        v_field_line.draw(field)
        h_field_line = Line(Point(0, 40 * (i + 1)), Point(400, 40 * (i + 1)))
        h_field_line.setOutline("light gray")
        h_field_line.draw(field)

    # Color start and end squares
    start = Rectangle(Point(0, 0), Point(40, 40))
    start.setFill("green")
    start.setOutline("light gray")
    start.draw(field)
    end = Rectangle(Point(360, 360), Point(400, 400))
    end.setFill("red")
    end.setOutline("light gray")
    end.draw(field)

    # Draw black holes
    blackcenter1, blackcenter2 = blackHoles(field)

    # Create spin square Rectangle
    while True:
        # Make sure spin square is not drawn on top of black holes, and repeat
        #   location process if it is on top of a black hole
        spin_x = randint(2, 9) * 40 - 20
        spin_y = randint(2, 9) * 40 - 20
        spin_square = Rectangle(Point(spin_x - 17, spin_y - 17),
                                Point(spin_x + 17, spin_y + 17))
        if spin_x != blackcenter1.getX() and spin_y != blackcenter1.getY(
        ) or spin_x != blackcenter2.getX() and spin_y != blackcenter2.getY():
            break
    spin_square.setFill("blue")
    spin_square.draw(field)
    spin_text = Text(Point(spin_x, spin_y), "SPIN")
    spin_text.setTextColor("white")
    spin_text.draw(field)

    # Create initial Pete Rectangle
    pete = Rectangle(Point(4, 4), Point(36, 36))
    pete.setFill("gold")
    pete.draw(field)

    # Draw and return sensors
    sensors, goodsensors = drawSensors(field)

    # Return objects
    return field, pete, sensors, spin_square, blackcenter1, blackcenter2, goodsensors
예제 #6
0
def draw_searcher_move(s, i, win):
    '''
    For drawing purposes make sure the distace moved
    does not jump from one side of the env to the other
    '''
    if win is not None:
        if (
                abs(s.X[i] - s.X[i+1]) <= s.max_speed and
                abs(s.Y[i] - s.Y[i+1]) <= s.max_speed
        ):
            p = Line(Point(s.X[i], s.Y[i]), Point(s.X[i+1], s.Y[i+1]))
            p.setOutline("green")
            p.draw(win)
예제 #7
0
파일: life.py 프로젝트: stevemccoy/graphics
 def draw_grid(self):
     total_height = self.origin_y + self.cell_height * self.ny
     total_width = self.origin_x + self.cell_width * self.nx
     for i in range(self.nx + 1):
         x = self.origin_x + i * self.cell_width
         l = Line(Point(x, self.origin_y), Point(x, total_height))
         l.setOutline(self.gridcolour)
         l.draw(self.win)
     for i in range(self.ny + 1):
         y = self.origin_y + i * self.cell_height
         l = Line(Point(self.origin_x, y), Point(total_width, y))
         l.setOutline(self.gridcolour)
         l.draw(self.win)
예제 #8
0
    def draw_winning_line(self, start: tuple, end: tuple) -> None:
        """ Draw a line through the winning series of marks """

        if self.window is None:
            raise ValueError("Board does not have an open window!")

        start_x, start_y = self.coord_tile_to_grid(start[0], start[1])
        end_x, end_y = self.coord_tile_to_grid(end[0], end[1])

        pt1 = Point(start_x, start_y)
        pt2 = Point(end_x, end_y)

        line = Line(pt1, pt2)
        line.setWidth(4)
        line.setOutline('black')
        line.draw(self.window)
예제 #9
0
 def set_graphicals(self, quick_draw):
     """Draws the graph"""
     self.drawables = []
     self.drawable_path = []
     t = time.time()
     for node in self.graph:
         curr_loc = node.get_scaled_point()
         draw_node = Circle(curr_loc, 1)
         draw_node.setFill('red')
         draw_node.draw(self.win)
         self.drawables.append(draw_node)
         if not quick_draw:
             for neighbor in self.graph[node]:
                 if neighbor:
                     line = Line(curr_loc, neighbor.get_scaled_point())
                     line.draw(self.win)
                     self.drawables.append(line)
     if self.path is not None:
         for i in range(0, len(self.path) - 1):
             node_1 = self.path[i]
             node_2 = self.path[i + 1]
             cir = Circle(node_1.get_scaled_point(), 2)
             cir.setFill('Red')
             cir.setOutline('Red')
             self.drawable_path.append(cir)
             lin = Line(node_1.get_scaled_point(),
                        node_2.get_scaled_point())
             lin.setOutline('Red')
             lin.draw(self.win)
             self.drawable_path.append(lin)
         for i in range(0, len(self.optimal_path) - 1):
             node_1 = self.optimal_path[i]
             node_2 = self.optimal_path[i + 1]
             cir = Circle(node_1.get_scaled_point(), 5)
             cir.setFill('Blue')
             cir.setOutline('Blue')
             cir.draw(self.win)
             self.drawable_path.append(cir)
             lin = Line(node_1.get_scaled_point(),
                        node_2.get_scaled_point())
             lin.setOutline('Blue')
             lin.draw(self.win)
             self.drawable_path.append(lin)
     emit_verbose("Drawing RRT took", self.verbose, var=time.time() - t)
예제 #10
0
    def draw_grid(self, logic: bool = False) -> None:
        """ Draw the board's grid """
        window = self.window if not logic else self.logic_window
        if window is not None:
            # draw horizontals:
            for i in range(self.tile_size, self.window_height, self.tile_size):
                row_y = i
                line = Line(Point(0, row_y), Point(self.window_width, row_y))
                line.setOutline('black')
                line.setWidth(2)
                line.draw(window)

            # draw verticals
            for i in range(self.tile_size, self.window_width, self.tile_size):
                col_x = i
                line = Line(Point(col_x, 0), Point(col_x, self.window_height))
                line.setOutline('black')
                line.setWidth(2)
                line.draw(window)
예제 #11
0
파일: diff_graph.py 프로젝트: mckoss/labs
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill('red')
        c.draw(win)

    win.getMouse()
    win.close()
예제 #12
0
파일: diff_graph.py 프로젝트: mckoss/labs
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill("red")
        c.draw(win)

    win.getMouse()
    win.close()
예제 #13
0
 def X_make(p2):
     upper = p2.getX()
     lower = p2.getY()
     # Lower left Box
     if (p2.getX() < 2 and p2.getY() < 3):
         X_mark = Line(Point(-.5, 2.5), Point(1.5, .5))
         X_mark2 = Line(Point(-.5, .5), Point(1.5, 2.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[2][0] = 'X'
     # Left column middle box
     elif (p2.getX() < 2 and p2.getY() < 6):
         X_mark = Line(Point(-0.8, 5.5), Point(1.5, 3.5))
         X_mark2 = Line(Point(-.8, 3.5), Point(1.5, 5.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[1][0] = 'X'
     # Top left box
     elif (p2.getX() < 2 and p2.getY() < 9):
         X_mark = Line(Point(-.8, 8.5), Point(1.5, 6.5))
         X_mark2 = Line(Point(-.8, 6.5), Point(1.5, 8.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[0][0] = 'X'
     # Bottom row middle box
     elif (p2.getX() < 5 and p2.getY() < 3):
         X_mark = Line(Point(2.5, 2.5), Point(4.5, .5))
         X_mark2 = Line(Point(4.5, 2.5), Point(2.5, .5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[2][1] = 'X'
     # Middle row middle box
     elif (p2.getX() < 5 and p2.getY() < 6):
         X_mark = Line(Point(2.5, 5.5), Point(4.5, 3.5))
         X_mark2 = Line(Point(2.5, 3.5), Point(4.5, 5.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[1][1] = 'X'
     # Top row middle box
     elif (p2.getX() < 5 and p2.getY() < 9):
         X_mark = Line(Point(2.5, 8.5), Point(4.5, 6.5))
         X_mark2 = Line(Point(4.5, 8.5), Point(2.5, 6.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[0][1] = 'X'
     # Bottom row rightmost box
     elif (p2.getX() < 8 and p2.getY() < 3):
         X_mark = Line(Point(5.5, .5), Point(7.5, 2.5))
         X_mark2 = Line(Point(5.5, 2.5), Point(7.5, .5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[2][2] = 'X'
     # Right column middle box
     elif (p2.getX() < 8 and p2.getY() < 6):
         X_mark = Line(Point(5.5, 3.5), Point(7.5, 5.5))
         X_mark2 = Line(Point(5.5, 5.5), Point(7.5, 3.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[1][2] = 'X'
     # right column top box
     elif (p2.getX() < 8 and p2.getY() < 9):
         X_mark = Line(Point(5.5, 8.5), Point(7.5, 6.5))
         X_mark2 = Line(Point(5.5, 6.5), Point(7.5, 8.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[0][2] = 'X'
예제 #14
0
def pause_menu(right):

	start = 500 if right else 0
	prior = len(gw.items)

	pause_overlay = Image(Point(500, 250), MAP / "pause_overlay.png")
	pause_overlay.draw(gw)


	# Everything for the Character Information
	info_box = Rectangle(Point(551 - start, 100), Point(959 - start, 400))
	info_box.setFill(color_rgb(50, 50, 50))
	info_box.setWidth(3)
	info_box.draw(gw)

	# The Character Icon
	info_icon = Image(Point(613 - start, 163), MAPS / "characters" / f"{player.character_class}_portrait.png")
	info_icon.draw(gw)

	# Shows the Header that includes the player's name and level.
	info_header = Text(Point(572 - start, 179))
	info_header.setAnchor("w")
	info_header.setSize(22)
	info_header.setText(f"      {player.name + f'LV: {player.lvl}'.rjust(16)[len(player.name):]}\n      HP:\n      EXP:\nItems:")
	info_header.draw(gw)

	# Draw the HP bar.
	hp_bar = Bar(player.current_HP, player.base_HP, "red", Point(750 - start, 149), Point(948 - start, 173))
	hp_bar.show()


	# Draws the EXP bar
	exp_bar = Bar(player.current_EXP, player.next_EXP, "green", Point(750 - start, 179), Point(948 - start, 203))
	exp_bar.show()

	# Lists off the player's current inventory.
	info_header_underline = Line(Point(573 - start, 240), Point(937 - start, 240))
	info_header_underline.setWidth(1)
	info_header_underline.setOutline("white")
	info_header_underline.draw(gw)
	info_footer = Text(Point(573 - start, 246))
	info_footer.setAnchor("nw")
	info_footer.setSize(14)
	info_footer.setText(inventory())
	info_footer.draw(gw)

	
	# Lists off the pause menu options.
	choice_box = Rectangle(Point(start + 125, 165), Point(start + 370, 335))
	choice_box.setFill(color_rgb(50, 50, 50))
	choice_box.setWidth(3)
	choice_box.draw(gw)

	choice_text = Text(Point(start + 260, 250))
	choice_text.setAnchor("c")
	choice_text.setSize(20)
	choice_text.setText("Resume\nDrink Potion\nEat Apple\nSave Game\nQuit Game")
	choice_text.draw(gw)
	

	selector = Polygon(Point(start + 137, 183), Point(start + 137, 195), Point(start + 154, 189))
	selector.setFill("red")
	selector.draw(gw)

	selection = 0
	saved = False

	while True:
		
		while True:
			key = gw.checkKey().lower()

			if key != "":
				if key in ["space", "return"]:
					break

				elif key in ["escape"]:
					while selection > 0:
						selector.move(0, -30)
						selection -= 1


				if key in ["up", "w", "left", "a"]:
					selection = (selection - 1) % 5
					if selection != 4:
						selector.move(0, -30)
					else:
						selector.move(0, 120)


				elif key in ["down", "s", "right", "d"]:
					selection = (selection + 1) % 5
					if selection != 0:
						selector.move(0, 30)
					else:
						selector.move(0, -120)

		# Resume Game
		if selection == 0:
			for i in gw.items[prior:]: i.undraw()
			return

		# Drink Potion
		if selection == 1:
			if player.items["Potions"] == 0:
				dialogue("You have no more potions to drink.", right=right)
			elif player.current_HP == player.base_HP:
				dialogue("You are already at max HP", right=right)
			else:
				player.items["Potions"] -= 1
				player.current_HP += round(randint(4, 10) * 4.2)
				if player.current_HP > player.base_HP:
					player.current_HP = player.base_HP
				hp_bar.update(player.current_HP, player.base_HP)

		# Eat Apple
		if selection == 2:
			if player.items["Apples"] == 0:
				dialogue("You have no more apples to eat.", right=right)
			elif player.current_HP == player.base_HP:
				dialogue("You are already at max HP", right=right)
			else:
				player.items["Apples"] -= 1
				player.current_HP += randint(1, 4)
				if player.current_HP > player.base_HP:
					player.current_HP = player.base_HP
				hp_bar.update(player.current_HP, player.base_HP)

		# Save Game
		if selection == 3:
			saved = True
			save_state = open("save_state.txt", "w")  
			
			stats_to_save = [player.character_class, player.name, player.lvl, player.attack, player.defense, 
				player.current_HP, player.base_HP, player.current_SP, player.base_SP, player.current_EXP, player.next_EXP,
				player.gold, player.items, game_stats
			]

			line_to_save = ''
			for i in stats_to_save:
				line_to_save = line_to_save + str(i) + "\n"

			save_state.write(b64encode(line_to_save.encode("UTF-8")).decode("UTF-8"))
			save_state.close()

			dialogue("Game saved.", right=right)

		# Quit Game
		if selection == 4:

			if not saved:
				dialogue(f"You have not saved recently.")

			if dialogue("Are you sure you want to quit?", ["Yes", "No"], right=right) == 0:
				raise GameOver('Town Quit')

		info_footer.setText(inventory())