# SwiderskiNicholasHW3.py# Displaying simple graphics# 4.24.11# Nicholas Swiderski# CSC 110.05# Copied from TreeTest.py# Required import statement for Gui toolsimport Gui# Named Constants CANVAS_WIDTH = 640CANVAS_HEIGHT = 480# Function Definition Sectiondef draw_simple_tree(base_x, base_y, height): # draw trunk trunk_x1 = base_x - height * 0.05 trunk_x2 = base_x + height * 0.05 trunk_y1 = base_y trunk_y2 = base_y + height / 2.0 canvas.rectangle([[trunk_x1, trunk_y1], [trunk_x2, trunk_y2]], \ fill='brown', width = 0) # draw crown # the polygon has 3 points, peak, lower left (LL), and lower right (LR) LL_x = base_x - height * 0.2 LR_x = base_x + height * 0.2 L_y = base_y + height * 0.3 canvas.polygon([[base_x, base_y + height], [LL_x, L_y], [LR_x, L_y]], \ fill='darkgreen', width=0)def draw_tree_cluster(x, y, size): draw_simple_tree(x - 0.15 * size, y + size / 2.0, 0.5 * size) draw_simple_tree(x - 0.3 * size, y + size * 0.3, 0.6 * size) draw_simple_tree(x, y, 0.8 * size)####################################################################### DO NOT CHANGE ANYTHING BELOW THIS LINE####################################################################### Setup the canvas -- canvas is the drawing area# Note that 'win' and 'canvas' are GLOBAL VARIABLES in this programwin = Gui.Gui()win.title('Playing around with Gui')canvas = win.ca(width = CANVAS_WIDTH, height = CANVAS_HEIGHT)# Here are some colors you can use: 'white', 'gray', 'black', 'red',# 'green', 'blue', 'cyan', 'yellow', 'magenta', 'brown', 'darkgreen'# Hundreds of colors here: http://tmml.sourceforge.net/doc/tk/colors.html# seperated in the way it is to make the functions i wrote more obvious# draw_snowman_head(int, int)# Draw snowman head at the given coordinatesdef draw_snowman_head(x, y): canvas.circle([x,y], 20, 'white') canvas.circle([x-6, y+3], 3, 'black') canvas.circle([x+6, y+3], 3, 'black')# draw_snowman_body(int, int, float)# Draw snowman body at the given coordinates and scaled by the given scale factordef draw_snowman_body(x, y, scale): canvas.circle([x,y], 20*scale, 'white') canvas.circle([x,y+7], 3*scale, 'black') canvas.circle([x,y-7], 3*scale, 'black')# draw_snowman(int, int)# Draw snowman at the given coordinatesdef draw_snowman(x, y): draw_snowman_body(x, y-45, 1.5) draw_snowman_body(x, y, 1.2) draw_snowman_head(x, y+35)# draw_stickman(int, int)# Draw stickman at the given coordinatesdef draw_stickman(x, y): canvas.circle([x,y], 20, 'white') canvas.line([[x,y-19], [x,y-89]], 'black') #left arm canvas.line([[x,y-39], [x-30,y-59]], 'black') #right arm canvas.line([[x,y-39], [x+30,y-59]], 'black') #left leg canvas.line([[x,y-89], [x-20,y-119]], 'black') #right leg canvas.line([[x,y-89], [x+20,y-119]], 'black')# draw things on the canvasdraw_tree_cluster(0, 0, 50)draw_tree_cluster(-40, -30, 65)draw_tree_cluster(60, -120 , 120)draw_simple_tree(-80, -150, 140)draw_simple_tree(-100, -180, 160)#draw_snowman(50,15)draw_stickman(0,0)draw_snowman(100,15)draw_stickman(250,145)draw_snowman(-100,86)draw_stickman(24,80)draw_snowman(-200,15)# show the windowwin.mainloop()