For Loop Exercises

1.

Add code inside the loop to modify flowers.jpg as follows: remove all the green from the image, leaving red and blue unchanged.


 


For the following two puzzle images, the red, green, and blue values have been divided by a factor of 5, 10, or 20, but we don't know which color was divided by which value. Write code to multiply the red, green, and blue by 5, 10, and 20 to restore the images to a more normal color.

2.

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.


 

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


 


4.

Write code to fix the puzzle-copper.png image. The red values in the image are random speckle noise. The real image is in the blue and green values, which have been divide by 10.


 


5.

There is an image of someplace famous hidden in the puzzle-sunny.png image. The image is in one color (for you to figure out), but it has been divided by 5. The other two colors are random speckle noise. Write code to reveal the real image: figure out which color contains the image and multiply it by 5. Remove the speckle noise of the other two colors. The resulting image will be all in one color.


 


6.


a yellow banana

Write code to create a "negative filter" for the banana.jpg image. A negative filter replaces each color with its inverse (by subtracting the current red, green, or blue value from 255). For example, purple would become green, and white would become black.


 


7.


a california poppy

Write code to create a "purple-scale filter" for the "poppy.jpg". Recall that grayscale renders the average brightness into gray; instead, we'll only set the red and blue values to have the average brightness value, with the green value as 0.


 


8.

Use a for loop to turn the 3x3 pixel square at the top right corner of x.png yellow.


 


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 8: for-loop-ex1 for-loop-ex2 for-loop-ex3 for-loop-ex4 for-loop-ex4 for-loop-ex6 for-loop-ex7 for-loop-ex8

      (code appears here)