'''
Created on Dec 12, 2010

@author: clifton
'''
from zellegraphics import GraphWin, Rectangle, Point
from random import random

# Constants
SIZE = 240
INSET = 10

def nestedBoxes(colors, numberOfBoxes):
    '''This displays a window with nested boxes, with colors chosen at random
       from the given list.'''
    win = GraphWin('Nested Box', SIZE, SIZE)
    
    individualBoxInset = INSET
    spaceAvailable = (SIZE - 2 * INSET) / 2
    stepSize = spaceAvailable / numberOfBoxes
    for i in range(numberOfBoxes):
        box = Rectangle(Point(individualBoxInset,individualBoxInset), 
                        Point(SIZE - individualBoxInset, SIZE - individualBoxInset))
        #c = colors[i % len(colors)]
        c = colors[int(random()*len(colors))]
        box.setFill(c)
        #box.setWidth(0)
        box.draw(win)
        individualBoxInset += stepSize
    
    win.getMouse()
    win.close()


def main():
    colors = ['red','orange', 'yellow', 'green', 'blue', 'violet']
    n = 10
    nestedBoxes(colors, n)

if __name__ == '__main__':
    main()