Visual+Lab+2

[[file:Visual Lab 2.zip]]
Download and unzipwhich contains all the files you will need for this assignment. Open the files in DrJava. All the code you write for this assignment should be added to this file.


 * Be sure to test your code after completing each exercise**

negate
Complete the method, which should show the "negative" of the current image. This means that every red, green, and blue value should be replaced by 255 minus that value. For example, if the color of a pixel in the original image is (25, 150, 210), then that pixel's color should be xchanged to (230, 105, 45). So, if our image originally looks like this: and we call the method, then the window should now contain the following image:

brightness
We can estimate how bright a particular color appears by averaging its red, green, and blue components. Complete the method, which should return the average of the given 3 color components.

grayScale
Complete the method, which should modify the current image so that it now appears in shades of gray. In order for a color to appear as a shade of gray, it must have equal parts red, green, and blue. For example, the color (116, 116, 116) will appear as a somewhat medium gray, and (222, 222, 222) will appear as a very bright gray. We'll need to replace each color in the original image with an appropriate shade of gray. We'll call the method to determine how bright the original color was. This will tell us what shade of gray to use. For example, if the original color is (20, 0, 100), then its average brightness is 40, so we'll replace that color with (40, 40, 40), which will appear as a very dark gray. So, if the current image is and we call the, then the window should now contain the following image:

reduceColors
Implement the method, which takes in a value called , and reduces the number of colors in the picture. This is done by examining each pixel's red, green, and blue components, and dividing and then multiplying each of those values by. For example, if is 63, and we're examining a color with a red component value of 150, then we'll compute 150 / 63 * 63, which will give us a new red component value of 126. (Make sure you understand why.) In fact, with a of 63, every color component value from 126 to 188 will be converted into a component value of 126. (Do you see why?) Therefore, many different colors will be converted into the same color, and we'll therefore reduce the number of colors in the picture. And the larger the span value, the fewer colors we'll have left in the picture. Be sure to test your code using different values. If the original picture looked like this and we use a of 63, the resulting image will look like this:

tint
Complete the method, which should multiply the color components of every pixel in the current image by the corresponding coefficients, making sure not to allow any color component to exceed 255. For example, if the color of a pixel in the original image is (25, 150, 210), and we pass the coefficients 0.5, 1, and 2 to, then the resulting color should be (12, 150, 255). (Make sure you understand why.) So, if the original image looks like this and we call (to increase the red parts, decrease the green parts, and leave the blue parts unchanged), then the window should now contain the following image:

Challenge: flip
Write a method called that flips the image horizontally. So, for example, if the window refers to the following image and we call, then the window should now contain the following image: