home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 August / ENTER.ISO / files / gimp-2.0.5-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / truchet.scm < prev    next >
Encoding:
Text File  |  2004-09-26  |  5.5 KB  |  164 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ; You should have received a copy of the GNU General Public License
  13. ; along with this program; if not, write to the Free Software
  14. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ;
  16. ;    Truchet  - a script to create Truchet patterns 
  17. ;                 by Adrian Likins <aklikins@eos.ncsu.edu>
  18. ;                 http://www4.ncsu.edu/~aklikins/
  19. ;    version about .8 give or take
  20. ;
  21. ;  Lots of thanks to Quartic for his help.
  22. ;
  23. ;
  24. ;         The utility of this script is left as an exercise for the reader.
  25.  
  26. (define (center-ellipse img cx cy rx ry op aa feather frad)
  27.   (gimp-ellipse-select img (- cx rx) (- cy ry) (+ rx rx ) (+ ry ry ) op aa feather frad))
  28.  
  29. (define (use-tiles img drawable height width img2 drawable2 xoffset yoffset)
  30.   (gimp-edit-copy drawable2)
  31.   (let ((floating-sel (car (gimp-edit-paste drawable FALSE))))
  32.     (gimp-layer-set-offsets floating-sel xoffset yoffset)
  33.     (gimp-floating-sel-anchor floating-sel)
  34.     )
  35. )
  36.  
  37.  
  38. (define (create-tiles img drawable1 drawable2 size thickness backcolor forecolor)
  39.   (let* (
  40.      (half-thickness (/ thickness 2))
  41.      (outer-radius (+ (/ size 2) half-thickness))
  42.      (inner-radius (- (/ size 2) half-thickness))
  43.      )
  44.  
  45.     (gimp-selection-all img)
  46.     (gimp-palette-set-background backcolor)
  47.     (gimp-edit-fill drawable1 BACKGROUND-FILL)
  48.  
  49.     (let* (
  50.        (tempSize (* size 3))
  51.        (temp-img (car (gimp-image-new tempSize tempSize RGB)))
  52.        (temp-draw (car (gimp-layer-new temp-img tempSize tempSize RGB-IMAGE "Jabar" 100 NORMAL-MODE)))
  53.       )
  54.       (gimp-image-undo-disable temp-img)
  55.       (gimp-image-add-layer temp-img temp-draw 0)
  56.       (gimp-palette-set-background backcolor)
  57.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  58.       
  59.       
  60.       (center-ellipse temp-img size size outer-radius outer-radius CHANNEL-OP-REPLACE TRUE FALSE 0)
  61.       (center-ellipse temp-img size size inner-radius inner-radius CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  62.       
  63.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius CHANNEL-OP-ADD TRUE FALSE 0)
  64.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  65.       (gimp-palette-set-background forecolor)
  66.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  67.       
  68.       (gimp-selection-none temp-img)
  69.  
  70.       (gimp-image-resize temp-img size size (- size) (- size))
  71.       ; woo hoo it works....finally...
  72.  
  73.  
  74.       (gimp-selection-all temp-img)
  75.       (gimp-edit-copy temp-draw)
  76.       (let ((floating-sel (car (gimp-edit-paste drawable2 FALSE))))
  77.     (gimp-floating-sel-anchor floating-sel))
  78.  
  79.       
  80.       (let ((floating-sel (car (gimp-edit-paste drawable1 FALSE))))
  81.     (gimp-floating-sel-anchor floating-sel))
  82.  
  83.       (let ((drawble (car (gimp-flip drawable1 1)))))
  84.     
  85.  
  86.       ;(gimp-display-new temp-img)
  87.       (gimp-image-delete temp-img)
  88.       )
  89.     )
  90. )
  91.  
  92.  
  93. (define (script-fu-truchet size thickness backcolor forecolor xtiles ytiles)
  94.   (let* (
  95.      (width (* size xtiles))
  96.      (height (* size ytiles))
  97.      (img (car (gimp-image-new width height RGB)))
  98.      (tile (car (gimp-image-new size size RGB)))
  99.      (layer-one (car (gimp-layer-new img width height
  100.                      RGB-IMAGE "Rambis" 100 NORMAL-MODE)))
  101.      (tiledraw1 (car (gimp-layer-new tile size size
  102.                      RGB-IMAGE "Johnson" 100 NORMAL-MODE)))
  103.      (tiledraw2 (car (gimp-layer-new tile size size
  104.                      RGB-IMAGE "Cooper" 100 NORMAL-MODE)))
  105.      (Xindex 0)
  106.      (Yindex 0)
  107.      (old-bg (car (gimp-palette-get-background)))
  108.      )
  109.  
  110.     (gimp-image-undo-disable img)
  111.     (gimp-image-undo-disable tile)
  112.     
  113.     (gimp-image-add-layer img layer-one 0)
  114.     (gimp-image-add-layer tile tiledraw1 0)
  115.     (gimp-image-add-layer tile tiledraw2 0)
  116.  
  117.  
  118.     ;just to look a little better
  119.     (gimp-selection-all img)
  120.     (gimp-palette-set-background backcolor)
  121.     (gimp-edit-fill layer-one BACKGROUND-FILL)
  122.     (gimp-selection-none img)
  123.  
  124.     (create-tiles tile tiledraw1 tiledraw2 size thickness backcolor forecolor)
  125.     
  126.  
  127.     (while (<= Xindex xtiles)
  128.        (while (<= Yindex ytiles)
  129.           (if (= (rand 2) 0)
  130.               (use-tiles img layer-one height width tile tiledraw1 (* Xindex size) (* Yindex size))
  131.               (use-tiles img layer-one height width tile tiledraw2 (* Xindex size) (* Yindex size))
  132.               )
  133.           (set! Yindex (+ Yindex 1))
  134.           )
  135.        (set! Yindex 0)
  136.        (set! Xindex (+ Xindex 1))
  137.        )
  138.     
  139.     
  140.     (gimp-image-delete tile)
  141.     (gimp-palette-set-background old-bg)
  142.     (gimp-image-undo-enable img)
  143.     (gimp-display-new img)
  144.     )
  145.   )
  146.  
  147. (script-fu-register "script-fu-truchet"
  148.             _"<Toolbox>/Xtns/Script-Fu/Patterns/T_ruchet..."
  149.             "Create a Truchet pattern \n\nWorks best with even sized thicknesses"
  150.             "Adrian Likins <aklikins@eos.ncsu.edu>"
  151.             "Adrian Likins"
  152.             "1997"
  153.             ""
  154.  
  155.             SF-ADJUSTMENT _"Block Size" '(32 2 512 1 10 1 1)
  156.             SF-ADJUSTMENT _"Thickness" '(2 1 512 1 10 1 1)
  157.             SF-COLOR      _"Background Color" '(255 255 255)
  158.             SF-COLOR      _"Foreground Color" '(0 0 0)
  159.             SF-ADJUSTMENT _"Number of X Tiles" '(5 1 512 1 10 1 1)
  160.             SF-ADJUSTMENT _"Number of Y Tiles" '(5 1 512 1 10 1 1)
  161.             )
  162.