Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142218

Convert percentage to colors in javascript

$
0
0

I would like to generate color according to value from -1 to 1

the base colors are

My gaps are H:0 =1, H:60 = 0.5 , H:170= 0, H:200= -1 ( S:100 and L:50 ) enter image description here

I have found an example that convert percentage from green to red.

function percentageToColor(percentage, maxHue = 200, minHue = 0) {
  const hue = percentage * (maxHue - minHue) + minHue;
  return `hsl(${hue}, 100%, 50%)`;
}

I would like to adapt it to my case by adding blue and use values from -1 to 1 by respecting the gaps equivalences as I mentioned above but I don't see how to do it.

Upate

I would like to use HSL/HSV

I'm looking for a way to find relation between percentage and H value


Viewing all articles
Browse latest Browse all 142218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>