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)
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 = []
def draw_path(final_path): for i in final_path: dot = Circle( Point((i.j * square_size) + square_size / 2, (i.i * square_size) + square_size / 2), 10) dot.setFill(color_rgb(206, 141, 14)) dot.setOutline(color="white") dot.setWidth(3) dot.draw(win)
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)
def drawPiece(pieceCode, x, y): if pieceCode == 1: color, mirror, shape, xEye = pieceColors[0], -1, horseShape, 60 elif pieceCode == 2: color, mirror, shape, xEye = pieceColors[0], 1, appleShape, 0 elif pieceCode == -1: color, mirror, shape, xEye = pieceColors[1], 1, horseShape, 40 else: color, mirror, shape, xEye = pieceColors[1], 1, appleShape, 0 poly = Polygon([Point(x + 50 + mirror * (xPoint - 50) * squareSize / 100, y + yPoint * squareSize / 100) for (xPoint, yPoint) in shape]) poly.setFill(color) poly.setOutline("black") poly.setWidth(2) poly.draw(win) if xEye > 0: eye = Circle(Point(x + xEye * squareSize / 100, y + 30), 3) eye.setFill("black") eye.setOutline("black") eye.setWidth(1) eye.draw(win)
def update_board(second_per_update): # A* current = min(openSet, key=lambda o: o.f) # BFS # current = openSet[0] # DIJKSTRA # current = min(openSet, key=lambda o: o.g) for i in openSet: if i not in open_update: rect = i.rectangle(i.i, i.j) rect.setOutline(color_rgb(167, 239, 180)) rect.setWidth(3) rect.draw(win) open_update.append(i) # text = i.fScoreText(i.i, i.j) # text.setOutline(color_rgb(19, 10, 200)) # text.setStyle("bold") # text.draw(win) dot = Circle( Point(current.j * square_size + square_size / 2, current.i * square_size + square_size / 2), 10) dot.setOutline(color_rgb(206, 141, 14)) dot.setWidth(3) dot.draw(win) for i in closeSet: if i not in closed_update: rect = i.rectangle(i.i, i.j) rect.setOutline(color_rgb(239, 167, 167)) rect.setWidth(3) rect.draw(win) closed_update.append(i) # text = i.fScoreText(i.i, i.j) # text.setOutline(color_rgb(19, 10, 200)) # text.setStyle("bold") # text.draw(win) openSet_score.setText(openSet.__len__()) closedSet_score.setText(closeSet.__len__()) time.sleep(second_per_update)
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 = []
from graphics import GraphWin, Line, Circle, Oval, Point win = GraphWin(width=620, height=250) line = Line(Point(10, 10), Point(190, 190)) line.setWidth(2) line.draw(win) circle = Circle(Point(350, 110), 100) circle.setWidth(2) circle.draw(win) ellipse = Oval(Point(510, 10), Point(610, 190)) ellipse.setWidth(2) ellipse.draw(win) win.getMouse()
Point((299 + 75), (299 - 82)), Point((299 + 90), (299 - 100)), Point((299 + 134), (299 - 75)), Point((299 + 141), (299 - 93)), Point((299 + 90), (299 - 120))) right_eye.setFill('black') right_eye.draw(win) # Mouth - Overlapping Circles frown = Circle(Point(299, 505), 165) frown.setFill('black') frown.draw(win) frown_cover = Circle(Point(299, 650), 260) frown_cover.setFill(color_rgb(90, 255, 84)) frown_cover.setWidth(0) frown_cover.draw(win) # Tongue - Circle & Polygon Combo with Black Vertical Line tongue_tip = Circle(Point(299, 405), 30) tongue_tip.setFill(color_rgb(90, 255, 84)) tongue_tip.setWidth(3) tongue_tip.draw(win) tongue = Rectangle(Point(269, 403), Point(329, 348)) tongue.setFill(color_rgb(90, 255, 84)) tongue.setWidth(0) tongue.draw(win) tongue_ctr = Line(Point(299, 348), Point(299, 385)) tongue_ctr.setWidth(4)
class circle: def __init__(self,window,P1,level): from graphics import GraphWin,Circle import random from time import time self.p1=P1 self.window=window self.cir=Circle(self.p1,0.4) self.level=level self.cir.setWidth(0) i=random.randrange(6,9+self.level) self.color=i if self.color==6: #颜色对应数字 self.cir.setFill("red") if self.color==7: self.cir.setFill("green") if self.color==8: self.cir.setFill("black") if self.color==9: self.cir.setFill("blue") if self.color==10: self.cir.setFill("orange") for s in range(100): cirs=Circle(self.p1,0.0+s*0.004) if self.color==6: cirs.setFill("red") if self.color==7: cirs.setFill("green") if self.color==8: cirs.setFill("black") if self.color==9: cirs.setFill("blue") if self.color==10: cirs.setFill("orange") cirs.draw(self.window) empty=0 #空循环控制时间(time间隔太大) while empty<=30000: empty=empty+1 cirs.undraw() self.cir.draw(self.window) self.activate=True def click(self,pr): from graphics import Circle import time pd=False if self.activate==True and (pr.getX()-self.p1.getX())**2+(pr.getY()-self.p1.getY())**2<=0.24: for i in range(3): #点击动画 self.cir.move(0,-0.12/3.0) time.sleep(0.01) for i in range(3): self.cir.move(0,0.12/3.0) time.sleep(0.01) for i in range(3): self.cir.move(0,-0.12/3.0) time.sleep(0.01) for i in range(3): self.cir.move(0,0.12/3.0) time.sleep(0.01) pd=True return pd def undraw(self): self.cir.undraw() def close(self): self.cir.undraw() self.activate=False def move(self,pr): self.cir.move(pr.getX()-self.p1.getX(),pr.getY()-self.p1.getY()) self.p1.move(pr.getX()-self.p1.getX(),pr.getY()-self.p1.getY())
def draw_o(x, y): global items c = Circle(Point(x*SIZE+SIZE/2, y*SIZE+SIZE/2), SIZE/2 - PADDING) c.setWidth(4) c.draw(win) items.append(c)
def draw_circle(win, centre, radius, colour): """Helper function for drawing a circle.""" circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win)