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...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

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