Posted on Sep 3
My step by step process of making a Menger Sponge of level 3 using BeetleBlocks, a visual programming environment for 3D design that everyone can enjoy via the Web browser:
Repeatedly letting the beetle place a cube of unit length and move the same length forward makes a square bar.
It can trivially turn into a plate by nesting the bar making process within the outer
repeat with the y-coordinate shift (
change absolute y by 1).
Nesting once more in the same way produces a (bigger) cube. Moving around a block of code without breaking its syntactic structure is where a visual programming language really shines.
Skipping a cube randomly still yields a cube but sponge look and feel emerge.
Before attempting to turn it into a Menger sponge,
we wrap the conditional in a predicate named
menger as a preparation.
Another preparation, the
floor reporter using
Now the groundwork is done, we try implementing the Menger sponge of level 1 (
iteration = 1). The interface of the
menger predicate is tabulated below.
|Input||Expected Actual Value|
||The position of the beetle.|
||The number of iterations (The level) of a Menger sponge.|
||The starting x-coordinate (inclusive) of the sponge.|
||The terminating x-coordinate (exclusive) of the sponge.|
||The starting y-coordinate (inclusive) of the sponge.|
||The terminating y-coordinate (exclusive) of the sponge.|
||The starting z-coordinate (inclusive) of the sponge.|
||The terminating z-coordinate (exclusive) of the sponge.|
||The given point lies in a cell constituting the sponge (not in a hole).|
||The given point is in a hole of the sponge.|
A "hole" is made if two of the coordinates lie in middle thirds.
The final step is making the
menger predicate recursive.
The recursion terminates if the
iterations (level) equals to zero.
A level-0 Menger sponge is just a cube without any hole in it. Hence, the predicate returns
If the level is greater than zero, we recalculate the range of a sub-sponge and recurse down one level (
iterations - 1).
2015 My gh-pages