plug-ins/script-fu/scripts/alien-glow-arrow.scm Make helper functions

2004-03-23  Simon Budig  <simon@gimp.org>

	* plug-ins/script-fu/scripts/alien-glow-arrow.scm
	* plug-ins/script-fu/scripts/beveled-pattern-arrow.scm: Make
	helper functions local to the scripts. The better fix for
	bug #136868. Should also be done for a lot of other scripts,
	but is too likely to introduce new bugs to do this now.
This commit is contained in:
Simon Budig 2004-03-23 14:18:13 +00:00 committed by Simon Budig
parent eb7cce40e3
commit eed77aa635
3 changed files with 134 additions and 105 deletions

View File

@ -1,3 +1,11 @@
2004-03-23 Simon Budig <simon@gimp.org>
* plug-ins/script-fu/scripts/alien-glow-arrow.scm
* plug-ins/script-fu/scripts/beveled-pattern-arrow.scm: Make
helper functions local to the scripts. The better fix for
bug #136868. Should also be done for a lot of other scripts,
but is too likely to introduce new bugs to do this now.
2004-03-23 Sven Neumann <sven@gimp.org>
* INSTALL

View File

@ -24,51 +24,68 @@
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
(define (make-point x y)
(cons x y))
(define (point-x p)
(car p))
(define (point-y p)
(cdr p))
(define (point-list->double-array point-list)
(define (convert points array pos)
(if (not (null? points))
(begin
(aset array (* 2 pos) (point-x (car points)))
(aset array (+ 1 (* 2 pos)) (point-y (car points)))
(convert (cdr points) array (+ pos 1)))))
(let* ((how-many (length point-list))
(a (cons-array (* 2 how-many) 'double)))
(convert point-list a 0)
a))
(define (make-arrow size
offset)
(list (make-point offset offset)
(make-point (- size offset) (/ size 2))
(make-point offset (- size offset))))
(define (rotate-points points size orientation)
(map (lambda (p)
(let ((px (point-x p))
(py (point-y p)))
(cond ((= orientation 0) (make-point px py)) ; right
((= orientation 1) (make-point (- size px) py)) ; left
((= orientation 2) (make-point py (- size px))) ; up
((= orientation 3) (make-point py px))))) ; down
points))
(define (script-fu-alien-glow-right-arrow size
orientation
glow-color
bg-color
flatten)
; some local helper functions, better to not define globally,
; since otherwise the definitions could be clobbered by other scripts.
(define (map proc seq)
(if (null? seq)
'()
(cons (proc (car seq))
(map proc (cdr seq)))))
(define (for-each proc seq)
(if (not (null? seq))
(begin
(proc (car seq))
(for-each proc (cdr seq)))))
(define (make-point x y)
(cons x y))
(define (point-x p)
(car p))
(define (point-y p)
(cdr p))
(define (point-list->double-array point-list)
(define (convert points array pos)
(if (not (null? points))
(begin
(aset array (* 2 pos) (point-x (car points)))
(aset array (+ 1 (* 2 pos)) (point-y (car points)))
(convert (cdr points) array (+ pos 1)))))
(let* ((how-many (length point-list))
(a (cons-array (* 2 how-many) 'double)))
(convert point-list a 0)
a))
(define (make-arrow size
offset)
(list (make-point offset offset)
(make-point (- size offset) (/ size 2))
(make-point offset (- size offset))))
(define (rotate-points points size orientation)
(map (lambda (p)
(let ((px (point-x p))
(py (point-y p)))
(cond ((= orientation 0) (make-point px py)) ; right
((= orientation 1) (make-point (- size px) py)) ; left
((= orientation 2) (make-point py (- size px))) ; up
((= orientation 3) (make-point py px))))) ; down
points))
; the main function
(let* ((img (car (gimp-image-new size size RGB)))
(grow-amount (/ size 12))
(blur-radius (/ size 3))

View File

@ -20,61 +20,65 @@
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
(define (map proc seq)
(if (null? seq)
'()
(cons (proc (car seq))
(map proc (cdr seq)))))
(define (for-each proc seq)
(if (not (null? seq))
(begin
(proc (car seq))
(for-each proc (cdr seq)))))
(define (make-point x y)
(cons x y))
(define (point-x p)
(car p))
(define (point-y p)
(cdr p))
(define (point-list->double-array point-list)
(let* ((how-many (length point-list))
(a (cons-array (* 2 how-many) 'double))
(count 0))
(for-each (lambda (p)
(aset a (* count 2) (point-x p))
(aset a (+ 1 (* count 2)) (point-y p))
(set! count (+ count 1)))
point-list)
a))
(define (rotate-points points size orientation)
(map (lambda (p)
(let ((px (point-x p))
(py (point-y p)))
(cond ((= orientation 0) (make-point px py)) ; right
((= orientation 1) (make-point (- size px) py)) ; left
((= orientation 2) (make-point py (- size px))) ; up
((= orientation 3) (make-point py px))))) ; down
points))
(define (make-arrow size offset)
(list (make-point offset offset)
(make-point (- size offset) (/ size 2))
(make-point offset (- size offset))))
(define (script-fu-beveled-pattern-arrow size orientation pattern)
; define some local helper functions
(define (map proc seq)
(if (null? seq)
'()
(cons (proc (car seq))
(map proc (cdr seq)))))
(define (for-each proc seq)
(if (not (null? seq))
(begin
(proc (car seq))
(for-each proc (cdr seq)))))
(define (make-point x y)
(cons x y))
(define (point-x p)
(car p))
(define (point-y p)
(cdr p))
(define (point-list->double-array point-list)
(let* ((how-many (length point-list))
(a (cons-array (* 2 how-many) 'double))
(count 0))
(for-each (lambda (p)
(aset a (* count 2) (point-x p))
(aset a (+ 1 (* count 2)) (point-y p))
(set! count (+ count 1)))
point-list)
a))
(define (rotate-points points size orientation)
(map (lambda (p)
(let ((px (point-x p))
(py (point-y p)))
(cond ((= orientation 0) (make-point px py)) ; right
((= orientation 1) (make-point (- size px) py)) ; left
((= orientation 2) (make-point py (- size px))) ; up
((= orientation 3) (make-point py px))))) ; down
points))
(define (make-arrow size offset)
(list (make-point offset offset)
(make-point (- size offset) (/ size 2))
(make-point offset (- size offset))))
; the main function
(let* ((old-bg-color (car (gimp-palette-get-background)))
(img (car (gimp-image-new size size RGB)))
(background (car (gimp-layer-new img size size RGB-IMAGE "Arrow" 100 NORMAL-MODE)))
(bumpmap (car (gimp-layer-new img size size RGB-IMAGE "Bumpmap" 100 NORMAL-MODE)))
(big-arrow (point-list->double-array (rotate-points (make-arrow size 6) size orientation)))
(med-arrow (point-list->double-array (rotate-points (make-arrow size 7) size orientation)))
(small-arrow (point-list->double-array (rotate-points (make-arrow size 8) size orientation))))
(img (car (gimp-image-new size size RGB)))
(background (car (gimp-layer-new img size size RGB-IMAGE "Arrow" 100 NORMAL-MODE)))
(bumpmap (car (gimp-layer-new img size size RGB-IMAGE "Bumpmap" 100 NORMAL-MODE)))
(big-arrow (point-list->double-array (rotate-points (make-arrow size 6) size orientation)))
(med-arrow (point-list->double-array (rotate-points (make-arrow size 7) size orientation)))
(small-arrow (point-list->double-array (rotate-points (make-arrow size 8) size orientation))))
(gimp-image-undo-disable img)
(gimp-image-add-layer img background -1)
@ -134,15 +138,15 @@
(script-fu-register "script-fu-beveled-pattern-arrow"
_"<Toolbox>/Xtns/Script-Fu/Web Page Themes/Beveled Pattern/_Arrow..."
"Beveled pattern arrow"
"Federico Mena Quintero"
"Federico Mena Quintero"
"July 1997"
""
SF-ADJUSTMENT _"Size" '(32 5 150 1 10 0 1)
SF-OPTION _"Orientation" '(_"Right"
_"Left"
_"Up"
_"Down")
SF-PATTERN _"Pattern" "Wood")
_"<Toolbox>/Xtns/Script-Fu/Web Page Themes/Beveled Pattern/_Arrow..."
"Beveled pattern arrow"
"Federico Mena Quintero"
"Federico Mena Quintero"
"July 1997"
""
SF-ADJUSTMENT _"Size" '(32 5 150 1 10 0 1)
SF-OPTION _"Orientation" '(_"Right"
_"Left"
_"Up"
_"Down")
SF-PATTERN _"Pattern" "Wood")