Esempio n. 1
0
    def create(self):
        '''
        draw the sprite and call the proper behavior
        '''
        self.body = g.Circle(g.Point(self.x,self.y),self.radius)
        self.circle1=g.Circle(g.Point(self.x-self.radius*3/4,self.y+self.radius),self.radius/4)
        self.circle2=g.Circle(g.Point(self.x-self.radius/4,self.y+self.radius),self.radius/4)
        self.circle3=g.Circle(g.Point(self.x+self.radius/4,self.y+self.radius),self.radius/4)
        self.circle4=g.Circle(g.Point(self.x+self.radius*3/4,self.y+self.radius),self.radius/4)
        self.rectangle=g.Rectangle(
            g.Point(self.x-self.radius,self.y),g.Point(self.x+self.radius,self.y+self.radius))

        parts = [self.body, self.rectangle, self.circle1, self.circle2, self.circle3, self.circle4]
        for part in parts:
            part.setFill('grey')
            part.setOutline('grey')
            part.draw(self.w)

        if self.behavior =='wait':
            self.wait()
        elif self.behavior =='patrol':
            self.patrolDirecton = 'towards P2'
            self.patrol()
        elif self.behavior =='explore':
            self.exploreCounter = 0
            self.explore()
        if self.behavior =='chase':
            self.chasePlayer()
Esempio n. 2
0
def ptMoneyMap():
    MainWin = graphics.GraphWin("MoneyMap", 800, 700)
    MoneyList = GetMoneyList(100, 0.1, 18)
    line = graphics.Line(graphics.Point(80, 20), graphics.Point(80, 600))
    line.draw(MainWin)
    for y in range(600, 30, -20):
        kline = graphics.Line(graphics.Point(80, y), graphics.Point(88, y))
        kline.draw(MainWin)
        txt = graphics.Text(graphics.Point(60, y), str(600 - y))
        txt.draw(MainWin)

    x = 100
    YearNum = 0
    for CurrentMoney in MoneyList:
        StartPoint = graphics.Point(x, 600 - CurrentMoney)
        x += 15
        YearTxt = graphics.Text(graphics.Point(x, 610), str(YearNum) + "年")
        YearNum += 1
        YearTxt.draw(MainWin)
        x += 15
        EndPoint = graphics.Point(x, 600)

        cRectangle = graphics.Rectangle(StartPoint, EndPoint)
        cRectangle.setFill("green")

        cRectangle.draw(MainWin)

        x += 5
    for i in range(10):
        pt = MainWin.getMouse()
        print("clicked x:", pt.getX(), ",y:", pt.getY())
Esempio n. 3
0
def draw_tree():
    trunk = gr.Rectangle(gr.Point(400, 370), gr.Point(410, 430))
    trunk.setFill('#663300')
    trunk.setWidth(3)
    trunk.draw(window)

    vertices_tree1 = [
        gr.Point(300, 370),
        gr.Point(405, 300),
        gr.Point(500, 370)
    ]
    vertices_tree1 = gr.Polygon(vertices_tree1)
    vertices_tree1.setFill('#003300')
    vertices_tree1.setWidth(3)
    vertices_tree1.draw(window)

    vertices_tree2 = [
        gr.Point(330, 330),
        gr.Point(405, 270),
        gr.Point(480, 330)
    ]
    vertices_tree2 = gr.Polygon(vertices_tree2)
    vertices_tree2.setFill('#003300')
    vertices_tree2.setWidth(3)
    vertices_tree2.draw(window)

    vertices_tree3 = [
        gr.Point(360, 290),
        gr.Point(405, 240),
        gr.Point(450, 290)
    ]
    vertices_tree3 = gr.Polygon(vertices_tree3)
    vertices_tree3.setFill('#003300')
    vertices_tree3.setWidth(3)
    vertices_tree3.draw(window)
Esempio n. 4
0
def convert_area_coordinates(str_area):
    area_coordinates = convert_str_coordinates(str_area)
    if (len(area_coordinates) != 4):
        raise Exception()
    return graphics.Rectangle(
        graphics.Point(area_coordinates[0], area_coordinates[1]),
        graphics.Point(area_coordinates[2], area_coordinates[3]))
