; =====================================================================
; Fiery Steel - yet another silly script from WWWWolf
; =====================================================================
; Copyright (C) 9.5.1998 Urpo Lankinen.
; Greatly enhanced on 19.5.1998.
;  Distributed under GPL. Permission granted to distribute this script
;  with *anything* that has *something* to do with The GIMP.
; =====================================================================
;
; E-mail: <wwwwolf@iki.fi> Homepage: <URL:http://www.iki.fi/wwwwolf/>
;
; RCS: $Id: fierysteel.scm,v 1.2 1998/05/19 14:38:36 urpo Exp urpo $
;
; This script was inspired by "Terminator 2: Judgement Day"
; opening scene.
;
; The result: letters of steel (well, aluminium...) in hellfire.
; "You know, it was not really easy for a mere layman to figure out
; the flame-generation script"... but with a dragon around, it was
; much easier.
;
; For coolest results, Use Scott font from CorelDRAW!...
; (But Crillee/FreeFonts produces pretty kewl results, too.)
;
; Hey, you can use GUMP (Mail plugin) to mail this image...
; ...a complete redefinition of "flame"!
;

(define (script-fu-fiery-steel
	 text font size grad perc txtbord fierytog sprd rndamt fulltog)
  (let* ((img (car (gimp-image-new 256 256 RGB)))
	 (bg-layer (car (gimp-text img -1 0 0 text 10 TRUE
				     size PIXELS "*" font "*" "r" "*" "*")))
	 (text-layer (car (gimp-text img -1 0 0 text 10 TRUE
				     size PIXELS "*" font "*" "r" "*" "*")))
	 (width (car (gimp-drawable-width text-layer)))
	 (height (car (gimp-drawable-height text-layer)))
	 (text2-layer (car (gimp-text img -1 0 0 text 10 TRUE
				     size PIXELS "*" font "*" "r" "*" "*")))
	 (brd-layer
	  (car (gimp-layer-new img width height
			       GRAYA_IMAGE "border" 100 OVERLAY)))

	 (old-fg (car (gimp-palette-get-foreground)))
	 (old-bg (car (gimp-palette-get-background))))

    (gimp-image-disable-undo img)
    (gimp-layer-set-name text-layer "Text")
    (gimp-layer-set-name text2-layer "Text2")
    (gimp-layer-set-name bg-layer "Bg")
    (gimp-image-resize img width height 0 0)

    ; ÄKSÖN =========================================================

    ; Background

    (gimp-image-set-active-layer img bg-layer)
    (gimp-selection-all img)
    (gimp-palette-set-foreground '(0 0 0))
    (gimp-bucket-fill img bg-layer FG-BUCKET-FILL NORMAL 100 255 FALSE 1 1)
    (gimp-palette-set-foreground old-fg)
    (gimp-selection-none img)

    ; Do the gradient
    (gimp-image-set-active-layer img text2-layer)
    (gimp-layer-set-preserve-trans text2-layer TRUE)     ; Preserve trans.
    (gimp-gradients-set-active grad)
    (gimp-blend img text2-layer
		CUSTOM NORMAL LINEAR 100 0 REPEAT-NONE 0 3 0.2
		(/ width 2) 0 (/ width 2) height)
    (gimp-layer-set-preserve-trans text2-layer FALSE)
    ; and hide the bg and this new one
    (gimp-layer-set-visible bg-layer FALSE)
    (gimp-layer-set-visible text-layer TRUE)
    (gimp-layer-set-visible text2-layer FALSE)

    ; Add white layer
    (set! tmp-layer
	  (car (gimp-layer-new img width height RGB_IMAGE "Temp" 100 NORMAL)))
    (gimp-image-add-layer img tmp-layer 3)
    (gimp-image-set-active-layer img tmp-layer)
    (gimp-selection-all img)
    (gimp-palette-set-foreground '(255 255 255))
    (gimp-bucket-fill img tmp-layer FG-BUCKET-FILL NORMAL 100 255 FALSE 1 1)
    (gimp-palette-set-foreground old-fg)
    (gimp-selection-none img)

    ; Merge, blur, bump
    (set! bump-layer
	  (car (gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)))
    (gimp-layer-set-visible bg-layer TRUE)
    (plug-in-gauss-iir 1 img bump-layer txtbord TRUE TRUE)
    (gimp-layer-set-visible bump-layer FALSE)
    (gimp-layer-set-visible text2-layer TRUE)

    ; Twiddle the brightness a little
    (gimp-brightness-contrast img text2-layer -20 -20)

    ; Bumpmapping depends on do we need the flames or not...
    (plug-in-bump-map 1 img text2-layer bump-layer
		      (if (eq? fierytog FALSE) 135.00 90.00)
		      (if (eq? fierytog FALSE) 45.00 30.0)
		      6 0 0 0 0 FALSE FALSE LINEAR)

    (gimp-image-remove-layer img bump-layer)

    ; And that was the easy part. ::sigh::

    (if (eq? fierytog TRUE)
	(let* ((sheight (* height perc))
	      (ycoord (- height sheight)))
					; Add a layer
	  (set! fire1-layer
		(car (gimp-layer-new img width height RGBA_IMAGE "Fire 1"
				     100 NORMAL)))
	  (gimp-image-add-layer img fire1-layer 0)
					; Clear it
	  (gimp-selection-all img)
	  (gimp-edit-clear img fire1-layer)
					; Make lower part red
	  (gimp-rect-select img 0 ycoord width sheight REPLACE FALSE 0)
	  (gimp-palette-set-foreground '(180 0 20))
	  (gimp-bucket-fill img fire1-layer FG-BUCKET-FILL NORMAL
			    100 255 FALSE 1 1)
	  (gimp-selection-none img)

	  ; Do nasty stuff to the lower fire layer
	  (plug-in-ripple 1 img fire1-layer
			  (/ width 8) (/ height 8) 1 0 1 FALSE FALSE)
	  (plug-in-whirl-pinch 1 img fire1-layer
			       45 0 0.7)

	  ; Copy the layer, make it yellow, shift down a bit
	  (set! fire2-layer
		(car (gimp-layer-copy fire1-layer TRUE)))
	  (gimp-image-add-layer img fire2-layer 0) ; top
	  (gimp-layer-set-name fire2-layer "Fire 2")

	  (gimp-image-set-active-layer img fire2-layer)
	  (gimp-layer-set-preserve-trans fire2-layer TRUE)
	  (gimp-palette-set-foreground '(228 170 4)) ; Yellow
	  (gimp-selection-all img)
	  (gimp-bucket-fill img fire2-layer FG-BUCKET-FILL NORMAL
			    100 255 FALSE 1 1)
	  (gimp-layer-set-preserve-trans fire2-layer FALSE)
	  (gimp-selection-none img)

	  (gimp-channel-ops-offset img fire2-layer FALSE 1 0 (/ height 8))

	  ; The third fire layer
	  (set! fire3-layer
		(car (gimp-layer-copy fire1-layer TRUE)))
	  (gimp-image-add-layer img fire3-layer 0) ; top
	  (gimp-layer-set-name fire3-layer "Fire 3")
	  (gimp-channel-ops-offset img fire3-layer FALSE 1 0
				   (* 2.6 (/ height 8)))

	  ; resize the said layer...
	  (gimp-image-set-active-layer img fire3-layer)
	  (gimp-selection-all img)
	  (gimp-scale img fire3-layer TRUE 0
		      (* height 0.6) width height)

	  ; spread, spindle, mutilate
	  (plug-in-spread 1 img fire1-layer 0 (* 3 sprd))
	  (plug-in-spread 1 img fire2-layer 0 (* 2 sprd))
	  (plug-in-spread 1 img fire3-layer 0 (* 1.5 sprd))

	  ; Merge the layers
	  (gimp-layer-set-visible text2-layer FALSE)
	  (gimp-layer-set-visible bg-layer FALSE)

	  (set! fire-layer
		(car (gimp-image-merge-visible-layers
		      img EXPAND-AS-NECESSARY)))
	  (gimp-layer-set-name fire-layer "Fire")

	  (gimp-layer-set-preserve-trans fire-layer TRUE)
	  (plug-in-gauss-rle 1 img fire-layer (* 2 sprd) TRUE TRUE)
	  (gimp-layer-set-preserve-trans fire-layer FALSE)	      

	  (gimp-layer-set-visible text2-layer TRUE)
	  (gimp-layer-set-visible bg-layer TRUE)

	  (plug-in-noisify 1 img fire-layer TRUE 0.2 0.2 0.2 0.2)
	  (plug-in-noisify 1 img fire-layer TRUE 0.2 0.2 0.2 0.2)

	  (plug-in-gauss-rle 1 img fire-layer (* 2 sprd) TRUE TRUE)

	  ; Then, Let's nastyize it.
	  (gimp-layer-set-preserve-trans fire-layer TRUE)
	  (plug-in-randomize 1 img fire-layer 2 80 rndamt)
	  (gimp-layer-set-preserve-trans fire-layer FALSE)	      
	  (plug-in-oilify 1 img fire-layer 3 0)

	  ; Finally, make the flames burrrrrn...
	  (gimp-layer-set-mode fire-layer ADDITION)

	  (if (eq? fulltog FALSE)
	      (begin
		(gimp-layer-set-visible bg-layer FALSE)
		(set! text2-layer
		      (car (gimp-image-merge-visible-layers
			    img EXPAND-AS-NECESSARY)))
		(gimp-layer-set-visible bg-layer TRUE)))
	  )) ; End of fiery stuff

    ; End of Action(tm) =============================================
    (gimp-palette-set-background old-bg)
    (gimp-palette-set-foreground old-fg)
    (gimp-image-enable-undo img)
    (gimp-display-new img)))

;
; Hajaa-ho!
;
(script-fu-register
 "script-fu-fiery-steel"
 "<Toolbox>/Xtns/Script-Fu/Logos/Fiery Steel"
 "An effect inspired by the \"Terminator 2: Judgement Day\"
  opening titles. Metallic letters in hellfire. $Revision: 1.2 $"
 "Urpo Lankinen <wwwwolf@iki.fi>"
 "Urpo Lankinen <wwwwolf@iki.fi>"
 "9 May 1998 (Enhanced greatly on 19 May)"
 ""
 SF-VALUE  "Text String"           "\"RGRNCA\""
 SF-VALUE  "Font"                  "\"crillee\""
 SF-VALUE  "Font Size"             "140"
 SF-VALUE  "Gradient"              "\"Brushed_Aluminium\""
 SF-VALUE  "Engulfment percentage" "0.50"
 SF-VALUE  "Text border"           "3.5"
 SF-TOGGLE "Fire effects"          TRUE
 SF-VALUE  "Spread coefficient"    "5"
 SF-VALUE  "# of fire randomizes"  "40"
 SF-TOGGLE "Fire over background"   FALSE
 )

; BTW, if you're wondering what "RGRNCA" means, surf to:
; <URL:http://www.iki.fi/wwwwolf/games/nethack/index.html>
