Skip to main content
Participant
February 15, 2023
Answered

Responsive colour change in After Effects

  • February 15, 2023
  • 1 reply
  • 976 views

Hi Everyone,

 

I just want to ask if it's possible to create a responsive colour change in After Effects. I created a composition where I have a white text colour and a dark background.

 

What I wanted is for whenever I change the background to a light colour, the text colour would change to black so the text would still be visible. Is this possible?

 

Thank you very much!

This topic has been closed for replies.
Correct answer Dan Ebberts

If you start with white text, and add a black fill color animator to it, you could add an expression to the range selector's amount property that would sample the center pixel of the background layer and go with black if the luminance is over 50%. Something like this should work:

 

 

bg = thisComp.layer("background");
rgb = bg.sampleImage([bg.width,bg.height]/2,[.5,.5]);
hsl = rgbToHsl(rgb);
hsl[2] > .5 ? 100 : 0

 

 

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
February 15, 2023

If you start with white text, and add a black fill color animator to it, you could add an expression to the range selector's amount property that would sample the center pixel of the background layer and go with black if the luminance is over 50%. Something like this should work:

 

 

bg = thisComp.layer("background");
rgb = bg.sampleImage([bg.width,bg.height]/2,[.5,.5]);
hsl = rgbToHsl(rgb);
hsl[2] > .5 ? 100 : 0

 

 

Participant
February 15, 2023

Hi @Dan Ebberts . Thanks for your response. I tried it but it says Error: expression result must be of dimension 4, not 1 Maybe I can ask if you can drop an EA file here so I can dissect it? >_<

Dan Ebberts
Community Expert
Community Expert
February 15, 2023

Sorry, the expression gets applied to the Amount property in the Advanced section of the Range Selector, not to the Fill Color property.