[英]Create Fisheye effect with JES with python, code results in blank image
該代碼運行無誤,並返回空白圖像,同時打印了顏色和坐標顯示編號,但由於某種原因似乎沒有編寫任何內容。 希望有人能看到我看不到的東西:
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)
問題似乎是您對setColor()
調用。 在此語句中,您還可以調用getPixel()
,它引用的是pic
而不是fisheye
。
請將此聲明更改為以下內容:
setColor( getPixel(fisheye, int(x2),int(y2)) , colour)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.