Question: In the text ( on pp . 1 5 8 1 5 9 ) , we developed this function to draw fractal trees ( note

In the text (on pp.158159), we developed this function to draw fractal trees (note that some printings of the text contain a typo on p.159the function name drawTree on the second and fourth lines from the top of the page should read fractalTree as shown in the corrected code below):
def fractalTree(trunkLength):
if trunkLength <10:
return
else:
turtle.forward(trunkLength)
turtle.left(45)
fractalTree(trunkLength/2.0)
turtle.right(90)
fractalTree(trunkLength/2.0)
turtle.left(45)
turtle.backward(trunkLength)
This function draws trees with a fixed angle (45 degrees), always decreases their trunk length by a factor of 2, and stops when trunkLength becomes less than 10.
Your task is to write a more flexible function fractalTree2(angle, scale, trunkLength, levels). fractalTree2 takes the angle as an argument. It also takes scale, which specifies an amount by which we multiply trunk length as we go from one level to the next (i.e., if we set the scale to 0.5, it will cut trunkLength in half at each level). It also uses the variable levels to determine how many levels to go before stopping.
Here's an example:
>>> fractalTree2(45,0.75,100,4)
If you would like to, you can customize your recursive drawings with other features (colors, etc.).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!