Esempio n. 5
0
def draw_ship_deck():
    global ship_deck1

    ship_deck1 = gr.Rectangle(gr.Point(80, 370), gr.Point(140, 320))
    ship_deck1.setFill('white')
    ship_deck1.setOutline('white')
    ship_deck1.draw(window)
Esempio n. 6
0
def clear_window():
    """Clear entire window.

    """
    rectangle = gr.Rectangle(gr.Point(0, 0), gr.Point(SIZE_X, SIZE_Y))
    rectangle.setFill('green')
    rectangle.draw(window)
Esempio n. 7
0
def runTestsGraphics(ggame):
    # First run the standard tests (same as for the model)
    runTests(ggame)

    # For these tests to work, you need to have a getWindow-method in GraphicGame
    w = ggame.getWindow()

    circ_type = type(graphics.Circle(graphics.Point(0, 0), 10))
    rect_type = type(
        graphics.Rectangle(graphics.Point(0, 0), graphics.Point(1, 1)))

    everything = w.items
    circles = [x for x in w.items if type(x) == circ_type]
    rectangles = [x for x in w.items if type(x) == rect_type]

    test(
        len(circles) == 2,
        "there should be two circles drawn after running tests")

    test(len(rectangles) == 2, "there should be two rectangles initially")

    rect_pos = [x.getCenter().getX() for x in rectangles]
    test(-90 in rect_pos and 90 in rect_pos,
         "rectangles should be at x=-90 and x=90")

    # Fire a red projectile and move it a bit
    ggame.setCurrentWind(0)
    ggame.getCurrentPlayer().fire(30, 30).update(2)

    circles = [x for x in w.items if type(x) == circ_type]

    test(
        len(circles) <= 2,
        "there should never be more than two circles! You need to undraw old cannonballs"
    )
Esempio n. 8
0
def fitness(genome, window, timeStep=Settings.defaultTimeStep):
    for x in [failBox, statBox] + lines:
        x.draw(window)

    game = Pong.game()
    while game.gamesLeft:
        networkSprites = Draw.genomeToObjects(genome, 100)
        ball = graphics.Circle(
            graphics.Point(300 * game.ballX, 100 + (300 * game.ballY)), 15)
        ball.setFill('blue')
        paddle = graphics.Rectangle(
            graphics.Point(300, 100 + (300 * game.paddleY)),
            graphics.Point(310, 100 + (300 * (game.paddleY + game.paddleH))))
        paddle.setFill('black')
        for q in networkSprites + [ball, paddle]:
            q.draw(window)
        time.sleep(timeStep)
        for q in networkSprites + [ball, paddle]:
            q.undraw()
        game.updatePaddle(genome.evaluate(game.getState()))
        game.updateBall()

    for x in [failBox, statBox] + lines:
        x.undraw()
    return (game.bounces)
Esempio n. 9
0
 def make_background(self):
     """Draws the right area of the screen where game statistcs are kept"""
     p1 = grf.Point(self.win.width - 200, 0)
     p2 = grf.Point(self.win.width, self.win.height)
     background = grf.Rectangle(p1, p2)
     background.setFill('grey')
     return background
Esempio n. 10
0
def building():
    '''стены дома'''
    building = gr.Rectangle(gr.Point(w / 3 - 100, h / 2 - 100),
                            gr.Point(w / 3 + 100, h / 2 + 100))
    building.setFill('gray')
    building.setWidth(5)
    building.draw(window)
Esempio n. 11
0
def wind():
    '''окно в доме'''
    wind = gr.Rectangle(gr.Point(w / 3 - 40, h / 2 - 40),
                        gr.Point(w / 3 + 40, h / 2 + 40))
    wind.setFill('yellow')
    wind.setWidth(5)
    wind.draw(window)
