Created
March 24, 2009 04:19
-
-
Save hyperlogic/83935 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Gimp script-fu plugin | |
;; | |
;; Draws a sqaure grid with the specified size into a new layer. | |
;; The lines of the grid are drawn using the current brush & foreground color. | |
;; | |
;; Author: Anthony J. Thibault | |
;; email: ajt@hyperlogic.org | |
;; | |
;; Copyright (c) 2009 Anthony J. Thibault | |
;; | |
;; Permission is hereby granted, free of charge, to any person obtaining a copy | |
;; of this software and associated documentation files (the "Software"), to deal | |
;; in the Software without restriction, including without limitation the rights | |
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
;; copies of the Software, and to permit persons to whom the Software is | |
;; furnished to do so, subject to the following conditions: | |
;; | |
;; The above copyright notice and this permission notice shall be included in | |
;; all copies or substantial portions of the Software. | |
;; | |
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
;; THE SOFTWARE. | |
;; globals | |
(define (g-image nil)) | |
(define (g-size nil)) | |
(define (g-width nil)) | |
(define (g-height nil)) | |
(define (g-layer nil)) | |
(define (draw-line a b) | |
(let ((v (car (gimp-vectors-new g-image "grid")))) | |
(gimp-image-add-vectors g-image v -1) | |
(let ((stroke-id (car (gimp-vectors-bezier-stroke-new-moveto v (car a) (cdr a))))) | |
(gimp-vectors-bezier-stroke-lineto v stroke-id (car b) (cdr b)) | |
(gimp-vectors-stroke-close v stroke-id) | |
(gimp-edit-stroke-vectors g-layer v)))) | |
(define (draw-horiz-lines n) | |
(if (> n 0) | |
(let ((y (* n g-size))) | |
(draw-line (cons 0 y) (cons g-width y)) | |
(draw-horiz-lines (- n 1))) | |
#t)) | |
(define (draw-vert-lines n) | |
(if (> n 0) | |
(let ((x (* n g-size))) | |
(draw-line (cons x 0) (cons x g-height)) | |
(draw-vert-lines (- n 1))) | |
#t)) | |
(define (script-fu-grid-render image size) | |
;; set globals | |
(set! g-image image) | |
(set! g-size size) | |
(set! g-width (car (gimp-image-width image))) | |
(set! g-height (car (gimp-image-height image))) | |
(set! g-layer (car (gimp-layer-new image | |
g-width | |
g-height | |
1 ; rbga | |
"grid" ; name | |
100 ; opacity | |
0))) ; combination mode | |
(gimp-image-undo-disable image) | |
(gimp-image-add-layer image g-layer -1) | |
(gimp-drawable-fill g-layer 3) ; transparent fill | |
(let ((num-columns (quotient g-width g-size)) | |
(num-rows (quotient g-height g-size))) | |
(draw-horiz-lines num-rows) | |
(draw-vert-lines num-columns)) | |
(gimp-image-undo-enable image)) | |
;; register | |
(script-fu-register | |
"script-fu-grid-render" ;func name | |
"GridRender" ;menu label | |
"Draws a sqaure grid with the specified size into a new layer. The lines of the grid are drawn using the current brush & foreground color." | |
"Anthony Thibault" ;author | |
"Copyright 2009, Anthony Thibault" ;copyright notice | |
"Feb 23, 2009" ;date created | |
"RGB*" ;image type that the script works on | |
SF-IMAGE "Image" 0 | |
SF-VALUE "Grid Size" "32" ;size | |
) | |
(script-fu-menu-register "script-fu-grid-render" "<Image>/Script-Fu") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment