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

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Circuit board effect
  4. ; Copyright (c) 1997 Adrian Likins
  5. ; aklikins@eos.ncsu.ed
  6. ;
  7. ;  Genrates what looks a little like the back of an old circuit board.
  8. ;  Looks even better when gradmapped with a suitable gradient.
  9. ;
  10. ; This script doesnt handle or color combos well. ie, black/black 
  11. ;  doesnt work..
  12. ;  The effect seems to work best on odd shaped selections because of some
  13. ; limitations in the maze codes selection handling ablity
  14. ;
  15. ;
  16. ; This program is free software; you can redistribute it and/or modify
  17. ; it under the terms of the GNU General Public License as published by
  18. ; the Free Software Foundation; either version 2 of the License, or
  19. ; (at your option) any later version.
  20. ; This program is distributed in the hope that it will be useful,
  21. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23. ; GNU General Public License for more details.
  24. ; You should have received a copy of the GNU General Public License
  25. ; along with this program; if not, write to the Free Software
  26. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  
  28.  
  29. (define (script-fu-circuit image
  30.                drawable
  31.                mask-size
  32.                seed
  33.                remove-bg
  34.                keep-selection
  35.                seperate-layer)
  36.   (let* (
  37.      (type (car (gimp-drawable-type-with-alpha drawable)))
  38.      (image-width (car (gimp-image-width image)))
  39.      (image-height (car (gimp-image-height image)))
  40.      (old-fg (car (gimp-palette-get-foreground)))
  41.     )
  42.     
  43.     (gimp-image-undo-disable image)
  44.     (gimp-layer-add-alpha drawable)
  45.     
  46.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  47.     (begin
  48.       (gimp-selection-layer-alpha drawable)
  49.       (set! active-selection (car (gimp-selection-save image)))
  50.       (set! from-selection FALSE))
  51.     (begin
  52.       (set! from-selection TRUE)
  53.       (set! active-selection (car (gimp-selection-save image)))))
  54.     
  55.     (set! selection-bounds (gimp-selection-bounds image))
  56.     (set! select-offset-x (cadr selection-bounds))
  57.     (set! select-offset-y (caddr selection-bounds))
  58.     (set! select-width (- (cadr (cddr selection-bounds)) select-offset-x))
  59.     (set! select-height (- (caddr (cddr selection-bounds)) select-offset-y))
  60.     
  61.     (if (= seperate-layer TRUE)
  62.     (begin
  63.       (set! effect-layer (car (gimp-layer-new image
  64.                           select-width
  65.                           select-height
  66.                           type
  67.                           "effect layer"
  68.                           100
  69.                           NORMAL)))
  70.       
  71.       (gimp-image-add-layer image effect-layer -1)
  72.       (gimp-layer-set-offsets effect-layer select-offset-x select-offset-y)
  73.       (gimp-selection-none image)
  74.       (gimp-edit-clear effect-layer)
  75.       (gimp-selection-load active-selection)
  76.       (gimp-edit-copy drawable)
  77.       
  78.       (let ((floating-sel (car (gimp-edit-paste effect-layer FALSE))))
  79.         (gimp-floating-sel-anchor floating-sel)
  80.         )
  81.       (gimp-image-set-active-layer image effect-layer )))
  82.     (set! active-layer (car (gimp-image-get-active-layer image)))
  83.  
  84.     (if (and
  85.      (= remove-bg TRUE)
  86.      (= old-bg '(0 0 0)))
  87.     (gimp-palette-set-foreground '(0 0 0))
  88.     (gimp-palette-set-foreground '(14 14 14)))
  89.     
  90.     (gimp-selection-load active-selection)
  91.     (plug-in-maze 1 image active-layer 5 5 TRUE 0 seed 57 1)
  92.     (plug-in-oilify 1 image active-layer mask-size 0)
  93.     (plug-in-edge 1 image active-layer 2 1)
  94.     (gimp-desaturate active-layer)
  95.     
  96.     (if (and
  97.      (= remove-bg TRUE)
  98.      (= seperate-layer TRUE))
  99.     (begin
  100.       (gimp-by-color-select
  101.        active-layer
  102.        '(0 0 0)
  103.        15
  104.        2
  105.        TRUE
  106.        FALSE
  107.        10
  108.        FALSE)
  109.       (gimp-edit-clear active-layer)))
  110.     
  111.     (gimp-palette-set-foreground old-fg)
  112.     
  113.     (if (= keep-selection FALSE)
  114.     (gimp-selection-none image))
  115.     
  116.     (gimp-image-undo-enable image)
  117.     (gimp-image-remove-channel image active-selection)
  118.     (gimp-image-set-active-layer image drawable)
  119.     (gimp-displays-flush)))
  120.  
  121. (script-fu-register "script-fu-circuit"
  122.             _"<Image>/Script-Fu/Render/Circuit..."
  123.             "Fills the current selection with something that looks 
  124.                      vaguely like a circuit board."
  125.             "Adrian Likins <adrian@gimp.org>"
  126.             "Adrian Likins"
  127.             "10/17/97"
  128.             "RGB* GRAY*"
  129.             SF-IMAGE "Image" 0
  130.             SF-DRAWABLE "Drawable" 0
  131.             SF-ADJUSTMENT _"Oilify Mask Size" '(17 3 50 1 10 0 1)
  132.             SF-ADJUSTMENT _"Circuit Seed" '(3 1 3000000 1 10 0 1)
  133.             SF-TOGGLE _"No Background (only for separate layer)" FALSE
  134.             SF-TOGGLE _"Keep Selection" TRUE
  135.             SF-TOGGLE _"Separate Layer" TRUE)
  136.