9.9. Chapter Exercises

Fix the indention below to correctly set the red to the green, the green to the blue, and the blue to the red.

Hint: If your program runs out of time while it is running, it is probably because you are redrawing the window as you change each pixel. You should only draw the window one time!

Fix 4 syntax errors in the code below so that it correctly sets the green in all pixels to 0.

Fill in the missing code on lines 9, 12, and 18 below so that the blue value of each pixel ends up 1/2 of what it used to be.

Fix the indention below to correctly so that the red and green values for each pixel are set to be the same as its blue value. This should make a black & white version of the image.

Write code that for each pixel, adds the y value of its location to the red. You will have to use the nested-loop approach to iterating through all of the pixels so that you have access to the x and y coordinates of the pixel you are working with.

Write code that blacks out the top half of the image by setting just the pixels in the top half to have a color value of 0, 0, 0. You will have to use the nested-loop approach and only visit the pixels in the top half.

Remember to use // when dividing the width or height so that you don’t get a decimal (float) answer.

Write code top copy the top half of the image to the bottom half. You should end up with something that has two copies of the top of mount hood.

You must use loops that track x and y locations to loop through all of the possible x,y pairs. Then use getPixel and setPixel to copy from x, y to x, y + half the height of the image.

Hint: You saw a program to make a mirror image of the top half of an image. This is pretty similar…

You have attempted of activities on this page