Using SiMPLE to Create Mazes


Creating mazes with SiMPLE is very easy. The SiMPLE Online Append Library contains a module named "mazekit". The "mazekit" module lets you create programs that generate and display mazes of different sizes, shapes, and colors. For example, the following very short SiMPLE program:

Program Listing

would produce this maze:

How to Use the "mazekit" Module

The "mazekit" module consists of the following three tasks:

Task:                    maze (x, y, nx, ny, size, frame) @

Description:             Draws a maze on the screen.

Calling Parameters:      x, y:    the location at which the top-left corner
                                  of the maze is to be drawn.
                         nx, ny:  the number of cells in the horizontal and
                                  vertical directions. (50 x 50 Maximum)
                         size:    the half-size (i.e., radius) of each cell.
                         frame:   <0,  no frame around the maze.
                                  >=0, frame around the maze (separated from
                                       the maze by "frame" number of cells).

   The color of the background will be the current "solidcolor" value.
   The color of the walls will be the current "linecolor" value.
   The thickness of the walls will be the current "linesize" value.
______________________________________________________________________________

Task:                    drawwall (xn, yn, dir) @

Description:             Draws the specified wall in the specified maze cell.

Calling Parameters:      xn, yn: the location number of the cell (0,0 is the
                                 top-left cell).
                         dir:    the direction of the wall from the center of
                                 the cell:
                                     "N" (or "U") = North (or Up)
                                     "S" (or "D") = South (or Down)
                                     "E" (or "R") = East (or Right)
                                     "W" (or "L") = West (or Left)
______________________________________________________________________________

Task:                    erasewall (xn, yn, dir) @

Description:             Erases the specified wall in the specified maze cell.

Calling Parameters:      (Same as for the "drawwall task.)

The "location number" of a cell is simply a pair of integers that specify the grid location of the cell as referenced from the top-left corner of the maze:

Location Numbers

Let's modify our previous program listing so that it draws a red maze on a yellow background. And let's also "knock out" one of the cell walls on the left side of the maze so that there will be a way to get inside the maze from the outside:

Program Listing

In line 5 of the listing we create the opening by invoking the "erasewall" task to "knock out" the west wall of the cell at location number: 0,7. Then (in lines 6 and 7), we invoke the "drawwall" task to slightly extend the maze wall to the west from the opening. [Notice that negative values are permissible for the location numbers of cells. This merely means that such cells lie to the west (and/or north) of the maze.]



  [ Webmaster | FAQ's | Home Page | Contact Us ]