{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ecs10-12-1

# ecs10-12-1 - Final ECS 10 11/24 This This room Mon Dec 8...

This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 12/2/2008 Final ECS 10 11/24 This This room, Mon Dec 8, 8-10 AM 8Two Two programs. Will cover the whole course. Bring Bring a (Blue) Scantron 2000. Bring Bring book, notes. Recommended: print outs of homework programs, programs we did in class. Assignment Assignment Due Due Dec. 3. Try to go to lab hours today or Tues and get it done. Problems Problems installing PIL? Some tips, link on on assignment Web page. If all else fails, work in the lab or 73 Hutchinson. Pixelating Pixelating an Image A 10x10 block of pixels is 100 pixels. 10x10 Choose Choose the color of one pixel to fill the whole 10x10 block. I don’t care which one you choose. I chose one one in the middle of the block. Block Block of Pixels Block of Pixels 1 12/2/2008 Pixel Locations in a Block Pixel Pixel (0,0) is the upper left. Pixel Pixel (9,9) is the lower right of the first block we want to color. Second block upper left is (10,0), lower right (10 is is (19,9) Identifying a Block Identify Identify a block by the pixel location of its upper left corner. Let’s Let’s call this (LeftX, UpperY) (LeftX, UpperY) (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) … … … First Block LeftX = 0, UpperY = 0 Second Block LeftX = 10, UpperY = 0 Picking a color getpixel(LeftX, UpperY) getpixel(LeftX, UpperY) will get the color of the pixel in the upper left of the block. How How would you get a pixel in the middle? (Note: this is nice, but not required. It is fine (Note: but It to to use the color of the upper-left pixel). upper- Filling Filling in the Block Write Write a function that takes the upper-left upperpixel of the block, and the color, as inputs, and fills in all the pixels in the block with that color color. No No return statement! This function just colors the image, it does not compute a value to return. Need Need a double for loop to generate the locations of all the pixels in the block. 2 12/2/2008 First few lines… def colorBlock(location, color): # double for loop to make x,y im.putpixel((x,y), color) # No return statement! Notice im, Notice im, the image, is being used as a global variable. Another Another way to do it would be to pass image as an argument. Testing Testing this function Have Have your program fill in just the first block. Once Once this works, you’ll need a loop to generate the upper-left corner pixel of every upperblock. block Getting Getting All Upper-left UpperPixels You’ll You’ll need another double for loop. Here Here is a similar problem: counting by tens. Let’s Let’s write a single for loop that counts from 0 to 100 by tens. 100 n = 100 k = 10 Count Count to n by k’s for count in range(n/k): print count*k So your program? First First step: generate the upper-left pixels of all upperthe blocks in the first column. You’ll need a counting loop, like we just did. How to test? Second Second step: generate all the columns. Test? Test? Data Data Types We We have seen several kinds of data: int, int, float, string, Boolean, file, and now image There There was no image type until we imported the Image module. h Modules Modules can extend the language by creating new data types as well as new functions. The The new data types are more complicated things built out of existing data types. Eg, Eg, Image is a file with lots of fancy methods. 3 12/2/2008 Objects New New data types are called objects. objects Lots Lots of the modules you will want to use will define new objects. Next time: a quick primer on objects. This This is the chapter in the book we are skipping. 4 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online