07LoopsForPictures2009

# 07LoopsForPictures2009 - CS1315 Introduction to Media...

This preview shows pages 1–8. Sign up to view the full content.

CS1315: Introduction to Media Computation Using Loops for Pictures

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Use a loop! Our first picture recipe def decreaseRed(picture): for pixel in getPixels (picture): value = getRed (pixel) setRed (pixel, value * 0.5) Used like this: >>> file = "/Users/monica/MediaSources/katie.jpg” >>> file = pickAFile() # or this way instead >>> picture = makePicture(file) >>> show(picture) >>> decreaseRed(picture) >>> repaint(picture)
Once we make it work for one picture, it will work for any picture. Why? Or how is that possible?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Think about what we just did Did we change the program at all? Did it work for all the different examples? What was the parameter variable picture each time, then? It was the value of whatever picture we provided when we ran it! def decreaseRed(picture): for pixel in getPixels (picture): value = getRed (pixel) setRed (pixel, value * 0.5)
Read it as a Recipe Recipe: To decrease the red Ingredients: One picture, pass it in, and that names it picture Step 1: Get all the pixels of picture . For each pixel pixel in the set of pixels… Step 2: Get the value of the red of that pixel pixel , and set it to 50% of its original value def decreaseRed(picture): for pixel in getPixels (picture): value = getRed (pixel) setRed (pixel, value * 0.5)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Let’s use something with known red to manipulate: Santa Claus
What if you decrease Santa’s red again and again and again…?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern