home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / truchet.scm < prev    next >
Encoding:
Text File  |  2000-12-27  |  5.5 KB  |  161 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 BG-IMAGE-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)))
  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 BG-IMAGE-FILL)
  58.       
  59.       
  60.       (center-ellipse temp-img size size outer-radius outer-radius REPLACE TRUE FALSE 0)
  61.       (center-ellipse temp-img size size inner-radius inner-radius SUB TRUE FALSE 0)
  62.       
  63.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius ADD TRUE FALSE 0)
  64.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius SUB TRUE FALSE 0)
  65.       (gimp-palette-set-background forecolor)
  66.       (gimp-edit-fill temp-draw BG-IMAGE-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 RGB "Rambis" 100 NORMAL)))
  100.      (tiledraw1 (car (gimp-layer-new tile size size RGB "Johnson" 100 NORMAL)))
  101.      (tiledraw2 (car (gimp-layer-new tile size size RGB "Cooper" 100 NORMAL)))
  102.      (Xindex 0)
  103.      (Yindex 0)
  104.      (old-bg (car (gimp-palette-get-background)))
  105.      )
  106.  
  107.     (gimp-image-undo-disable img)
  108.     (gimp-image-undo-disable tile)
  109.     
  110.     (gimp-image-add-layer img layer-one 0)
  111.     (gimp-image-add-layer tile tiledraw1 0)
  112.     (gimp-image-add-layer tile tiledraw2 0)
  113.  
  114.  
  115.     ;just to look a little better
  116.     (gimp-selection-all img)
  117.     (gimp-palette-set-background backcolor)
  118.     (gimp-edit-fill layer-one BG-IMAGE-FILL)
  119.     (gimp-selection-none img)
  120.  
  121.     (create-tiles tile tiledraw1 tiledraw2 size thickness backcolor forecolor)
  122.     
  123.  
  124.     (while (<= Xindex xtiles)
  125.        (while (<= Yindex ytiles)
  126.           (if (= (rand 2) 0)
  127.               (use-tiles img layer-one height width tile tiledraw1 (* Xindex size) (* Yindex size))
  128.               (use-tiles img layer-one height width tile tiledraw2 (* Xindex size) (* Yindex size))
  129.               )
  130.           (set! Yindex (+ Yindex 1))
  131.           )
  132.        (set! Yindex 0)
  133.        (set! Xindex (+ Xindex 1))
  134.        )
  135.     
  136.     
  137.     (gimp-image-delete tile)
  138.     (gimp-palette-set-background old-bg)
  139.     (gimp-image-undo-enable img)
  140.     (gimp-display-new img)
  141.     )
  142.   )
  143.  
  144. (script-fu-register "script-fu-truchet"
  145.             _"<Toolbox>/Xtns/Script-Fu/Patterns/Truchet..."
  146.             "Create a Truchet pattern \n\nWorks best with even sized thicknesses"
  147.             "Adrian Likins <aklikins@eos.ncsu.edu>"
  148.             "Adrian Likins"
  149.             "1997"
  150.             ""
  151.  
  152.             SF-ADJUSTMENT _"Block Size" '(32 2 512 1 10 1 1)
  153.             SF-ADJUSTMENT _"Thickness" '(2 1 512 1 10 1 1)
  154.             SF-COLOR      _"Background Color" '(255 255 255)
  155.             SF-COLOR      _"Foreground Color" '(0 0 0)
  156.             SF-ADJUSTMENT _"Number of X Tiles" '(5 1 512 1 10 1 1)
  157.             SF-ADJUSTMENT _"Number of Y Tiles" '(5 1 512 1 10 1 1)
  158.             )
  159.