示例#1
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)
示例#2
0
def draw_tour(tour):
    from graphics import Point, Circle, Line, GraphWin
    maxX = max([x for x, y in tour])
    minX = min([x for x, y in tour])
    maxY = max([y for x, y in tour])
    minY = min([y for x, y in tour])

    N = 750
    norm_x = N / (maxX - minX)
    norm_y = N / (maxY - minY)

    win = GraphWin("TSP", N, N)
    for n in tour:
        c = Point(*norm(n, norm_x, norm_y, minX, minY))
        c = Circle(c, 2)
        c.draw(win)

    for i, _ in enumerate(tour[:-1]):
        p1 = norm(tour[i], norm_x, norm_y, minX, minY)
        p2 = norm(tour[i + 1], norm_x, norm_y, minX, minY)
        l = Line(Point(*p1), Point(*p2))
        l.draw(win)

    win.getMouse()
    win.close()
def draw_tour(path_d, all_nodes):
	from graphics import Point, Circle, Line, GraphWin
	maxX = max([x for x, y in all_nodes])
	minX = min([x for x, y in all_nodes])
	maxY = max([y for x, y in all_nodes])
	minY = min([y for x, y in all_nodes])

	N = 750
	norm_x = N/(maxX - minX)
	norm_y = N/(maxY - minY)

	win = GraphWin("TSP", N, N)
	for n in all_nodes:
		c = Point(*norm(n, norm_x, norm_y, minX, minY))
		c = Circle(c, 3)
		c.draw(win)

	for (k, subdict) in path_d.iteritems():
		#t = Text(Point(*subdict['center']*N), k)
		#t.draw(win)
		if not subdict['hasBeenSplit']:
			p = Point(*norm(subdict['center'], norm_x, norm_y, minX, minY))

			c1i, c2i = subdict['connections']
			c1 = Point(*norm(path_d[str(c1i)]['center'], norm_x, norm_y, minX, minY))
			c2 = Point(*norm(path_d[str(c2i)]['center'], norm_x, norm_y, minX, minY))
			l1 = Line(p, c1)
			l2 = Line(p, c2)
			l1.draw(win)
			l2.draw(win)

	win.getMouse()
	win.close()
def draw_line(win, colour, point1, point2, current_tile):
    """Helper function for drawing lines."""
    current_line = Line(Point(*point1), Point(*point2))
    current_line.setWidth(2)
    current_line.setFill(colour)
    current_line.draw(win)
    current_tile.append(current_line)
示例#5
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)
示例#6
0
 def createWindow(self, N):
     """
     Create the graphics window.
     Arguments:
         self - the SkewerUI instance
         N - the capacity of the skewer
     """
     self.win = GraphWin("Shish Kebab", 800, 200)
     self.win.setCoords( \
         WIN_LOW_LEFT_X, \
         WIN_LOW_LEFT_Y - 0.1, \
         WIN_LOW_LEFT_X+(N+1)*FOOD_WIDTH, \
         WIN_UP_RIGHT_Y + 0.1 \
     )
     
     # draw skewer
     line = Line( \
         Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         Point(N, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0) \
     )
     line.setWidth(LINE_THICKNESS)
     line.draw(self.win)
     handle = Circle( \
         Point(N-.1, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         SKEWER_HANDLE_RADIUS \
     )
     handle.setFill(BKGD_COLOR)
     handle.setWidth(LINE_THICKNESS)
     handle.draw(self.win)
     self.items = []
示例#7
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)
示例#8
0
def make_new_line(g1, g2, lines, win):
    new_line = GraphLine(g1, g2)
    lines.append(new_line)
    g1.vertex.connect_node(g2.vertex)
    handle_possible_intersections(new_line, lines, win)
    win_line = Line(g1.point, g2.point)
    win_line.setWidth(3)
    win_line.draw(win)