def playGame(maze, c):
    d = {}
    mazeWin = graphics.GraphWin("Maze",
                                len(maze.data[0]) * cellSize,
                                len(maze.data) * cellSize)
    for y in range(len(maze.data)):
        for x in range(len(maze.data[y])):
            p1 = graphics.Point(cellSize * x, cellSize * y)
            p2 = graphics.Point(cellSize * (x + 1), cellSize * (y + 1))
            d[(x, y)] = graphics.Rectangle(p1, p2)
            rect = d[(x, y)]
            cell = maze.data[y][x]
            if cell.wall:
                rect.setFill("blue")
            elif cell.special == 'G':
                rect.setFill("red")
            elif cell.special == '@':
                rect.setFill("green")
            else:
                rect.setFill("white")
            rect.draw(mazeWin)
    while True:
        x = c.col
        y = c.row
        char = msvcrt.getwch()
        if char == 'a':
            if not maze.data[y][x - 1].wall:
                c.special = False
                c = maze.data[y][x - 1]
                d[(x, y)].setFill("white")
                d[(x - 1, y)].setFill("green")
        if char == 's':
            if not maze.data[y + 1][x].wall:
                c.special = False
                c = maze.data[y + 1][x]
                d[(x, y)].setFill("white")
                d[(x, y + 1)].setFill("green")
        if char == 'd':
            if not maze.data[y][x + 1].wall:
                c.special = False
                c = maze.data[y][x + 1]
                d[(x, y)].setFill("white")
                d[(x + 1, y)].setFill("green")
        if char == 'w':
            if not maze.data[y - 1][x].wall:
                c.special = False
                c = maze.data[y - 1][x]
                d[(x, y)].setFill("white")
                d[(x, y - 1)].setFill("green")
        if char == 'q':
            print("Bye!")
            time.sleep(1)
            return "QUIT"
        if c.special == 'G':
            c.special = '@'
            print("Congratulations! You've completed the maze!")
            time.sleep(1)
            mazeWin.close()
            return "Next Level"
        c.special = '@'
Esempio n. 13
0
def die(x,y,window):
  p1 = graphics.Point(x-75,y-75)
  p2 = graphics.Point(x+75,y+75)
  die = graphics.Rectangle(p1,p2)
  die.draw(window)

  pl1 = graphics.Point(x-25,y-125)
  line1 = graphics.Line(p1,pl1)
  line1.draw(window)

  p1l2 = graphics.Point(x+75,y-75)
  p2l2 = graphics.Point(x+125,y-125)
  line2 = graphics.Line(p1l2,p2l2)
  line2.draw(window)

  p1l3 = graphics.Point(x+75,y+75)
  p2l3 = graphics.Point(x+125,y+25)
  line3 = graphics.Line(p1l3,p2l3)
  line3.draw(window)

  p1l4 = graphics.Point(x-25,y-125)
  p2l4 = graphics.Point(x+125,y-125)
  line4 = graphics.Line(p1l4,p2l4)
  line4.draw(window)

  p1l5 = graphics.Point(x+125,y-125)
  p2l5 = graphics.Point(x+125,y+25)
  line5 = graphics.Line(p1l5,p2l5)
  line5.draw(window)
