The Menger Sponge

Here's a little implementation of the Menger Sponge using the beautiful FieldTrip graphics library. Screenshots of various recursion depths are of course required:

a cube, the first step in drawing a menger sponge

with a bit more detail now

this one is looking kind of sponge-like... for a mathematician

SOOOO many cubes!

You can also see a video of the beautiful zooming, spinning version, but be warned that it is actually the inverse menger sponge! This was before my teammates told me I was doing it all wrong and straightened me out.

Building this beautiful program

The build process is quite complicated indeed. If you are on Linux, I highly recommend trying to run the binary I built once before going down this path, just in case that works. Otherwise, grab the source and get started...
  1. Grab GHC 6.10. You will probably also need libedit, which is not such a common library. It should be in your repositories; building from source is not too painful, either.
  2. Get cabal-install from Hackage. The tar has a script called that should run the install process for you, grabbing dependencies as it goes. Remember to put ~/.cabal/bin in your PATH afterwards.
  3. Install reactive-fieldtrip from Hackage. Now that you have cabal-install, this should be as easy as typing
    cabal update
    cabal install reactive-fieldtrip
    Of course, you and I both know that "should" really means "won't". This step is almost guaranteed to fail, but hopefully it should at least make it to the reactive package before it fails.
  4. Extract the source for reactive in a temporary directory, and change AVector to Diff in Point2.hs and Point3.hs:
    tar xf ~/.cabal/packages/*/*
    cd FieldTrip-*
    cd src/Graphics/FieldTrip
    sed -i s/AVector/Diff/ Point?.hs
    cd -
    cabal install
  5. Now hit up cabal install reactive-fieldtrip again. This time it should succeed.
  6. Okay! You have now got the whole dependency tree for this short program installed. Whew! At this point, you can runhaskell menger.hs to run it once, or use
    ghc --make menger
    if you plan on running it several times.