Created
May 22, 2022 21:52
-
-
Save felix-lipski/e6cd94adaa449304018e665856d5a3a0 to your computer and use it in GitHub Desktop.
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 numWithOpacity = (nums, by) => | |
"#" + | |
nums.map((x) => Math.round(x + (255 - x) * (1 - by)).toString(16)).join(""); | |
const hexWithOpacity = (rgbHex, by) => | |
numWithOpacity( | |
[rgbHex.slice(1, 3), rgbHex.slice(3, 5), rgbHex.slice(5, 7)].map((hex) => | |
parseInt(hex, 16) | |
), | |
by | |
); | |
// console.log(hexWithOpacity("#000000", 0.26)); | |
console.log(numWithOpacity([0, 0, 0], 0.54)); | |
// console.log(numWithOpacity([33, 33, 33], 0.26)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment