Image-4 Exercises

< CS101

Here we'll do 5-10-20 puzzles like the one shown in lecture. For each puzzle image, the red, green, and blue values have been divided by a factor of 5, 10, or 20, but you don't know which factor was used on which color. Write code to fix the image, multiplying each color by 5, 10 or, 20 to get them back to their original values. Reminder: here is the line to use in the loop to multiply, for example, the red value of each pixel by 20:

  pixel.setRed(pixel.getRed() * 20);

There are a few solutions that look somewhat correct, but just one solution that looks exactly right. Figure out that solution.

1.

Write code to fix the 51020-poppy.png image which should show an orange California Poppy in the foreground (the California state flower!). The background is mostly out of focus green shapes with some brown, and 1 out of focus poppy.


image-4-ex1

 

2.

Write code to fix the 51020-stop-sky.png image which should show a red stop sign with a background of a light blue sky and green tree leaves.


image-4-ex2

 

3.

Write code to fix the 51020-oranges.png image which should show a box of oranges. The box itself is dull gray. The sign on the box is black, with "organic" written in light orange, and the rest of the letters are white. There are some close-but-not-quite solutions. If the white letters have a green tint, you're not there yet


image-4-ex3

 


Each click of a Run button saves that code on the computer running the browser. The button below retrieves the all code exercises listed to the right of the button.

count 3 : image-4-ex1 image-4-ex2 image-4-ex3

(code appears here)