Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

A little Subroutine to build Means between two Dimensional Vectors

Thu Jan 27, 2022 1:21 pm

Dear Community,
:roll: I'm really silly but why Workings followed Code not :roll:
Code:
(define (adapt l1 l2 m)
  (if (null? l)
      '()
      (cons ((* (car l1) m) + (* (car l1) ( - 1 m))
            (adapt (cdr l1) ( cdr l2) m))
        )
    )
)
 
(define (painter 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
       
    )
)


:oops: The Idea behind this Code is to Mixing both Colors:
Color1 '(12 12 12)
Color2 '(122 122 122)
Not when the Subroutine Painter is called
Which Should Paint a Rectangle Across the Screen
And in the Hights y yd :geek

:gaah Dear Community I hope you can help me.
But it can been that this is Working, and Mistake
is anywhere Else in my Program. :hoh

Thomas Lahme

P.S.: The Complete Program is attached. But in this Version the Canvas must Uniformy Colored, but the Program results in a Mixed Colored Image.

Re: A little Subroutine to build Means between two Dimensional Vectors

Thu Jan 27, 2022 2:26 pm

Hello

    adapt does not work because:
  • "l" is not defined. It is supposed to be l1
  • The + operator is between its two operands instead to start its list

adapt is the identity function independently of l2 and m. It always returns its first operand l1.
Since
R => R*m - R*(m-1) = R
G => G*m - G*(m-1) = G
B => B*m - B*(m-1) = B
Note your inversion (- 1 m) meaning that it is not an addition but a subtraction.

Never use l1 or l2 because it is so clause of 11 or 12.
It is about color so call them color1 and color2.

Never use a parameter having only one letter such as m.
It is not about mathematics!

Always align parenthesis.
Always give an example with the expected result.
Code:
(define (adapt color1 color2 ratio)
   (if (null? color1)
      '()
      (cons   (+(* (car color1) ratio) (* (car color1) (- 1 ratio)))
            (adapt (cdr color1) (cdr color2) ratio)
)   )   )


In the Script-Fu console:
Code:
(adapt  '(12 12 12)  '(it does not matter) 0.4)

The expected result will be:
(12.0 12.0 12.0)

Re: A little Subroutine to build Means between two Dimensional Vectors

Fri Jan 28, 2022 9:33 am

Hey AlSchemist,
I have tested your Script and have found an Error which leads me to another Error.
Code:
> (define (adapt color1 color2 ratio)
   (if (null? color1)
      '()
      (cons   (+(* (car color1) ratio) (* (car color2) (- 1 ratio)))
            (adapt (cdr color1) (cdr color2) ratio)
)   )   )
adapt
> (adapt  '(12 12 12)  '(1 1 1) 0.4)
(5,4.0 5,4.0 5,4.0)
> (adapt  '(12 12 12)  '(12 12 12) 0.4)
(12.0 12.0 12.0)
> (adapt  '(12 12 12)  '(6 6 6) 0.4)
(8,4.0 8,4.0 8,4.0)


I hope you can see that I must changed the Second Color1 to Color2.
This is in Because I need the Mixing between Color1 and Color2.
Then I have get another Error, When I give the Subroutine equal Lists all working.
But when I try to mix different Lists I got duplicated Values near the Right Result but computational Wrong.

So I now have tried to address Results which are Integer-Lists,
Code:
> (adapt  '(12 12 12)  '(6 6 6) 0.5)
(9.0 9.0 9.0)
> (adapt  '(12 12 12)  '(0 0 0) 0.5)
(6.0 6.0 6.0)
> (adapt  '(12 12 12)  '(0 0 0) 0.75)
(9.0 9.0 9.0)

then It works perfectly

I think that I have understand the Mathematical Background, and them seams correct
but can Anybody find the Problem.
Post a reply