April 12, 2010

Tutorial: Maze Maker

The tutorial maze-maker.html (view source) is an introduction to functions.

It breaks down the work for drawing a random maze into five functions:

  • fillsquares sets up a global array with a grid of SVG squares.
  • setcolor sets the color of a single square at position (x, y).
  • getcolor returns the color of a single square at position (x, y).
  • shuffled returns a shuffled copy of an array.
  • makemaze draws a random maze in the grid using recursion.

The program is begging to be extended by adding a maze solver.

Maze-making and maze-solving is a good excuse for explaining recursion. Any ideas for a gentler (but interesting) introduction to functions?

Posted by David at April 12, 2010 03:01 AM

That maze is dang hard

Posted by: Baon at January 10, 2012 09:31 AM

Is there a pencil code version of this?

Posted by: beg at September 12, 2014 07:32 AM
Post a comment

Remember personal info?