Overview

This is a Processing sketch inspired by the Coding Train’s Coding Challenge #2 on create a Menger Sponge.

Keys:

  • w and s move in and out respectively
  • UP / DOWN tilts the object forward and back
  • LEFT / RIGHT rotates the object around a vertical access
  • c resets the iteration to the first step
  • r toggles the rotation on / off.

Mouse:

  • Click (anywhere) … generates the next step in the recursion (up to a limit, to avoid generating too many boxes)

Source code: (View on Github)