Programming Assignment # 3

Due: November 9.


In this assignment you will write a graphics program that uses colors to represent the values of a function in two variables. For example the function might be something like

F(x,y) = sin(x) * exp(-x^2 - y^2).

The function is computed over a two dimensional grid of values. The graphics display area has a corresponding grid of elements, where each element will be assigned a color that reflects the value of the function at the corresponding point. This is done in the following way. First, the value of the function at all the points in the grid is computed. You then compute the minimum and maximum values that the function takes, and divide that range (Max-Min) into 8 or so intervals, each of which gets one color. All that remains is to build the display using those colors.

The display is a two dimensional array of graphic objects. Each object is drawn with a separate command. The Graphics chapter in the text discusses how this is done. The color is specified by calling setColor on the graphic object which is the argument of the paint method for the enclosing applets.

Note that there is no interaction with the user in this assignment. The function is built into the program. However, once the basic assignment is complete, you should try to do something fancier. For example, you could add some buttons to recompute the function with higher resolution, add a choice of functions to display, or have a zoom capability that replots the region that a user selects. A nice feature is to display the value at a point where the mouse clicks. Other suggestions for variations are also welcome!