Copy link to clipboard
Copied
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!
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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? >_<
Copy link to clipboard
Copied
Sorry, the expression gets applied to the Amount property in the Advanced section of the Range Selector, not to the Fill Color property.
Copy link to clipboard
Copied
Oh my god! That worked!!! Thank you so much @Dan Ebberts . I really appreciate your help. 🙂