Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You may remember using recursion in lab to draw a fractal tree. As it turns out, recursion lends itself very easily to the drawing of

image text in transcribed

You may remember using recursion in lab to draw a fractal tree. As it turns out, recursion lends itself very easily to the drawing of fractals. For this problem, you are to write a recursive function, squares (t,length, depth), that uses the turtle module to draw the following fractal: where each square is bordered on its side by a square with half its side length. The formal parameters given above are as follows: t is the turtle object, length is the side length of the current square, and depth is the remaining number of generations of squares to draw. In the above example, the initial depth was set to 3. Therefore, you can infer that each recursive call to squares ) will divide length by 2 and subtract depth by 1. It is best to think about this problem geometrically before you start writing your function. Work out how you can get the turtle from where it is to where it should be using only the variables you have available to you (each recursive call to the function must draw its part correctly without reference to values used in other calls). You may find the turtle methods .xcor () and ycor (or, equivalently, -pos ()) and .goto) useful. You wil need to write a main function in which you prompt for the initial depth, create a turtle object, set speed to 0, and call squares (). The initial length you will use is 200. Constraints: You may assume that the given depth is a non-negative integer . You must use turtle.speed (0) in main before you call your function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

11. will not accept dishonor.

Answered: 1 week ago