Question: The method should draw the 2D array of ints with the given Graphics object as a series filled 1x1 rectangles with the color set to
The method should draw the 2D array of ints with the given Graphics object as a series filled 1x1 rectangles with the color set to a grayscale value between white and black.
The shade of gray should be scaled to the elevation of the map. Recall, in RGB color, if each of RGB values are the same, youll get a shade of gray. Thus, there are 256 possible shades of gray from black (0,0,0) to middle gray (128,128,128), to white (255, 255, 255).
To make the shade of gray, you should use the min and max values in the 2D array (you just wrote helper methods to find these!) to scale each int to a value between 0 and 255 inclusive. (Note: this requires math! Think about it.) Once you have found your value between 0 and 255, call you need to set the fill color just before drawing the rectangle.
int c = //calculated grayscale value g.setColor(new Color(c, c, c)); g.fillRect(x,y,1,1);
Need help finding what c should be. Min and Max are int variables with the values 4400 (max) and 1300 (min).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
