#polygon1.py
"""Interactively chose polygon vertices, with total entered in shell.
Illustrates use of Text, Polygon, getMouse.

Shows intermediate polygons by drawing and undrawing.
"""

from graphics import *

def main():
    width = 300
    height = 300
    infoHeight = 15
    size = input("Enter the number of sides:  ")
    win = GraphWin("%d Sides" % size, width, height)
    instructions = Text(Point(width/2, infoHeight),
                     "Click %d vertices:" % size)
    instructions.draw(win)
    
    vertices = []
    poly = Polygon(vertices) # so it can be undrawn  
    for i in range(size): 
        pt = win.getMouse()
        poly.undraw()
        vertices.append(pt) # append method adds to the list
        poly = Polygon(vertices)  
        poly.draw(win)

    poly.setFill("yellow")
    instructions.setText("Click anywhere to quit.")
    win.getMouse()
    win.close()

main()