示例#9
0
def draw_iks(x, y):
    global items
    line1 = Line(Point(x*SIZE+PADDING, y*SIZE+PADDING), Point((x+1)*SIZE-PADDING, (y+1)*SIZE-PADDING))
    line1.setWidth(WIDTH)
    line1.draw(win)
    items.append(line1)
    line2 = Line(Point(x*SIZE+PADDING, (y+1)*SIZE-PADDING), Point((x+1)*SIZE-PADDING, (y)*SIZE+PADDING))
    line2.setWidth(WIDTH)
    line2.draw(win)
    items.append(line2)
示例#10
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
示例#11
0
 def draw_horizontal_grid_lines():
     for i_row in range(n_rows + 1):
         x0 = left_margin
         y0 = upper_margin + i_row * cell_height
         pt0 = Point(x0, y0)
         pt1 = Point(x0 + grid_width, y0)
         line = Line(pt0, pt1)
         if i_row % order == 0:
             line.setWidth(thick)
         else:
             line.setWidth(0)
         line.draw(win)
示例#12
0
 def draw_vertical_grid_lines():
     for i_col in range(n_cols + 1):
         x0 = left_margin + i_col * cell_height
         y0 = upper_margin
         pt0 = Point(x0, y0)
         pt1 = Point(x0, y0 + grid_height)
         line = Line(pt0, pt1)
         if i_col % order == 0:
             line.setWidth(thick)
         else:
             line.setWidth(0)
         line.draw(win)
示例#13
0
 def frame(self, win, s):
     header = Text(Point(350, 650), s)
     header.draw(win)
     for i in range(6):
         line = Line(Point(0, (i + 1) * 100), Point(700, (i + 1) * 100))
         line.draw(win)
     for i in range(7):
         horizontal = Line(Point((i + 1) * 100, 600), Point((i + 1) * 100,
                                                            0))
         horizontal.draw(win)
     for i in range(7):
         day = Text(Point((i * 100) + 50, 625), self.weekDays.get(i))
         day.draw(win)
示例#14
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)
示例#15
0
 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)
示例#16
0
def draw_patch_window():
    """
    9. Write a function draw_patch_window() (without parameters) which displays, in
    a graphics window of size 100 × 100 pixels, the patch design which is
    labelled with the final digit of your student number. The patch design
    should be displayed in red, as in the table. It's important that your
    program draws the patch design accurately, but don't worry if one pixel is
    chopped off at the edge of the window. Note that you don't need to draw a
    border around the patch design.
    """
    win = GraphWin("Patch design", 100, 100)
    for distance in (20, 40, 60, 80, 100):
        line = Line(Point(0, distance), Point(distance, 0))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(100 - distance, 0), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    for distance in (20, 40, 60, 80):
        line = Line(Point(distance, 100), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(0, distance), Point(100 - distance, 100))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    win.getMouse()
    win.close()
示例#17
0
def table_tennis_scorer():
    """
    8. Write a table_tennis_scorer() function that allows the user to keep track
    of the points of two players in a game of table tennis. In table tennis, the
    first player to reach 11 points wins the game; however, a game must be won
    by at least a two point margin. The points for the players should be
    displayed on two halves of a graphics window, and the user clicks anywhere
    on the appropriate side to increment a player's score. As soon as one player
    has won, a 'wins' message should appear on that side.
    """
    win = GraphWin("Table tennis scorer", 500, 500)
    win.setCoords(0, 0, 1, 1)

    left_score = 0
    right_score = 0

    divider = Line(Point(0.5, 0), Point(0.5, 1))
    divider.draw(win)

    left_score_text = Text(Point(0.25, 0.6), 0)
    left_score_text.setSize(35)
    left_score_text.draw(win)

    right_score_text = Text(Point(0.75, 0.6), 0)
    right_score_text.setSize(35)
    right_score_text.draw(win)

    while not ((left_score >= 11 or right_score >= 11) and
               (left_score >= (right_score + 2) or right_score >=
                (left_score + 2))):
        cursor = win.getMouse()
        if cursor.getX() <= 0.5:
            left_score += 1
            left_score_text.setText(left_score)
        else:
            right_score += 1
            right_score_text.setText(right_score)

    if left_score > right_score:
        winner_text_centre = Point(0.25, 0.5)
    else:
        winner_text_centre = Point(0.75, 0.5)

    winner_text = Text(winner_text_centre, "Winner")
    winner_text.setSize(20)
    winner_text.draw(win)

    cursor = win.getMouse()
    win.close()
