spi-sponge.py

The file spi-sponge.py is an adaptation of szgpovinteract.py, which was included with the 6/20/2006 (approximate) release of Aszgard.

Onto the szgpovinteract scene, I grafted code from my own POV-Ray scene which produces a partial image of the Menger sponge, dynamically modeled using an adaptive recursion algorithm.

Adaptive Recursion

Effective frame rate in a szgpov-based rtica depends heavily upon the total amount of time required by POV-Ray to render a bitmap of the scene. The factors are described in some detail in the document szgpov.html.

My adaptive recursion algorithm for defining a localized portion of the Menger sponge primarily addresses the time-to-parse issue. It works in this way:

  1. Establish a minimum recursion level (which appears in the POV-Ray code output by spi-sponge.py as "RECURSION_MIN"). In spi-sponge.py, this value is set to 2.
  2. Establish a maximum recursion level ("RECURSION_MAX").
  3. Invoke recursive macro CutOut, with the parameters center, factor, and RecLevel. The initial call to the macro is with center = <0,0,0>, factor = 1, RecLevel = 1.
    1. If maximum recursion has been reached (RecLevel is equal to RECURSION_MAX), draw a colored block, and exit macro.
    2. Otherwise, loop through the centerpoints of the 20 smaller cubes that remain after subdividing the full cube and removing 7 smaller cubes, per the rule for the Menger sponge.
      For each of the 20:
      1. If current recursion level is less than the established minimum, recursively invoke the CutOut macro, with
        • center—this sub-cube's centerpoint
        • factor—the current factor times 1/3
        • RecLevel—the current RecLevel plus 1
      2. Otherwise, calculate the distance from the current sub-cube's centerpoint to the "focus" point. The focus point is approximately the center of a small ball manipulated with the wand by the CUBE/CAVE user.
        If the sum of the calculated distance plus the current recursion level is less than RECURSION_MAX, recursively invoke the CutOut macro as above.
The source code for spi-sponge.py is here.