The following method, create_carpet, initiates the recursion to a certain recursive level according to a user-defined
Parameter mslevel, defined under
Global Definitions in the
Model Builder. It sets a limit at 5 levels in order to avoid creating an exceedingly large geometry. The method assumes that you have created a 2D Component and that you have declared an integer scalar variable
counter.
The method create_carpet in turn calls the main recursive function
carpet, listed below, using four input arguments for the recursion level, the center
x- and
y-coordinates, and the current side length.
Note that the number of square geometry objects defined for the level 3 carpet is 512. The number of geometry objects for a level-N carpet is
8N. This means that for the maximum level 5 set by the method
create_carpet, the resulting geometry has 32,768 geometry objects.
The following method, create_sponge, initiates the recursion.
The method sponge, shown below, is called by the above method and recursively creates a Menger sponge.
In this case, the number of geometry objects grows with the level N as 20N and the level-2 sponge shown above has 400 block geometry objects.