示例#18
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)
示例#19
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()
示例#20
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)
示例#21
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()
示例#22
0
class Goal:
    def __init__(self, vel, pos, win):
        self.vel_x, self.vel_y = vel[0], vel[1]
        self.vel = np.array([self.vel_x, self.vel_y])
        self.pos_x = pos[0]
        self.pos_y = pos[1]
        self.win = win

    def set_graphicals(self):
        # draw player
        self.body = Circle(Point(scale(self.pos_x), scale(self.pos_y)), 7)
        self.body.setFill('red')
        # Note: downwards in Y is the positive direction for this graphics lib
        self.arrow = Line(
            Point(scale(self.pos_x), scale(self.pos_y)),
            Point(scale(self.pos_x + self.vel_x),
                  scale(self.pos_y + self.vel_y)))
        self.arrow.setFill('black')
        self.arrow.setArrow('last')
        self.body.draw(self.win)
        self.arrow.draw(self.win)
def drawLeg():
    link1length = float(input("Plz input your link1 length:"))
    link2length = float(input("Plz input your link2 length:"))
    print("Plz click a point that you wanna caculate IK")
    p = win.getMouse()
    seta1, seta2 = Ik(link1length, link2length,
                      p.getX() - baseX, baseY - p.getY(), 2)  #因为要输入长度,所以减去基坐标
    if seta1 == 0 and seta2 == 0:
        print("out of range cannot reach the point")
    x1 = link1length * math.cos(seta1)  #使用增量  未用实际量
    y1 = math.sqrt(link1length**2 - x1**2)
    x2 = link2length * math.cos(seta1 + seta2)  #
    y2 = math.sqrt(link2length**2 - x2**2)
    link1 = Line(Point(baseX, baseY), Point(x1 + baseX, baseY - y1))
    link2 = Line(Point(x1 + baseX, baseY - y1),
                 Point(baseX + x1 + x2, baseY - y1 - y2))

    link1.draw(win)
    link2.draw(win)
    win.getMouse()
    win.close()
示例#24
0
class Face:
    def __init__(self, window, center, size):
        eyeSize = 0.15 * size
        eyeOff = size / 3.0
        mouthSize = 0.8 * size
        mouthOff = size / 2.0
        self.head = Circle(center, size)
        self.head.draw(window)
        self.leftEye = Circle(center, eyeSize)
        self.leftEye.move(-eyeOff, -eyeOff)
        self.rightEye = Circle(center, eyeSize)
        self.rightEye.move(eyeOff, -eyeOff)
        self.leftEye.draw(window)
        self.rightEye.draw(window)
        p1 = center.clone()
        p1.move(-mouthSize / 2, mouthOff)
        p2 = center.clone()
        p2.move(mouthSize / 2, mouthOff)
        self.mouth = Line(p1, p2)
        self.mouth.draw(window)

    def Move(self, dx, dy):
        for p in self.points:
            p.Move(dx, dy)

    def Flinch(self, center, size, window):
        eyesize = 0.15 * size
        eyeOff = size / 3.0
        self.leftEye = Line(Point(center.x + eyesize / 2, center.y),
                            Point(center.x - eyesize / 2, center.y))
        self.leftEye.move(-eyeOff, -eyeOff)
        self.rightEye = Circle(center, eyesize)
        self.rightEye.move(eyeOff, -eyeOff)
        self.leftEye.draw(window)
        self.rightEye.draw(window)
