C481 B581 Computer Graphics
Dana Vrajitoru
Homework 4

Due date: Wednesday, February 9.

Download the new version of the gradients program composed of the following files (save them in a different folder). Compile it with the "make" command and run the application with the command "grad" (or ./grad).

Ex. 1 Introduce the new function you have written for homework 2 to draw a radial gradient (defined as "circular" gradient in that homework) into the application and make all the necessary changes for the program to run properly with this addition. If you have any other gradients from the previous homework you can add them too.

Ex. 2 Consider the following definition of the image based on 2 colors. For every point of the image, we're going to compute the number
a = f(x, y)
where f is a function, 0 <= f <= 1, and x and y are the coordinates of the point. Then we can compute the color components as:
r = a * r1 + (1-a) * r2
g = a * g1 +(1-a) * g2
b = a * b1 + (1-a) * b2

An example of such function would be
f(x, y) = fabs(cos(2*pi*(x*x + y*y)/(width*width + height*height)))

Write at least one function that generates the image with this method and integrate it in the application. You can use anything you find interesting for this except for the exact equation I gave as an example.

Note. To use functions like the cos, you need to include the header <cmath> and link the math library with the option -lm.
Here's an example of the result from my function:
blue_blue.jpg

Ex. 3 a. Create a new menu called "Color" and move the color selection items from the edit menu into the new one. Move the separator between the existing gradients and your gradients.

b. Add an item to the color menu that reverses the values of the two colors. For this you have to subtract r1 to b2 (all of them) from 255.

c. Add an item to the file menu that reads an image from a file of type ppm and displays it on our window. If the image file is bigger than the window size, use only the part of the image that fits in the window. Note that you have to read the image into the pixmap, then display the pixmap in the drawing area by calling Draw_pixmap. This way update events for the window will continue to display the same window.

Send me: all the source files you've modified after all the exercises (all of the changes describe one final product). Do not change the file names.