タイトルで述べたように、このコード pice の変数ドットは、変数にまったく触れずに、いくつかの論理ステートメントの後で None 値になります。コードからわかるように、"print dot" には 2 つの異なるステートメントがあります。私は実験を行いましたが、最初の実験では、以前に割り当てられたように "[(1,1,1),(1,1,1)..." という出力が得られました。ただし、2番目の出力は「なし」です。なぜこれが起こるのか、それを修正する方法があるかどうか誰かが教えてくれますか?
def detectDots(surface):
dots = [(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1),(1,1,1)]
print dots
for y in range(0,480):
for x in range(0,640):
color = surface.get_at((x,y))
if color.r > 250 and color.g < 70 and color.b < 80:
inDots = True
notInDots = []
for i in range(0,8):
print dots
if math.sqrt((abs(x - dots[i][0])*abs(x - dots[i][0]))+(abs(y - dots[i][1])*abs(y - dots[i][1]))) < 20:
dots[i] = (((dots[i][0]*dots[i][2]+x)/(dots[i][2]+1)),((dots[i][1]*dots[i][2]+y)/(dots[i][2]+1)),(dots[i][2]+1))
else:
notInDots.append(i)
inDots = False
else:
dots = None