# File Name: Exercise3_3.py
# Purpose: generate a "scatter plot" of (100, 50), (72, 10), (30, 27), (50, 13), (90, 43).
# Author: Emily G. Allen

# NOTE: I did not use a function for each specific task because multiple tasks needed access to the points
# it would have been less efficient to recreate the points for each function

# import graphics
from graphics import *

def main():
    # dimensions of window; I used variable so I could change them more easily
    xsize = 300
    ysize = 300

    # create window
    win = GraphWin('My Scatter Plot', xsize, ysize)

    # adjust coordinates to make plotting easier; scaled to fit maximum points
    win.setCoords(0,0, 150, 150)

    # distance of axis from edge of window
    xoffset = 20 
    yoffset = 20
                  
    # draw axes
    xaxis = Line(Point(xoffset, yoffset), Point(150, yoffset))
    xaxis.draw(win)

    yaxis = Line(Point(xoffset,yoffset), Point(xoffset, 120))
    yaxis.draw(win)

    # create points
    p1 = Point(100, 50) 
    p2 = Point(72, 10)
    p3 = Point(30, 27)
    p4 = Point(50, 13)
    p5 = Point(90, 43)

    # move points relative to axis
    p1.move(xoffset,yoffset)
    p2.move(xoffset,yoffset)
    p3.move(xoffset,yoffset)
    p4.move(xoffset,yoffset)
    p5.move(xoffset,yoffset)

    # draw the points
    p1.draw(win)
    p2.draw(win)
    p3.draw(win)
    p4.draw(win)
    p5.draw(win)

    # connect the points with lines
    line1 = Line(p3, p4)
    line2 = Line(p4, p2)
    line3 = Line(p2, p5)
    line4 = Line(p5, p1)

    # draw the lines
    line1.draw(win)
    line2.draw(win)
    line3.draw(win)
    line4.draw(win)

    # alternatively, with circles
    c1 = Circle(p1, 2) # circle has center at pt 1 and radius of 5
    c2 = Circle(p2, 2)
    c3 = Circle(p3, 2)
    c4 = Circle(p4, 2)
    c5 = Circle(p5, 2)

    c1.setFill('red') # lets make it pretty
    c2.setFill('red')
    c3.setFill('red')
    c4.setFill('red')
    c5.setFill('red')
    
    # draw the circles
    c1.draw(win)
    c2.draw(win)
    c3.draw(win)
    c4.draw(win)
    c5.draw(win)

    # NOTE: don't need to move the circle because the points have already been moved!

    # create the text labels
    xlabel = Text(Point(75, yoffset/2), 'X')
    ylabel = Text(Point(xoffset/2, 75), 'Y')

    # draw the labels
    xlabel.draw(win)
    ylabel.draw(win)
    
    win.getMouse() # wait for mouse
    win.close() # close the window

main()
    