示例#25
0
def five_click_stick_figure():
    """
    9. [harder] Write a five_click_stick_figure() function that allows the user
    to draw a (symmetric) stick figure in a graphics window using five clicks of
    the mouse to determine the positions of its features. Each feature should be
    drawn as the user clicks the points.

    Hint: the radius of the head is the distance between points 1 and 2 — see
    the previous practical.

    Note: only the y-coordinate of point (3) should be used — its x coordinate
    should be copied from point (1).
    """
    win = GraphWin("Five Click Stick Figure", 800, 600)
    message = Text(Point(400, 15), "Click to create your stick figure")
    message.draw(win)

    head_centre = win.getMouse()
    head_centreX, head_centreY = head_centre.getX(), head_centre.getY()
    head_perim = win.getMouse()
    head_perimX, head_perimY = head_perim.getX(), head_perim.getY()
    head_radius = math.sqrt((head_perimX - head_centreX)**2 +
                            (head_perimY - head_centreY)**2)
    head = Circle(head_centre, head_radius)
    head.draw(win)

    torso = win.getMouse()
    torso_line = Line(Point(head_centreX, head_centreY + head_radius),
                      Point(head_centreX, torso.getY()))
    torso_line.draw(win)

    arm_reach = win.getMouse()
    arm_length = head_centreX - arm_reach.getX()
    arms_line = Line(Point(arm_reach.getX(), arm_reach.getY()),
                     Point(head_centreX + arm_length, arm_reach.getY()))
    arms_line.draw(win)

    leg_reach = win.getMouse()
    left_leg_line = Line(Point(head_centreX, torso.getY()),
                         Point(leg_reach.getX(), leg_reach.getY()))
    left_leg_line.draw(win)

    leg_distance = head_centreX - leg_reach.getX()
    right_leg_line = Line(Point(head_centreX, torso.getY()),
                          Point(head_centreX + leg_distance, leg_reach.getY()))
    right_leg_line.draw(win)

    await_user_input(win)
示例#26
0
def plot_rainfall():
    """
    10. [harder] Write a function, plot_rainfall(), that plots a histogram for
    daily rainfall figures over a 7 day period. The rainfall figures should be
    entered one-by-one into a text entry box within the window. The bars of the
    histogram should be numbered along the bottom.
    """
    win = GraphWin("Plot Rainfall", 550, 300)

    message = Text(Point(275, 15), "Enter rainfall in mm over the last 7 days")
    message.draw(win)
    input_box = Entry(Point(275, 50), 10)
    input_box.draw(win)

    line1 = Line(Point(50, 70), Point(50, 260))
    line2 = Line(Point(50, 260), Point(470, 260))
    line1.draw(win)
    line2.draw(win)

    for i in range(7):
        text = Text(Point(70 + i * 60, 270), "Day " + str(i + 1))
        text.draw(win)

    for i in range(6):
        text = Text(Point(30, 255 - i * 36), i * 40)
        text.draw(win)

    for i in range(7):
        win.getMouse()
        box_message = int(input_box.getText())

        Rectangle(Point(50 + i * 60, 260 - box_message),
                  Point(110 + i * 60, 260)).draw(win)

    message.setText("You're all finished")

    await_user_input(win)
示例#27
0
    def create_window(self, capacity):
        """
        Create the graphics window.
        :param capacity: the capacity of the skewer (for the window size)
        :return: None
        """

        self.win = GraphWin("Shish Kebab", 800, 200)
        self.win.setCoords(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y - 0.1,
                           WIN_LOW_LEFT_X + (capacity + 1) * FOOD_WIDTH,
                           WIN_UP_RIGHT_Y + 0.1)

        # draw skewer
        line = Line(Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y + WIN_HEIGHT / 2.0),
                    Point(capacity, WIN_LOW_LEFT_Y + WIN_HEIGHT / 2.0))
        line.setWidth(LINE_THICKNESS)
        line.draw(self.win)
        handle = Circle(
            Point(capacity - .1, WIN_LOW_LEFT_Y + WIN_HEIGHT / 2.0),
            SKEWER_HANDLE_RADIUS)
        handle.setFill(BKGD_COLOR)
        handle.setWidth(LINE_THICKNESS)
        handle.draw(self.win)
        self.items = []
