FORUMS: list search recent posts

# Changing color lightness using expression.

FAQ   •   VIEW ALL
 Changing color lightness using expression. on Sep 2, 2015 at 5:43:50 pm

Is there any way to change color lightness using a expression?

 Re: Changing color lightness using expression.on Sep 2, 2015 at 5:56:54 pm

I don't know if this is what you're after, but here's an example that would change the lightness of a Fill effect color to 25% of its current value:

f = .25; // lightness factor
hsl = rgbToHsl(value);
hslToRgb([hsl[0],hsl[1],hsl[2]*f,hsl[3]])

Dan

 Re: Changing color lightness using expression.on May 23, 2016 at 8:33:20 pm

Hi Dan

How to make this "change lightness" work, if I want to link to color control expression

comp("control").layer("control").effect("Color Control")("Color")

Thx!

 Re: Changing color lightness using expression.on May 23, 2016 at 8:57:01 pm

Like this maybe:

c = comp("control").layer("control").effect("Color Control")("Color").value;
f = .25; // lightness factor
hsl = rgbToHsl(c);
hslToRgb([hsl[0],hsl[1],hsl[2]*f,hsl[3]])

Dan

 Re: Changing color lightness using expression.on May 23, 2016 at 9:02:54 pm

It's working. Thx a lot!

 Re: Changing color lightness using expression.on Sep 2, 2015 at 6:12:00 pmLast Edited By Xavier Gomez on Sep 2, 2015 at 6:16:19 pm

Colors are in RGB format.
You have to convert to HLS, lower the "L" then convert back to RGB.

The problem is how much you want to lower.
It can be by a flat amount, or by a percentage of the current value.

amount = 0.2;
c = value;// (or pickwhip a color property)
// convert to HLS
c = rgbToHsl(c);
// lower the L
c[1] = Math.max(0, c[1]-amount);
// back to RGB
hslToRgb(c);

To lower by a certain percentage instead of a flat amount, replace the lowering part by:
c[1] -= c[1]*amount;

In both cases amount should be a number in the range [0,1].

Xavier.

Edit : A bit late, it doesnt bring more !!!