All pastes #2009171 Raw Edit

Untitled

public text v1 · immutable
#2009171 ·published 2010-12-03 02:09 UTC
rendered paste body
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; SCRIPT-FU-RANDOM-BRUSH produces an image of a random brush stamps
; version 1.0   12/2/2010
; Copyright (c) 2010   Daniel Wilkerson
;
;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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
;
;Copy of the license at http://td-e.com/site/gpl.php


(define (script-fu-random-brush curr-layer numStamps tempbrush brushColor isRandomColor)

  (let* (
      ; Save the foreground & background colors
      (old-fg (car (gimp-palette-get-foreground)))
      (old-bg (car (gimp-palette-get-background)))
      (old-brush (car (gimp-context-get-brush)))
      (width (car (gimp-drawable-width curr-layer)))
      (height (car (gimp-drawable-height curr-layer)))     
      (image (car (gimp-drawable-get-image curr-layer)))
      (layer-one (car (gimp-layer-new image width height RGB-IMAGE "Stamps" 100 NORMAL-MODE)))
      (ii 0)
      (ns 0)
      (xs 0)
      (ys 0)
      (randomColor brushColor)
      (pixw (cons-array 2 'byte))
    )

    (srand (realtime))
    
    (gimp-image-undo-disable image)
    (gimp-image-add-layer image layer-one 0)

    (gimp-palette-set-foreground brushColor)
    (gimp-layer-add-alpha layer-one)
    (gimp-drawable-fill layer-one 3)  ;0 FG, 1 BG, 2 white, 3 trans   
    (gimp-context-set-brush (car tempbrush))
   
    ;generating stamps
    (while (< ns numStamps)
      (set! ns (+ ns 1))
      (set! xs (rand width))
      (set! ys (rand height))
      (aset pixw 0 (rand width))
      (aset pixw 1 (rand height))
     
          (if (= isRandomColor FALSE)
              (set! randomColor (gimp-image-pick-color image curr-layer xs ys FALSE FALSE 1))
              (gimp-palette-set-foreground randomColor)  
          ); end if
 
      (gimp-paintbrush-default layer-one 2 pixw)

      ; preparing the exit of the loop
      (set! ii (+ ii 1))
      (if (> ii 10000) (set! ns numStamps))
    ) ; end of loop

    ; Restore the old foreground & brush
    (gimp-palette-set-foreground old-fg)
    (gimp-context-set-brush old-brush)

    ;(gimp-display-new image)
    (gimp-image-undo-enable image)
  )
)

(script-fu-register "script-fu-random-brush"
                    "<Toolbox>/Xtns/Script-Fu/Patterns/Random Brush"
                    "Creates a Random Brush pattern."
                    "D. Wilkerson"
                    "D. Wilkerson"
                    "2010.12.02"
                    ""
                    SF-DRAWABLE "Image" 0
                    SF-ADJUSTMENT "Number of Stamps"  '(400 1 10000 10 10 0 1)
                    SF-BRUSH "Brush" '("Circle (03)" 100 44 0)
                    SF-COLOR "Color" '(0 102 255)
                    SF-TOGGLE "Random Color" TRUE			
)