0

此代码运行没有错误并返回一个空白图像,打印有意义的颜色和坐标的显示数字,但由于某种原因,似乎没有写入任何内容。希望有人会看到我看不到的东西:

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)
4

1 回答 1

0

问题似乎是您对setColor(). 在此语句中,您还有一个调用getPixel()是引用pic而不是fisheye

请将此声明更改为以下内容:

setColor( getPixel(fisheye, int(x2),int(y2)) , colour)

于 2014-11-26T08:50:27.973 回答