ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

change colour fill based on opacity

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
rosie skinner
change colour fill based on opacity
on Mar 28, 2018 at 9:31:34 am

Hi everybody!

I'm a relative expressions newbie so please excuse my ignorance with this...

I want to have the colour of a layer change based on the opacity of another layer. I want there to be 4 colours so I used an if else expression... can someone please tell me where I'm going wrong... I'd really appreciate some help!


color=effect("Fill")("Color")
num=thisComp.layer("Colour Control Icing").effect("Icing 4")("Opacity");
varWhite=thisComp.layer("Colour Control Icing").effect("Icing 1")("Color");
varBrown=thisComp.layer("Colour Control Icing").effect("Icing 2")("Color");
varPink=thisComp.layer("Colour Control Icing").effect("Icing 3")("Color");
varBlue=thisComp.layer("Colour Control Icing").effect("Icing 4")("Color");

if (num&lt;25){varWhite};
if (num>25 && num&lt;50){varBrown};
if (num&lt;75 && num> 50){varPink};
else (num>75}{varBlue};
color;


Return to posts index

Jamie Bradshaw
Re: change colour fill based on opacity
on Mar 28, 2018 at 11:17:24 am

Hi.

I think there might have been a few errors in what you were trying to achieve. If you want I can try and take you through why as I'm not all that busy at the moment.

Try using this code in the Colour property...

controlLayer = thisComp.layer("Colour Control Icing");
controlOpacity = controlLayer.opacity;

varWhite = controlLayer.effect("Icing 1")("Color");
varBrown = controlLayer.effect("Icing 2")("Color");
varPink = controlLayer.effect("Icing 3")("Color");
varBlue = controlLayer.effect("Icing 4")("Color");

if (controlOpacity &lt; 25) {
varWhite;
} else if (controlOpacity &lt; 50) {
varBrown;
} else if (controlOpacity &lt; 75) {
varPink;
} else {
varBlue;
}


Return to posts index

rosie skinner
Re: change colour fill based on opacity
on Mar 28, 2018 at 11:23:39 am

Thanks so much for the help!

Did you mean post it into the effects - fill - color property? Because I did that and it didn't work... The error is saying Error at line 9 : Expected...?

But also if you could explain it that'd be wonderful!


Return to posts index


Jamie Bradshaw
Re: change colour fill based on opacity
on Mar 28, 2018 at 11:24:04 am

hmm I forgot about that bug... I wonder if this pastes better...



controlLayer = thisComp.layer("Colour Control Icing");
controlOpacity = controlLayer.opacity;

varWhite = controlLayer.effect("Icing 1")("Color");
varBrown = controlLayer.effect("Icing 2")("Color");
varPink = controlLayer.effect("Icing 3")("Color");
varBlue = controlLayer.effect("Icing 4")("Color");

if (controlOpacity < 25) {
varWhite;
} else if (controlOpacity < 50) {
varBrown;
} else if (controlOpacity < 75) {
varPink;
} else {
varBlue;
}



JimJam•Graphics
http://www.jimjamgraphics.com/


Return to posts index

rosie skinner
Re: change colour fill based on opacity
on Mar 28, 2018 at 11:36:03 am

Boom! That works! Thanks so much!

Why do you not need to set a lower parameter? I would have thought that if you are telling the computer that a value under 50 should make it pink and a value under 75 should make it white then for a value of say 40 it wouldn't know whether to choose pink or white?

Also how would it work if I wanted to base it on a slider instead of opacity? I've read the slider doesn't necessarily output a number so it confuses things?


Return to posts index

Jamie Bradshaw
Re: change colour fill based on opacity
on Mar 28, 2018 at 11:54:30 am

In this case you don't need to set a lower parameter because of the 'else' aspect of the 'if' statements.

So... lets say that the opacity is 40... It would get to this line...


if (controlOpacity < 25) {

...and then as 40 is not less than 25 it would jump straight to the next 'else if' bit of code...


} else if (controlOpacity < 50) {

...and as 40 is less than 50 it will execute the code...

varBrown;

...however, it when it gets to the next bit, there is another 'else if'. Which is the same as saying 'otherwise do this'. As it already met the correct conditions, it will ignore that and move on.

Does that make sense?

It's pretty easy to change it to a Slider to control it, but first you'd need to know how you want that slider to behave? Do you still want it to be a value between 0-100 and it acts just the same as when you had it linked to opacity?


Return to posts index


rosie skinner
Re: change colour fill based on opacity
on Mar 28, 2018 at 4:07:28 pm

That makes sense...

Re: the slider control... I've just replaced the opacity control with the slider control and it works perfectly!

Thanks for all your help!


Return to posts index

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