C481 B581 Computer Graphics
Dana Vrajitoru
C481/B581 Homework 3

Due date: Monday, February 6.

Ex. 1 Download the following files in a separate folder (you don't want to mix the main.cc and the Makefile with those of another program). The name of the executable is now fractal:
Makefile
sierpinski.h
sierpinski.cc
main.cc
glheader.h
interface.h
interface.cc

Compile and run the program. The result should be similar to the following image:

a. Add a 4 more cases in the key function with numerical values where the level of detail of the fractal is set increasingly (it does not have to be in increments of 1).

b. Implement the Sierpinski carpet function and replace the call to the function drawing the gasket with the one drawing the carpet. Here is an example of this fractal:

The idea in the carpet fractal is to start with a square and divide it in 3, then apply the procedure recursively to all of the 9 squares except for the center one. You may have to define additional functions for this fractal depending on how you choose to implement it.

The parameters of this function will be the following. The Point2 parameter represents the lower left corner of the square. The second parameter represents the width of the edges of the square, and the 3 other corners can be obtained by adding it on x and on y to the first corner. The third parameter is the precision of the fractal and can be used in a similar way to the gasket.

c. Add functionality to the interface to be able to translate the image using the arrow keys and to zoom in and out using the PageUp and PageDown keys. For this purpose, declare a couple of global variables for the translation over x and over y, initialized as 0, and a third one for the scaling factor, initialized as 1. We'll apply the same factor both over x and over y. Find appropriate values to increment these variables when the keys are pressed.

In the function display, after the calls to the color functions, add a call to the function
glLoadIdentity();
to reset all the transformations applied to the scene. Then call
glTranslatef(x, y, 0);
with 0 for the z component to make it a 2D transformation. Finally, call the function
glScalef(factor, factor, 1);
to scale the scene. Use your own variable names as parameters for these functions.

Just like in the previous homework, add a case for the letters 'r' and 'R' where you reset the translation vector and scale factor to the default values.

Upload to Canvas: the source file(s) that you modified. Make sure to upload the sierpinski.h file too if you add anything to it.