; The GIMP -- an image manipulation program ; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; ; Check Tile --- create a check tile pattern image ; Copyright (C) 2001 Iccii ; ; -------------------------------------------------------------------- ; version 0.1 2001/12/08 Iccii ; - Initial relase ; version 0.2 2004/09 Raymond Ostertag ; - Ported to Gimp2 ; -------------------------------------------------------------------- ; Reference Web site ; http://www.sx.sakura.ne.jp/~koki/ex-21-30/example25.html ; -------------------------------------------------------------------- ; ; 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 (script-fu-checktile tile-size ; Size of one tile ntiles ; Number of tiles (if ntiles is n, create nxn pattern) band-width ; Colored band width in pixel layer-mode ; Layer mode for each layers color-balance ; Balance for coloring rand-seed ; Random seed (if rand-seed isn't -1, it's user specific) mirror? ; Create symmenterical pattern? same-width? ; Fix band width or add width +-50% ? ) (define (modulo n m) (fmod n m)) (define (get-layer-mode mode) (cond ; bg-color: 0 = white, 1 = Black ((= mode 0) (list MULTIPLY-MODE 0)) ; 0 ((= mode 1) (list SCREEN-MODE 1)) ; 1 ((= mode 2) (list DIFFERENCE-MODE 1)) ; 1 (or 0) ((= mode 3) (list ADDITION-MODE 1)) ; 1 ((= mode 4) (list DARKEN-ONLY-MODE 0)) ; 0 ((= mode 5) (list LIGHTEN-ONLY-MODE 1)) ; 1 ('else (list NORAML-MODE 0)) )) (let* ( (seed (if (= rand-seed -1) (modulo (realtime) 32768) rand-seed)) (old-fg (car (gimp-palette-get-foreground))) (old-bg (car (gimp-palette-get-background))) (width (max tile-size band-width)) (height (max tile-size band-width)) (img (car (gimp-image-new width height RGB))) (layer (car (gimp-layer-new img width height RGB-IMAGE (string-append "Check Pattern #" (number->string seed)) 100 NORMAL-MODE))) (tile-length-limit (if (equal? mirror? TRUE) (/ tile-size 2) tile-size)) (count 0) ) ; end variable definition (srand seed) (gimp-image-undo-disable img) (gimp-palette-set-background '(0 0 0)) (gimp-image-add-layer img layer -1) (gimp-drawable-fill layer WHITE-FILL) (while (< count tile-length-limit) (let* ((band-step (if (equal? same-width? TRUE) band-width (+ band-width (* (- (rand band-width) (/ band-width 2)) 0.5))))) ;; band-width+-50% (gimp-rect-select img 0 count width (+ count band-step) CHANNEL-OP-REPLACE FALSE 0) (gimp-palette-set-foreground (list (rand 256) (rand 256) (rand 256))) (gimp-edit-fill layer (if (< (rand 100) (- 100 color-balance)) ; 0-100% (if (= (cadr (get-layer-mode layer-mode)) 0) WHITE-FILL BACKGROUND-FILL) FOREGROUND-FILL)) (gimp-selection-none img) (set! count (+ count band-step)))) (if (equal? mirror? TRUE) (begin (gimp-rect-select img 0 0 width (/ height 2) CHANNEL-OP-REPLACE FALSE 0) (gimp-edit-copy layer) (gimp-rect-select img 0 (/ height 2) width height CHANNEL-OP-REPLACE FALSE 0) (gimp-floating-sel-anchor (car (gimp-edit-paste layer 0))) (gimp-rect-select img 0 (/ height 2) width height CHANNEL-OP-REPLACE FALSE 0) (gimp-flip layer ORIENTATION-VERTICAL) (gimp-floating-sel-anchor (car (gimp-image-get-floating-sel img))) (gimp-selection-none img))) (set! layer-copy (car (gimp-layer-copy layer TRUE))) (gimp-image-add-layer img layer-copy -1) (gimp-layer-set-mode layer-copy (car (get-layer-mode layer-mode))) (plug-in-rotate 1 img layer-copy 1 FALSE) (set! result-layer (car (gimp-image-merge-down img layer-copy EXPAND-AS-NECESSARY))) (plug-in-tile 1 img result-layer (* width ntiles) (* height ntiles) FALSE) (gimp-palette-set-foreground old-fg) (gimp-palette-set-background old-bg) (gimp-image-undo-enable img) (gimp-display-new img) )) (script-fu-register "script-fu-checktile" "/Xtns/Script-Fu/Patterns/Check Tile..." "Create an check tile pattern image" "Iccii " "Iccii" "Dec, 2001" "" SF-ADJUSTMENT "Tile Size" '(100 2 1000 1 1 0 1) SF-ADJUSTMENT "Number of Tiles" '(3 1 100 1 1 0 1) SF-ADJUSTMENT "Width of Bands" '(2 1 100 1 1 0 1) SF-OPTION "Layer Mode" '("Multiply" "Screen" "Difference" "Addition" "Darken Only" "Lighten Only") SF-ADJUSTMENT "Color Balance (%)" '(60 0 100 1 1 0 0) SF-ADJUSTMENT "Random Seed" '(-1 -1 32767 1 1 0 1) SF-TOGGLE "Mirror" TRUE SF-TOGGLE "Same Band Width" FALSE )