Skip to content

Instantly share code, notes, and snippets.

@jjmartucci
Created May 15, 2014 15:15
Show Gist options
  • Save jjmartucci/ff3af10649b586f00719 to your computer and use it in GitHub Desktop.
Save jjmartucci/ff3af10649b586f00719 to your computer and use it in GitHub Desktop.
SASS - Convert HWB to RGB
@function hslToRgb($hsl-color) {
@return mix($hsl-color,$hsl-color);
}
@function hwbToRgb($hue, $white, $black, $alpha: 1) {
// convert white and black values to decimals
$white: if($white != 0, $white / 100%, $white);
$black: if($black !=0, $black / 100%, $black);
$rgb: hslToRgb(hsl($hue, 100%, 50%));
$red: ( red($rgb) / 255 ) * (1 - $white - $black);
$red: $red + $white;
$green: ( green($rgb) / 255 ) * (1 - $white - $black);
$green: $green + $white;
$blue: ( blue($rgb) / 255 ) * (1 - $white - $black);
$blue: $blue + $white;
@return rgba($red * 255, $green * 255, $blue * 255, $alpha);
}
// hwb here is represented as degree, then white and black as a percentage
$test: hwbToRgb(60, 20%, 20%);
body{
background: $test;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment