[Note: this webpage last modified Friday, 04-Feb-2011 19:44:51 EST]
Note that the notes on this webpage are for what I expect we might cover for both Monday and Wednesday.
Did you take your online quiz for last time's lecture?
Today's attendance quiz.
Will talk about turning in the homework later today.
Let's review first. ADVICE - create two sheets, one with "what we know so far" and one with "mistakes to avoid".
What we know so far, Python stuff: integer and floating point arithmetic (floating point uses a decimal point, integer does not, can do % with integers, order of operations is first determined by parentheses then *, /, and %, then +, and -), printing with print, strings (sequences of characters/letters, e.g. "hello world"), variable (name for a spot in memory that you can put into with something like >>> x = 5, and you can get the value out with something like >>> print x).
What we know so far, JES image stuff: filename = pickAFile(), pic = makePicture(filename), show(pic).
What we know so far - add your own to my list! And there are more in the book.
Mistakes to avoid: Python is case sensitive for both variable names and function names (so PickAFile won't work because it should be pickAFile, and x is different than X), use the right spellings for function and variable names, don't put a space in between a function and the parenthesis after it (so pickAFile () is wrong, but pickAFile() is right), for assigning to a variable the variable goes on the left hand side of the equal (so x = 3 is right but 3 = x is wrong).
Mistakes to avoid - add your own to my list! And there are more in the book.
We also talked about variables being stored in memory last time. Today we talk about how data is stored on the computer - numbers, text, and pictures. Best of all, we get to do something with the pictures.
Actually, we will do that both today and next time.
First, let's take some time for questions. We can talk about the online quiz from last lecture or the homework if you want?
Computer memory and hard drive just has 0's and 1's, but we can interpret these 0's and 1's in different ways.
Can interpret them as a number if we think of the 0's and 1's as the binary representation of a number (e.g., 1100 in binary means 1*23 + 1*22 + 0*21 + 0*20 just like 1954 in decimal means 1*103 + 9*102 + 5*101 + 4*100.
Can interpret numbers as text by having a code for which numbers stand for which letters. Can look at this code by typing ord('a'), ord('b'), etc. in Python.
Once the computer knows how to interpret the bits as numbers, text, etc. then we can use that and don't need to worry about it. It helps us to know how it is actually done just like it helps someone designing a car to know what material each part is made out of, or helps a chef to know what the ingredients are made of (what properties does flour have, baking powder, etc.). The car designer does not have to make the parts, and the chef does not need to make the ingredients, but they need to know about them. We as Python programmers don't need to tell the computer how to interpret bits as numbers and text, but sometimes we need to know how the computer does this to write our "recipes"/programs.
How about interpreting the 0's and 1's as a picture (drum roll please...)?
Look at the screen close, will see a bunch of dots. That is what a picture is to a computer - just a collection of dots and what colors those dots should be. Our eyes have three different types of color receptors (red, green, and blue roughly), so the computer just needs to know how bright each of those colors should be. The image on the screen, say of a flower, does not capture all the information that is in the real flower (what does it taste like, for example), but the red/green/blue values are enough to make the picture on the screen look just like the real flower to our eyes/brains. If the dots are small enough, we can't tell the difference when we are looking from far enough away.
So this is what an image is to the computer - just a collection of dots and what the red, green, and blue values are for those dots. We can specify "how much red" or "how much green" by giving a number for how bright that color should be in the dot. In JES, we use 0 to mean "none" and 255 to mean "all". If we list out all of those numbers (how much red, green, and blue) for each pixel, then that is an image file.
Actually, what we have described is one type of image format - a bitmap. There are other formats - Jpeg, Gif, and others. JES is really nice because it will convert images in the other formats to a bitmap so that we can work with the image just as if it were stored in the bitmap format we have described. Yeh to JES!
So now how do we access the pixels of an image in JES?
You can use the MediaTools/Picture Tool on images you have already loaded with makePicture.
pixel = getPixel(pic, r, c) gives you a pixel (containing red, green, and blue values) for the pixel in the picture pic that is in the "r-th row and c-th column", so the upper lefthand corner you would get by getPixel(pic, 0, 0) and the bottom lefthand corner of a 150x250 picture you would get by getPixel(pic, 150-1, 250-1). 150-1 and 250-1 because Python (and just about all programming languages) start counting at 0.
Or you can use pixels = getPixels(pic) to get all of the pixels into the variable called pixels in a single "one-dimensional array" - the pixels are listed one after the other with the first row first, then the second row, etc. So you would use pixel = pixels[0] to get the upper lefthand corner pixel and pixel = pixels[(150-1)*(250-1)] to get the bottom righthand corner of a 150x250 picture.
You can get the red/green/blue values with the functions getRed, getGreen, and getBlue. You can set the values with the functions setRed, setGreen, and setBlue.
Other JES picture functions: getWidth and getHeight get the width and height of a picture that was loaded by makePicture, getX and getY get the row and column coordinates of a pixel, getColor gets the color values of a pixel, makeColor creates a new color with given red/green/blue, setColor sets the color of a pixel, pickAColor lets you pick a color with a GUI, writePictureTo saves a picture to the hard drive
Losing track of the various JES functions and how to use them - look them up in the JES help files!
And we did not even talk about functions in files yet, did we? So we'll talk about those as well. Can save a python program into a file, syntax to make it a function, load the program, then can use it without having to type it in again, woo hoo! Make sure to call the file "something.py" since that reminds you and the computer that it is a "Python file". And now you will be freed from the bondage of having to retype things in the command window, and you are officially entering the rans of CS where the motto is "be lazy" - never do something twice (i.e., write a program to do the first time, then reuse that program the next time you need to do it).
The assigned reading for the next lecture, what we will talk about next time - no assigned reading, we will continue working on what we started today.
Make sure to take your online quiz and turn in your homework.
How to turn in homework - either email me, or use blackboard. I'd prefer you try turning it in with blackboard, but if you are having problems then you can email me.