Lec16Images2

Lec16Images2 - # hint: you sometimes need to use extra...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1) nested loops 2) Draw things in a blank window 3) Make filters def colorRowBlack(row, image): for column in range(image.getWidth()): image.setPixel(column,row,Pixel(0,0,0)) def colorRowsBlack(start,end,image): for myRow in range(start,end): colorRowBlack(myRow,image) Let’s write this in a different way: def colorRowsBlack(start,end,image): for myRow in range(start,end): for column in range(image.getWidth()): image.setPixel(column,myRow,Pixel(0,0,0)) for x in [0,1,2,3,4]: for y in [1,2,3]: print(x,y) x = 0 y = 1 print(x,y) y = 2 print(x,y) y = 3 print(x,y) x = 1 y = 1 print(x,y) y = 2 print(x,y) y = 3 print(x,y) x = 0 for y in range(0): x = 1 for y in range(1): * x = 2 for y in range(2): ** Let’s practice going from a for loop to a while loop myList = [“hello”,”hi”,”yippee”] for item in myList: print(item) 1) initialization for the loop variable 2) the condition (how many times to iterate) 3) update the state
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # hint: you sometimes need to use extra variables myList = [hello,hi,yippee] # initialization item = myList[0] number = 0 while ( number < len(myList)): print(item) # change of state number = number + 1 item = myList[number] We want to turn all pixels into gray pixels of different shades. White: 255,255,255 Black: 0,0,0 What characteristic makes a pixel be gray? Gray pixels have all values the same. Given a color pixel with three different values, I need to choose what value to give all three that is the same. getRed(), getBlue(), getGreen() Lets take the average of the three values and make that my gray value. def makePixelGray(pixel): red = pixel.getRed() green = pixel.getGreen() blue = pixel.getBlue() gray = (red + green + blue) // 3 newPixel = cImage.Pixel(gray,gray,gray) return newPixel...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 8 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 2

Lec16Images2 - # hint: you sometimes need to use extra...

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

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