Skip to content

Instantly share code, notes, and snippets.

@nuintun
Created July 2, 2020 08:05
Show Gist options
  • Save nuintun/6131415298f30dcede37eabb5be23736 to your computer and use it in GitHub Desktop.
Save nuintun/6131415298f30dcede37eabb5be23736 to your computer and use it in GitHub Desktop.
hex 和 rgb 颜色转换
function rgb2hex(red, green, blue) {
const rgb = (red << 16) | (green << 8) | blue;
return `#${rgb.toString(16).padStart(6, '0')}`;
}
function hex2rgb(hex) {
return [(hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment