Created
August 3, 2024 03:26
-
-
Save nakajmg/8232c887fe1e9e95401c63147ddee409 to your computer and use it in GitHub Desktop.
This function calculates the color value for a specified color code as it appears when an opacity is applied to it, matching the visual appearance of the color as if the opacity was not applied.
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
function adjustColorWithOpacity({r, g, b, alpha}) { | |
return [r,g,b].map((v) => { | |
const _alpha = Math.round((1 - alpha)* 10) / 10; | |
return Math.max(Math.round((v - (_alpha) * 255) / (alpha)), 0) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment