# Add your comments here # __author__='Your name here' from turtle import * # ----------write your code here ----------- def shrub(trunkLength, angle, shrinkFactor, minLength): """Draws a shrub with the specified parameters. Returns a tuple consisting of the total number of branches and the total length of the branches (including the trunk) of the shrub""" # -------------------------------------------- def testShrub (trunkLength, angle, shrinkFactor, minLength): """Testing code for shrub function.""" setup(600, 600, 0, 0) # Set size of turtle window and bring it to the top of the screen speed(0) # Set the speed; 0=fastest, 1=slowest, 6=normal pensize(1) # Choose a pen thickness # Move turtle to lower middle pointing up setpos(0, -(window_height()/2.0 - 20)) setheading(90) clear() # Clear any existing turtle drawings testInputString = ('shrub(' + str(trunkLength) + ', ' + str(angle) + ', ' + str(shrinkFactor) + ', ' + str(minLength) + ')') # Put testInputString in title at top of window title(testInputString) # Draw shrub and get returned result numBranches, lengthBranches = shrub(trunkLength, angle, shrinkFactor, minLength) testOutputString = testInputString + ' -> ' + str(numBranches) + ' branches, '+ str(lengthBranches) + ' total branch length' # Put testOutputString in title at top of window title(testOutputString) # Make sure the window can close on click exitonclick() # Uncomment each of the lines below to test. # You can only run one invocation of testShrub at a time. #testShrub(100, 15, 0.8, 60) #testShrub(100, 15, 0.8, 50) testShrub(100, 15, 0.8, 10) #testShrub(100, 30, 0.82, 10) #testShrub(200, 90, 0.75, 10)