Mazes in CoffeeScript
Posted by Jamis on February 09, 2011 @ 09:30 AM
So, the CoffeeScript sources for my maze demos are at https://github.com/jamis/csmazes.
I’ve tried to anticipate most questions about building, installation, and usage in the readme, but in a nutshell:
- You’ll need to install CoffeeScript if you want to do anything with the code.
- “examples/index.html” has widgets for all the implemented algorithms for you to play with.
- “Maze.createWidget” is the quick-and-easy way to embed a maze somewhere.
- You can do it the hard way, too, if you need more control: instantiate a maze with the algorithm of your choice, then call Maze#step until the maze is generated (or Maze#generate to do it all at once).
Note that the implementations there are optimized for animating the algorithms; the source code is not a good place to learn how a typical maze implementation might look. Every algorithm is broken down so that it can be called piecewise, one step at a time. If you were going to implement any of these for any “serious” purpose, odds are you’d do it much more efficiently, and without all the ceremony that csMazes requires.
Still, if you just want to embed an animation of a maze algorithm on a web page, csMazes works quite well. Except for IE7. And probably other IE’s as well. (If you’re an IE guru, I’d appreciate patches, but please make sure your fixes don’t impact the animation performance on other browsers. I was able to make IE render the mazes okay, but then the animation performance on Chrome was abyssmal.)
The code is in the public domain, so do with it what you will. If you do something fun with it, let me know!