Mazes are a lot of fun - both to solve, and to create. So when it came time to make a flyer to hand out at events we couldn't pass up the opportunity to write a little code to create some mazes!
The end result turned out to be a series of flyers where each one has a different maze on it. We created a series of 10 differen mazes, which can be downloaded here.
There are a number of ways to create a maze in code. The simplest way to think about the process it is to start with a piece of graph paper - for example, a 5 by 5 grid of cells with walls:
Then, erase some of the walls until you have a path:
Finally, erase some more walls to create false paths:
That's pretty much the concept. The trick, of course is in the details of how this concept is translated into code. We won't go into actual code here, but a good set of questions to think about when planning to write some code to create mazes is:
- What is the data - i.e. what do you need to keep track of?
- How should the data be stored in code - i.e. what are the data structures (e.g. points, arrays, etc.) needed?
- What is the simplest part of the process that could be considered "one step"?
Enjoy the mazes!