[Part I. GIMP基礎功]

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

24.5 程式waves-anim.scm分三部份

若要徹底瞭解waves-anim.scm,可仿傚第22章的方式,單步執行,來分析每一行程式碼的作用。

若用PSPad開啟程式檔(或任何文字編輯器),看到的Script-Fu程式碼,變數會對得很整齊。HTML會把大量的空白省略,因此程式碼的排版變成了下面這樣子。我替Script-Fu程式碼加上行號乎,方便讀者閱讀。

程式waves-anim.scm分三部份:
  • 1~31行:註解,功能說明與版權聲明。
  • 32~94行::定義函式,在測試程式的過程中,可將它改為(define (script-fu-waves-anim2 … ))
  • 95~112行:註冊函式,可將它改為(script-fu-register " script-fu-waves-anim2 " … )

第1到第31行:註解說明1: ; GIMP - The GNU Image Manipulation Program
2: ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
3: ;
4: ; This program is free software; you can redistribute it and/or modify
5: ; it under the terms of the GNU General Public License as published by
6: ; the Free Software Foundation; either version 2 of the License, or
7: ; (at your option) any later version.
8: ;
9: ; This program is distributed in the hope that it will be useful,
10: ; but WITHOUT ANY WARRANTY; without even the implied warranty of
11: ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: ; GNU General Public License for more details.
13: ;
14: ; You should have received a copy of the GNU General Public License
15: ; along with this program; if not, write to the Free Software
16: ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17: ;
18: ;
19: ; waves-anim.scm version 1.01 1997/12/13
20: ;
21: ; CHANGE-LOG:
22: ; 1.00 - initial release
23: ; 1.01 - some code cleanup, no real changes
24: ;
25: ; Copyright (C) 1997 Sven Neumann <sven@gimp.org>
26: ;
27: ;
28: ; Makes a copy of your image and creates an animation of the active layer
29: ; as if a stone was thrown into the image. The animation may be saved with
30: ; the gif-plug-in.
31:

第32到第94行:定義函式32: (define (script-fu-waves-anim img
33: drawable
34: amplitude
35: wavelength
36: num-frames
37: invert)
38: (let* ((amplitude (max 0 amplitude))
39: (wavelength (max 0 wavelength))
40: (num-frames (max 1 num-frames))
41: (remaining-frames num-frames)
42: (phase 0)
43: (phaseshift (/ 360 num-frames))
44: (image (car (gimp-image-duplicate img)))
45: (source-layer (car (gimp-image-get-active-layer image))))
46:
47: (gimp-image-undo-disable image)
48:
49: (if (= invert TRUE)
50: (set! phaseshift (- 0 phaseshift)))
51:
52: (while (> remaining-frames 1)
53: (let* (
54: (waves-layer (car (gimp-layer-copy source-layer TRUE)))
55: (layer-name (string-append "Frame "
56: (number->string
57: (- (+ num-frames 2)
58: remaining-frames) 10
59: )
60: " (replace)"))
61: )
62: (gimp-layer-set-lock-alpha waves-layer FALSE)
63: (gimp-image-add-layer image waves-layer -1)
64: (gimp-drawable-set-name waves-layer layer-name)
65:
66: (plug-in-waves RUN-NONINTERACTIVE
67: image
68: waves-layer
69: amplitude
70: phase
71: wavelength
72: 0
73: FALSE)
74:
75: (set! remaining-frames (- remaining-frames 1))
76: (set! phase (- phase phaseshift))
77: )
78: )
79:
80: (gimp-drawable-set-name source-layer "Frame 1")
81: (plug-in-waves RUN-NONINTERACTIVE
82: image
83: source-layer
84: amplitude
85: phase
86: wavelength
87: 0
88: FALSE)
89:
90: (gimp-image-undo-enable image)
91: (gimp-display-new image)
92: )
93: )
94:

第95到第112行:註冊函式95: (script-fu-register "script-fu-waves-anim"
96: _"_Waves..."
97: _"Create a multi-layer image with an effect like a stone was thrown into the current image"
98: "Sven Neumann <sven@gimp.org>"
99: "Sven Neumann"
100: "1997/13/12"
101: "RGB* GRAY*"
102: SF-IMAGE "Image" 0
103: SF-DRAWABLE "Drawable" 0
104: SF-ADJUSTMENT _"Amplitude" '(10 1 101 1 10 1 0)
105: SF-ADJUSTMENT _"Wavelength" '(10 0.1 100 1 10 1 0)
106: SF-ADJUSTMENT _"Number of frames" '(6 1 512 1 10 0 1)
107: SF-TOGGLE _"Invert direction" FALSE
108: )
109:
110: (script-fu-menu-register "script-fu-waves-anim"
111: "<Image>/Filters/Animation/Animators")
112: