0

I have a linear gradient like below: linearGradient

HTML object after created haves:

childNodes: NodeList(7)
0: <stop offset="0%" stop-color="#0080ff">​​​
1: <stop offset="7.142857142857142%" stop-color="#00ff00">​​​
2: <stop offset="21.428571428571427%" stop-color="#ffff00">​​​
3: <stop offset="35.714285714285715%" stop-color="#ffa500">​​​
4: <stop offset="57.14285714285714%" stop-color="#ff0000">​​​
5: <stop offset="78.57142857142857%" stop-color="#8A2BE2">​​​
6: <stop offset="100%" stop-color="#800080">

​​ javascript object like:

    myGradient = {
      20: "#0080ff",
      25: "#00ff00",
      35: "#ffff00",
      45: "#ffa500",
      60: "#ff0000",
      75: "#8A2BE2",
      90: "#800080"
    }

How can i inverse a RGB color back to value like example: RGB(255, 124, 0) => 57?

I have searched but answers were % of linear gradient to rgb. Not rgb back to value. Many thanks!

  • Isn't it just random percentage that does not directly reflect color? I don't think you can calculate that out, unless you have some formula for that. E.g. `(R + G + B) * coef = 57`, than `(255 + 124) * 6.64912 ~= 57` – Justinas Jul 27 '23 at 09:47
  • I think you are looking for Hue and [how to calculate it](https://stackoverflow.com/questions/23090019/fastest-formula-to-get-hue-from-rgb) – Moritz Ringler Jul 27 '23 at 10:37

0 Answers0