import turtle # Comp Sci 111 Lab 4: Functions and turtle graphics # This program uses turtle graphics to draw stuff. # Written by ccm 9/ 2013 #======================Function Definitions # ----- draw a box with x,y at lower left corner. def drawBox (x , y, size, color): turtle.penup() # stop drawing turtle.goto(x,y) turtle.pendown() # start drawing turtle.pencolor(color) turtle.setheading(0) # facing east turtle.forward(size) turtle.left(90) # north turtle.forward(size) turtle.left(90) # west turtle.forward(size) turtle.left(90) # south turtle.forward(size) turtle.penup() #=====================START HERE drawBox( 0,0, 50, "blue") drawBox(-100, -100, 100, "green") drawBox(-300, -300, 200, "black") drawBox(-310, -310, 200, "black") # Your assignment: # Write a function called drawFlower(x, y). It takes arguments x and y # and draws a pretty flower at location (x,y). # Your flower should have more than one petal: also write a function called # drawPetal (x,y) that draws an individual petal. OK to add more arguments # for color or angle if you like. # Your drawFlower function should call the drawPetal function multiple # times to draw the separate petals. # Don't forget to call drawFlower from the main code section! # Variations on the assignment: ok to try one of these instead. # Try these ideas # 1. Define a function that draws one of your initial letters (such as # drawM or drawC. Then define a drawMonoGram function that writes # your initial letter multiple times, to make a fancy monogram/logo. # You can do this by changing the starting point, the original heading, # and/or the pen color. # 2. Define a function that draws a picture of Lord Jeff at the specified # coordinates. Then call it multiple times to make an army of Jeffs.. # 3. Write a new drawBox method that also takes as an argument a # heading to start the turtle at. Call it with different start # locations and headings to make a pretty spiral-type pattern. # 4. Try using recursion to get the drawBox function to repeat a pattern # either shifting it or shrinking it, or both. BUTNOTE this should # only be done if you can figure out how to includ an if statement to # stop infinite recursion. We will talk about this next week.