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 makes the white pixels in the right half of the image below turn black. The left half of the image should stay the same.

Although perfect white is (255, 255, 255), the pixels in the image are not all perfectly white. Write your code to turn any pixel that has red, green, and blue values of above 230 to black (0, 0, 0).

Hint: Start by trying to make all the white pixels in the image turn black. then add a condition to check the x value of the pixel to see if it is in the right half of the image (more than half the image’s width).

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.

Hint: Start by writing a function that returns True always. That will let you run the program but will change every pixel. Then add a condition to say True or False based on the r, g, b values passed in.

You have attempted of activities on this page