Forums › Adobe After Effects Expressions › Smooth Change Color linked to a slider
Smooth Change Color linked to a slider
massimo ghidini
May 3, 2020 at 1:23 pmHi everyone!
This is my little problem:I need to create some bars go up&down with different colors applied within this range:
0-30% red
30-70% yellow
70-100% greenAll of that must be linked to a slider. So, there aren’t any problems if the color change on the limit, in a pop way I mean,
because I wrote something like this on the stroke property:r= thisComp.layer(“100%”).effect(“Control Number”)(“Slider”);
if (r<=30){[255,0,0,1]};
if(r>30 && r<70){[255,234,0,1]};
if(r>70){[0,0,255,1]};But I really need to create smooth transition from one color to the other one.
I tried different ways…but nothing works!The last script I wrote is this one:
Col=thisComp.layer(“100%”).effect(“Control Number”)(“Slider”);
red=[255,0,0,1];
yellow=[255,234,0,1];
green=[0,255,0,1];if(Col<30){red};
if(Col>30 && Col<70){yellow};
if(Col>70){green};linear(Col,0,100,red,green)
And the color returns always yellow.
I found some other topic similar to this one but it was around hex numbers, so I had some problems to convert that model into the one I need…Hope to get back some useful tips!!!
Thank you so much!Massimo
Dan Ebberts
May 3, 2020 at 4:29 pmIt’s not clear how you want the colors to change exactly, but this example would change from red to green (with yellow in the middle) across the full range of the slider:
Col=thisComp.layer("100%").effect("Control Number")("Slider");
red=[1,0,0,1];
yellow=[1,1.5,0,1];
green=[0,1,0,1];
if (Col < 50)
linear (Col,0,50,red,yellow)
else
linear (Col,50,100,yellow,green)
Dan
massimo ghidini
May 3, 2020 at 4:44 pmHi Dan!
Thanks so much…it works perfectly!!! ☺Can I ask you to explain why You use the arrays with values 1 or 1.5 instead of 2**, please?
I’m a beginner with all this process.
Thanks a lot anyway!Massimo
Dan Ebberts
May 3, 2020 at 5:07 pmOops, there’s a mistake in there. Yellow should be:
yellow=[1,1,0,1];
In expressions, the color values are normalized to be between 0.0 and 1.0 and expressed as arrays:
[red,green,blue,alpha]
So red is [1,0,0,1], white is [1,1,1,1] etc.
Dan
Nithish kumar
May 5, 2020 at 2:00 amHi massimo ghidini
Pls pay attention that ita a comma between 1 and 5. It’s not 1.5…coz color values can be only from 0 to 1….
Nithish
Log in to reply.