;Trying to reproduce this selection here: http://gimpchat.com/viewtopic.php?f=23&t=14475
(define (script-fu-difference-clouds2 image
                                     drawable turbulance seed detail xsize ysize)

  (let* ((draw-offset-x (car (gimp-drawable-offsets drawable)))
         (draw-offset-y (cadr (gimp-drawable-offsets drawable)))
         (has-sel       (car (gimp-drawable-mask-intersect drawable)))
         (sel-offset-x  (cadr (gimp-drawable-mask-intersect drawable)))
         (sel-offset-y  (caddr (gimp-drawable-mask-intersect drawable)))
         (width         (cadddr (gimp-drawable-mask-intersect drawable)))
         (height        (caddr (cddr (gimp-drawable-mask-intersect drawable))))
         (type          (car (gimp-drawable-type-with-alpha drawable)))
         (diff-clouds   (car (gimp-layer-new image width height type
                                             "Clouds" 100 LAYER-MODE-DIFFERENCE-LEGACY)))
         (offset-x      0)
         (offset-y      0)
        )

    (gimp-image-undo-group-start image)

    ; Add the cloud layer above the current layer
    (gimp-image-insert-layer image diff-clouds 0 -1)

    ; Clear the layer (so there are no noise in it)
    (gimp-drawable-fill diff-clouds FILL-TRANSPARENT)

    ; Selections are relative to the drawable; adjust the final offset
    (set! offset-x (+ draw-offset-x sel-offset-x))
    (set! offset-y (+ draw-offset-y sel-offset-y))

    ; Offset the clouds layer
    (if (gimp-item-is-layer drawable)
      (gimp-layer-translate diff-clouds offset-x offset-y))

    ; Show the solid noise dialog
    (plug-in-solid-noise 1 image diff-clouds 0 turbulance seed detail xsize ysize)

    ; Merge the clouds layer with the layer below
    (gimp-image-merge-down image diff-clouds EXPAND-AS-NECESSARY)

    (gimp-image-undo-group-end image)

    (gimp-displays-flush)
  )
)

