#3.1.py
 
# Let's write  simple program to draw grid lines (spacing is of our choosing). This
# will help us choose coordinates to place points/objects in the graphical window.


def wait():
    dummy = input(" ")
 
from graphics import *  #get access to all of graphics.py's functions

import sys
 
def main():
 
    wait()
    #first get a window
 
    w = GraphWin("Example Window",800,800,autoflush=False)
                       #(0,0) is at top left corner
                       #(799,799) is at bottom-right corner
                       # x is horizontal, y is vertical
                       # in (x,y)


    done = False

    while (not done):

        spacing = int (input("Enter small integer to use as pixel spacing: "))
        if (spacing > 200):
            print(" Integer is too large ")
            sys.exit()
 
        grid(w,800,spacing)

        draw_quickly(w) #using a bit of a trick here with the "autoflush" option off
                        #in the Graphwin constructor (see above), and the clear_objects()
                        #function.
                        #Without these, the drawing will proceed slowly line by line, and
                        #wiping out each line will also proceed slowly. With this trick
                        #the entire grid appears (and disapears) in one-shot.

                        #if the author provided a clear() method and a draw_quick()
                        #method we would not have to think about this.

        resp = input("Want to try another spacing?Y/N: ")
        if (resp != "Y"): break

        clear_objects(w)

    return
 

def grid(win,size,spacing): #draw grid lines, assuming its a SQUARE grid of side size

    for j in range(0,size,spacing):
        hline = Line(Point(j+spacing,0), Point(j+spacing,800))
        hline.draw(win)
        vline = Line(Point(0,j+spacing), Point(800,j+spacing))
        vline.draw(win)
    return

def draw_quickly(win):
    win.update()        #autoflush is false, so it will show all the lines at once
    return

def clear_objects(win):
    for item in win.items[:]:
        item.undraw()
    win.update()        #autoflush is false, so it will clear all the lines at once
        
    
    
