"""
Recursive circles (graphics); practice with multiple recursive calls.
Author: Sara Mathieson
Date: 12/6/17
"""
from graphics import *
import math
def get_color(n):
"""This creates a kind of purple/blue color scheme"""
r = n*20
return color_rgb(r,128,128)
def rcircles(pt, radius, n, window):
"""
Draw a circle at the given point with given radius. Then recursively call
the function twice, once to the left and once to the right, each with half
the radius of the current circle.
"""
# no base case, but we do have a way of stopping
if n > 0:
# draw one circle
c = Circle(pt, radius)
c.draw(window)
c.setFill(get_color(n))
x = pt.getX()
y = pt.getY()
# left circle
left = Point(x-radius/2, y)
rcircles(left, radius/2, n-1, window)
# right circle
right = Point(x+radius/2, y)
rcircles(right, radius/2, n-1, window)
def main():
# as the user for the number of recursive levels
n = int(input("Enter an integer: "))
# make the graphics window
width = 600
height = 600
win = GraphWin("Recursive Circles", width, height)
# initialize the center and radius, then call our recursive function
center = Point(width/2, height/2)
radius = width/2
rcircles(center, radius, n, win)
win.getMouse()
win.close()
main()