I didn't use any slides today. Instead, we had a very interactive session where we looked at a variety of issues that arise when we switch from processing pictures with a single loop (normally done when you modify a picture as a whole) to processing pictures with a pair of nested loops (normally done when you are focusing only on part of the picture).
These issues included:
def mysteryMethod(picture):
for x in range(1,getWidth(picture)):
for y in range(1,getHeight(picture)):
pixel = getPixel(picture,x,y)
redPart = getRed(pixel)
greenPart = getGreen(pixel)
bluePart = getBlue(pixel)
val = (redPart + greenPart + bluePart)/3
setColor(pixel,makeColor(val,val,val))
The largest of these issues is that range(a,b) returns the list of numbers starting at a and counting by 1s until it reaches b-1. For example: range(1,5) returns the list of numbers [1,2,3,4] but NOT 5. Thus, while we are tempted to say something like range(1,getWidth(picture)) to count the pixels across a picture this actually leaves the last column untouched.
We demonstrated this by looking carefully at our makeGrayscale() method above to see that the last row and last columns remained untouched (OOPS!)
Finally, we spent a few minutes talking about what is involved with mirroring part of a picture onto the other part of a picture and how we would do this (independent of code).