-
HEX or RGB to HSL calculator
Hi Guys? Does anyone know of a formula or resource for getting the After Effects friendly HSL value for a color? For example, I have a hex value of FBD142…what’s the best way of finding out the HSL color value to include in a script?
What I’m trying to accomplish is setting my text color value to either BLACK or WHITE based on the color of the background Solid layer it is on top of, but also include some IF/ELSE statements assigning BLACK or WHITE text to specific background colors (leaving all other dynamically selected). I’ve been able to get the overall BLACK and WHITE dynamic selection down, but am struggling with the IF/ELSE exception list. I think I’m close, I just need that HSL color value formula. Here’s what I have so far.
A Solid layer named “Master Control” that has a Color Control effect applied and this script in the “Color” parameter:
sampleImage(transform.position)This selects the color of the Solid layer and stores it in the “Color” parameter of the Color Control effect for that Solid layer.
I then have a Text layer named “Sample Text” that has a Fill effect applied. That Fill effect this script attached:
sampleColor = thisComp.layer("Master Color").effect("Color Control")("Color");
hsl = rgbToHsl(sampleColor);if (hsl[2] < 0.5) [1,1,1,1] else [0,0,0,1];
I believe this analyzes the Solid layer color and if the Lightness value is less than 50% it sets the text color to WHITE otherwise set the text color to BLACK.
I would like to add some additional IF/ELSE statements that basically say…If the Lightness value is less than 50% set the color to WHITE otherwise set it to black, unless the background solid color = XXXXXX, or background solid color = YYYYYYY, or background solid color = ZZZZZ, in which case, no matter the Lightness value, set the text color for XXXXXX, or YYYYYY, or ZZZZZZ to WHITE.
This question makes sense in my head but looks ridiculous when I write it out! I’m very sorry about that. Please let me know if I can clear anything up for anyone. Thank you in advance!