I am trying to calculate linear gradient in Elixir.
Something like this
def linear_gradient(percentage, start_color, stop_color), do: color
I was initially thinking of transforming colors to rgb, and calculate percentage for each canal, but I am not sure it will work that way.
Is there someone who can point me to how css linear gradient are calculated? I would like to implement something similar in Elixir. The idea is to visually represent percentages.
Hi @kokolegorille, I don’t know if this is what you want (never had do do something similar before), but I found this spec, see if it helps: CSS Images Module Level 3.
I would consider converting the start and end points to the LAB colour space and then doing the interpolation. LAB separates luminance (the L) which you want to be constant from the colour axes (AB) which you can then interpolate.
Yes, HSV is also good because it’s a perceptual colour space (as is LAB). I suggested LAB because it’s quite simple to interpolate between two points (a1,b1 to a2,b2) keeping L (luminance) constant. But HSL or HSV would be good alternatives.