6.6. Using an Image Library

Similarly, in the image processing example, we used from image import *. That made the functions getPixels() and getRed() accessible. We could also define a new function that returns a new color, or a new procedure that changes the image.

The for p in pixels on line 9 let’s us loop through all of the pixels in the image and change the red value for each pixel. We’ll talk more about looping (repeating steps) in the next chapter.

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.

This ability to name functions and procedures, and sets of functions and procedures, and absolutely anything and any set of things in a computer is very powerful. It allows us to create abstractions that make the computer easier to program and use. More on that in a future chapter.

Note

Discuss topics in this section with classmates.

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