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:
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...
- 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.
- Get cabal-install from Hackage. The tar has a script called
bootstrap.sh
that should run the install process for you, grabbing dependencies as it goes. Remember to put ~/.cabal/bin
in your PATH afterwards.
- 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.
- Extract the source for
reactive
in a temporary directory, and change AVector
to Diff
in Point2.hs
and Point3.hs
:
tar xf ~/.cabal/packages/hackage.haskell.org/FieldTrip/*/*
cd FieldTrip-*
cd src/Graphics/FieldTrip
sed -i s/AVector/Diff/ Point?.hs
cd -
cabal install
- Now hit up
cabal install reactive-fieldtrip
again. This time it should succeed.
- 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
./menger
if you plan on running it several times.