home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / fireanim-1_1.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  7.2 KB  |  211 lines

  1. ; Fire animation script for The GIMP
  2. ; Version 0.5
  3. ; Copyright (c) 1998 / 1999
  4. ; Vidar Madsen <vidar@prosalg.no>
  5. ;
  6. ; --- Introduction ---
  7. ; Basically, it takes an image (with an alpha-channel), and sets
  8. ; it on fire. ;-) The user can specify how many frames should be
  9. ; used, and which gradient to use to color the flames. The defaults
  10. ; ought to work nicely most of the time, though.
  11. ;
  12. ; --- ChangeLog ---
  13. ;  6. Feb 1999: v0.5 - Fixed to work with GIMP 1.1.x. Thanks to Seth
  14. ;                      Burgess for pointing out the differences.
  15. ; 11. Aug 1998: v0.4 - Background layer is now working!
  16. ; 11. Aug 1998:      - Fixed a tiny float bug
  17. ; 11. Aug 1998: v0.3 - Added angle and distance
  18. ;            Thanks to Dan Everton <deverton@cit.gu.edu.au>
  19. ;  8. Aug 1998:      - Added some code to add a custom background
  20. ;            It is _NOT_ working at the moment, though!
  21. ;  5. Aug 1998:      - Added some error-checking
  22. ;  5. Aug 1998: v0.2 - Made the script create a new image
  23. ;  4. Aug 1998:      - Uses 'plug-in-spread' instead of randomize
  24. ;  4. Aug 1998: v0.1 - First public release!
  25. ;
  26. ; --- Disclaimer ---
  27. ; This program is free software; you can redistribute it and/or modify
  28. ; it under the terms of the GNU General Public License as published by
  29. ; the Free Software Foundation; either version 2 of the License, or
  30. ; (at your option) any later version.
  31. ; This program is distributed in the hope that it will be useful,
  32. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  34. ; GNU General Public License for more details.
  35.  
  36. (define (script-fu-fireanim-doit image drawable mask xoffs yoffs)
  37.   (plug-in-spread 1 image drawable 1 1)
  38.   (gimp-levels drawable 0 1 255 1.0 0 242)
  39.   (gimp-selection-layer-alpha mask)
  40.   (plug-in-noisify 1 image drawable FALSE 2.0 2.0 2.0 0.0)
  41.   (gimp-selection-grow image 1)
  42.   (plug-in-noisify 1 image drawable FALSE 0.3 0.3 0.3 0.0)
  43.   (gimp-selection-grow image 2)
  44.   (plug-in-gauss-rle TRUE image drawable 1.0 TRUE TRUE)
  45.   (gimp-selection-none image)
  46.   (gimp-channel-ops-offset drawable TRUE 0 xoffs yoffs)
  47.   (gimp-selection-layer-alpha mask)
  48.   (gimp-palette-set-background '(255 255 255))
  49.   (gimp-edit-fill drawable)
  50.   (gimp-selection-none image)
  51. )
  52.  
  53. (define (script-fu-fireanim-prep image drawable orig gradient)
  54.   (gimp-levels drawable 0 1 200 1.0 0 255)
  55.   (gimp-gradients-set-active gradient)
  56.   (plug-in-gradmap TRUE image drawable)
  57.   (gimp-selection-all image)
  58.   (gimp-selection-layer-alpha orig)
  59.   (gimp-edit-copy orig)
  60.   (gimp-floating-sel-anchor (car (gimp-edit-paste drawable FALSE)))
  61.   (gimp-selection-none image)
  62. )
  63.  
  64. (define (script-fu-fireanim-copylayer dstimage dstdrawable srcimage srcdrawable)
  65.   (gimp-selection-all dstimage)
  66.   (gimp-edit-clear dstdrawable)
  67.   (gimp-selection-none dstimage)
  68.   (gimp-selection-all srcimage)
  69.   (gimp-edit-copy srcdrawable)
  70.   (gimp-floating-sel-anchor (car (gimp-edit-paste dstdrawable FALSE)))
  71. )
  72.  
  73.  
  74. (define (script-fu-fireanim origimage origdrawable nframes oframes pframes
  75.     gradient framerate angle distance usebackgnd backgnd)
  76.  
  77.   (if (< nframes oframes) (error "Number of frames < overlap-frames!"))
  78.   (gimp-gradients-set-active gradient)
  79.  
  80.   (set! width (car (gimp-image-width origimage)))
  81.   (set! height (car (gimp-image-height origimage)))
  82.   (set! xoffs (* distance (sin (* angle (/ 3.141592654 180)))))
  83.   (set! yoffs (- 0 (* distance (cos (* angle (/ 3.141592654 180))))))
  84.   (set! image (car (gimp-channel-ops-duplicate origimage)))
  85.   (set! drawable (car (gimp-image-get-active-layer image)))
  86.  
  87.   (gimp-image-disable-undo image)
  88.  
  89.   (set! numlayers (car (gimp-image-get-layers image)))
  90.   (set! layerlist (cadr (gimp-image-get-layers image)))
  91.   (set! count numlayers)
  92.   (while (> count 0)
  93.     (set! count (- count 1))
  94.     (if (not (= (aref layerlist count) drawable))
  95.         (gimp-image-remove-layer image (aref layerlist count))
  96.     )
  97.   )
  98.  
  99.   (if (= usebackgnd TRUE) (begin
  100.     (set! bgimage (car (gimp-drawable-image backgnd)))
  101.     (set! bgcopy (car (gimp-layer-new image width height RGBA_IMAGE "bgcopy" 100 NORMAL)))
  102.     (gimp-image-add-layer image bgcopy 0)
  103.     (script-fu-fireanim-copylayer image bgcopy bgimage backgnd)
  104.     (gimp-layer-set-visible bgcopy FALSE)
  105.   ))
  106.  
  107.   (set! frame (car (gimp-layer-new image width height RGBA_IMAGE "frame" 100 NORMAL)))
  108.  
  109.   (gimp-palette-set-background '(0 0 0))
  110.   (gimp-selection-all image)
  111.   (gimp-edit-fill frame)
  112.  
  113.   (gimp-palette-set-background '(255 255 255))
  114.   (gimp-selection-layer-alpha drawable)
  115.   (gimp-edit-fill frame)
  116.  
  117.   (gimp-image-add-layer image frame 0)
  118.   (gimp-layer-set-visible frame FALSE)
  119.  
  120.   (gimp-layer-set-visible drawable FALSE)
  121.  
  122.   (set! count 0)
  123.   (while (< count pframes)
  124.     (script-fu-fireanim-doit image frame drawable xoffs yoffs)
  125.     (set! count (+ count 1))
  126.   )
  127.  
  128.   (set! larray (cons-array (+ nframes oframes 1)))
  129.   (set! count 1)
  130.   (while (<= count (+ nframes oframes))
  131.     (script-fu-fireanim-doit image frame drawable xoffs yoffs)
  132.     (set! newlayer (car (gimp-layer-copy frame TRUE)))
  133.     (script-fu-fireanim-prep image newlayer drawable gradient)
  134.     (if (= usebackgnd TRUE) (begin
  135.         (set! bglayer (car (gimp-layer-copy bgcopy TRUE)))
  136.         (gimp-image-add-layer image newlayer 0)
  137.         (gimp-image-add-layer image bglayer 1)
  138.         (gimp-layer-set-visible bglayer TRUE)
  139.         (gimp-layer-set-visible newlayer TRUE)
  140.         (set! newlayer (car (gimp-image-merge-visible-layers image 2)))
  141.     ))
  142.     (aset larray count newlayer) 
  143.     (gimp-layer-set-name newlayer
  144.         (string-append "Frame " (number->string count) " (" (number->string framerate) "ms) (replace)"))
  145.     (if (= usebackgnd FALSE) (begin
  146.         (gimp-image-add-layer image newlayer 0)
  147.     ))
  148.     (gimp-layer-set-visible newlayer FALSE)
  149.     (set! count (+ count 1))
  150.   )
  151.  
  152.   (gimp-layer-set-visible drawable FALSE)
  153.  
  154.   (set! count 1)
  155.   (while (<= count oframes)
  156.     (set! opac (* 100 (- 1.0 (/ count (+ oframes 1)))))
  157.     (set! framea (aref larray count))
  158.     (set! frameb (aref larray (+ count nframes)))
  159.     (gimp-layer-set-visible framea TRUE)
  160.     (gimp-layer-set-visible frameb TRUE)
  161.     (gimp-layer-set-opacity frameb opac)
  162.     (set! framea (car (gimp-image-merge-visible-layers image 2)))
  163.     (aset larray count framea)
  164.     (gimp-layer-set-visible framea FALSE)
  165.     (set! count (+ count 1))
  166.   )
  167.  
  168.   (set! count 1)
  169.   (while (<= count nframes)
  170.     (set! framea (aref larray count))
  171.     (gimp-layer-set-visible framea TRUE)
  172.     (set! count (+ count 1))
  173.   )
  174.  
  175.   (gimp-image-set-active-layer image framea)
  176.   (gimp-image-remove-layer image drawable)
  177.   (gimp-image-remove-layer image frame)
  178.   (if (= usebackgnd TRUE)
  179.     (gimp-image-remove-layer image bgcopy)
  180.   )
  181.  
  182.   (gimp-display-new image)
  183.  
  184.   (gimp-selection-none image)
  185.   (gimp-selection-none origimage)
  186.   (gimp-image-enable-undo image)
  187.   (gimp-displays-flush)
  188. )
  189.  
  190. (script-fu-register
  191.     "script-fu-fireanim"
  192.     "<Image>/Script-Fu/Animators/FireAnim"
  193.     "FireAnim"
  194.     "Vidar Madsen <vidar@prosalg.no>"
  195.     "Vidar Madsen"
  196.     "6. Feb 1999"
  197.     "RGBA"
  198.     SF-IMAGE "Input Image" 0
  199.     SF-DRAWABLE "Input Drawable" 0
  200.     SF-VALUE "# of frames" "15"
  201.     SF-VALUE "Overlap frames" "6"
  202.     SF-VALUE "Prep frames" "15"
  203.     SF-VALUE "Gradient" "\"Incandescent\""
  204.     SF-VALUE "Framerate (ms)" "50"
  205.     SF-VALUE "Angle (Degrees)" "0"
  206.     SF-VALUE "Distance" "2"
  207.     SF-TOGGLE "Use background?" FALSE
  208.     SF-DRAWABLE "Background" 0
  209. )
  210.