Created
January 18, 2024 13:05
-
-
Save OkancanCosar/0c39a80d0aae933d3862bac98e6c357f to your computer and use it in GitHub Desktop.
percentage to hex color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const perc2color = (perc: number) => { | |
var r, g, b = 0; | |
if (perc < 50) { | |
r = 255; | |
g = Math.round(5.1 * perc); | |
} | |
else { | |
g = 255; | |
r = Math.round(510 - 5.10 * perc); | |
} | |
var h = r * 0x10000 + g * 0x100 + b * 0x1; | |
return '#' + ('000000' + h.toString(16)).slice(-6); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment