Implement the radialShadow() method in TransformablePicture. This time, your image transformations will use the x and y coordinates of each pixel to change each pixel in a different way based on its location. To make this easier, you will use a pair of nested for loops to explicitly control the x and y variables over the entire coordinate range of the image. Be sure to read the section on "Nested For Loops" in 08: Grouping Objects Using Lists and Nested For Loops to be prepared for writing these loops. As a reminder, you can use two numeric for loops (one inside the other) to repeat over all possible x coordinates, and for each x value, repeat over all possible y values:
for (int x = 0; x < this.getWidth(); x++) {
for (int y = 0; y < this.getHeight(); y++) {
Pixel pix = this.getPixel(x, y);
...
}
}
Study the construction of these loops to make sure you understand how they work. Within them, you will have access to the x and y loop variables, so you can always access the current location.
The radialShadow() method takes a parameter called rate that represents how "slowly" the transformation increases its effect. For any image, we can say (0, 0) is the upper left corner. For any pixel, the x-coordinate represents the distance from the left edge of the picture, and the y-coordinate represents the distance from the top edge. We can add these two together to approximate the distance of any pixel (how many steps across plus how many steps down) from the upper left corner. For every pixel in the image, using a pair of nested for loops, radialShadow() should reduce the brightness of the red, green, and blue color components of the pixel by an amount equal to the sum of the x and y coordinates divided by the rate. Use adjustPixel() to change all three color components by a negative amount. This will create a "radial" (or vaguely circular) shadow pattern on the image that is brightest in the upper left corner and gets progressively darker the farther away from the upper left corner you get. A rate of 1 produces the fastest shadow, that goes to black much closer to the upper left corner. Larger parameter values slow down the speed of the "shadow", allowing you to achieve interesting effects. How would you code this method?