14.6. Chapter Exercises

The code below is supposed to change the white in the French flag to aqua (Aqua is made by mixing blue and green with no red). Arrange and indent the blocks to make a correct program. You will not use them all.

Write a program below to change all the greenish pixels in this image to the color: red 30, green 100, blue 150 (a slightly grayish blue).

Hint: The greenish pixels are not a pure green they have almost as much red as they do green. A sample color value might be: 111 red, 115 green, 65 blue. However, they are not all exactly the same color. You will need to figure out a recipe to select the right colors from the image.

Write a program below that inverts all the colors in the right half of the image. To invert a color, set its value to be 255 minus the old value - something like pixel.red = 255 - pixel.red. The image is 300x300, so any pixel at an x value of 150+ is on the right hand side.

Hint: start by inverting all of the pixels to pass the first test. Then add a condition to only apply the changes to the right half.

Write the function isYellow that accepts red, green, and blue values as its parameters and returns True if both the green and red values are at least 40 more than the red value. If the blue value is close to, or above, either the green or red, it should return False.

Once you write the function, it will be used to turn the goal keeper’s jersey from yellow to aqua by swapping the red and blue values.

You have attempted of activities on this page