Created
May 15, 2014 15:15
-
-
Save jjmartucci/ff3af10649b586f00719 to your computer and use it in GitHub Desktop.
SASS - Convert HWB to RGB
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 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