def draw_house_walls(window, x, y, width, height):
    walls = gr.Rectangle(gr.Point(x - width // 2, y),
                         gr.Point(x + width // 2, y - height))
    walls.setFill("red")
    walls.draw(window)
    draw_house_window(window, x, y - height // 4,
                      width // 3, height // 2)
Esempio n. 15
0
	def update(self, masterDict):
		"""Count the total numbers of sick and healthy community members and display them 
		in the box. masterDict is a dictionary of community members."""
		# if objects (including text) are drawn onscreen, undraw them
		if self.infoBox:
			self.infoBox.undraw()
		if self.sickNumber:
			self.sickNumber.undraw()
		if self.healthyNumber:
			self.healthyNumber.undraw()
		self.infoBox = graphics.Rectangle(graphics.Point(600, 650), graphics.Point(750, 750))
		self.infoBox.setFill("purple4")
		numHealthy = 0
		numSick = 0
		for key in masterDict:
			numHealthy += masterDict[key][0]
			numSick += masterDict[key][1]
		self.healthyNumber = graphics.Text(graphics.Point(675, 725),"HEALTHY:" + str(numHealthy))
		self.sickNumber = graphics.Text(graphics.Point(675, 675),"SICK:" + str(numSick))
		self.healthyNumber.setSize(20)
		self.sickNumber.setSize(20)
		self.healthyNumber.setStyle("bold")
		self.sickNumber.setStyle("bold")
		self.healthyNumber.setFill("white")
		self.sickNumber.setFill("white")
		self.infoBox.draw(self.win)
		self.healthyNumber.draw(self.win)
		self.sickNumber.draw(self.win)
Esempio n. 16
0
def showField():  #Generates window and basic objects
    """Generates window and basic objects, returns window and object list."""
    if settings[3]:  #Hardcore setting
        lw = gr.GraphWin("Pysweeper | HARDCORE Game", settings[0] * 40,
                         (settings[1] * 40) + 40, False)
    else:
        lw = gr.GraphWin("Pysweeper | Game", settings[0] * 40,
                         (settings[1] * 40) + 40, False)
    lw.setBackground(gr.color_rgb(33, 33, 33))
    li = []
    # 0: Top bar background
    # 1: Remaining flags
    # 2: Timer
    # 3: Reset icon

    li.append(gr.Rectangle(gr.Point(0, 0), gr.Point(lw.width, 40)))
    li[0].setWidth(0)
    li[0].setFill(gr.color_rgb(66, 66, 66))

    li.append(gr.Text(gr.Point(30, 20), "000"))
    li[1].setSize(20)
    li[1].setFill(gr.color_rgb(250, 250, 250))

    li.append(gr.Text(gr.Point(lw.width - 30, 20), "000"))
    li[2].setSize(20)
    li[2].setFill(gr.color_rgb(250, 250, 250))

    li.append(gr.Image(gr.Point(lw.width / 2, 20), "img/Reset.png"))
    li[1].setText((3 - len(str(rflags))) * "0" + str(rflags))

    for i in li:
        i.draw(lw)

    lw.flush()
    return lw, li
Esempio n. 17
0
	def __init__(self,win,x,y,width,height):
		Thing.__init__(self,win, "wall", position = [x,y])
		self.width = width
		self.height = height
		thickness = self.width
		length = self.height
		self.vis = [gr.Rectangle(gr.Point ((x-thickness/2)*self.scale, self.win.getHeight()-y*self.scale), gr.Point( ((x+thickness/2)*self.scale) , self.win.getHeight()-(y+ length)*self.scale)) ]
Esempio n. 18
0
	def create2(self):

		w2 = g.GraphWin('Level 2', 750, 700, autoflush = False)
		self.w = w2

		#drawing borders of map
		self.line_seg(g.Point(0,0),g.Point(0, 700))
		self.line_seg(g.Point(0,700),g.Point(750, 700))
		self.line_seg(g.Point(750,0),g.Point(750, 700))
		self.line_seg(g.Point(50,0),g.Point(750, 0))

		#the winning landing spot
		stairs = g.Rectangle(g.Point(0, 0),g.Point(70, 100))
		stairs.setFill('yellow')
		stairs.setOutline('yellow')
		stairs.draw(self.w)
		
		#drawing walls
		self.make_box(g.Point(70, 0), g.Point(250, 100))
		self.make_box(g.Point(200, 0), g.Point(250, 200))
		self.make_box(g.Point(0, 200), g.Point(150, 250))
		self.make_box(g.Point(0, 250), g.Point(50, 350))

		self.make_box(g.Point(100, 350), g.Point(350, 400))
		#self.make_box(g.Point(300, 300), g.Point(350, 350))
		self.make_box(g.Point(100, 400), g.Point(200, 450))
		self.make_box(g.Point(250, 400), g.Point(300, 450))

		self.make_box(g.Point(300, 100), g.Point(350, 200))
		self.make_box(g.Point(300, 200), g.Point(450, 250))
		self.make_box(g.Point(400, 0), g.Point(450, 350))

		self.make_box(g.Point(500, 0), g.Point( 750, 100))
		self.make_box(g.Point(700, 0), g.Point(750, 350))

		self.make_box(g.Point(500, 200), g.Point(650, 250))

		self.make_box(g.Point(0, 400), g.Point(50, 650))
		self.make_box(g.Point(100, 550), g.Point(250, 600))
		self.make_box(g.Point(350, 500), g.Point(650, 550))
		self.make_box(g.Point(600, 350), g.Point(650, 500))

		self.make_box(g.Point(500, 350), g.Point(550, 400))

		self.make_box(g.Point(700, 400), g.Point(750, 600))
		self.make_box(g.Point(0, 650), g.Point(750, 700))


		bould = self.make_boulder(g.Point(75,325))
		self.move_boulder_H(bould, True, 50, 400, 50)


		self.trapl2t1 = fire_trap(self.w, g.Point(350, 350), g.Point(500, 400), 2000)
		self.listOfTrapPoints.append((g.Point(350, 350), g.Point(500, 400), self.trapl2t1))
		self.trapl2t2 = fire_trap(self.w, g.Point(150, 200), g.Point(300, 250), 2000)
		self.listOfTrapPoints.append((g.Point(150, 200), g.Point(300, 250), self.trapl2t2))
		
		self.w.getMouse()
		self.w.close()
Esempio n. 19
0
def draw_ship_flag():
        ship_flag_canvas = gr.Rectangle(gr.Point(125, 305), gr.Point(135, 315))
        ship_flag_canvas.setFill('red')
        ship_flag_canvas.setOutline('red')
        ship_flag_canvas.draw(window)

        ship_flag_line = gr.Line(gr.Point(125, 320), gr.Point(125, 315))
        ship_flag_line.draw(window)
 def __init__(self, win, r, mon_wid, mon_max_vel, mon_acc):
     self.center = r - mon_wid // 2
     self.sq = graphics.Rectangle(graphics.Point(r - mon_wid, 0),
                                  graphics.Point(r, mon_wid))
     self.sq.draw(win)
     self.max_vel = mon_max_vel
     self.acc = mon_acc
     self.xvel0 = 0.0
Esempio n. 21
0
	def create(self):
		'''
		Draws the fire trap at the given coordinates defined in __init__
		'''
		self.trap = g.Rectangle(self.p1, self.p2)
		self.trap_on = True
		self.trap.setFill('red')
		self.trap.draw(self.w)
Esempio n. 22
0
def clear_window():
    rectangle = gr.Rectangle(gr.Point(0, 0), gr.Point(SIZE_X, SIZE_Y))
    rectangle.setFill("green")
    rectangle.draw(window)

    sun = gr.Circle(gr.Point(400, 400), 50)
    sun.setFill("yellow")
    sun.draw(window)
Esempio n. 23
0
    def create_body(self):

        p1 =  graphics.Point(self.spec['house_x_left'], self.spec['house_y_bottom'])
        p2 = graphics.Point(self.spec['house_x_right'], self.spec['house_y_top'])

        # draw main rectangle of house
        self.body = graphics.Rectangle(p1,p2)
        self.body.setFill("pink")
def remain_background(w):
    r1 = gr.Rectangle(gr.Point(0, SIZE_Y * 11 / 12), gr.Point(SIZE_X, SIZE_Y))
    r1.setOutline('yellow4')
    r1.setFill('yellow4')

    r1.draw(w)

    draw_fish(coords_fish)
Esempio n. 25
0
def build_house(window, upper_left_corner, width):
    """ Build house """
    height = calculate_sizes(width)
    beginX, beginY = upper_left_corner.x, upper_left_corner.y
    endX, endY = (beginX + width), (beginY + height)
    begin = gr.Point(beginX, beginY)
    end = gr.Point(endX, endY)

    # house
    rec = gr.Rectangle(begin, end)
    rec.draw(window)

    # roof
    p = gr.Polygon(gr.Point(beginX - 10, beginY),
                   gr.Point(beginX + width / 2, beginY - height / 5),
                   gr.Point(beginX + width + 10, beginY))
    p.draw(window)

    # windows
    win1 = gr.Rectangle(gr.Point(beginX + width / 2 + 5, beginY - 25),
                        gr.Point(beginX + width / 2 - 5, beginY - 10))
    win1.draw(window)

    win2 = gr.Rectangle(gr.Point(beginX + width / 4 + 10, beginY + 10),
                        gr.Point(beginX + width / 4 - 10, beginY + 40))
    win2.draw(window)

    win3 = gr.Rectangle(gr.Point(beginX + width * 3 / 4 + 10, beginY + 10),
                        gr.Point(beginX + width * 3 / 4 - 10, beginY + 40))
    win3.draw(window)

    win4 = gr.Rectangle(gr.Point(beginX + width / 4 + 10, beginY + 70),
                        gr.Point(beginX + width / 4 - 10, beginY + 100))
    win4.draw(window)

    win5 = gr.Rectangle(gr.Point(beginX + width * 3 / 4 + 10, beginY + 70),
                        gr.Point(beginX + width * 3 / 4 - 10, beginY + 100))
    win5.draw(window)

    win6 = gr.Rectangle(gr.Point(beginX + width / 4 + 10, beginY + 130),
                        gr.Point(beginX + width / 4 - 10, beginY + 160))
    win6.draw(window)

    win7 = gr.Rectangle(gr.Point(beginX + width * 3 / 4 + 10, beginY + 130),
                        gr.Point(beginX + width * 3 / 4 - 10, beginY + 160))
    win7.draw(window)

    # door
    door = gr.Rectangle(gr.Point(endX - width / 2 + 10, endY - 30),
                        gr.Point(endX - width / 2 - 10, endY))
    door.draw(window)
Esempio n. 26
0
def buildBullet():
    bullet = gr.Polygon(gr.Point(270, 102), gr.Point(270, 124),
                        gr.Point(290, 124), gr.Point(300, 113),
                        gr.Point(290, 102))
    bullet.setFill("orange")
    bulletBack = gr.Rectangle(gr.Point(270, 102), gr.Point(280, 124))
    bulletBack.setFill("black")
    return [bullet, bulletBack]
Esempio n. 27
0
def draw_house():
    chimney = gr.Line(gr.Point(375, 200), gr.Point(375, 210))
    chimney.setWidth(7)

    house = gr.Rectangle(gr.Point(300, 210), gr.Point(450, 320))
    house.setFill('grey')

    window1 = gr.Rectangle(gr.Point(310, 220), gr.Point(340, 250))
    window1.setFill('yellow')

    window2 = gr.Rectangle(gr.Point(440, 220), gr.Point(410, 250))
    window2.setFill('yellow')

    chimney.draw(window)
    house.draw(window)
    window1.draw(window)
    window2.draw(window)
Esempio n. 28
0
def draw_universe():
    rectangle = gr.Rectangle(gr.Point(0, 0), gr.Point(SIZE_X, SIZE_Y))
    rectangle.setFill('darkblue')
    rectangle.draw(window)

    sun = gr.Circle(gr.Point(400, 400), 50)
    sun.setFill('yellow')
    sun.draw(window)
Esempio n. 29
0
def start_window():
    rectangle = gr.Rectangle(gr.Point(0, 0), gr.Point(SIZE_X, SIZE_Y))
    rectangle.setFill("green")
    rectangle.draw(window)

    center = gr.Circle(gr.Point(400, 300), 2)
    center.setFill("yellow")
    center.draw(window)
Esempio n. 30
0
def draw_forest(window, horizon_height, number_of_trees):
    for i in range(number_of_trees):
        my_tree = gr.Rectangle(gr.Point(20 * i, horizon_height - 20),
                               gr.Point(20 + 20 * i, horizon_height + 20))
        my_tree.draw(window)
        my_tree.setFill("green")

    return 0