# William M. Farmer
# 21 December 2010
#
# This is a solution for Lab 08: Unmarked Assignment 5.
#

import math
from graphics import *

def distanceBetweenPoints(pt1, pt2):
    xDistanceSquared = (pt1.getX() - pt2.getX()) ** 2
    yDistanceSquared = (pt1.getY() - pt2.getY()) ** 2
    return math.sqrt(xDistanceSquared + yDistanceSquared)

def drawCircle(window, center, radius, color):
    circ = Circle(center,radius)
    circ.setFill(color)
    circ.draw(window)
    return circ

def main():

    # Creates window with coordinate system
    win = GraphWin("Simple GUI", 500, 500)
    win.setCoords(0,0,100,100)

    # Draws initial circle
    c = Point(50,50)
    circ = drawCircle(win, c, 25, "red")

    # Runs interactive loop
    run = True
    while run: 

       # Gets mouse click
       p = win.getMouse() 
       d = distanceBetweenPoints(c,p)
       r = circ.getRadius()

       # Redraws circle
       circ.undraw()
       if d < r/4:
           run = False
       elif r/4 <= d and d <= r:
           circ = drawCircle(win, c, 0.8 * r, "red")
       else:
           circ = drawCircle(win, c, 1.1 * r, "red")

    # Terminates program
    win.close()

main()

# Design Question
# 
# No.  An indefinite loop is required because the number of times that
# the user could click on the window is unbounded.  An indefinite loop
# could be simulated by a for loop that (1) iterates a number of times
# that is larger than the number of times a user could possibly click
# the window and (2) uses a break statement to jump out of the loop when
# the user clicks near the center of the circle.  Using an indefinite
# loop is the preferred approach.
# 
# Testing Question
# 
# A test case would be a finite sequence of pairs (a,b) where a is the
# distance from a mouse click to the center of the circle and b is the
# expected radius of the redrawn circle.  For example,
# 
#   [(26,28.6), (30,33), (34,37,4), (39, 42.9)]
# 
# would be a test case in which the user clicks successively outside of
# the circle four times.  A good set of test cases would include several
# patterns of clicking such as:
# 
#   1. Repeatedly clicking outside the circle.
# 
#   2. Repeatedly clicking inside the circle.
# 
#   3. Repeatedly clicking inside the circle followed by outside the
#      circle.
     
