# Menger fractals

I’ve already done a post on menger fractals a while ago, but I thought it was time to switch them on in wooscript.

There are a few basic controls which I’ve also added into the language so you can have some fun with different types of menger fractal. Of course, the classic fractal is the menger sponge. To build a menger sponge, you take a 3x3x3 block of cubes, and remove the cubes from the centre of each face, and from the centre of the cube.

That gives you a simple cube with a single iteration.

Menger sponge, iteration 1

For the next step of the fractal, replace each of these cubes with a new 3x3x3 block of cubes, and perform the same removals. Continue this process and you end up with a menger sponge. This fractal has a few interesting properties, notably an infinite surface area and zero volume. Neat innit.

Menger Sponge, iteration 4

To add a menger cube you simply call the primitive like so

`menger`

This will add a menger sponge with 4 iterations. If you want to change the number of iterations I’ve added it as a standard floating point variable to the state machine. So for an iteration of 2 try

`mengeriterations=2`

Finally I’ve also allowed you to override the sponge pattern used on the cube, which can give some really interesting results.

To do this use the new function mengerpattern() and pass it a 27 digit number with a 1 for a cube, and a 0 for a hole. i.e. the standard menger sponge can be set like this.

`mengerpattern(111101111101000101111101111)`

But what about if we try some other patterns for this? One of my favourite is the tie fighter. This is two panels, with a single cube in the centre.

`mengerpattern(101101101101111101101101101)`

Menger tie fighter, iteration 6

If you carry on messing about with the patterns (of which there are nearly a billion) you can build some other really interesting shapes. How about this one?

Menger tree

Menger tree from the ground

Anyway, hope you enjoy it. I’ll add the script and support for menger sponges to version 0.96 of Wooscripter which I’m aiming to release in a week or so. Follow me on twitter, or like the facebook page, if you want to keep up to date!