def draw_eye_face_left(): eyell = gr.Circle(gr.Point(180, 235), 10) eyell.draw(window) eyell.setFill('forestgreen') eyerl = gr.Circle(gr.Point(220, 235), 10) eyerl.draw(window) eyerl.setFill('forestgreen') eyezll = gr.Circle(gr.Point(180, 235), 3) eyezll.draw(window) eyezll.setFill('black') eyezrl = gr.Circle(gr.Point(220, 235), 3) eyezrl.draw(window) eyezrl.setFill('black')
def drawing_planets(): global pl1, pl2, pl3 """drawing planets""" pl1 = gr.Circle(gr.Point(x1, y1), 5) pl1.draw(window) pl1.setFill('red') pl2 = gr.Circle(gr.Point(x2, y2), 5) pl2.draw(window) pl2.setFill('blue') pl3 = gr.Circle(gr.Point(x3, y3), 5) pl3.draw(window) pl3.setFill('green')
def draw_cloud(x, y, radius): temp_x = x for i in range(0, 2, 1): cloud_piece = gr.Circle(gr.Point(x, y), radius) cloud_piece.setFill('#ecf0f1') cloud_piece.draw(window) x += radius y += radius x = temp_x - 15 for j in range(0, 3, 1): cloud_piece = gr.Circle(gr.Point(x, y), radius) cloud_piece.setFill('#ecf0f1') cloud_piece.draw(window) x += radius
def draw_eye_face_right(): eyelr = gr.Circle(gr.Point(300, 235), 10) eyelr.draw(window) eyelr.setFill('mediumturquoise') eyerr = gr.Circle(gr.Point(340, 235), 10) eyerr.draw(window) eyerr.setFill('mediumturquoise') eyezlr = gr.Circle(gr.Point(300, 235), 3) eyezlr.draw(window) eyezlr.setFill('black') eyezrr = gr.Circle(gr.Point(340, 235), 3) eyezrr.draw(window) eyezrr.setFill('black')
def ship_init(x, y, scale): """ Create the list of objects needed to draw a ship at position (x,y) with the given scale """ shapes = [] '''separate rectangles triangles for the body of the ship, mast, and flag and circle for the windows''' body = gr.Rectangle(gr.Point(x, y), gr.Point(x + scale * 200, y + scale * 100)) body.setFill(gr.color_rgb(218, 165, 32)) shapes.append(body) mast = gr.Rectangle(gr.Point(x + scale * 100, y - 250 * scale), gr.Point(x + scale * 110, y)) mast.setFill(gr.color_rgb(222, 184, 135)) shapes.append(mast) t1 = gr.Polygon(gr.Point(x, y), gr.Point(x - scale * 50, y + scale * 50), gr.Point(x, y + scale * 100)) t1.setFill(gr.color_rgb(218, 165, 32)) shapes.append(t1) t2 = gr.Polygon(gr.Point(x + scale * 200, y), gr.Point(x + scale * 250, y + scale * 50), gr.Point(x + scale * 200, y + scale * 100)) t2.setFill(gr.color_rgb(218, 165, 32)) shapes.append(t2) flag = gr.Polygon(gr.Point(x + scale * 110, y - 150 * scale), gr.Point(x + scale * 160, y - 200 * scale), gr.Point(x + scale * 110, y - 250 * scale)) flag.setFill(gr.color_rgb(255, 0, 255)) shapes.append(flag) window1 = gr.Circle(gr.Point(x + 40 * scale, y + 50 * scale), 10) window1.setFill(gr.color_rgb(230, 230, 250)) shapes.append(window1) window2 = gr.Circle(gr.Point(x + 100 * scale, y + 50 * scale), 10) window2.setFill(gr.color_rgb(230, 230, 250)) shapes.append(window2) window3 = gr.Circle(gr.Point(x + 160 * scale, y + 50 * scale), 10) window3.setFill(gr.color_rgb(230, 230, 250)) shapes.append(window3) return shapes
def draw_man(win): head = gr.Circle(gr.Point(500, 300), 70) body = gr.Circle(gr.Point(500, 500), 130) left_arm = gr.Line(gr.Point(370, 500), gr.Point(270, 600)) right_arm = gr.Line(gr.Point(630, 500), gr.Point(730, 600)) left_leg = gr.Line(gr.Point(500, 630), gr.Point(400, 730)) right_leg = gr.Line(gr.Point(500, 630), gr.Point(600, 730)) head.setFill('pink') body.setFill('green') head.draw(win) body.draw(win) left_arm.draw(win) right_arm.draw(win) left_leg.draw(win) right_leg.draw(win)
def serd(): serd1 = gr.Polygon(gr.Point(292, 305), gr.Point(315, 330), gr.Point(338, 305)) serd1.setWidth(2) serd1.setOutline('red') serd1.setFill('red') serd2 = gr.Circle(gr.Point(303, 300), 13) serd2.setOutline('red') serd2.setFill('red') serd3 = gr.Circle(gr.Point(327, 300), 13) serd3.setOutline('red') serd3.setFill('red') serd1.draw(window) serd2.draw(window) serd3.draw(window)
def snowman(cx,cy,r): p1 = graphics.Point(cx,cy) snowman1 = graphics.Circle(p1,r) snowman1.setFill("white") snowman1.draw(winterWin) p2 = graphics.Point(cx,(115/150)*cy) snowman2 = graphics.Circle(p2,(25/35)*r) snowman2.setFill("white") snowman2.draw(winterWin) p3 = graphics.Point(cx, (85/150)*cy) snowman3 = graphics.Circle(p3,(15/35)*r) snowman3.setFill("white") snowman3.draw(winterWin)
def draw_cloud(x, y, size): # x, y - координаты центра левого нижнего круга, size - радиус одного круга global clouds clouds = [] for j in range(3): cloud_circle = gr.Circle(gr.Point(x, y), size) x += size clouds.append(cloud_circle) x = x - 2.5 * size y = y - size for j in range(2): cloud_circle = gr.Circle(gr.Point(x, y), size) x += size clouds.append(cloud_circle) for cloud_circle in clouds: draw(cloud_circle, 'white')
def __init__(self, title, size, window_shape, node_factory): self.width, self.height = window_shape self.shape = g.Circle(g.Point(self.width / 2, self.height / 2), min(self.width, self.height) / 3) self.win = g.GraphWin(title, self.width, self.height) self.nodes = dict() for node_id in range(size): self.nodes[node_id] = node_factory.create_node(node_id, size, self.shape, self.win)
def cloud(w1, h1, r): circle1 = gr.Circle(gr.Point(w1, h1), r)#круги отдалил друг от друга и их увеличил circle2 = gr.Circle(gr.Point(w1 + r+10, h1), r) circle3 = gr.Circle(gr.Point(w1 +3 * r / 2, h1 + r / 2), r) circle4 = gr.Circle(gr.Point(w1 + r / 2, h1 + r / 2), r) circle5 = gr.Circle(gr.Point(w1 - r / 2, h1 + r / 2), r) circle1.setFill('#a0a0a0')#сделал другой цвет облакам circle2.setFill('#a0a0a0') circle3.setFill('white') circle4.setFill('#a0a0a0') circle5.setFill('white') circle1.draw(window) circle2.draw(window) circle3.draw(window) circle4.draw(window) circle5.draw(window)
def landscape_init(x, y, scale): """ Create the list of objects needed to draw a landscape at position (x,y) with the given scale """ shapes = [] '''3 rectangle and 1 circle for different parts of landscape like sky, sun, grass, and water''' sky = gr.Rectangle(gr.Point(x, y - 500 * scale), gr.Point(x + scale * 1000, y + scale * 500)) sky.setFill(gr.color_rgb(135, 206, 235)) shapes.append(sky) sun = gr.Circle(gr.Point(x + 200 * scale, y - 250 * scale), 70) sun.setFill(gr.color_rgb(255, 69, 0)) shapes.append(sun) grass = gr.Rectangle(gr.Point(x, y), gr.Point(x + scale * 450, y + scale * 350)) grass.setFill(gr.color_rgb(0, 128, 0)) shapes.append(grass) water = gr.Rectangle(gr.Point(x + scale * 450, y), gr.Point(x + scale * 1000, y + scale * 700)) water.setFill(gr.color_rgb(70, 130, 180)) shapes.append(water) return shapes
def cannonball_animation_frame(shapes, frame_num, win): """Cannonball animation. The animation will involve one big cannonball shooting out of the cannon. shapes is a list containing the graphics objects needed to draw the cannonball scene. frame_num is a number indicating which frame of the animation it is. win is the GraphWin object containing the scene. This animates by creating up to 20 little cannonball circles too. Each circle creeps across the screen until it gets to the edge""" p1 = shapes[2].getP1() p2 = shapes[2].getP2() dy = p2.getY() - p1.getY() newy = (p1.getY() + p2.getY()) * 0.5 newx = p2.getX() - dy * 0.5 if frame_num % 2 == 0 and len(shapes) < 22: c = gr.Circle(gr.Point(newx, newy), 0.4 * dy) c.setFill(gr.color_rgb(150, 150, 150)) c.draw(win) shapes.append(c) for shape in shapes[5:]: shape.move(25, 0) center = shape.getCenter() if center.y < 0: mx = newx - center.getX() my = newy - center.getY() shape.move(mx, my)
def cloud(x, y, scale): """ Draws cloud in window Parameters ---------- x : INT Horizontal position. y : INT Vertical position. scale : FLOAT Scale factor. Returns ------- SHOWING CLOUD. """ shift_x = 0 shift_y = 0 k = 1 for i in range(2): for j in range(3 - k): cloud = gr.Circle(gr.Point(x + shift_x, y + shift_y), 30 * scale) cloud.setFill('White') cloud.draw(window) shift_x += 20 * scale shift_x = -30 * scale / 2 shift_y += 20 * scale k -= 1
def update_player(player=MassiveParticle( 1, State(pos=200 * np.ones((2, 1)), vel=np.zeros((2, 1)))), player_circle=graphics.Circle(graphics.Point(0, 0), 10), move_ticker=0): Speed = 2 pygame.event.pump() events = pygame.event.get() if move_ticker <= 0: for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: player.state.vel -= np.array([[0], [Speed]]) move_ticker = 10 elif event.key == pygame.K_DOWN: player.state.vel += np.array([[0], [Speed]]) move_ticker = 10 elif event.key == pygame.K_RIGHT: player.state.vel += np.array([[Speed], [0]]) move_ticker = 10 elif event.key == pygame.K_LEFT: player.state.vel -= np.array([[Speed], [0]]) move_ticker = 10 else: move_ticker -= 1 return move_ticker
def draw_clouds(x, x1, y): for m in range(3): for m in range(2): cloud = gr.Circle(gr.Point(x, y), 25) cloud.setFill('white') cloud.draw(window) x = x + 35 for m in range(3): cloud1 = gr.Circle(gr.Point(x1, y + 20), 25) cloud1.setFill('white') cloud1.draw(window) x1 = x1 + 30 x = x - 150 x1 = x1 - 180 y = y + 50
def bird_init(x, y, scale): """ Create the list of objects needed to draw a bird at position (x,y) with the given scale """ bird = [] '''separate rectangles triangle and circle for the body of the bird, beak, and legs''' body = gr.Rectangle(gr.Point(x, y), gr.Point(x + scale * 75, y + scale * 25)) body.setFill(gr.color_rgb(107, 142, 35)) bird.append(body) leg1 = gr.Rectangle(gr.Point(x, y + 25 * scale), gr.Point(x + scale * 10, y + 40 * scale)) leg1.setFill(gr.color_rgb(95, 158, 160)) bird.append(leg1) leg2 = gr.Rectangle(gr.Point(x + 30, y + 25 * scale), gr.Point(x + scale * 40, y + 40 * scale)) leg2.setFill(gr.color_rgb(95, 158, 160)) bird.append(leg2) head = gr.Circle(gr.Point(x + 75 * scale, y - 5 * scale), 15) head.setFill(gr.color_rgb(127, 255, 215)) bird.append(head) beak = gr.Polygon(gr.Point(x + 85 * scale, y * scale), gr.Point(x + scale * 105, y - scale * 10), gr.Point(x + scale * 85, y - scale * 20)) beak.setFill(gr.color_rgb(255, 215, 0)) bird.append(beak) return bird
def draw_ball(coords): circle = gr.Circle(coords, 10) circle.setFill('red') circle.draw(window) return circle
def test_scene(): """ Create a window and plot a scene with a of a steam plant in it. """ win = gr.GraphWin('title', 1000, 700, False) # the four separate functions for objects landscape = landscape_init(0, 385, 1.0) cannon = cannon_init(50, 300, 1.0) ship = ship_init(700, 330, 1.0) bird = bird_init(300, 100, 1.0) #drawing the four separate object functions draw(landscape, win) draw(bird, win) draw(cannon, win) draw(ship, win) win.update() # ANIMATION for loop to shoot "big shot' and cannonballs, and BIRD for frame_num in range(60): time.sleep(0.15) print frame_num cannonball_animation_frame(cannon, frame_num, win) bird_animation_frame(bird, frame_num, win) win.update() if win.checkMouse(): break for frame_num in range(65, 300): time.sleep(0.05) bird_animation_frame(bird, frame_num, win) '''make bird go faster here to avoid boat on fire''' fire = [] c = gr.Circle(gr.Point(800, 300), 10) c.draw(win) fire.append(c) for item in fire: dx = random.randint(-80, 80) dy = random.randint(-115, 100) item.move(dx, dy) hot = [ gr.color_rgb(255, 255, 0), gr.color_rgb(255, 0, 0), gr.color_rgb(255, 69, 0), gr.color_rgb(255, 165, 0) ] item.setFill(random.choice(hot)) if random.random() < 0.2: oldshape = random.choice(fire) newshape = oldshape.clone() newshape.draw(win) fire.append(newshape) win.update() if win.checkMouse() != None: break win.getMouse() win.close()
def cloud(): cloud1 = gr.Circle(gr.Point(80, 60), 20) cloud2 = gr.Circle(gr.Point(95, 60), 20) cloud3 = gr.Circle(gr.Point(110, 75), 20) cloud4 = gr.Circle(gr.Point(90, 75), 20) cloud5 = gr.Circle(gr.Point(70, 75), 20) cloud1.setFill('white') cloud2.setFill('white') cloud3.setFill('white') cloud4.setFill('white') cloud5.setFill('white') cloud1.draw(window) cloud2.draw(window) cloud3.draw(window) cloud4.draw(window) cloud5.draw(window)
def draw_telo(ball_1, ball_2, ball_3): coord() for i in A: circle = gr.Circle(i.coords, 3) circle.setFill('red') circle.draw(window)
def showAnchor(self): """ Optional method to visually see the anchor point """ dot = gr.Circle( gr.Point(self.anchor[0] * self.scale, self.win.getHeight() - self.anchor[1] * self.scale), self.radius * self.scale) dot.draw(self.win)
def genomeToObjects(genome, size): circles = [] lines = [] for x in genome.nodeGenes: newCircle = graphics.Circle( graphics.Point(x.loc[0] * size, x.loc[1] * size), size * Settings.nodeSizeRatio) newCircle.setFill( graphics.color_rgb(int(255 / (1 + (math.e**-x.output()))), int(255 / (1 + (math.e**-x.output()))), int(255 / (1 + (math.e**-x.output()))))) circles.append(newCircle) for y in genome.connectionGenes: A = genome.nodeGenes[int(y.A)].loc Z = genome.nodeGenes[int(y.Z)].loc newLine = graphics.Line(graphics.Point(A[0] * size, A[1] * size), graphics.Point(Z[0] * size, Z[1] * size)) if y.E: if y.W > 0: newLine.setFill('green') else: newLine.setFill('red') else: newLine.setFill('black') newLine.setWidth(abs(y.W) * (size * Settings.connectionSizeRatio)) lines.append(newLine) return (lines + circles)
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] testCond(-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] testCond( len(circles) <= 2, "there should never be more than two circles! You need to undraw old cannonballs" )
def random_walk_2d(n): import random import math import graphics win=graphics.GraphWin("Random Walk Sketch", 200,200) win.setCoords(-10,-10,10,10) x,y=0,0 x_values=[] y_values=[] for i in range(n): #number of steps stated by user movement=random.randint(1,4) if movement==1: x+=1 elif movement==2: y+=1 elif movement==3: x-=1 else: y-=1 x_values.append(x) y_values.append(y) Point=graphics.Point(x,y) Circle=graphics.Circle(Point,.50) Circle.draw(win) Circle.setFill("red1") Circle.setOutline("red1") walk=graphics.Text(graphics.Point(x,y),"") walk.draw(win) walk.setText("Walk {0}".format(i+1)) walk.setSize(10) x_last_value=x_values[len(x_values)-1] y_last_value=y_values[len(y_values)-1] distance_difference=math.sqrt(((x_last_value-0)**2)+((y_last_value-0)**2)) win.getMouse() return distance_difference
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)
def draw_sun(): sun = gr.Circle(gr.Point(700, 100), 40) sun.setFill('yellow') sun.setOutline('orange') sun.setWidth(10) sun.draw(window)
def draw_sun(window, x, y, r): center = gr.Point(x, y) sun = gr.Circle(center, r) sun.setFill('white') sun.setOutline('yellow') sun.draw(window)
def main(): win = gr.GraphWin("Circle", 500, 500, False ) shapes = [] c = gr.Circle( gr.Point(250, 250), 10) c.draw( win ) shapes.append( c ) while True: time.sleep( 0.1 ) for shape in shapes: dx = random.randint( -10, 10 ) dy = random.randint( -10, 10 ) shape.move( dx, dy ) r = random.randint( 0, 255 ) g = random.randint( 0, 255 ) b = random.randint( 0, 255 ) color = gr.color_rgb( r, g, b ) shape.setFill( color ) if random.random() < 0.2: oldshape = random.choice( shapes ) newshape = oldshape.clone() newshape.draw( win ) shapes.append( newshape ) win.update() if win.checkMouse() != None: break win.close()
def right_eye(length): """ This function drawing right eye :param x: horizontal position of the eye :param y: vertical position of the eye :param radius: radius of the eye """ eye2 = gr.Circle(gr.Point(0.6 * length, 0.33 * length), 0.065 * length) eye2.setFill('white') eye2.setOutline('white') eye2_center = gr.Circle(gr.Point(0.59 * length, 0.35 * length), 0.035 * length) eye2_center.setFill('black') eye2.draw(window) eye2_center.draw(window)