FORUMS: list search recent posts

If/Else statement to control text color

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Paul Connors
If/Else statement to control text color
on Nov 7, 2016 at 1:26:40 pm

Hi Guys. I'm trying to write an If/Else statement to control the color of a text layer based on the color of a solid. In short, I want to either have the text be black if the solid color is on the lighter side or have the text be white if the solid color is on the darker side. I have a solid layer named "Solid 1" that has a color control effect on it and uses the sampleImage expression to determine it's own color. I then have a text layer named "Text 1" with a Fill effect that has it's color parameter pickwhipped to the color parameter of the color control effect on "Solid 1." What that does is make "Text 1" the same color as "Solid 1." Now I just need to add an If/Else statement within the Fill effect on Text 1 that says: if the color sample from solid one is above this brightness threshold then make this fill output = black (000000), else make this fill output = white (FFFFFF), but I don't know how to accomplish that. Any help would be greatly appreciated!

Solid 1 has an Color Control effect with a color parameter named: "Color." Here is the expression on that layer:

thisComp.layer("Solid 1").effect("Color Control")("Color")

Text 1 has a Fill effect with a Color parameter named: "Color." Here is the expression on that layer:

thisComp.layer("Solid 1").effect("Color Control")("Color")

-Thanks,
Paul


Return to posts index

Fredrik Åkerlund
Re: If/Else statement to control text color
on Nov 7, 2016 at 6:05:47 pm

Ok, first of all: I have the flu so forgive my mistakes and lack of clarity but something like this should work:

Use the function sampleimage() to sample color of a layer.
Convert from RGB to HSL (rgbToHsl()).
Check the value of the HSL arrays ”lightness” value and if it´s less than 0.5, set text color to white, else set text color to white.

or in some pseudocode:

sampleColor = targetLayer.sampleImage(samplePoint, sampleRadius);

hsl = rgbToHsl(sampleColor);

if (hsl[2] < 0.5)
set text color to white
else
set text color to black

I´ll try it later and post some proper code if I just manage to get out of bed. :)


Return to posts index

Paul Connors
Re: If/Else statement to control text color
on Nov 8, 2016 at 3:17:45 pm

Hi Fredrik. This worked perfectly...thank you very much! I hope you're feeling better. Having the flu is a real downer.

For anyone else interested this is what the final code looked like:

• Solid layer named "Solid-1" with a Color Control effect. This expression is on the "Color" parameter within the Color Control effect:
sampleImage(anchorPoint, [1,1], true, time)
• Text layer named "Text-1" with a Fill effect. This expression is on the "Color" parameter within the Fill effect:
sampleColor = thisComp.layer("Solid-1").effect("Color Control")("Color");
hsl = rgbToHsl(sampleColor);
if (hsl[2] < 0.5) [1,1,1,1] else [0,0,0,1];


Hope that helps someone in the future. And all credit goes to Mr. Fredrik Akerlund who posted to this thread above. Thanks again Fredrik!


Return to posts index


Cassius Marques
Re: If/Else statement to control text color
on Nov 7, 2016 at 6:10:52 pm

Try to add c=thisComp.layer("Solid 1").effect("Color Control")("Color");
((c[0]>0.5)||(c[1]>0.5)||(c[2]>0.5)?[0,0,0,0]:[1,1,1,1])
to the fill effect

Cassius Marques
http://www.zapfilmes.com


Return to posts index

Paul Connors
Re: If/Else statement to control text color
on Nov 8, 2016 at 3:28:42 pm

Huzzah. This works as well!!! Thank you very much Mr, Marques!


Return to posts index

Fredrik Åkerlund
Re: If/Else statement to control text color
on Nov 8, 2016 at 5:50:49 pm

I'm glad it worked and happy to help. I'll have to try it myself because now I get all these ideas... :D


Return to posts index

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