This task gives you practice using recursion to process information in lists.
In this task, you will create a file named recursiveCircles.py and write functions concentricCircles and colorListCircles. concentricCircles does the exact same thing the function of the same name from the circles task, while colorListCircles is a new function that is similar to multicolorCircles from that task, but not as complex. However, for this task, you are not allowed to use any loops, and must use recursion instead.
Your circles.py file should begin with this header, which you should paste into the file and fill out (as usual, each function you write must be documented):
"""
Authors:
Consulted:
Date:
Purpose: CS 111 circles task: draws concentric circles in alternating
colors.
"""
You will need to import turtle and turtleBeads by putting the following lines at the beginning of your code (import turtleBeads first so that the beLoud print statements will work correctly):
from turtleBeads import *
from turtle import *
You can download the turtleBeads.py file here. Make sure it's in the same folder as your circles.py file.
Remember that you are expected to write at least 2 additional tests for each function.
Part A: concentricCircles
The concentricCircles function should draw exactly the same pattern as the concentricCircles function from the earlier circles task. The only difference is how it draws the pattern: you are not allowed to use any loops, and you must use recursion instead.
The concentricCircles examples below show how the function should work.
As a reminder, here is the specification for concentricCircles function:
It draws a series of concentric circles, where the first parameter specifies the radius of the outermost circle, and the second parameter specifies the number of circles to draw. When viewed as nested rings, all rings should have the same thickness.
The third and fourth parameters specify an outer color and an other color, respectively. The outer color is used for the outermost circle, and then every other circle in from the edge alternates between that color and the other color.
We will test both how many circles are drawn as well as whether the correct circles are drawn in the correct order.
Hint: Each function call frame only needs to draw a single circle.
Note that you must use the turtleBeads drawDot function to draw each circle.
As an extra goal, your function should call drawDot in only one place, and should only contain one recursive call.
Part B: colorListCircles
The colorListCircles function must draw concentric circles using colors from a list. It has two parameters: the first specifies the radius of the largest circle, and the second is a list of colors. The number of concentric circles drawn is the length of the list, and these circles are colored, from largest to smallest, by the colors in the list from first to last. When viewed as nested rings, all rings should have the same thickness. If the list is empty, nothing should be drawn.
The colorListCircles examples below show how colorListCircles should work.
We will test both how many circles are drawn as well as whether the correct circles are drawn in the correct order. As in concentricCircles, you may not use any loops and you must use recursion. Also, you will still need to use drawDot.
As an extra goal, your function should call drawDot in only one place, and should only contain one recursive call.
Notes:
As usual, you must document every function you write and you should not waste fruit or waste boxes.
If you get stuck with a function, try the case-by-case method of recursive problem solving.
Part A: concentricCircles
ex1:
concentricCircles(60, 3, 'HotPink', 'LightSkyBlue1')
prints:
A HotPink dot at (0, 0) with radius 60
A LightSkyBlue1 dot at (0, 0) with radius 40
A HotPink dot at (0, 0) with radius 20
draws:
ex2:
concentricCircles(190, 4, 'LightSalmon2', 'Khaki1')
prints:
A LightSalmon2 dot at (0, 0) with radius 190
A Khaki1 dot at (0, 0) with radius 142
A LightSalmon2 dot at (0, 0) with radius 95
A Khaki1 dot at (0, 0) with radius 48
draws:
ex3:
concentricCircles(140, 7, 'Gold', 'DeepSkyBlue')
prints:
A Gold dot at (0, 0) with radius 140
A DeepSkyBlue dot at (0, 0) with radius 120
A Gold dot at (0, 0) with radius 100
A DeepSkyBlue dot at (0, 0) with radius 80
A Gold dot at (0, 0) with radius 60
A DeepSkyBlue dot at (0, 0) with radius 40
A Gold dot at (0, 0) with radius 20
draws:
Part B: colorListCircles
ex1:
colorListCircles(160, ['black', 'blue', 'red', 'yellow'])
prints:
A black dot at (0, 0) with radius 160
A blue dot at (0, 0) with radius 120
A red dot at (0, 0) with radius 80
A yellow dot at (0, 0) with radius 40
draws:
ex2:
colorListCircles(180, ['red', 'orange', 'yellow', 'green', 'blue', 'navy', 'purple3'])
prints:
A red dot at (0, 0) with radius 180
A orange dot at (0, 0) with radius 154
A yellow dot at (0, 0) with radius 129
A green dot at (0, 0) with radius 103
A blue dot at (0, 0) with radius 77
A navy dot at (0, 0) with radius 51
A purple3 dot at (0, 0) with radius 26
draws:
ex3:
colorListCircles(150,['Aquamarine2','Khaki2','LimeGreen','Aquamarine2','Khaki2','LimeGreen','Aquamarine2','Khaki2','LimeGreen','Aquamarine2','Khaki2','LimeGreen','Aquamarine2','Khaki2','LimeGreen',])
prints:
A Aquamarine2 dot at (0, 0) with radius 150
A Khaki2 dot at (0, 0) with radius 140
A LimeGreen dot at (0, 0) with radius 130
A Aquamarine2 dot at (0, 0) with radius 120
A Khaki2 dot at (0, 0) with radius 110
A LimeGreen dot at (0, 0) with radius 100
A Aquamarine2 dot at (0, 0) with radius 90
A Khaki2 dot at (0, 0) with radius 80
A LimeGreen dot at (0, 0) with radius 70
A Aquamarine2 dot at (0, 0) with radius 60
A Khaki2 dot at (0, 0) with radius 50
A LimeGreen dot at (0, 0) with radius 40
A Aquamarine2 dot at (0, 0) with radius 30
A Khaki2 dot at (0, 0) with radius 20
A LimeGreen dot at (0, 0) with radius 10
draws:
When you've completed this assignment, make sure your file(s) are named following the course's naming convention ([wellesley username]_[assignment]_[task name]) and submitted through Gradescope. Reminder that detailed instructions can also be found on the Lab 1 page.