FORUMS: list search recent posts

HEX or RGB to HSL calculator

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Paul Connors
HEX or RGB to HSL calculator
on Mar 20, 2017 at 4:33:41 pm

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!


Return to posts index

Kevin Camp
Re: HEX or RGB to HSL calculator
on Mar 20, 2017 at 6:59:14 pm

i don't know of an easy way to convert hex to RGB color (it would be nice to have a hexToRgb() function....).

since you can enter hex values in the color picker, could you have several color controls on your master color layer that you could add you hex values, and then have the expression compare the master color to those?

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Paul Connors
Re: HEX or RGB to HSL calculator
on Mar 20, 2017 at 7:41:32 pm

Hi Kevin. Thanks for your response. Unfortunately it's kind of an all or nothing thing. The Color Control on my Master Color layer actually has the "sampleImage" function running on it. That's how it's getting it's color value. But I agree, a hexToRgb() function would be great!


Return to posts index


Dan Ebberts
Re: HEX or RGB to HSL calculator
on Mar 20, 2017 at 10:46:28 pm

See if this helps:

hexColor = 0xfbd142;
r = (hexColor >> 16)/255;
g = ((hexColor & 0x00ff00) >> 8)/255;
b = (hexColor & 0xff)/255;
hsl = rgbToHsl([r,g,b,1]);


Dan



Return to posts index

Paul Connors
Re: HEX or RGB to HSL calculator
on Mar 21, 2017 at 11:56:09 am

H Dan. This totally works. How on Earth did you come up with this?!? Thank you very much.


Return to posts index

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