(define (script-fu-lightning image layer 
			blur-radius
			hue
			gamma
         )
	
		(let* 
		   (
		   (width (car (gimp-image-width image)))
		   (height (car (gimp-image-height image)))
		   )
			;(gimp-image-undo-disable image); DN = NO UNDO
			(gimp-context-push)
			(gimp-image-undo-group-start image)                   ;undo-group in one step
			
			(gimp-context-set-foreground '(255 255 255))
			(gimp-context-set-background '(0 0 0))
			(define active-vectors (car (gimp-image-get-active-vectors image)))
			(define bw-layer (car (gimp-layer-new image width height RGBA-IMAGE "black white" 100 LAYER-MODE-NORMAL-LEGACY)))
			(gimp-image-insert-layer image bw-layer 0 0)
			(gimp-selection-all image)
			(gimp-edit-fill bw-layer FILL-BACKGROUND)
			(gimp-context-set-brush "2. Hardness 100")
			(gimp-context-set-brush-size blur-radius)
			;(gimp-edit-stroke-vectors bw-layer active-vectors)
			(python-fu-vector-to-line-stroke 1 image active-vectors bw-layer "#FFFFFF"  blur-radius ;color width
			                                                                    "round" ;capstyle "butt","square","round"
                                                                                "round" ;joinstyle "miter","round","bevel"
																				10 ;miterlimit google if don't understand what this is)
																				"crispEdges"
			)
			
			
			
			
			
			;repeat this step 
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			(define layer-name "lightning 1")
			(define layer-1 (car (gimp-layer-new image width height RGBA-IMAGE layer-name 100 LAYER-MODE-NORMAL-LEGACY)))
			(gimp-image-insert-layer image layer-1 0 0)
			
			
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-BACKGROUND)
			(gimp-selection-none image)
			(plug-in-gauss 1 image layer-1 blur-radius blur-radius 1)
			
			(script-fu-difference-clouds2 image layer-1 1 1 15 16.0 16.0) ;turbulance seed detail xsize ysize)
			(set! layer-1 (car (gimp-image-get-layer-by-name image layer-name)))
			;select grow feather
			(gimp-image-select-color image CHANNEL-OP-REPLACE bw-layer '(255 255 255))
			(gimp-selection-grow image (* (/(* 6 1.0) 38) blur-radius))
			(gimp-selection-feather image (* (/(* 8 1.0) 38) blur-radius))
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-none image)
			(gimp-invert layer-1)
			(gimp-levels layer-1 HISTOGRAM-VALUE 0 255 gamma 0 255)
			(gimp-colorize layer-1 hue 50 0)
			
			
			
			
			;repeat this step 
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			(define layer-name "lightning 2")
			(define layer-1 (car (gimp-layer-new image width height RGBA-IMAGE layer-name 100 LAYER-MODE-NORMAL-LEGACY)))
			(gimp-image-insert-layer image layer-1 0 0)
			
			
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-BACKGROUND)
			(gimp-selection-none image)
			(plug-in-gauss 1 image layer-1 blur-radius blur-radius 1)
			
			(script-fu-difference-clouds2 image layer-1 1 2 15 16.0 16.0) ;turbulance seed detail xsize ysize)
			(set! layer-1 (car (gimp-image-get-layer-by-name image layer-name)))
			;select grow feather
			(gimp-image-select-color image CHANNEL-OP-REPLACE bw-layer '(255 255 255))
			(gimp-selection-grow image (* (/(* 6 1.0) 38) blur-radius))
			(gimp-selection-feather image (* (/(* 8 1.0) 38) blur-radius))
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-none image)
			(gimp-invert layer-1)
			(gimp-levels layer-1 HISTOGRAM-VALUE 0 255 gamma 0 255)
			(gimp-colorize layer-1 hue 50 0)
			
			
			;repeat this step 
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			(define layer-name "lightning 3")
			(define layer-1 (car (gimp-layer-new image width height RGBA-IMAGE layer-name 100 LAYER-MODE-NORMAL-LEGACY)))
			(gimp-image-insert-layer image layer-1 0 0)
			
			
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-BACKGROUND)
			(gimp-selection-none image)
			(plug-in-gauss 1 image layer-1 blur-radius blur-radius 1)
			
			(script-fu-difference-clouds2 image layer-1 1 3 15 16.0 16.0) ;turbulance seed detail xsize ysize)
			(set! layer-1 (car (gimp-image-get-layer-by-name image layer-name)))
			;select grow feather
			(gimp-image-select-color image CHANNEL-OP-REPLACE bw-layer '(255 255 255))
			(gimp-selection-grow image (* (/(* 6 1.0) 38) blur-radius))
			(gimp-selection-feather image (* (/(* 8 1.0) 38) blur-radius))
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-none image)
			(gimp-invert layer-1)
			(gimp-levels layer-1 HISTOGRAM-VALUE 0 255 gamma 0 255)
			(gimp-colorize layer-1 hue 50 0)
			
			
			;repeat this step 
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			(define layer-name "lightning 4")
			(define layer-1 (car (gimp-layer-new image width height RGBA-IMAGE layer-name 100 LAYER-MODE-NORMAL-LEGACY)))
			(gimp-image-insert-layer image layer-1 0 0)
			
			
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-BACKGROUND)
			(gimp-selection-none image)
			(plug-in-gauss 1 image layer-1 blur-radius blur-radius 1)
			
			(script-fu-difference-clouds2 image layer-1 1 4 15 16.0 16.0) ;turbulance seed detail xsize ysize)
			(set! layer-1 (car (gimp-image-get-layer-by-name image layer-name)))
			;select grow feather
			(gimp-image-select-color image CHANNEL-OP-REPLACE bw-layer '(255 255 255))
			(gimp-selection-grow image (* (/(* 6 1.0) 38) blur-radius))
			(gimp-selection-feather image (* (/(* 8 1.0) 38) blur-radius))
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-none image)
			(gimp-invert layer-1)
			(gimp-levels layer-1 HISTOGRAM-VALUE 0 255 gamma 0 255)
			(gimp-colorize layer-1 hue 50 0)
			
			
			;repeat this step 
			(gimp-image-select-item image CHANNEL-OP-REPLACE active-vectors)
			(define layer-name "lightning 5")
			(define layer-1 (car (gimp-layer-new image width height RGBA-IMAGE layer-name 100 LAYER-MODE-NORMAL-LEGACY)))
			(gimp-image-insert-layer image layer-1 0 0)
			
			
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-BACKGROUND)
			(gimp-selection-none image)
			(plug-in-gauss 1 image layer-1 blur-radius blur-radius 1)
			
			(script-fu-difference-clouds2 image layer-1 1 5 15 16.0 16.0) ;turbulance seed detail xsize ysize)
			(set! layer-1 (car (gimp-image-get-layer-by-name image layer-name)))
			;select grow feather
			(gimp-image-select-color image CHANNEL-OP-REPLACE bw-layer '(255 255 255))
			(gimp-selection-grow image (* (/(* 6 1.0) 38) blur-radius))
			(gimp-selection-feather image (* (/(* 8 1.0) 38) blur-radius))
			(gimp-selection-invert image)
			(gimp-edit-fill layer-1 FILL-FOREGROUND)
			(gimp-selection-none image)
			(gimp-invert layer-1)
			(gimp-levels layer-1 HISTOGRAM-VALUE 0 255 gamma 0 255)
			(gimp-colorize layer-1 hue 50 0)
			
			(gimp-image-remove-layer image bw-layer)
			
		   ;(gimp-image-undo-enable image) ;DN = NO UNDO
			(gimp-image-undo-group-end image)                     ;undo group in one step
			(gimp-context-pop)
			(gimp-displays-flush)
	    )
	
	
    
) ;end of define
(script-fu-register
  "script-fu-lightning"         ;function name
  "<Image>/Script-Fu/Lighting like Zeus ..."    ;menu register
  "Creates 5 lightning frames based on active path"       ;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-ADJUSTMENT "Gaussian Blur Radius" '(38 1 200 1 10 1 0)
  SF-ADJUSTMENT "Colorize Hue" '(224 0 360 1 10 0 0)
  SF-ADJUSTMENT "Levels Gamma" '(0.12 0.10 10.00 1 1 2 0)
  
  ;SF-GRADIENT   "Gradient 1"           ""
  ;SF-GRADIENT   "Gradient 2"           ""
  ;SF-ADJUSTMENT   "Border width pixels" '(50 0 1000 1 10 0 0)
  ;SF-OPTION     "Color Curves Preset" (strbreakup (car (python-fu-get-color-curves-presets-names 1)) ",")
)
