I use LESS, and I would like to take advantage by various integrated color functions that allow to set only few basic colors, and then derive others changing Hue, Saturation, Lightness, Spin, ecc.
Let's imagine that we have the following 2 colors (a light-green and a dark-green in this example) in my colorizer:
@primary-color: rgb(0,100,60);
@secondary-color: rgb(185,215,50);
I would like to explicitly set only @primary-color
and then obtain @secondary-color
after an appropriate HSL transformation. (for example darken(hsl(90, 80%, 50%), 20%
) )
Is there any way to determine what hsl setting I have to apply to @primary-color
in order to gain @secondary-color
?
In other words:
Given 2 RGB color definitions, is there any way to determine what difference in terms of Hue, Saturation and Lightness, exist between them, to express @secondary-color
as a variations of @primary-color
?
P.S.: maybe also with help of external tools like Photoshop, if necessary.
Here is the way to calculate the difference between the hue, saturation and lightness values of two colors and then use it to calculate the second color based on the first.
The individual steps are as follows:
hue()
,saturation()
andlightness()
functions. This function can be used separately just to output the differences alone.spin()
function by passing the hue difference between the two colorssaturate()
ordesaturate()
functions depending on the difference.darken()
orlighten()
functions depending on the difference.This answer is a Less adaptation of this SASS Article on how to calculate one color from another.
Compiled CSS:
If you would just wish to obtain the differences between two colors, then you could use a loop like below to output the differences in terms of hue, saturation and lightness values.
The above code will compare the corresponding values in both lists and output their difference like below: