[Part I. GIMP基礎功]

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

24.7 波浪圖,修改成可「單行」執行的 Python-Fu

修改後的程式碼,與測試的結果圖
  • 啟動 GIMP Python Console
  • 將下面的程式碼,全部選取、複製、再貼到 Python Console 提示符號 >>> 之後,按下 Enter 。
  • 過一會,就會看到結果圖。
gradient = "Land 1"
pdb.gimp_context_set_gradient(gradient)
pdb.script_fu_flatland(256, 256, 80, 3.0, 4.0, 4.0)
img_array = gimp.image_list()
img = img_array[0] # 假設目前只有 flat land 這個影像視窗
pdb.gimp_image_flatten(img)
drawable = pdb.gimp_image_active_drawable(img)

amplitude = 10
wavelength = 10
num_frames = 6
invert = FALSE
amplitude = max(0, amplitude)
wavelength = max(0, wavelength)
num_frames = max(1, num_frames)
remaining_frames = num_frames
phase = 0
phaseshift = 360 / num_frames
image = pdb.gimp_image_duplicate(img)
source_layer = pdb.gimp_image_get_active_layer(image)

pdb.gimp_image_undo_disable(image)

if invert:
  phaseshift = - phaseshift

while remaining_frames > 1:
  waves_layer = pdb.gimp_layer_copy(source_layer, TRUE)
  layer_name = "Frame " +  str(num_frames + 2 - remaining_frames) + " (replace)"
  pdb.gimp_layer_set_lock_alpha(waves_layer, FALSE)
  pdb.gimp_image_add_layer(image, waves_layer, -1)
  pdb.gimp_drawable_set_name(waves_layer, layer_name)
  pdb.plug_in_waves(image, waves_layer, amplitude, phase, wavelength, 0, FALSE)
  remaining_frames = remaining_frames - 1
  phase = phase - phaseshift


pdb.gimp_drawable_set_name(source_layer, "Frame 1")
pdb.plug_in_waves(image, source_layer, amplitude, phase, wavelength, 0, FALSE)

pdb.gimp_image_undo_enable(image)
pdb.gimp_display_new(image)