; script: SphereFold.scm
; author: Tin Tran
; date: April 18, 2016
; experimental

(define (script-fu-random-font image layer 
            font
            font-size		
            characters			
         )
	
		(let* 
		   (
		   (width (car (gimp-image-width image)))
		   (height (car (gimp-image-height image)))
		   (count 0)
		   (text-layer 0)
		   (alphabet '("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
		   )
			;(gimp-image-undo-disable image); DN = NO UNDO
			
			(gimp-image-undo-group-start image)                   ;undo-group in one step
			(while (< count characters)
			    (gimp-context-set-foreground (list (rand 256)(rand 256)(rand 256)))
				(set! text-layer (car (gimp-text-layer-new image (list-ref alphabet (rand 52))
										   font
										   font-size
										   0
									  )
								 )
				)
				(gimp-image-insert-layer image text-layer 0 0)
				(gimp-item-transform-rotate text-layer (/(*(*(rand 360)2)3.1415) 360)
				                                       TRUE 0 0
				)
				(gimp-layer-translate text-layer (rand width) (rand height))
				(set! count (+ count 1))
			)
			
			
			
		   ;(gimp-image-undo-enable image) ;DN = NO UNDO
			(gimp-image-undo-group-end image)                     ;undo group in one step
			(gimp-displays-flush)
	    )
	
	
    
) ;end of define
(script-fu-register
  "script-fu-random-font"         ;function name
  "<Image>/Script-Fu/Create New/Random Font ..."    ;menu register
  "Creates A random font background"       ;description
  "Tin Tran"                          ;author name
  "copyright info and description"         ;copyright info or description
  "2016"                          ;date
  "RGB*, GRAY*"                        ;mode
  SF-IMAGE      "Image" 0                   
  SF-DRAWABLE   "Layer" 0
  SF-FONT "Font" "Sans"
  SF-ADJUSTMENT "Font Size(pixels)" '(50 10 8000 1 10 0 0)
  SF-ADJUSTMENT "Characters to generate" '(200 10 8000 1 10 0 0)
)
