home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / beveled-pattern-arrow.scm < prev    next >
Encoding:
Text File  |  2000-12-27  |  4.8 KB  |  149 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Beveled pattern arrow for web pages
  4. ; Copyright (C) 1997 Federico Mena Quintero
  5. ; federico@nuclecu.unam.mx
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19. (define (map proc seq)
  20.   (if (null? seq)
  21.       '()
  22.       (cons (proc (car seq))
  23.         (map proc (cdr seq)))))
  24.  
  25. (define (for-each proc seq)
  26.   (if (not (null? seq))
  27.       (begin
  28.     (proc (car seq))
  29.     (for-each proc (cdr seq)))))
  30.  
  31. (define (make-point x y)
  32.   (cons x y))
  33.  
  34. (define (point-x p)
  35.   (car p))
  36.  
  37. (define (point-y p)
  38.   (cdr p))
  39.  
  40. (define (point-list->double-array point-list)
  41.   (let* ((how-many (length point-list))
  42.      (a (cons-array (* 2 how-many) 'double))
  43.      (count 0))
  44.     (for-each (lambda (p)
  45.         (aset a (* count 2) (point-x p))
  46.         (aset a (+ 1 (* count 2)) (point-y p))
  47.         (set! count (+ count 1)))
  48.           point-list)
  49.     a))
  50.  
  51. (define (rotate-points points size orientation)
  52.   (map (lambda (p)
  53.      (let ((px (point-x p))
  54.            (py (point-y p)))
  55.        (cond ((= orientation 0) (make-point px py))           ; right
  56.          ((= orientation 1) (make-point (- size px) py))  ; left
  57.          ((= orientation 2) (make-point py (- size px)))  ; up
  58.          ((= orientation 3) (make-point py px)))))        ; down
  59.        points))
  60.  
  61. (define (make-arrow size offset)
  62.   (list (make-point offset offset)
  63.     (make-point (- size offset) (/ size 2))
  64.     (make-point offset (- size offset))))
  65.  
  66. (define (script-fu-beveled-pattern-arrow size orientation pattern)
  67.   (let* ((old-bg-color (car (gimp-palette-get-background)))
  68.      (img (car (gimp-image-new size size RGB)))
  69.      (background (car (gimp-layer-new img size size RGB_IMAGE "Arrow" 100 NORMAL)))
  70.      (bumpmap (car (gimp-layer-new img size size RGB_IMAGE "Bumpmap" 100 NORMAL)))
  71.      (big-arrow (point-list->double-array (rotate-points (make-arrow size 6) size orientation)))
  72.      (med-arrow (point-list->double-array (rotate-points (make-arrow size 7) size orientation)))
  73.      (small-arrow (point-list->double-array (rotate-points (make-arrow size 8) size orientation))))
  74.  
  75.     (gimp-image-undo-disable img)
  76.     (gimp-image-add-layer img background -1)
  77.     (gimp-image-add-layer img bumpmap -1)
  78.  
  79.     ; Create pattern layer
  80.  
  81.     (gimp-palette-set-background '(0 0 0))
  82.     (gimp-edit-fill background BG-IMAGE-FILL)
  83.     (gimp-patterns-set-pattern pattern)
  84.     (gimp-bucket-fill background PATTERN-BUCKET-FILL NORMAL 100 0 FALSE 0 0)
  85.  
  86.     ; Create bumpmap layer
  87.  
  88.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  89.  
  90.     (gimp-palette-set-background '(127 127 127))
  91.     (gimp-rect-select img 1 1 (- size 2) (- size 2) REPLACE FALSE 0)
  92.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  93.  
  94.     (gimp-palette-set-background '(255 255 255))
  95.     (gimp-rect-select img 2 2 (- size 4) (- size 4) REPLACE FALSE 0)
  96.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  97.  
  98.     (gimp-palette-set-background '(127 127 127))
  99.     (gimp-free-select img 6 big-arrow REPLACE TRUE FALSE 0)
  100.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  101.  
  102.     (gimp-palette-set-background '(0 0 0))
  103.     (gimp-free-select img 6 med-arrow REPLACE TRUE FALSE 0)
  104.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  105.  
  106.     (gimp-selection-none img)
  107.  
  108.     ; Bumpmap
  109.  
  110.     (plug-in-bump-map 1 img background bumpmap 135 45 2 0 0 0 0 TRUE FALSE 0)
  111.  
  112.     ; Darken arrow
  113.  
  114.     (gimp-palette-set-background '(255 255 255))
  115.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  116.  
  117.     (gimp-palette-set-background '(192 192 192))
  118.     (gimp-free-select img 6 small-arrow REPLACE TRUE FALSE 0)
  119.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  120.  
  121.     (gimp-selection-none img)
  122.  
  123.     (gimp-layer-set-mode bumpmap MULTIPLY)
  124.  
  125.     (gimp-image-flatten img)
  126.  
  127.     (gimp-palette-set-background old-bg-color)
  128.     (gimp-image-undo-enable img)
  129.     (gimp-display-new img)))
  130.  
  131.  
  132. (script-fu-register "script-fu-beveled-pattern-arrow"
  133.             _"<Toolbox>/Xtns/Script-Fu/Web Page Themes/Beveled Pattern/Arrow..."
  134.             "Beveled pattern arrow"
  135.             "Federico Mena Quintero"
  136.             "Federico Mena Quintero"
  137.             "July 1997"
  138.             ""
  139.             SF-ADJUSTMENT _"Size"     '(32 5 150 1 10 0 1)
  140.             SF-OPTION     _"Orientation" '(_"Right" 
  141.                             _"Left" 
  142.                             _"Up" 
  143.                             _"Down")
  144.             SF-PATTERN    _"Pattern"     "Wood")
  145.