Skip to main content

Exercises 21.8 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.


This program should make a black-and-white image by setting the red and green values for each pixel to be the same as the pixel’s blue value. Write the missing code:


Write code to set the red value of each pixel to 255. This should give the entire image a rosy tint.


Write code to multiply the r, g, and b color of each pixel by 0.8. In other words, for each color channel (r, g, b), get its current value, multiply that by 0.8, and use the answer as the new value for the color. This should make the image darker.


Write code that for each pixel, adds the y value of its location to its red color.
You have attempted of activities on this page.