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.

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted 1 of 3 activities on this page