Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. Next , it will loop through every 4th pixel in every 4th row and do the following. It will compute the total of the red, green and blue levels of the pixel, divide that by 9, then add the result to 24. That number will be the note number played by playNote. That means that the darker the pixel, the lower the note; the lighter the pixel, the higher the note. It will play that note at full volume (127) for a tenth of a second (100 milliseconds). Every time it moves to a new row, it prints out the row number (y value) on the console. Your main function will ask the user to select a file with a picture. It will print the number of notes to be played (which is the number of pixels in the picture divided by 16; why?). It will then call the listenToPicture function.
Here's what I have so far, and I'm not sure how to set up looping through every 4th pixels in every 4th row. Any help will be greatly appreciate.
def main():
pic= makePicture( pickAFile())
printNow (getPixels(pic)/16)
listenToPicture(pic)
def listenToPicture(pic):
show(pic)
w=getWidth(pic)
h=getHeight(pic)
for px in getPixels(pic):
r= getRed(px)
g= getGreen(px)
b= getBlue(px)
tot= (r+g+b)/9
playNote= tot + 24