07LoopsForPictures2009

07LoopsForPictures2009 - CS1315: Introduction to Media...

Info iconThis 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
Background image of page 1

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

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

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

View Full DocumentRight 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)
Background 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)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Let’s use something with known red to manipulate: Santa Claus
Background image of page 6
What if you decrease Santa’s red again and again and again…? >>> file = pickAFile()
Background image of page 7

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

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

This note was uploaded on 01/26/2012 for the course CS 1315 taught by Professor Sweat during the Fall '08 term at Georgia Tech.

Page1 / 24

07LoopsForPictures2009 - CS1315: Introduction to Media...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online