# File: GraphicsExample.py
# Purpose: example use of graphics for lecture 2/19
# Author: Emily G. Allen

# import graphics library
from graphics import *

center = Point(320, 240) # a gobal variable that will work in all functions

def drawPoint(win):  # draw a point
    point = Point(320, 240)   # create a point in the middle
    point.setOutline('purple') # change the point's color
    point.draw(win)  # draw the point

    win.getMouse() # wait for mouse click
    point.undraw() # undraw the point

def drawLine(win):  # draw a line
    line = Line(Point(10, 20), center)   # create a line
    line.setOutline('red') # change the line's color
    line.setWidth(5)     # change the line's width
    line.draw(win) # draw the line

    win.getMouse() # wait for mouse clicke
    line.undraw() # undraw the line

def drawCircle(win): # draw a circle
    circle = Circle(center, 50) # create the circle
    circle.setFill('cyan') # change the fill
    circle.setWidth(5) # change the outline width
    circle.setOutline('blue') # change the outline color
    circle.draw(win)

    win.getMouse() # wait for the mouse click
    circle.undraw() # undraw the circle

def drawRect(win): # draw a rectangle
    rect = Rectangle(Point(10, 10), center) # create the rectangle
    rect.setFill('white') # set the rectangle fill
    rect.setOutline('green') # change the outline color
    rect.setWidth(10) # change the outline width
    rect.draw(win) # draw the rectangle

    win.getMouse() # wait for mouse click
    rect.undraw() # undraw the rectangle

def drawOval(win): # draw an oval
    oval = Oval(Point(10, 10), center) # create the oval
    oval.setFill('white') # set the  fill
    oval.setOutline('green') # change the outline color
    oval.setWidth(10) # change the outline width
    oval.draw(win) # draw the oval

    win.getMouse() # wait for mouse click
    oval.undraw() # undraw the oval

def drawPolygon(win): # draw a polygon
    poly = Polygon(Point(10, 10), Point(100, 10), center) # create the polygon
    poly.setFill('purple') # set the  fill
    poly.setOutline('red') # change the outline color
    poly.setWidth(3) # change the outline width
    poly.draw(win) # draw the polygon

    win.getMouse() # wait for mouse click
    poly.undraw() # undraw the polygon
    
def drawText(win): # draw some text
    text = Text(center, 'Hello World!!!') # create the text
    text.setOutline('red') # change the outline colors
    text.draw(win) # draw the text

    win.getMouse() # wait for mouse click
    text.undraw() # undraw the text

def main():
    # create graphics window
    win = GraphWin('My First Graphics Window', 640, 480)

    # change the color of the window
    win.setBackground('grey')
    # win.setBackground('yellow4')

    drawPoint(win) # points
    drawLine(win) # lines
    drawCircle(win) # circles
    drawRect(win) # rectangles
    drawOval(win) # ovals
    drawPolygon(win) # polygon
    drawText(win) # text

    Text(center, 'GOODBYE!!!').draw(win)  # say goodbye
    win.getMouse() # wait for mouse click
    win.close() # close window

main()
