[Part I. GIMP基礎功]

[Part II. 一種效果的誕生]
[Part III. Script-Fu的秘密]



24.8 波浪圖,修改過程中,須注意的 Python 語法特點

max 函數,取最大值
  • 情況不同於 rand 函數,很幸運,max 函數,Scheme 與 Python ,用法類似。
Scheme code
(define amplitude (max 0 amplitude))
(define wavelength (max 0 wavelength))
(define num-frames (max 1 num-frames))

Python code
amplitude = max(0, amplitude)
wavelength = max(0, wavelength)
num_frames = max(1, num_frames)


數字轉為字串,以及字串的串接
Scheme code
(define layer-name (string-append "Frame "
(number->string (- (+ num-frames 2) remaining-frames) 10) " (replace)"))

Python code
layer_name = "Frame " +  str(num_frames + 2 - remaining_frames) + " (replace)"


加減乘除四則運算
Scheme code
(define phaseshift (/ 360 num-frames))

Python code
phaseshift = 360 / num_frames

Scheme code
(set! remaining-frames (- remaining-frames 1))
(set! phase (- phase phaseshift))

Python code
remaining_frames = remaining_frames - 1
phase = phase - phaseshift


while 條件控制的敘述
Scheme code 要注意括號對齊

(while (> remaining-frames 1)
(define waves-layer (car (...)))
......
(set! phase (- phase phaseshift))
)

Python code 要注意縮排

while remaining_frames > 1:
  waves_layer = pdb.gimp_layer_copy(...)
  ......
  phase = phase - phaseshift


RGB 顏色的指定
Scheme code
(define text-color "black")
(define bg-color "white")

Python code
text_color = (0, 0, 0)
bg_color = (255, 255, 255)