sf change a colors value?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

sf change a colors value?

Nolan Clayton
I don't know if this is the right list but how do you change the Value
(HSV) of a color in script-fu.

I am playing with the sphere script.  And I would like to change the
lighting intensity.

Example:
Color (255 0 0)
I want a new color as if the only the value had been changed to like 50,
so then the new color would be (128 0 0). Thanks in advance.
_______________________________________________
Gimp-user mailing list
[hidden email]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user
Reply | Threaded
Open this post in threaded view
|

Re: sf change a colors value?

Nolan Clayton
Figured it out!  Here is the semifinished script.

;  Create a 3D sphere with optional shadow
;  The sphere's principle color will be the foreground
;  Parameters:
;   bg-color: background color
;   sphere-color: color of sphere
;   radius: radius of the sphere in pixels
;   light:  angle of light source in degrees
;   shadow: whather to create a shadow as well

(define (script-fu-sphere-plus radius
   light
   light-position
   light-intensity
   shadow
   bg-color
   sphere-color
   keep-selection)
   (let* ((width (* radius 3.75))
  (height (* radius 2.5))
  (img (car (gimp-image-new width height RGB)))
  (drawable (car (gimp-layer-new img width height RGB-IMAGE
  "Sphere Layer" 100 NORMAL-MODE)))
  (radians (/ (* light *pi*) 180))
  (cx (/ width 2))
  (cy (/ height 2))
  (light-x (+ cx (* radius (* light-position (cos radians)))))
  (light-y (- cy (* radius (* light-position (sin radians)))))
  (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
  (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
  (offset (* radius 0.1)))

     (gimp-context-push)

     (gimp-image-undo-disable img)
     (gimp-image-add-layer img drawable 0)
     (gimp-context-set-foreground sphere-color)
     (gimp-context-set-background bg-color)
     (gimp-edit-fill drawable BACKGROUND-FILL)

     (set! light-i (list (* (car sphere-color) light-intensity)
  (* (cadr sphere-color) light-intensity)
  (* (caddr sphere-color) light-intensity) ))
     (gimp-context-set-background light-i)

     (if (and
  (or (and (>= light 45) (<= light 75))
      (and (<= light 135) (>= light 105)))
  (= shadow TRUE))
  (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
       (shadow-h (* radius 0.5))
       (shadow-x cx)
       (shadow-y (+ cy (* radius 0.65))))
   (if (< shadow-w 0)
       (prog1 (set! shadow-x (+ cx shadow-w))
      (set! shadow-w (- shadow-w))))

   (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h
        CHANNEL-OP-REPLACE TRUE TRUE 7.5)
   (gimp-edit-bucket-fill drawable BG-BUCKET-FILL MULTIPLY-MODE 100
0 FALSE 0 0)))

     (gimp-ellipse-select img (- cx radius) (- cy radius)
  (* 2 radius) (* 2 radius) CHANNEL-OP-REPLACE TRUE
FALSE 0)

     (gimp-edit-blend drawable FG-BG-RGB-MODE NORMAL-MODE
      GRADIENT-RADIAL 100 offset REPEAT-NONE FALSE
      FALSE 0 0 TRUE
      light-x light-y light-end-x light-end-y)

     (if (= keep-selection FALSE) (gimp-selection-none img))
     (gimp-image-undo-enable img)
     (gimp-display-new img)

     (gimp-context-pop)))

(script-fu-register "script-fu-sphere-plus"
     _"_Sphere Plus..."
     "Simple sphere with a drop shadow"
     "Spencer Kimball, Nolan Clayton"
     ""
     "1996, 2005"
     ""
     SF-ADJUSTMENT _"Radius (pixels)"    '(100 5 500 1 10 0
1)
     SF-ADJUSTMENT _"Lighting (degrees)" '(45 0 360 1 10 0
0)
     SF-ADJUSTMENT _"Lighting (position)"  '(0 0 1 .2 1 1
0)
     SF-ADJUSTMENT _"Lighting (intensity)"  '(0 0 1 .1 1 1
0)
     SF-TOGGLE     _"Shadow"             TRUE
     SF-COLOR      _"Background color"   '(255 255 255)
     SF-COLOR      _"Sphere color"       '(255 0 0)
     SF-TOGGLE    _"Keep Selection"     TRUE
     )


(script-fu-menu-register "script-fu-sphere-plus"
  _"<Toolbox>/Xtns/Script-Fu/Misc")



_______________________________________________
Gimp-user mailing list
[hidden email]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user
Reply | Threaded
Open this post in threaded view
|

Re: sf change a colors value?

Joao S. O. Bueno Calligaris
In reply to this post by Nolan Clayton
On Friday 03 June 2005 04:40, Nolan Clayton wrote:

> I don't know if this is the right list but how do you change the
> Value (HSV) of a color in script-fu.
>
> I am playing with the sphere script.  And I would like to change
> the lighting intensity.
>
> Example:
> Color (255 0 0)
> I want a new color as if the only the value had been changed to
> like 50, so then the new color would be (128 0 0). Thanks in
> advance. _______________________________________________


The Bad news: there are no procedures in the PDB to deal with with RGB
<-> HSV conversion.
When I needed these, I was told to write my own conversion procedure
inside the script. (it was a python script, so it won't fit you).

        JS
        -><-

> Gimp-user mailing list
> [hidden email]
> http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user
_______________________________________________
Gimp-user mailing list
[hidden email]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user
Reply | Threaded
Open this post in threaded view
|

Re: sf change a colors value?

Sven Neumann
Hi,

"Joao S. O. Bueno Calligaris" <[hidden email]> writes:

> The Bad news: there are no procedures in the PDB to deal with with
> RGB <-> HSV conversion.  When I needed these, I was told to write my
> own conversion procedure inside the script. (it was a python script,
> so it won't fit you).

There are RGB <-> HSV conversion routines in libgimpcolor. Language
bindings should provide this functionality.


Sven
_______________________________________________
Gimp-user mailing list
[hidden email]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user
Reply | Threaded
Open this post in threaded view
|

Re: sf change a colors value?

Nolan Clayton
In reply to this post by Nolan Clayton

HSV
In case anyone didn't get this.  Here is how I changed the value of a
color in script-fu.  You could do something similar for Saturation and I
guess hue, not sure though it would create the desired effect if you
played with the hue.


;;sphere-color is a color
;;light-i  will be the new color
;;light-intensity is the new value (HSV)


>    (set! light-i (list (* (car sphere-color) light-intensity) ;;Red
> (* (cadr sphere-color) light-intensity) ;;Green
> (* (caddr sphere-color) light-intensity) )) ;;Blue
>    (gimp-context-set-background light-i)

_______________________________________________
Gimp-user mailing list
[hidden email]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user