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…? >>> file = pickAFile()

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.

## 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
Ask a homework question - tutors are online