(define (script-fu-SetDivider )
    (begin
        (define canvas-dx 300) ; Define the Wide of the Picture
        (define canvas-dy 200) ; Define the Hight of the Picture
        ; Construct the Image
        (set! image (car (gimp-image-new canvas-dx canvas-dy RGB))) ; Create a New Image with Seetings
        (set! layer (car (gimp-layer-new image canvas-dx canvas-dy RGB-IMAGE "Proj1" 100 0))) ; Creates the layer to paint on it
        
        (gimp-image-add-layer image layer 0) ; Put this Layer to the Image
        
        ;(set! colorfg (gimp-context-get-foreground))
        ; (set! colorbg (gimp-context-get-background))
        (CCdividerWrap 0 200) ; Start Calculation
        (gimp-display-new image); Shows final Result
    )
  )
  
(define ( CCdividerWrap y1 y2)
; My Wraper he decides to make futher Divisions or Paint a Primitive Rectangle
    (begin
        (define dy (- y2 y1)) ; Calculate the hight of the resulting Rectangle 
        (cond
            ((< dy 30) (CCpainter y1 dy))
            ((>= dy 30) (CCdivider y1 y2))
        )
    )
)
  
(define ( CCdivider y1 y2 ) ; Calculate futher Divisions
    (begin
        (define dy1 (+ (random (- y2 y1)) y1 )) ; Calculate the higher Division-Point
        (define dy2 (+ (random (- y2 dy1)) dy1 )) ; Calculate the lower Division-Point
        
        (dividerWrap y1 dy1) ; Try to Estimate Paint or Division for each Part of Division
        (dividerWrap dy1 dy2)
        (dividerWrap dy2 y2)
    )
)

(define (adapt l1 l2 m)
  (if (null? l)
      '()
      (cons ((* (car l1) m) + (* (car l1) ( - 1 m))
            (adapt (cdr l1) ( cdr l2) m))
        )
    )
)
  
(define (CCpainter y dy ) ; Paint the founded Rectangle
    (begin
        (define color (adapt '(12 12 12) '(122 122 122) 0.4) ) ; Defines a shade of Red as Color for the Rectangle
        (gimp-image-select-rectangle image 2 0 y 300 dy ) ; Defines the Shape for the Rectangle
        (gimp-context-set-foreground color) ; Set the Color to fill the Shape of the Rectangle
        (gimp-edit-fill layer FILL-FOREGROUND) ; Paint finally the Rectangle
        
    )
)
    
  
  

 (script-fu-register
    "script-fu-SetDivider"                        ;func name
    "Create an Easy Diveded Canvas"                                  ;menu label
    "This is the second Script for the Divider Project \
     The Chalange of the Divider Project is the simple \
     Divsion of Parameter Space \
     The Easy-Divider does this for a vertical Canvas \
     but between the given Fore and Back-GroundColors"              ;description
    "Thomas Lahme"                             ;author
    "Copyright:: Its under the GPL"        ;copyright notice
    "January 2022"                          ;date created
    ""                     ;image type that the script works on
   )
  (script-fu-menu-register "script-fu-SetDivider" "<Image>/CreCo/Dividers/DividerAboutSetColors/Divider010Test")