def drawAxis(win, new_view):
    L1 = Line(Point(0, 0), Point(new_view.xVmax, 0))
    L2 = Line(Point(0, 0), Point(0, new_view.yVmax))
    L3 = Line(Point(0, 0), Point(new_view.xVmin, new_view.yVmin))
    L1.setFill('blue')
    L2.setFill('blue')
    L3.setFill('blue')
    L1.setArrow("last")
    L2.setArrow("last")
    L3.setArrow("last")
    L1.draw(win)
    L2.draw(win)
    L3.draw(win)
    return win
示例#29
0
def draw_patch(win, x, y, colour):
    """Helper function for drawing a patch design."""
    for distance in (20, 40, 60, 80, 100):
        line = Line(Point(x, distance + y), Point(x + distance, y))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(x + 100 - distance, y), Point(x + 100, y + distance))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)

    for distance in (20, 40, 60, 80):
        line = Line(Point(x + distance, y + 100), Point(x + 100, y + distance))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(x, y + distance), Point(x + 100 - distance, y + 100))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)
示例#30
0
    def _setup(self):
        circle = Circle(Point(250, 250), self.r)  # set center and radius
        circle.setWidth(3)
        circle.draw(self.win)

        line = Line(Point(250, 225), Point(250, 285))
        line.setWidth(3)
        line.draw(self.win)

        line2 = Line(Point(280, 250), Point(250, 225))
        line2.setWidth(3)
        line2.draw(self.win)

        line3 = Line(Point(220, 250), Point(250, 225))
        line3.setWidth(3)
        line3.draw(self.win)
示例#31
0
def liang_barsky_clip(x1, y1, x2, y2):
    dx = x2 - x1
    dy = y2 - y1
    p = [-dx, dx, -dy, dy]
    q = [x1 - x_min, x_max - x1, y1 - y_min, y_max - y1]
    for i, val in enumerate(p):
        if val == 0:
            print("Line is parallel to one of the clipping boundry")
            if q[i] >= 0:
                if i < 2:
                    if y1 < y_min:
                        y1 = y_min
                    if y2 > y_max:
                        y2 = y_max
                    clip_line = Line(Point(x1, y1), Point(x2, y2))
                    clip_line.draw(win)
                if i > 1:
                    if x1 < x_min:
                        x1 = x_min
                    if x2 > x_max:
                        x2 = x_max
                    clip_line = Line(Point(x1, y1), Point(x2, y2))
                    clip_line.draw(win)
    t1 = 0.0
    t2 = 1.0
    r = 0

    print(t1, t2)
    for i in range(4):
        r = q[i] / p[i]
        print(q[i], p[i])
        if p[i] < 0:
            if t1 <= r:
                t1 = r
        else:
            if t2 > r:
                t2 = r
        print(t1, t2, r)
    print(t1, t2)
    if t1 < t2:
        x11 = x1 + t1 * p[1]
        x22 = x1 + t2 * p[1]
        y11 = y1 + t1 * p[3]
        y22 = y1 + t2 * p[3]
        print("(x1: %d , y1 : %d),(x2: %d , y2 : %d)" % (x11, y11, x22, y22))
        clip_line = Line(Point(int(x11), int(y11)), Point(int(x22), int(y22)))
        clip_line.draw(win)
示例#32
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)
示例#33
0
                r = int(r)
                c = int(c)
                if is_vert == '':
                    rec = Rectangle(points[r][c], points[r+1][c+1])
                    rec.setFill(colors[player])
                    rec.draw(win)
                    scores[player] += 1
                    score_text[player].undraw()
                    score_text[player].setText('{}:{}'.format(wins[player], scores[player]))
                    score_text[player].draw(win)
                else:
                    if is_vert:
                        line = Line(points[r][c], points[r+1][c])
                    else:
                        line = Line(points[r][c], points[r][c+1])
                    line.draw(win)
                    line.setFill(colors[player])

                printer(win, results_dir, f, i, j)
            (n1, s1), (n2, s2) = scores.items()
            if s1 > s2:
                winner = n1
            elif s2 > s1:
                winner = n2
            else:
                winner = None

            if winner:
                wins[winner] += 1
                score_text[winner].undraw()
                score_text[winner].setText('{}:{}'.format(wins[winner], scores[winner]))