Question: Python programming !! Latest python version, please include comments Your PA involves implementing a recursive program pattern0 to produce the turtle graphics patterns shown below.
Your PA involves implementing a recursive program pattern0 to produce the turtle graphics patterns shown below. To help you, you can assume that you have available a user-defined function square0 that takes length len and coordinates x and y as input and draws a red square with a black border of side length len and centered at coordinates (x.y). Here is how to use this function: from turtle import Screen, Turtle s = Screen() t = Turtle() square(t,0,0,300) # makes turtle t draw square centered at (0,0) with side length 300 pixels Executing the above would result in the following display: The above happens to also be pattern(1), or more precisely the output of pattern t,0,0,300,1). The base case, pattern(0) is just nothing... Here is pattern(2): >>> pattern(t,0,0,300,2) # makes turtle t draw pattern 2 with the main square centered at (0,0) and with side length 300 pixels Each of the four small squares is centered at an endpoint of the original square and has length 1/2.2 of the original square. Note how some squares are drawn on top of others: the squares on top are drawn after the squares on the bottom. The patterns pattern(3) and pattern(4) are similarly defined, using recursion: >>>pattern(t,0,0,300,3) >>pattern(t,0,0,300,4)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
