home *** CD-ROM | disk | FTP | other *** search
GIMP Script-Fu Script | 2000-12-27 | 7.2 KB | 211 lines |
- ; Fire animation script for The GIMP
- ; Version 0.5
- ; Copyright (c) 1998 / 1999
- ; Vidar Madsen <vidar@prosalg.no>
- ;
- ; --- Introduction ---
- ; Basically, it takes an image (with an alpha-channel), and sets
- ; it on fire. ;-) The user can specify how many frames should be
- ; used, and which gradient to use to color the flames. The defaults
- ; ought to work nicely most of the time, though.
- ;
- ; --- ChangeLog ---
- ; 6. Feb 1999: v0.5 - Fixed to work with GIMP 1.1.x. Thanks to Seth
- ; Burgess for pointing out the differences.
- ; 11. Aug 1998: v0.4 - Background layer is now working!
- ; 11. Aug 1998: - Fixed a tiny float bug
- ; 11. Aug 1998: v0.3 - Added angle and distance
- ; Thanks to Dan Everton <deverton@cit.gu.edu.au>
- ; 8. Aug 1998: - Added some code to add a custom background
- ; It is _NOT_ working at the moment, though!
- ; 5. Aug 1998: - Added some error-checking
- ; 5. Aug 1998: v0.2 - Made the script create a new image
- ; 4. Aug 1998: - Uses 'plug-in-spread' instead of randomize
- ; 4. Aug 1998: v0.1 - First public release!
- ;
- ; --- Disclaimer ---
- ; This program is free software; you can redistribute it and/or modify
- ; it under the terms of the GNU General Public License as published by
- ; the Free Software Foundation; either version 2 of the License, or
- ; (at your option) any later version.
- ;
- ; This program is distributed in the hope that it will be useful,
- ; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ; GNU General Public License for more details.
-
- (define (script-fu-fireanim-doit image drawable mask xoffs yoffs)
- (plug-in-spread 1 image drawable 1 1)
- (gimp-levels drawable 0 1 255 1.0 0 242)
- (gimp-selection-layer-alpha mask)
- (plug-in-noisify 1 image drawable FALSE 2.0 2.0 2.0 0.0)
- (gimp-selection-grow image 1)
- (plug-in-noisify 1 image drawable FALSE 0.3 0.3 0.3 0.0)
- (gimp-selection-grow image 2)
- (plug-in-gauss-rle TRUE image drawable 1.0 TRUE TRUE)
- (gimp-selection-none image)
- (gimp-channel-ops-offset drawable TRUE 0 xoffs yoffs)
- (gimp-selection-layer-alpha mask)
- (gimp-palette-set-background '(255 255 255))
- (gimp-edit-fill drawable)
- (gimp-selection-none image)
- )
-
- (define (script-fu-fireanim-prep image drawable orig gradient)
- (gimp-levels drawable 0 1 200 1.0 0 255)
- (gimp-gradients-set-active gradient)
- (plug-in-gradmap TRUE image drawable)
- (gimp-selection-all image)
- (gimp-selection-layer-alpha orig)
- (gimp-edit-copy orig)
- (gimp-floating-sel-anchor (car (gimp-edit-paste drawable FALSE)))
- (gimp-selection-none image)
- )
-
- (define (script-fu-fireanim-copylayer dstimage dstdrawable srcimage srcdrawable)
- (gimp-selection-all dstimage)
- (gimp-edit-clear dstdrawable)
- (gimp-selection-none dstimage)
- (gimp-selection-all srcimage)
- (gimp-edit-copy srcdrawable)
- (gimp-floating-sel-anchor (car (gimp-edit-paste dstdrawable FALSE)))
- )
-
-
- (define (script-fu-fireanim origimage origdrawable nframes oframes pframes
- gradient framerate angle distance usebackgnd backgnd)
-
- (if (< nframes oframes) (error "Number of frames < overlap-frames!"))
- (gimp-gradients-set-active gradient)
-
- (set! width (car (gimp-image-width origimage)))
- (set! height (car (gimp-image-height origimage)))
- (set! xoffs (* distance (sin (* angle (/ 3.141592654 180)))))
- (set! yoffs (- 0 (* distance (cos (* angle (/ 3.141592654 180))))))
- (set! image (car (gimp-channel-ops-duplicate origimage)))
- (set! drawable (car (gimp-image-get-active-layer image)))
-
- (gimp-image-disable-undo image)
-
- (set! numlayers (car (gimp-image-get-layers image)))
- (set! layerlist (cadr (gimp-image-get-layers image)))
- (set! count numlayers)
- (while (> count 0)
- (set! count (- count 1))
- (if (not (= (aref layerlist count) drawable))
- (gimp-image-remove-layer image (aref layerlist count))
- )
- )
-
- (if (= usebackgnd TRUE) (begin
- (set! bgimage (car (gimp-drawable-image backgnd)))
- (set! bgcopy (car (gimp-layer-new image width height RGBA_IMAGE "bgcopy" 100 NORMAL)))
- (gimp-image-add-layer image bgcopy 0)
- (script-fu-fireanim-copylayer image bgcopy bgimage backgnd)
- (gimp-layer-set-visible bgcopy FALSE)
- ))
-
- (set! frame (car (gimp-layer-new image width height RGBA_IMAGE "frame" 100 NORMAL)))
-
- (gimp-palette-set-background '(0 0 0))
- (gimp-selection-all image)
- (gimp-edit-fill frame)
-
- (gimp-palette-set-background '(255 255 255))
- (gimp-selection-layer-alpha drawable)
- (gimp-edit-fill frame)
-
- (gimp-image-add-layer image frame 0)
- (gimp-layer-set-visible frame FALSE)
-
- (gimp-layer-set-visible drawable FALSE)
-
- (set! count 0)
- (while (< count pframes)
- (script-fu-fireanim-doit image frame drawable xoffs yoffs)
- (set! count (+ count 1))
- )
-
- (set! larray (cons-array (+ nframes oframes 1)))
- (set! count 1)
- (while (<= count (+ nframes oframes))
- (script-fu-fireanim-doit image frame drawable xoffs yoffs)
- (set! newlayer (car (gimp-layer-copy frame TRUE)))
- (script-fu-fireanim-prep image newlayer drawable gradient)
- (if (= usebackgnd TRUE) (begin
- (set! bglayer (car (gimp-layer-copy bgcopy TRUE)))
- (gimp-image-add-layer image newlayer 0)
- (gimp-image-add-layer image bglayer 1)
- (gimp-layer-set-visible bglayer TRUE)
- (gimp-layer-set-visible newlayer TRUE)
- (set! newlayer (car (gimp-image-merge-visible-layers image 2)))
- ))
- (aset larray count newlayer)
- (gimp-layer-set-name newlayer
- (string-append "Frame " (number->string count) " (" (number->string framerate) "ms) (replace)"))
- (if (= usebackgnd FALSE) (begin
- (gimp-image-add-layer image newlayer 0)
- ))
- (gimp-layer-set-visible newlayer FALSE)
- (set! count (+ count 1))
- )
-
- (gimp-layer-set-visible drawable FALSE)
-
- (set! count 1)
- (while (<= count oframes)
- (set! opac (* 100 (- 1.0 (/ count (+ oframes 1)))))
- (set! framea (aref larray count))
- (set! frameb (aref larray (+ count nframes)))
- (gimp-layer-set-visible framea TRUE)
- (gimp-layer-set-visible frameb TRUE)
- (gimp-layer-set-opacity frameb opac)
- (set! framea (car (gimp-image-merge-visible-layers image 2)))
- (aset larray count framea)
- (gimp-layer-set-visible framea FALSE)
- (set! count (+ count 1))
- )
-
- (set! count 1)
- (while (<= count nframes)
- (set! framea (aref larray count))
- (gimp-layer-set-visible framea TRUE)
- (set! count (+ count 1))
- )
-
- (gimp-image-set-active-layer image framea)
- (gimp-image-remove-layer image drawable)
- (gimp-image-remove-layer image frame)
- (if (= usebackgnd TRUE)
- (gimp-image-remove-layer image bgcopy)
- )
-
- (gimp-display-new image)
-
- (gimp-selection-none image)
- (gimp-selection-none origimage)
- (gimp-image-enable-undo image)
- (gimp-displays-flush)
- )
-
- (script-fu-register
- "script-fu-fireanim"
- "<Image>/Script-Fu/Animators/FireAnim"
- "FireAnim"
- "Vidar Madsen <vidar@prosalg.no>"
- "Vidar Madsen"
- "6. Feb 1999"
- "RGBA"
- SF-IMAGE "Input Image" 0
- SF-DRAWABLE "Input Drawable" 0
- SF-VALUE "# of frames" "15"
- SF-VALUE "Overlap frames" "6"
- SF-VALUE "Prep frames" "15"
- SF-VALUE "Gradient" "\"Incandescent\""
- SF-VALUE "Framerate (ms)" "50"
- SF-VALUE "Angle (Degrees)" "0"
- SF-VALUE "Distance" "2"
- SF-TOGGLE "Use background?" FALSE
- SF-DRAWABLE "Background" 0
- )
-