只是共享的增強版本,增加一些視覺效果(因爲視覺效果都不錯)。 ...
# 'divisor' : How much we expand the gradient (less is more)
# 'switch' : If True, start gradient from bottom to top
def fadeDownFromBlack(pic, divisor, switch=False):
w = getWidth(pic)
h = getHeight(pic)
startY = 0
endY = min(h-1, int(h/float(divisor)))
inc = 1
if (switch):
startY = h-1
endY = max(0, h-1 - int(h/float(divisor)))
inc = -1
color_ratio = float(divisor)/h
for y in range(startY, endY, inc):
for x in range(0,w):
px = getPixel(pic, x, y)
setRed(px, abs(startY - y)*(color_ratio)*getRed(px))
setGreen(px, abs(startY - y)*(color_ratio)*getGreen(px))
setBlue(px, abs(startY - y)*(color_ratio)*getBlue(px))
file = pickAFile()
picture = makePicture(file)
# The following commented line answers the question
#fadeDownFromBlack(picture, 2)
fadeDownFromBlack(picture, 0.7, True)
writePictureTo(picture, "/home/mad-king.png")
show(picture)
輸出(繪畫由科爾內留巴巴 - 瘋狂的國王):
............ ............. ......... ............
我假設你在使用PIL? (只是檢查。) – MatrixFrog 2010-02-10 23:16:23
我不這麼認爲,不。除非它帶有Jython 4.3。 – roger34 2010-02-11 00:08:07
從紙張:要通過適當的分數變暗你乘的紅色,綠色和藍色的水平像素。具體地,如果y是在畫面的上半部分,在第y行的所有像素具有其RGB級別乘以Y *(2.0 /小時),其中h是圖像的高度。圖片下半部分的像素不會改變。 我假設我不需要使用setBlue等呢?我會使用回報? – roger34 2010-02-11 00:13:53