07LoopsForPictures2009

07LoopsForPictures2009 - CS1315 Introduction to Media...

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

View Full Document Right Arrow Icon
CS1315: Introduction to Media Computation Using Loops for Pictures
Image of page 1

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

View Full Document Right Arrow Icon
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)
Image of page 2
Once we make it work for one picture, it will work for any picture. Why? Or how is that possible?
Image of page 3

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

View Full Document Right Arrow Icon
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)
Image of page 4
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)
Image of page 5

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

View Full Document Right Arrow Icon
Let’s use something with known red to manipulate: Santa Claus
Image of page 6
What if you decrease Santa’s red again and again and again…?
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern