views:

53

answers:

1

How do I do the second line in my main argument?

def main():
    pic= makePicture( pickAFile())
    ### It will print the number of notes to be played(which is the number of pixels in the    pic divided by 16, why?)###
    listenToPicture(pic)


def listenToPicture(pic):
    show(pic)
    w= getWidth(pic)
    h= getHeight(pic)
    for i in range(0, w, 4):
        for j in range(0, h, 4):
            for px in getPixels(pic):        
                r= getRed(px)
                g= getGreen(px)
                b= getBlue(px)
                tot= (r+g+b)/9
                playNote= tot + 24
+1  A: 

in function listenToPicture(), you have this code:

w= getWidth(pic)
h= getHeight(pic)
for i in range(0, w, 4):
    for j in range(0, h, 4):
        ....

strangely, i and j are not used in the rest of the code, but seem to explain why the number of notes are the number of pixels divided by 16.

the key is in range(0, w, 4) and range(0,h,4). do you know what they mean ? what are the 2 loops performing ? (if you need, draw yourself a small picture on a grid paper, and execute your algorithm by hand)

Adrien Plisson