[Part I. GIMP基礎功]

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



26.5 程式land.scm分三部份

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

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

程式land.scm分三部份:
  • 1~32行:註解,功能說明與版權聲明。
  • 33~70行:定義函式。
  • 71~91行:註冊函式。
請注意,有幾行程式(57、61、73)有註解符號,沒有作用。
第1到第32行:註解說明1: ; GIMP - The GNU Image Manipulation Program
2: ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
3: ;
4: ; Land --- create a pattern that resembles a Topographic map
5: ; Copyright (C) 1997 Adrian Karstan Likins
6: ; aklikins@eos.ncsu.edu
7: ;
8: ;
9: ; This script works on the current gradient you have loaded.
10: ; Some suggested gradients:
11: ; Land (produces a earthlike map)
12: ; Brushed_aluminum (looks like the moon)
13: ;
14: ;
15: ; Thanks to Quartic for helping me debug this thing.
16: ;
17: ; This program is free software; you can redistribute it and/or modify
18: ; it under the terms of the GNU General Public License as published by
19: ; the Free Software Foundation; either version 2 of the License, or
20: ; (at your option) any later version.
21: ;
22: ; This program is distributed in the hope that it will be useful,
23: ; but WITHOUT ANY WARRANTY; without even the implied warranty of
24: ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25: ; GNU General Public License for more details.
26: ;
27: ; You should have received a copy of the GNU General Public License
28: ; along with this program; if not, write to the Free Software
29: ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30:
31:
32:

第33到第70行:定義函式
33: (define (script-fu-land width height seed detail landheight seadepth xscale yscale gradient)
34: (let* (
35: (img (car (gimp-image-new width height RGB)))
36: (layer-one (car (gimp-layer-new img width height
37: RGB-IMAGE "Bottom" 100 NORMAL-MODE)))
38: (layer-two 0)
39: )
40: (gimp-context-set-gradient gradient)
41: (gimp-image-undo-disable img)
42: (gimp-image-add-layer img layer-one 0)
43:
44: (plug-in-solid-noise RUN-NONINTERACTIVE img layer-one TRUE FALSE seed detail xscale yscale)
45: (plug-in-c-astretch RUN-NONINTERACTIVE img layer-one)
46: (set! layer-two (car (gimp-layer-copy layer-one TRUE)))
47: (gimp-image-add-layer img layer-two -1)
48: (gimp-image-set-active-layer img layer-two)
49:
50: (plug-in-gradmap RUN-NONINTERACTIVE img layer-two)
51:
52:
53:
54: (gimp-by-color-select layer-one '(190 190 190) 55 CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
55: (plug-in-bump-map RUN-NONINTERACTIVE img layer-two layer-one 135.0 35 landheight 0 0 0 0 TRUE FALSE 0)
56:
57: ;(plug-in-c-astretch RUN-NONINTERACTIVE img layer-two)
58: (gimp-selection-invert img)
59: (plug-in-bump-map RUN-NONINTERACTIVE img layer-two layer-one 135.0 35 seadepth 0 0 0 0 TRUE FALSE 0)
60:
61: ;(plug-in-c-astretch RUN-NONINTERACTIVE img layer-two)
62:
63: ; uncomment the next line if you want to keep a selection of the "land"
64: (gimp-selection-none img)
65:
66: (gimp-display-new img)
67: (gimp-image-undo-enable img)
68: )
69: )
70:

第71到第91行:註冊函式
71: (script-fu-register "script-fu-land"
72: _"_Land..."
73: _"Create an image filled with a topographic map pattern"
74: "Adrian Likins <aklikins@eos.ncsu.edu>"
75: "Adrian Likins"
76: "1997"
77: ""
78: SF-ADJUSTMENT _"Image width" '(256 10 1000 1 10 0 1)
79: SF-ADJUSTMENT _"Image height" '(256 10 1000 1 10 0 1)
80: SF-ADJUSTMENT _"Random seed" '(32 0 15000000 1 10 0 1)
81: SF-ADJUSTMENT _"Detail level" '(4 1 15 1 5 0 0)
82: SF-ADJUSTMENT _"Land height" '(60 1 65 1 10 0 1)
83: SF-ADJUSTMENT _"Sea depth" '(4 1 65 1 10 0 1)
84: SF-ADJUSTMENT _"Scale X" '(4 0.1 16 1 5 0.1 0)
85: SF-ADJUSTMENT _"Scale Y" '(4 0.1 16 1 5 0.1 0)
86: SF-GRADIENT _"Gradient" "Land 1"
87: )
88:
89: (script-fu-menu-register "script-fu-land"
90: "<Image>/File/Create/Patterns")
91: