此代码运行没有错误并返回一个空白图像,打印有意义的颜色和坐标的显示数字,但由于某种原因,似乎没有写入任何内容。希望有人会看到我看不到的东西:
import math
def fisheye():
file = pickAFile()
pic = makePicture(file)
h = getHeight(pic)
w = getWidth(pic)
maxradius = sqrt(w**2 + h**2)/2
fisheye = makeEmptyPicture(int(w+maxradius), int(h+maxradius),white)
for x in range(0,w):
for y in range(0,h):
nyS = ( (2*x)/h ) - 1
nxS = ( (2*y)/w ) - 1
r = sqrt( nxS**2 + nyS**2 )
if( r >= 0.0 and r <= 1.0 ):
nr = (r + (1.0-r)) / 2.0
if( nr <= 1.0 ):
t = math.atan2(nyS,nxS)
nx = nr*cos(t)
ny = nr*sin(t)
x2 = (((nx+1)*w)/2.0)
y2 = (((ny+1)*h)/2.0)
color = getColor(getPixel(pic, x, y))
print max(color)
setColor( getPixel(pic, int(x2),int(y2)) , color)
explore(fisheye)