$30
CPSC 453 - 2019 Assignment 1
Generating and viewing the Menger sponge
The Menger sponge is an important object in mathematics and the theory of fractals. The
figures below show how it can be constructed.
1) Start with a layer of 9 cubes.
2) Remove the cube in the middle.
1
3) Create next layer of the sponge by adding 4 cubes in the corners, as shown.
4) Add the third layer, which has the same structure as the first layer shown in Step 2. If
you wish, you may think if this object as a cube subdivided into 17 sub-cubes, 7 of which
have been removed (one in the bottom layer, 5 in the middle, and 1 in the top layer.)
2
4’) Remove gaps between the cubes (actually, they were never needed for the
construction, but were shown in Fgures 1-4 to clearly illustrate the arrangement). This is
stage-1 Menger sponge.
5) Now, arrange 20 stage-1 Menger sponges in the same manner as the initial cubes have
been arranged. This is stage-2 sponge. If you prefer, you can also alternatively think of
the stage-2 sponge as resulting from the replacement of each cube in Figure 4 with a
stage-1 sponge.
3
6) Repeat Step 5 of the construction recursively a least one more time. Don’t go too far!
The number of sub-cubes and their faces grows very fast (exponentially)!
4
6’) Again, gaps in Figure 6 have only been added for illustrative purposes. The actual
Menger sponge does not have them.
5
Your assignment has two parts:
1. Write a program that generates and makes it possible to view the Menger sponge
using the traditional Open GL. Use different colors (or shades of gray) to
visualize faces with different orientations. Make it possible to explore the threedimensional structure of the sponge by rotating it and zooming in and out (using a
mouse). Make it possible to change the depth of recursion and to choose between
parallel and perspective projection using a menu. The program should properly
redisplay the sponge after the window has been resized. The image should then be
resized as well.
2. Bonus:
a. Keep the aspect ratio while resizing the window (1% of the final mark).
b. Implement shading as an optional alternative to rendering the sponge using
differently colored faces. Use menu to select the type of rendering (fixedcolored faces vs. shading). (1% of the final mark)
3. Reimplement Part 1 using core OpenGL
6