# Help with math logic for applying different lightness weights on colors

I have “colorA” with lightness = 0.69 (0-1)
I want to decrease its lightness to - 0.32

thats a -0.37 decrease

however I also have “colorB” with lightness = 0.16
and for that color I only want to decrease it to - 0.10

thats a -0.6 decrease

How do I achieve this with the same formula for both?

At the moment I have:

``````extraLightness= -0.357f;
finalLightness = originalLightness + extraLightness*(originalLightness *1.5f) ;
``````

this code causes “ColorA” to go from 0.69 to the desired 0.32
however “ColorB” goes from 0.16 to 0.074 (off by ~0.3)

how do I tune this formula so that colors with less lightness are less affected by “extralightness”? I feel like I am somewhat close to what I want already…

What can I do for this formula to apply less 0.3 on the darker color? I realize I’m not off by much but I also don’t quite understand what I can change to affect the range by which lightness changes.

I’m multiplying the decrease in lightness by the original lightness so colors with less original lightness get less affected by the change. But how can I modify the range/degree to how much the difference is supposed to be?

Some pointers with this logic would be appreciated, thanks!

use `AnimationCurve` in a range of [0,1] to define the specific function you want. You can set key values in the curve, and then set how you want the curve to interpolate between the two values. In the editor, it shows a graph view of the curve, so its easy to make adjustments there.

You don’t need to use it with animations, it will work for anything.

I need an actual math formula for this situation

Look up “How to find a polynomial from given points”. If you have only two points, you’re probably only going to be able to find a straight line though.

thanks I will look into it, I can add more points easily

If you want to interpolate with known tangents and slopes between points, you want to use splines, and probably the cubic hermite spline (which is what the `AnimationCurve` uses under the hood).