;;;
;;; draw-grid.scm
;;;
;;;
;;; Arch. Giuseppe Conte
;;;
;;; Raymond Ostertag 2004/09 changed menu entry
;;; 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.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Define the function:
(define (script-fu-draw-grid image inLayer dx dy angle tipo)
;tipo di griglia
;;;griglia
(if (= tipo 0)
(begin
(set! oriz 0)
(set! vert 0)
);begin
;(set! oriz 1)
);end if
;;;solo righe orizzontali
(if (= tipo 1)
(begin
(set! oriz 0)
(set! vert 1)
);begin
;(set! oriz 0)
);end if
;;;solo righe verticali
(if (= tipo 2)
(begin
(set! oriz 1)
(set! vert 0)
);begin
;(set! oriz 0)
);end if
;determina le dimensioni dell'immagine
(set! width (car (gimp-image-width image)))
(set! height (car (gimp-image-height image)))
;imposta un array per contenere le coordinate
(set! npoint 4)
(set! segment (cons-array 4 'double))
;imposta l'angolo in radianti
(set! alfa (* angle (/ *pi* 180)))
(set! outy (* width (tan alfa)))
(set! outx (* width (tan alfa)))
;calcola l'incremento verticale ed orizzontale
(set! qx (* dx (cos alfa)))
(set! qy (* dy (cos alfa)))
;imposta i prolungamenti sinistro e destro
(set! ks (+ height outy))
(set! kd (- 0 outy))
(set! cnt 0)
;coordinate iniziali x
(set! xa 0)
(set! xb width)
(set! ya 0)
(set! yb kd)
;inizio delle operazioni che potranno essere annullate con un solo undo
(gimp-undo-push-group-start image)
;tracciamento line orizzontali
(if (= oriz 0)
(begin
(while (<= cnt ks)
(set! ya (+ ya qy))
(set! yb (+ yb qy))
(aset segment 0 (* 1 xa))
(aset segment 1 (* 1 ya))
(aset segment 2 (* 1 xb))
(aset segment 3 (* 1 yb))
(gimp-pencil inLayer npoint segment)
(set! cnt (+ cnt qy))
);end while
);end begin
);end if
;tracciamento linee verticali
(set! kd (+ width outx))
(set! ks (- 0 outx))
(set! cnt 0)
;coordinate iniziali x
(set! xa ks)
(set! xb 0)
(set! ya 0)
(set! yb height)
(if (= vert 0)
(begin
(while (<= cnt kd)
(set! xa (+ xa qx))
(set! xb (+ xb qx))
(aset segment 0 (* 1 xa))
(aset segment 1 (* 1 ya))
(aset segment 2 (* 1 xb))
(aset segment 3 (* 1 yb))
(gimp-pencil inLayer npoint segment)
(set! cnt (+ cnt qx))
);end while
);end begin
);end if
;fine delle operazioni che potranno essere annullate con un solo undo
(gimp-undo-push-group-end image)
(gimp-displays-flush)
) ;;def
(script-fu-register
"script-fu-draw-grid"
_"/Script-Fu/Geometry/Draw Grid..."
"To draw grid or alone inclined parallel line."
"Arch. Giuseppe Conte "
"2003, Giuseppe Conte"
"13 Agosto 2003 - 72026 San Pancrazio Salentino (BR) - Italy"
"RGB* GRAY* INDEXED*"
SF-IMAGE "The Image" 0
SF-DRAWABLE "The Layer" 0
SF-ADJUSTMENT "Delta x" '(20 0 9999 1 10 0 1)
SF-ADJUSTMENT "Delta y" '(20 0 9999 1 10 0 1)
SF-ADJUSTMENT "Angle" '(45 0 89.9999 1 10 0 1)
SF-OPTION "Type:" '("Grid" "Horizontal lines" "Verticla lines")
)