def icecream_init(x,y,scale): ''' Creates the list of objects needed to draw an ice cream cone at position (x,y) with the given scale. ''' shapes = [] #cone IDX 0 t = gr.Polygon(gr.Point(x,y),gr.Point(x+5*scale,y-15*scale), gr.Point(x-5*scale,y-15*scale)) t.setFill(gr.color_rgb(222,184,135)) shapes.append(t) #scoops IDX 1-4 c = gr.Circle(gr.Point(x,y-20*scale),6*scale) c.setFill(gr.color_rgb(255,0,127)) shapes.append(c) c = gr.Circle(gr.Point(x,y-30*scale),6*scale) c.setFill(gr.color_rgb(0,255,128)) shapes.append(c) c = gr.Circle(gr.Point(x,y-40*scale),6*scale) c.setFill(gr.color_rgb(153,255,255)) shapes.append(c) c = gr.Circle(gr.Point(x,y-50*scale),6*scale) c.setFill(gr.color_rgb(255,153,153)) shapes.append(c) return shapes
def cat_init(x, y, scale): '''Creates and returns a list of graphics objects to make up a cat''' shapes = [] #cat p = gr.Polygon(gr.Point(x + scale * 180, y + scale * 40), gr.Point(x + scale * 190, y + scale * 35), gr.Point(x + scale * 190, y + scale * 50)) p.setFill(gr.color_rgb(30, 30, 30)) shapes.append(p) p = gr.Polygon(gr.Point(x + scale * 180, y + scale * 40), gr.Point(x + scale * 170, y + scale * 35), gr.Point(x + scale * 170, y + scale * 50)) p.setFill(gr.color_rgb(30, 30, 30)) shapes.append(p) c = gr.Circle(gr.Point(x + scale * 180, y + scale * 50), scale * 10) c.setFill(gr.color_rgb(0, 0, 0)) shapes.append(c) c = gr.Circle(gr.Point(x + scale * 175, y + scale * 50), scale * 2) c.setFill(gr.color_rgb(67, 205, 128)) shapes.append(c) c = gr.Circle(gr.Point(x + scale * 185, y + scale * 50), scale * 2) c.setFill(gr.color_rgb(67, 205, 128)) shapes.append(c) #body r = gr.Rectangle(gr.Point(x + scale * 155, y + scale * 60), gr.Point(x + scale * 185, y + scale * 80)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) c = gr.Circle(gr.Point(x + scale * 155, y + scale * 70), scale * 10) c.setFill(gr.color_rgb(0, 0, 0)) shapes.append(c) r = gr.Rectangle(gr.Point(x + scale * 120, y + scale * 65), gr.Point(x + scale * 155, y + scale * 70)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) r = gr.Rectangle(gr.Point(x + scale * 120, y + scale * 40), gr.Point(x + scale * 125, y + scale * 70)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) #legs r = gr.Rectangle(gr.Point(x + scale * 150, y + scale * 80), gr.Point(x + scale * 155, y + scale * 100)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) r = gr.Rectangle(gr.Point(x + scale * 165, y + scale * 80), gr.Point(x + scale * 170, y + scale * 100)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) r = gr.Rectangle(gr.Point(x + scale * 180, y + scale * 80), gr.Point(x + scale * 185, y + scale * 100)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) return shapes
def grass(x, y, scale): # define the grass cc1 = g.Circle( g.Point(x + 250 * (random.uniform(0.2, 3)) * scale, y + 150 * (random.uniform(1, 1.5)) * scale), random.uniform(5, 10)) # random grass generate cc1.setFill("green") cc2 = g.Circle( g.Point(x + 250 * (random.uniform(0.2, 3)) * scale, y + 150 * (random.uniform(1, 1.5)) * scale), random.uniform(5, 10)) # random grass generate cc2.setFill("green") test3 = [cc1, cc2] return test3
def init_sun(x, y, scale): # create a circle with the sun inner_sun = gr.Circle(gr.Point(x - scale * 260, y - scale * 200), 120 * scale) inner_sun.setFill('orange') outer_sun = gr.Circle(gr.Point(x - scale * 260, y - scale * 200), 150 * scale) outer_sun.setFill('yellow') # leg1 = gr.Rectangle( gr.Point ( x-scale*20, y+scale*60), gr.Point(x-scale*40, y+scale*180 )) # leg1.setFill('red') sun = [outer_sun, inner_sun] return sun
def init_man(x, y, scale): # define the man shapes and put them into a list # Head: Create a circle with the color brown head = gr.Circle(gr.Point(x + scale * 10, y - scale * 50), 20 * scale) head.setFill('brown') # arms : Create a rectangle with the color blue for the arms arms = gr.Rectangle(gr.Point(x + scale * 110, y), gr.Point(x - scale * 80, y - scale * 30)) arms.setFill('blue') # stomach : Create a rectangle with the color blue for the sh stomach = gr.Rectangle(gr.Point(x + scale * 70, y + scale * 60), gr.Point(x - scale * 50, y)) stomach.setFill('blue') # # leg2 : Create a rectangle with the color red for pants leg1 = gr.Rectangle(gr.Point(x - scale * 20, y + scale * 60), gr.Point(x - scale * 40, y + scale * 180)) leg1.setFill('red') # # leg2 : Create a rectangle with the color red for pants leg2 = gr.Rectangle(gr.Point(x + scale * 60, y + scale * 60), gr.Point(x + scale * 40, y + scale * 180)) leg2.setFill('red') # man creates the list of all the basic shapes created by zelle man = [head, arms, leg1, leg2, stomach] return man
def steam_animation_frame(shapes,frame_num,win): ''' Draws one frame of a steam plant animation. The animation will involve smoke rising out of the chimney. shapes is a list containing the graphics objects needed to draw the steam plant. frame_num is a number indicating which frame of animation it is. win is the GraphWin object containing the scene. This animates by creating up to 20 steam circles. Each circle creeps up the screen until it gets to the top, when it is brought back down to the smokestack so it can be used again. ''' p1 = shapes[0].getP1() p2 = shapes[0].getP2() dx = p2.getX() - p1.getX() newx = (p2.getX() + p1.getX())*0.5 newy = p2.getY() - dx*0.5 if frame_num % 2 == 0 and len(shapes) < 20: c = gr.Circle(gr.Point(newx,newy),0.4*dx) c.setFill(gr.color_rgb(150,150,150)) c.draw(win) shapes.append(c) for thing in shapes[3:]: thing.move(0,-10) center = thing.getCenter() if center.y < 0: mx = newx - center.getX() my = newy - center.getY() thing.move(mx,my)
def explosion_init(x, y, scale): shapes4 = [] explosion = gr.Circle(gr.Point(x + 35 * scale, y - scale * 9), 100) redexp = gr.color_rgb(255, 0, 0) explosion.setFill(redexp) shapes4.append(explosion) return shapes4
def crystalBall_init(x, y, scale): '''Creates and returns a list of graphics objects to make up a crystal Ball''' shapes = [] c = gr.Circle(gr.Point(x + scale * 230, y + scale * 70), scale * 20) c.setFill(gr.color_rgb(198, 226, 255)) shapes.append(c) return shapes
def main(argv): win=gr.GraphWin("My window",500,500) c=gr.Circle(gr.Point(250, 250),10) c.draw(win) win.getMouse() c.setFill("green") win.getMouse() c.move(50,-40) win.getMouse() win.close() return
def vehicle_init(x, y, scale): ''' Creates list of objects needed to draw a tan armored vehicle at posiiton (x,y) with given scale ''' shapes2 = [] vehicle = gr.Rectangle(gr.Point(x * scale + 100, y + scale * 30), gr.Point(x + scale * 30, y - scale * 1)) tan = gr.color_rgb(255, 239, 219) vehicle.setFill(tan) shapes2.append(vehicle) leftwheel = gr.Circle(gr.Point(x + scale * 44, y + scale * 40), 9 * scale) black = gr.color_rgb(0, 0, 0) leftwheel.setFill(black) shapes2.append(leftwheel) rightwheel = gr.Circle(gr.Point(x + scale * 88, y + scale * 40), 9 * scale) rightwheel.setFill(black) shapes2.append(rightwheel) return shapes2
def main(): # assign to win a GraphWin object made with title, width, height, and the value False win = gr.GraphWin("rocketship!", 600, 600, False) # (note the final parameter is not one we have used before. It makes it so the # window doesn't attempt to redraw after every change). # assign to shapes an empty list shapes = [] # assign to c a new Circle object at (250, 250) with radius 10 c = gr.Circle(gr.Point(250, 250), 10) # call the draw function of the circle object stored in c c.draw(win) # append the variable c to the list shapes shapes.append(c) # while True while True: # call time.sleep with a half-second delay (0.5) time.sleep(0.5) # for each thing in shapes for thing in shapes: # assign to dx a random integer between -10 and 10 dx = random.randint(-10, 10) # assign to dy a random integer between -10 and 10 dy = random.randint(-10, 10) # call the move method of the object referred to by thing, passing in dx and dy thing.move(dx, dy) #color r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) color = gr.color_rgb(r, g, b) thing.setFill(color) #clone if random.random() < 0.2: oldthing = random.choice(shapes) newthing = oldthing.clone() newthing.draw(win) shapes.append(newthing) # tell the window to update its display (call win.update()) win.update() # if win.checkMouse() is not None if win.checkMouse() is not None: break # break out of the while loop # close the window win.close()
def main(): win=g.GraphWin("My window", 1000, 600) x=0 y=0 scale=1 for i in range(30): cc1 = g.Circle(g.Point(x + 260 * (random.uniform(1,3)) * scale, y + 250 * (random.uniform(1,1.2)) * scale), random.uniform(5,10)) cc1.setFill("green") cc2 = g.Circle(g.Point(x + 260 * random.uniform(1, 2) * scale, y - 250 * random.uniform(1, 2) * scale), random.uniform(10, 20)) cc2.setFill("green") test4 = [cc1, cc2] for thing in test4: thing.draw(win) cc1.draw(win) win.getMouse() win.close()
def spaceship_animate(shapes, frame_num, win): '''given the spaceship list, a frame number, and a window, it draws the spaceship in the window for the given frame number''' p1 = shapes[0].getP1() p2 = shapes[0].getP2() dx = p2.getX() - p1.getX() newx = (p1.getX() + p2.getX()) / 2 newy = p1.getY() for i in range(2): c = gr.Circle(gr.Point(newx, newy), 0.4 * dx) r = random.randint(0, 255) g = random.randint(0, 255) b = random.randint(0, 255) color = gr.color_rgb(r, g, b) c.setFill(color) c.draw(win) shapes.append(c) for item in shapes[:4]: item.move(0, -dx * 0.25) count = 4 for item in shapes[4:]: c = item.getCenter() if c.getY() < newy + 5 * dx: if count % 2 == 0: item.move(random.randint(-5, -1), dx * 0.5) else: item.move(random.randint(1, 5), dx * 0.5) else: item.undraw() shapes.pop(count) count = count - 1 count = count + 1
def village(x, y, scale): # define the village b1 = g.Rectangle( g.Point(x + 100 * scale, y - 10 * scale), # house box point list g.Point(x + 150 * scale, y - 50 * scale)) b1.setFill("orange") c1 = g.Circle(g.Point(x + 125 * scale, y - 60 * scale), 30 * scale) # house roof box point list c1.setFill("pink") b2 = g.Rectangle( g.Point(x + 300 * scale, y - 10 * scale), # house box point list g.Point(x + 350 * scale, y - 50 * scale)) b2.setFill("grey") c2 = g.Circle(g.Point(x + 325 * scale, y - 60 * scale), 30 * scale) # house roof box point list c2.setFill("yellow") b3 = g.Rectangle( g.Point(x + 200 * scale, y - 10 * scale), # tree box point list g.Point(x + 220 * scale, y - 150 * scale)) b3.setFill("brown") c3 = g.Circle(g.Point(x + 210 * scale, y - 150 * scale), 50 * scale) # tree roof box point list c3.setFill("green") b4 = g.Rectangle( g.Point(x + 250 * scale, y - 10 * scale), # tree box point list g.Point(x + 270 * scale, y - 130 * scale)) b4.setFill("black") c4 = g.Circle(g.Point(x + 260 * scale, y - 130 * scale), 50 * scale) # tree roof box point list c4.setFill("light green") test2 = [b1, b2, c1, c2, b3, c3, b4, c4] return test2
def warhol(filename, listOfEffects): # read the image from the file use original=Image... # and get rows with Height, cols with Width... original = gr.Image(gr.Point(0, 0), filename) rows = original.getHeight() cols = original.getWidth() panels = len(listOfEffects) # create a window based on the image and how many copies which from the len(listOfEffects) win = gr.GraphWin('Warhol', cols * panels, rows) allimages = [] # for each effect from the filter file swaprb, reduceGreen, whitecover for i in range(panels): # clone the original image clone = original.clone() # duplicates the Image object # apply the filter to the clone, which filter to apply? if listOfEffects[i] == 'swaprb': filter.swaprb(clone) elif listOfEffects[i] == 'reduceGreen': filter.reduceGreen(clone) elif listOfEffects[i] == 'whitecover': filter.whitecover(clone) # move the image to the right location with their owner cols values clone.move(cols / 2 + i * cols, rows / 2) # draw the image into the window and append each copy into the images clone.draw(win) allimages.append(clone) # create some text at the last image center so the Points should be cols*2.5 and rows/2 sometext = gr.Text(gr.Point(cols * 2.5, rows / 2), "hello world") sometext.setFill('red') sometext.setSize(20) sometext.draw(win) # create a red circle outline the text so the circle center is the same as above Points patch = gr.Circle(gr.Point(cols * 2.5, rows / 2), 80) patch.setOutline("red") patch.draw(win) # return the window and return all the images return win, allimages
def main(argv): # create a window win = gr.GraphWin("My window", 500, 500) print("argument1 ", argv[1]) # create a circle c = gr.Circle(gr.Point(int(argv[2]), int(argv[3])), int(argv[1])) c.setFill(gr.color_rgb(100, 30, 100)) # draw the circle inot the window c.draw(win) # pause until user gets mouse win.getMouse() win.close() return
def warhol( filename, listOfEffects ): # read the image from the file original = gr.Image( gr.Point(0, 0), filename ) rows = original.getHeight() cols = original.getWidth() panels = len(listOfEffects) # create a window based on the image and how many copies win = gr.GraphWin( 'Warhol', cols*panels, rows ) allimages = [] # for each effect for i in range(panels): # clone the original image clone = original.clone() # duplicates the Image object # apply the filter to the clone, which filter to apply? if listOfEffects[i] == 'swaprg': image.swaprg( clone ) elif listOfEffects[i] == 'reduceRed': image.reduceRed( clone ) # implied else don't do anything # move the image to the right location clone.move( cols/2 + i*cols , rows/2 ) # draw the image into the window clone.draw(win) allimages.append( clone ) # create some text sometext = gr.Text( gr.Point( cols/2, rows/2+30 ), "Aaaaargh" ) sometext.setFill('red') sometext.setSize( 20 ) sometext.draw(win) # create an eye patch patch = gr.Circle( gr.Point( cols/2-15, rows/2-30 ), 8 ) patch.setFill( 'black' ) patch.draw(win) # return the window return win, allimages
def interactive(): win = gr.GraphWin( 'interactive demo', 500, 500, False ) r = gr.Rectangle( gr.Point( 220, 260 ), gr.Point( 280, 240 ) ) r.setOutline( 'purple' ) r.setFill( 'pink' ) r.setWidth( 3 ) r.draw( win ) counter = 0 falling = None # begin event loop while True: # infinite loop if counter % 100 == 0: if falling != None: falling.undraw() falling = gr.Circle( gr.Point( random.randint(0, 500), 0 ), 10 ) falling.setFill( 'blue' ) falling.draw(win) if falling != None: falling.move( random.randint(-3, 3), 5 ) counter += 1 key = win.checkKey() if key == 'q': break elif key == 'a': # move left r.move( -20, 0 ) elif key == 'w': # move up r.move( 0, -20 ) elif key == 's': # move down r.move( 0, 20 ) elif key == 'd': # move right r.move( 20, 0 ) win.update() # manually update the window print("Terminating") win.close()
def main(): win = gr.GraphWin("Press a key", 400, 400, False) shapes = [] c = gr.Circle(gr.Point(250, 250, 10)) c.draw(win) shapes.append(c) while True time.sleep(0.5) for thing in shapes: dx=random.randInt(-10,10) dy = random.randInt(-10,10) thing.move(dx,dy) win.update() if win.checkMouse() break win.close()
def main( argv ): # create a window win = gr.GraphWin( "My window", 500, 500 ) # create a circle c = gr.Circle( gr.Point( 250, 250 ), 10 ) # draw the circle into the window c.move( 50, -40 ) # relative move to a new location c.draw( win ) # draw into the window win.getMouse() # pause c.setFill( "green" ) # make the circle green win.getMouse() # pause c.undraw() # undraw the circle # pause until the user clicks the mouse win.getMouse() win.close() # close window return
def main(): ''' Draws circles with radius 10 in random colors and in random places in the window of given title and size until mouse is clicked in the window. ''' win = gr.GraphWin('Press a key', 400, 400, False) shapes = [] c = gr.Circle(gr.Point(250, 250), 10) c.draw(win) shapes.append(c) while True: time.sleep(0.5) for thing in shapes: r = random.randrange(0, 255) g = random.randrange(0, 255) b = random.randrange(0, 255) color = gr.color_rgb(r, g, b) thing.setFill(color) dx = random.randint(-10, 10) dy = random.randint(-10, 10) thing.move(dx, dy) if random.random() < 0.2: oldthing = random.choice(shapes) newthing = oldthing.clone() newthing.draw(win) shapes.append(newthing) win.update() if win.checkMouse(): break win.close()
def main(argv): # create a window win = gr.GraphWin("My window", 500, 500) # print("argument1 ", argv[1]) # create a circle c = gr.Circle(gr.Point(250, 250), 60) # c.setFill( gr.color_rgb( 100, 30, 100 ) ) # draw the circle inot the window c.draw(win) # pause until user gets mouse win.getMouse() # pause c.setFill("green") win.getMouse() c.move(50, -40) c.undraw() # pause to get the mouse again win.getMouse() win.close() return
def citywhale(x, y, scale): # define a polygon for the body, list of points bodylist = [ gr.Point(x + 5 * scale, y - 5 * scale), # starts at lower left of the whale body gr.Point(x + 25 * scale, y - 2 * scale), gr.Point(x + 45 * scale, y - 8 * scale), gr.Point(x + 70 * scale, y - 15 * scale), gr.Point(x + 100 * scale, y - 6 * scale), gr.Point(x + 90 * scale, y - 20 * scale), gr.Point(x + 100 * scale, y - 34 * scale), gr.Point(x + 80 * scale, y - 25 * scale), gr.Point(x + 55 * scale, y - 27 * scale), gr.Point(x + 45 * scale, y - 30 * scale), gr.Point(x + 30 * scale, y - 30 * scale), gr.Point(x + 24 * scale, y - 27 * scale), gr.Point(x + 8 * scale, y - 24 * scale), gr.Point(x - 8 * scale, y - 25 * scale) ] whalebody = gr.Polygon(bodylist) whalebody.setFill("purple") whalebody.setOutline("dark blue") whalebody.setWidth(4) # define a polygon for the mouth mouthlist = [ gr.Point(x + 24 * scale, y - 27 * scale), gr.Point(x + 8 * scale, y - 24 * scale), gr.Point(x - 8 * scale, y - 25 * scale), gr.Point(x + 8 * scale, y - 30 * scale) ] whalemouth = gr.Polygon(mouthlist) whalemouth.setFill("grey") whalemouth.setOutline("dark blue") whalemouth.setWidth(2) c1 = gr.Circle(gr.Point(x + 20 * scale, y - 20 * scale), 5) c1.setFill("black") # define four rectangles for the city b1 = gr.Rectangle(gr.Point(x + 30 * scale, y - 30 * scale), gr.Point(x + 34 * scale, y - 44 * scale)) b1.setFill('turquoise') b2 = gr.Rectangle(gr.Point(x + 34 * scale, y - 30 * scale), gr.Point(x + 38 * scale, y - 50 * scale)) b2.setFill('red') b3 = gr.Rectangle(gr.Point(x + 38 * scale, y - 30 * scale), gr.Point(x + 42 * scale, y - 40 * scale)) b3.setFill('green') b4 = gr.Rectangle(gr.Point(x + 42 * scale, y - 30 * scale), gr.Point(x + 46 * scale, y - 38 * scale)) b4.setFill('orange') # put all of these objects into a list whale = [whalebody, whalemouth, c1, b1, b2, b3, b4] # return the list return whale
def init_mario(x, y, scale): # Overalls as a polygon points = [ gr.Point(x + 0 * scale, y - 0 * scale), gr.Point(x + 0 * scale, y - 120 * scale), gr.Point(x + 10 * scale, y - 120 * scale), gr.Point(x + 10 * scale, y - 170 * scale), gr.Point(x + 20 * scale, y - 170 * scale), gr.Point(x + 20 * scale, y - 120 * scale), gr.Point(x + 40 * scale, y - 120 * scale), gr.Point(x + 40 * scale, y - 170 * scale), gr.Point(x + 50 * scale, y - 170 * scale), gr.Point(x + 50 * scale, y - 120 * scale), gr.Point(x + 60 * scale, y - 120 * scale), gr.Point(x + 60 * scale, y - 0 * scale), gr.Point(x + 40 * scale, y - 0 * scale), gr.Point(x + 40 * scale, y - 60 * scale), gr.Point(x + 20 * scale, y - 60 * scale), gr.Point(x + 20 * scale, y - 0 * scale) ] overalls = gr.Polygon(points) overalls.setFill('steel blue') # red shirt shirt = gr.Polygon(red_shirt_points(x, y, scale, False)) shirt.setFill('red') head = gr.Circle(gr.Point(x + 30 * scale, y - 195 * scale), 25 * scale) head.setFill('salmon') points = [ gr.Point(x - 15 * scale, y - 210 * scale), gr.Point(x - 15 * scale, y - 215 * scale), gr.Point(x + 5 * scale, y - 215 * scale), gr.Point(x + 10 * scale, y - 235 * scale), gr.Point(x + 50 * scale, y - 235 * scale), gr.Point(x + 60 * scale, y - 210 * scale) ] hat = gr.Polygon(points) hat.setFill('red') points = [ gr.Point(x + 5 * scale, y - 175 * scale), gr.Point(x + 10 * scale, y - 180 * scale), gr.Point(x + 20 * scale, y - 182 * scale), gr.Point(x + 40 * scale, y - 182 * scale), gr.Point(x + 50 * scale, y - 180 * scale), gr.Point(x + 55 * scale, y - 175 * scale), gr.Point(x + 55 * scale, y - 178 * scale), gr.Point(x + 50 * scale, y - 183 * scale), gr.Point(x + 40 * scale, y - 185 * scale), gr.Point(x + 20 * scale, y - 185 * scale), gr.Point(x + 10 * scale, y - 183 * scale), gr.Point(x + 5 * scale, y - 178 * scale) ] moustache = gr.Polygon(points) moustache.setFill('black') lefteye = gr.Circle(gr.Point(x + 22 * scale, y - 200 * scale), 3) righteye = gr.Circle(gr.Point(x + 38 * scale, y - 200 * scale), 3) lefteye.setFill('black') righteye.setFill('black') mario = [shirt, overalls, head, hat, moustache, lefteye, righteye] return mario
def witch_init(x, y, scale): '''Creates and returns a list of graphics objects to make up a witch''' shapes = [] #hat p = gr.Polygon(gr.Point(x, y - scale * 120), gr.Point(x + scale * 25, y - scale * 80), gr.Point(x - scale * 35, y - scale * 80), gr.Point(x - scale * 35, y - scale * 70), gr.Point(x + scale * 35, y - scale * 70), gr.Point(x + scale * 35, y - scale * 80), gr.Point(x - scale * 25, y - scale * 80)) p.setFill(gr.color_rgb(30, 30, 30)) shapes.append(p) #hatribbon p = gr.Polygon(gr.Point(x - scale * 25, y - scale * 80), gr.Point(x - scale * 23, y - scale * 85), gr.Point(x + scale * 23, y - scale * 85), gr.Point(x + scale * 25, y - scale * 80)) p.setFill(gr.color_rgb(128, 0, 128)) shapes.append(p) #witch's hair r = gr.Rectangle(gr.Point(x - scale * 15, y - scale * 70), gr.Point(x - scale * 25, y - scale * 30)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) r = gr.Rectangle(gr.Point(x + scale * 25, y - scale * 70), gr.Point(x + scale * 15, y - scale * 30)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) r = gr.Rectangle(gr.Point(x - scale * 15, y - scale * 70), gr.Point(x + scale * 15, y - scale * 60)) r.setFill(gr.color_rgb(0, 0, 0)) shapes.append(r) #witch's face r = gr.Rectangle(gr.Point(x - scale * 15, y - scale * 60), gr.Point(x + scale * 15, y - scale * 40)) r.setFill(gr.color_rgb(0, 205, 0)) shapes.append(r) c = gr.Circle(gr.Point(x - scale * 10, y - scale * 50), 1) c.setFill(gr.color_rgb(0, 0, 0)) shapes.append(c) c = gr.Circle(gr.Point(x + scale * 10, y - scale * 50), 1) c.setFill(gr.color_rgb(0, 0, 0)) shapes.append(c) p = gr.Polygon(gr.Point(x, y - scale * 43), gr.Point(x - scale * 3, y - scale * 47), gr.Point(x + scale * 3, y - scale * 47)) p.setFill(gr.color_rgb(255, 182, 193)) shapes.append(p) #witch body p = gr.Polygon(gr.Point(x, y - scale * 40), gr.Point(x - scale * 15, y + scale * 10), gr.Point(x + scale * 15, y + scale * 10)) p.setFill(gr.color_rgb(30, 30, 30)) shapes.append(p) p = gr.Polygon(gr.Point(x, y - scale * 40), gr.Point(x - scale * 15, y + scale * 10), gr.Point(x - scale * 25, y + scale * 10)) p.setFill(gr.color_rgb(128, 0, 128)) shapes.append(p) p = gr.Polygon(gr.Point(x, y - scale * 40), gr.Point(x + scale * 15, y + scale * 10), gr.Point(x + scale * 25, y + scale * 10)) p.setFill(gr.color_rgb(128, 0, 128)) shapes.append(p) return shapes
def dog_init(x,y,scale): ''' Creates the list of objects needed to draw a dog at position (x,y) with the given scale. ''' shapes = [] #body IDX 0 o = gr.Oval(gr.Point(x,y),gr.Point(x+200*scale,y-75*scale)) o.setFill(gr.color_rgb(139,69,19)) shapes.append(o) #tail IDX 1 t = gr.Polygon(gr.Point(x,y-40*scale),gr.Point(x+5*scale,y-45*scale), gr.Point(x-50*scale,y-100*scale)) t.setFill(gr.color_rgb(139,69,19)) shapes.append(t) #legs IDX 2-5 o = gr.Oval(gr.Point(x+20*scale,y-20*scale),gr.Point(x+30*scale,y+60*scale)) o.setFill(gr.color_rgb(139,69,19)) shapes.append(o) o = gr.Oval(gr.Point(x+27*scale,y-20*scale),gr.Point(x+37*scale,y+60*scale)) o.setFill(gr.color_rgb(139,69,19)) shapes.append(o) o = gr.Oval(gr.Point(x+153*scale,y-20*scale),gr.Point(x+163*scale,y+60*scale)) o.setFill(gr.color_rgb(139,69,19)) shapes.append(o) o = gr.Oval(gr.Point(x+170*scale,y-20*scale),gr.Point(x+180*scale,y+60*scale)) o.setFill(gr.color_rgb(139,69,19)) shapes.append(o) #head IDX 6 c = gr.Circle(gr.Point(x+210*scale,y-85*scale),40*scale) c.setFill(gr.color_rgb(139,69,19)) shapes.append(c) #ear IDX 7 o = gr.Oval(gr.Point(x+180*scale,y-120*scale),gr.Point(x+200*scale,y-60*scale)) o.setFill(gr.color_rgb(160,82,45)) shapes.append(o) #eye IDX 8 c = gr.Circle(gr.Point(x+220*scale,y-110*scale),8*scale) c.setFill(gr.color_rgb(30,144,255)) shapes.append(c) #nose IDX 9 c = gr.Circle(gr.Point(x+250*scale,y-90*scale),10*scale) c.setFill(gr.color_rgb(199,21,133)) shapes.append(c) #tongue IDX 10 o = gr.Oval(gr.Point(x+245*scale,y-75*scale),gr.Point(x+280*scale,y-80*scale)) o.setFill(gr.color_rgb(219,112,147)) shapes.append(o) #neck neck = gr.Polygon(gr.Point(x+200*scale,y-46*scale),gr.Point(x+190*scale,y-40*scale), gr.Point(x+230*scale,y+27*scale),gr.Point(x+237*scale,y+20)) neck.setFill(gr.color_rgb(139,69,19)) shapes.append(neck) return shapes
def background_init(x,y,scale): ''' Creates the list of objects needed to draw the background scene at position (x,y) with the given scale. ''' shapes = [] #sky IDX 0 r = gr.Rectangle(gr.Point(x,y),gr.Point(x+scale*400,y+scale*400)) r.setFill(gr.color_rgb(107,142,35)) shapes.append(r) #ground IDX 1 r = gr.Rectangle(gr.Point(x,y+300*scale),gr.Point(x+scale*400,y-scale*400)) r.setFill(gr.color_rgb(0,191,255)) shapes.append(r) #sun IDX 2 c = gr.Circle(gr.Point(x+325*scale,y+75*scale),20*scale) c.setFill(gr.color_rgb(255,255,0)) shapes.append(c) #yellow rays IDX 3-6 t = gr.Polygon(gr.Point(x+325*scale,y+40*scale),gr.Point(x+327*scale,y+50*scale), gr.Point(x+323*scale,y+50*scale)) t.setFill(gr.color_rgb(255,255,0)) shapes.append(t) t = gr.Polygon(gr.Point(x+360*scale,y+75*scale),gr.Point(x+350*scale,y+73*scale), gr.Point(x+350*scale,y+77*scale)) t.setFill(gr.color_rgb(255,255,0)) shapes.append(t) t = gr.Polygon(gr.Point(x+325*scale,y+110*scale),gr.Point(x+327*scale,y+100*scale), gr.Point(x+323*scale,y+100*scale)) t.setFill(gr.color_rgb(255,255,0)) shapes.append(t) t = gr.Polygon(gr.Point(x+290*scale,y+75*scale),gr.Point(x+300*scale,y+73*scale), gr.Point(x+300*scale,y+77*scale)) t.setFill(gr.color_rgb(255,255,0)) shapes.append(t) #orange rays IDX 7-10 t = gr.Polygon(gr.Point(x+352*scale,y+50*scale),gr.Point(x+341*scale,y+57*scale), gr.Point(x+344*scale,y+60*scale)) t.setFill(gr.color_rgb(255,150,0)) shapes.append(t) t = gr.Polygon(gr.Point(x+352*scale,y+100*scale),gr.Point(x+341*scale,y+93*scale), gr.Point(x+344*scale,y+90*scale)) t.setFill(gr.color_rgb(255,150,0)) shapes.append(t) t = gr.Polygon(gr.Point(x+298*scale,y+100*scale),gr.Point(x+309*scale,y+93*scale), gr.Point(x+306*scale,y+90*scale)) t.setFill(gr.color_rgb(255,150,0)) shapes.append(t) t = gr.Polygon(gr.Point(x+298*scale,y+50*scale),gr.Point(x+309*scale,y+57*scale), gr.Point(x+306*scale,y+60*scale)) t.setFill(gr.color_rgb(255,150,0)) shapes.append(t) return shapes