18.10. Write Code Exercises

Note

Remember that it can take a bit of time to process all the pixels in a picture! Check for errors below the code if it is taking a long time, but if you don’t see any errors just wait.

  1. Fix 4 syntax errors in the code below so that it correctly sets the red in all pixels to 0.

    Fix 4 syntax errors in the code below so that it correctly sets the red in all pixels to 0.

  1. The code below makes the image have a green-blue tint. Change 1 thing in order to make it have a red tint instead.

    The code below makes the image have a green-blue tint. Change 1 thing in order to make it have a red tint instead.

  1. Fix the indention below to correctly set the red to the green, the green to the blue, and the blue to the red.

    Fix the indention below to correctly set the red to the green, the green to the blue, and the blue to the red.

  1. Fix the 5 errors in the code, so that the red pixels get the value of the green, the green get the value of blue, and the blue get the value of the red. (The cat should look purple and gray)

    Fix the 5 errors in the code, so that the red pixels get the value of the green, the green get the value of blue, and the blue get the value of the red. (The cat should look purple and gray)

  1. Fill in the missing code on lines 9, 12, and 18 below to set the red to half the original value in all pixels in the picture.

    Fill in the missing code on lines 9, 12, and 18 below to set the red to half the original value in all pixels in the picture.

  1. Complete the code in order to set the blue value to an eighth of the green value plus an eighth of the red value.

    Complete the code in order to set the blue value to an eighth of the green value plus an eighth of the red value.

  1. Fix the indention in the code below so that it correctly increases the red in each pixel in the picture by 1.5.

    Fix the indention in the code below so that it correctly increases the red in each pixel in the picture by 1.5.

  1. Fix the code (without adding anything new) to make the picture completely black.

    Fix the code (without adding anything) to make the picture completely black.

  1. Fix the code below to correctly set the green and blue values to 0.75 times their current values.

    Fix the code below to correctly set the green and blue values to 0.75 times their current values.

  1. The code below sets all the pixels to half their original values with one for loop. Change the code so it uses 2 for loops that utilize the range function (1 for loop should be nested in the other).

    The code below sets all the pixels to half their original values with one for loop. Change the code so it uses 2 for loops that utilize the range function (1 for loop should be nested in the other).

  1. Change the following code to set the red to 0 for all pixels in the left half of the picture.

    Change the following code to set the red to 0 for all pixels in the left half of the picture.

  1. The code below makes the whole image have a blue-green tint. Change the code so that it makes an only blue tint in the bottom left corner.

    The code below makes the whole image have a blue-green tint. Change the code so that it makes an only blue tint in the bottom left corner.

  1. Change the code below to set the red value in the pixels in the bottom half of the picture to 0.

    Change the code below to set the red value in the pixels in the bottom half of the picture to 0.

  1. The code below makes the whole image seem red. Change it, so that only every 5 pixels get changed, so that it will look like a red grid.

    The code below makes the whole image seem red. Change it, so that only every 5 pixels get changed, so that it will look like a red grid.

  1. Change the following code into a procedure to keep only the green values in all pixels in a picture.

    Change the following code into a procedure to keep only the green values in all pixels in a picture.

Loading a dynamic question ...
Selecting from: pictures_ac_16, pictures_ac_16_pp

Loading a dynamic question ...
Selecting from: pictures_ac_17, pictures_ac_17_pp

Loading a dynamic question ...
Selecting from: pictures_ac_18, pictures_ac_18_pp

Loading a dynamic question ...
Selecting from: pictures_ac_19, pictures_ac_19_pp

Loading a dynamic question ...
Selecting from: pictures_ac_20, pictures_ac_20_pp

  1. Write code to create a subclass of the Image class with three different image effect functions and use each effect on a different part of the image. For example, you could turn the image into grayscale, keep only the green values, swap the red and green values, negate the image, etc. This is one possible solution. For example, the image shown below has one image effect on the first third of the image (negate), one on the second third (clear blue), and one on the final third (reduce red). It is using the image gal2.jpg

    Create a subclass of the Image class with three different image effect functions and use each effect on a different part of the image. For example, you could turn the image into grayscale, keep only the green values, swap the red and green values, negate the image, etc. This is one possible solution. For example, the image shown below has one image effect on the first third of the image (negate), one on the second third (clear blue), and one on the final third (reduce red). It is using the image gal2.jpg

You have attempted of activities on this page