15.4. Multiple If’s with Images

We can use multiple if’s to reduce the number of colors in an image. Let’s say that if we have a little bit of each of red, green, and blue, we want to make each of them zero. If we have more, we set them to a mid-range value like 120. This is called posterizing because it reduces all the colors in a picture to a small number of colors – like the ones you might use if you were making a poster.

Rewrite the code for posterizing an image using if and else rather than multiple if’s. Test that it still works correctly.

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted of activities on this page