CSC111 Programs for Week 12 2015
--D. Thiebaut (talk) 07:11, 20 April 2015 (EDT)
Display Maze Recursively
- Here's a skeleton program to start with...
# drawChessboardRecursive.py # D. Thiebaut # A recursive way of drawing a chessboard from graphics import * WIDTH = 600 HEIGHT = 600 NOCELLS = 8 SIDE = WIDTH // NOCELLS drawnCells = [] # keep track of cells already drawn def drawCell( row, col, color, win ): """draws a square cell of the given color on the given row and column""" x1 = col * SIDE y1 = row * SIDE x2 = x1 + SIDE y2 = y1 + SIDE cell = Rectangle( Point( x1, y1 ), Point( x2, y2 ) ) cell.setFill( color ) cell.draw( win ) def opposite( color ): """return the opposite color of a given color, assuming that the opposite of white is black, and conversely""" if color=="white": return "black" else: return "white" def recursiveDraw( row, col, color, win ): """recursively draw a chessboard""" return def main(): win = GraphWin( "Chessboard", WIDTH, HEIGHT ) recursiveDraw( 0, 0, "white", win ) win.getMouse() win.close() main()