[Note: this webpage last modified Friday, 04-Feb-2011 19:44:51 EST]
Make sure everyone's attendance scores are right - if they were here but do not have an attendance score, let me know.
Homework was due last night, did anyone have any problems?
Say some things about the last quiz and the homework.
Today: putting code into a file to create a function in Python, and how to deal with that in JES, JES commands to access/change pixels in a picture and save the picture
Example: computing the average of 4 numbers, and putting that into a function. Things we learn/need to know to be able to do this: (i) defining a function in the "program area" using the def keyword and : at the end of the first line, (ii) put the parameters/inputs to the function in paretheses, (iii) each "line code" that is part of the function is indented the same amount (normally two spaces), (iv) use the return keyword to return a value (set what the output of the function is).
Need to "Load Program" to have access to that function in the command area. Then call it just like any other function.
Can use print to do some printing, separate things you want printed by commas.
Example: remainders function to compute remainders mod 2, 3, and 5.
Using JES to get and change the colors of pixels. Lots of different functions you can use, for today we will use pixel = getPixel(pic, x, y) to get a a pixel in the x-th row and y-th column, setRed(pixel, number) to set the red value of the pixel to number (a value between 0 and 255), setBlue and setGreen to set the blue and green values, and writePictureTo to save the changes. Can also use getRed, getGreen, getBlue to do get the color values.
Warning about using JES with pictures - use it only with Jpeg pictures. It was acting strange when I used it on a Gif picture.
Things to look at for when using functions: forgetting the : in the first line, forgetting the def in the first line, forgetting to do indentation, make sure to use the same spelling/capitalization defining the function and using it in the command window, remember to do "Load Program", need to have same number and type of arguments when calling the function as there are parameters in the definition of the function.
You can come up with more...
For next time - introducing for loops, that lets us have access to all of the pixels in a picture easily, doing things like grayscale, turning the picture red or blue, woo hoo!
And make sure to take the quiz, and type things into JES to try them out!