Notifications
Clear all

[Closed] color values question

hello,
im fairly new to scripting and I have a little questions concerning color values;
Im trying to write a little script that would allow me to randomize values of the transparency filter color, after ive selected one from a color picker, and then specified how much “randomizing” I want.
So far Ive written this:

rollout simplewindow “randomize the transp. color value”
(
spinner transpcolorrandom “how much randomizing” range:[0,100,20] type:#integer
colorpicker filtre “transp. filter” color:[40,60,20]
button letsgo “GO”

  on letsgo pressed do

(
(for obj in selection do
obj.material.filtercolor=color (“red value of filtre”+(random 0 transpcolorrandom)) (“green value of filtre”+(random 0 transpcolorrandom)) (“blue value of filtre”+(random 0 transpcolorrandom))

)

)
createdialog simplewindow width:200 height:200

so how can i get here the Red, green and blue values of color variable ‘filtre’?
thanks i advance =)

2 Replies

Color values are practically interchangeble with point3 values, so what you could do is cast your filtercolor to a point3, and then use the .x, .y, and .z values. The only problem with that is that the random function has the potential to create oob (255<X<0) results, so you’d probably need to run your point3 through a function that does:


fn clampColor color =
( 
if color.x > 255 then color.x = 255
if color.x < 0 then color.x = 0
 
if color.y > 255 then color.y = 255
if color.y < 0 then color.y = 0
 
if color.z > 255 then color.z = 255
if color.z < 0 then color.z = 0
)

and then you can safely modify your color values like:


filterColorP3 = obj.material.filtercolor as point3
filterColorP3 = [filterColorP3.x+(random 0 transpcolorrandom), filterColorP3.y+(random 0 transpcolorrandom), filterColorP3.z+(random 0 transpcolorrandom)]
filterColorP3 = (clampColor filterColorP3) as color

hope that helps

edit: that clampColor() argument is probably not the best named argument out there; it’s actually wanting a point3 value, not a color value.

Thank you very much, im gonna try this asap,
Ill post the end result when its done, Im doing it basically to modify imported objects (likes trees from VUE) so their opacity, specular, diffuse etc. maps behave nicely with sublte changes from one to another.
It might help some people as well, who knows.