[Part I. GIMP基礎功]

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



27.8 迷彩圖,修改過程中,須注意的 Python 語法特點

rand 亂數的生成
  • 由於 rand 函數用法的差異,為求簡潔,Python 之中,直接引用 Scheme rand 函數所產生的數值。
Scheme code
(plug-in-solid-noise RUN-NONINTERACTIVE theImage thickLayer 1 0 (rand 65536) 1 inGrain inGrain)
(plug-in-solid-noise RUN-NONINTERACTIVE theImage thinLayer 1 0 (rand 65536) 1 inGrain inGrain)

Python code
rand_num1 = -17265
rand_num2 = 22498
pdb.plug_in_solid_noise(theImage, thickLayer, 1, 0, rand_num1, 1, inGrain, inGrain)
pdb.plug_in_solid_noise(theImage, thinLayer, 1, 0, rand_num2, 1, inGrain, inGrain)


四則運算
Scheme code
(set! theBlur (- 16 inGrain))

Python code
theBlur = (16 - inGrain)


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

(if (= inSmooth TRUE)
(script-fu-tile-blur theImage thickLayer theBlur TRUE TRUE FALSE)
)

Python code 要注意縮排

if (inSmooth):
  pdb.script_fu_tile_blur(theImage, thickLayer, theBlur, TRUE, TRUE, FALSE)


RGB 顏色的指定
Scheme code

(gimp-by-color-select thinLayer '(0 0 0) 127 CHANNEL-OP-REPLACE  TRUE FALSE 0 FALSE)

Python code 拆成兩行

color_black = (0, 0, 0)
pdb.gimp_by_color_select(thinLayer, color_black, 127, CHANNEL_OP_REPLACE, TRUE, FALSE, 0, FALSE)