# File: ChapterGraphics//grid.py
# Draw a grid with n x n squares
from graphics import *
winx, winy = 500, 500 # size window
win = GraphWin( "Grid", winx, winy )
def main():
horizontal(4)
vertical(5)
def horizontal(n): # Horizontal lines
side = winx / n # side of a grid square
for j in range(n):
lineH = Line(Point(0,j*side),Point(winx,j*side))
lineH.draw(win)
def vertical(n): # Vertical lines
side = winy / n # side of a grid square
for j in range(n):
lineH = Line(Point(j*side,0),Point(j*side,winy))
lineH.draw(win)
main()