ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Smooth Change Color linked to a slider

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
massimo ghidini
Smooth Change Color linked to a slider
on May 3, 2020 at 1:23:44 pm

Hi 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% green

All 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


Return to posts index

Dan Ebberts
Re: Smooth Change Color linked to a slider
on May 3, 2020 at 4:29:45 pm

It'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



Return to posts index

massimo ghidini
Re: Smooth Change Color linked to a slider
on May 3, 2020 at 4:44:17 pm

Hi 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


Return to posts index


Dan Ebberts
Re: Smooth Change Color linked to a slider
on May 3, 2020 at 5:07:46 pm

Oops, 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



Return to posts index

Nithish kumar
Re: Smooth Change Color linked to a slider
on May 5, 2020 at 2:00:15 am

Hi 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]