#polygon5.py
"""Interactively chose polygon vertices, ending when click above line.
Illustrates use of while loops, Text, Line, Polygon, getMouse.
"""

from graphics import *

def main():
    width = 300
    height = 300
    infoHeight = 15         
    lineHeight = 2* infoHeight
    win = GraphWin("Polygon Test", width, height)
    win.setCoords(0, 0, width, height)  # so up is really up!
    instructions = Text(Point(width/2, infoHeight),
                     "Enter vertex or click here to stop.")
    instructions.draw(win)
    Line(Point(0, lineHeight), Point(width, lineHeight)).draw(win)
    
    vertices = []
    pt = win.getMouse()  
    while pt.getY() > lineHeight:
        vertices.append(pt) 
        poly = Polygon(vertices)  
        poly.draw(win)
        pt = win.getMouse()
        poly.undraw()

    poly.draw(win)
    poly.setFill("yellow")
    instructions.setText("Click anywhere to quit.")
    win.getMouse()
    win.close()

main()
