我如何在主要参数中进行第二行?
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
答案 0 :(得分:1)
在函数listenToPicture()
中,您有以下代码:
w= getWidth(pic)
h= getHeight(pic)
for i in range(0, w, 4):
for j in range(0, h, 4):
....
奇怪的是,i
和j
未在其余代码中使用,但似乎解释了为什么笔记数是像素数除以16。
密钥位于range(0, w, 4)
和range(0,h,4)
。你知道他们的意思吗? 2个循环的表现是什么? (如果需要,在网格纸上绘制一张小图片,并手动执行算法)