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.

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 to set the blue to half the original value in all pixels in the picture.

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 use the same loops as the previous problem to just visit each pixel in the top half. Then use setPixel to copy the pixel that you get from x, y to x, y + half the height of the image.

The image should end up with two copies of the top half.

You have attempted of activities on this page