Python 如何打印要播放的音符数?

Python 如何打印要播放的音符数?,python,Python,我怎样做我主要论点的第二行 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)

我怎样做我主要论点的第二行

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

在函数
listenToPicture()
中,有以下代码:

w= getWidth(pic)
h= getHeight(pic)
for i in range(0, w, 4):
    for j in range(0, h, 4):
        ....
奇怪的是,
i
j
在代码的其余部分没有使用,但似乎可以解释为什么音符数是像素数除以16


钥匙位于
范围(0,w,4)
范围(0,h,4)
。你知道他们是什么意思吗?这两个循环的性能是什么?(如果需要,在网格纸上画一张小图片,然后手动执行算法)

在函数
listenToPicture()
中,您有以下代码:

w= getWidth(pic)
h= getHeight(pic)
for i in range(0, w, 4):
    for j in range(0, h, 4):
        ....
奇怪的是,
i
j
在代码的其余部分没有使用,但似乎可以解释为什么音符数是像素数除以16


钥匙位于
范围(0,w,4)
范围(0,h,4)
。你知道他们是什么意思吗?这两个循环的性能是什么?(如果需要,在网格纸上画一张小图片,然后手动执行算法)

像素数=宽度乘以高度(假设两者都以像素为单位)。您似乎有一些函数可以为您提供宽度和高度,因此您可以计算像素数。或者你还想要别的东西吗?我想如果你把笔记的数量从
main()
移动到
listenToPicture(pic)
。像素数=宽度乘以高度(假设两者都是以像素为单位)会更容易。您似乎有一些函数可以为您提供宽度和高度,因此您可以计算像素数。或者你还想要别的东西吗?我想如果你把笔记的打印从
main()
移动到
listenToPicture(pic)
,你会发现打印起来更容易。