The Menger SpongeHere'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 programThe 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.shthat should run the install process for you, grabbing dependencies as it goes. Remember to put
~/.cabal/binin 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-fieldtripOf 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
reactivepackage before it fails.
- Extract the source for
reactivein a temporary directory, and change
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-fieldtripagain. 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.hsto run it once, or use
ghc --make menger ./mengerif you plan on running it several times.