# display.py -- display forest
# This file is provided as a partial implementation of PA10

import tkinter
from tkinter import Canvas
from random import *

def display(forest, c):
    nrows = len(forest)
    ncols = len(forest[0])
    colors = ["red", "#202020", "lightgreen", "green", "darkgreen"]
    for row in range(nrows):
        for col in range(ncols):
            c.create_rectangle(col * 20, row * 20, (col + 1) * 20, (row + 1) *20,
			fill = colors[forest[row][col]],
			outline = "black")
    c.update() # force new pixels to display



def test_display():   
    n = 17   # for nxn matrix
    
    # seed the random number generator
    seed(15110)                            

    window = tkinter.Tk()   
    # create a canvas of size 340 X 340
    c = Canvas(window, width=n*20, height=n*20)
    c.pack()  
    
    # initialize forest matrix randomly
    forest = []
    for i in range(n):
        row = []
        for j in range(n):
            row.append(randrange(5)) # pick a random tree state (0-4) 
        forest.append(row)
        
    # display the forest using the display function
    display(forest, c)


