[Part I. GIMP基礎功]

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



27.6 迷彩圖,修改成可「單行」執行的 Script-Fu


(define inSize 256)
(define inGrain 7)
(define inColor1 '(33 100 58))
(define inColor2 '(170 170 60))
(define inColor3 '(150 115 100))
(define inSmooth FALSE)
(define inFlatten TRUE)

(define theWidth inSize)
(define theHeight inSize)
(define theImage (car (gimp-image-new theWidth theHeight RGB)))
(define baseLayer (car (gimp-layer-new theImage theWidth theHeight RGBA-IMAGE "Background" 100 NORMAL-MODE)))
(define thickLayer 0)
(define thinLayer 0)
(define theBlur 0)

;可以把顯示影像物件 theImage 提前到這裡
(gimp-display-new theImage)

(gimp-context-push)

(gimp-image-add-layer theImage baseLayer 0)

(set! thickLayer (car (gimp-layer-new theImage theWidth theHeight RGBA-IMAGE "Camo Thick Layer" 100 NORMAL-MODE)))
(gimp-image-add-layer theImage thickLayer 0)

(set! thinLayer (car (gimp-layer-new theImage theWidth theHeight RGBA-IMAGE "Camo Thin Layer" 100 NORMAL-MODE)))
(gimp-image-add-layer theImage thinLayer 0)

(gimp-selection-all theImage)
(gimp-context-set-background inColor1)
(gimp-drawable-fill baseLayer BACKGROUND-FILL)

(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)
(gimp-threshold thickLayer 127 255)
(gimp-threshold thinLayer 145 255)

(set! theBlur (- 16 inGrain))

(gimp-context-set-background inColor2)
(gimp-by-color-select thickLayer
        '(0 0 0) 127 CHANNEL-OP-REPLACE TRUE FALSE 0 FALSE)
(gimp-edit-clear thickLayer)
(gimp-selection-invert theImage)
(gimp-edit-fill thickLayer BACKGROUND-FILL)
(gimp-selection-none theImage)
(if (= inSmooth TRUE)
(script-fu-tile-blur theImage thickLayer theBlur TRUE TRUE FALSE)
)

(gimp-context-set-background inColor3)
(gimp-by-color-select thinLayer '(0 0 0) 127 CHANNEL-OP-REPLACE  TRUE FALSE 0 FALSE)
(gimp-edit-clear thinLayer)
(gimp-selection-invert theImage)
(gimp-edit-fill thinLayer BACKGROUND-FILL)
(gimp-selection-none theImage)

(if (= inSmooth TRUE)
(script-fu-tile-blur theImage thinLayer (/ theBlur 2) TRUE TRUE FALSE)
)

(if (= inFlatten TRUE)
(gimp-image-flatten theImage)
)
;已經把顯示影像物件 theImage 往前移
;(gimp-display-new theImage)
(gimp-context-pop)