Skip to content

Instantly share code, notes, and snippets.

@MaxArt2501
Last active August 31, 2020 17:09
Show Gist options
  • Save MaxArt2501/d9b485166a96b844da9a310549754eaf to your computer and use it in GitHub Desktop.
Save MaxArt2501/d9b485166a96b844da9a310549754eaf to your computer and use it in GitHub Desktop.
CMYK helper functions for SASS
@function cmyk_black($color) {
@return 1 - max(red($color), green($color), blue($color)) / 255;
}
@function cmyk_cyan($color) {
$black: cmyk_black($color);
@return if($black < 1, 1 - red($color) / 255 / (1 - $black), 0);
}
@function cmyk_magenta($color) {
$black: cmyk_black($color);
@return if($black < 1, 1 - green($color) / 255 / (1 - $black), 0);
}
@function cmyk_yellow($color) {
$black: cmyk_black($color);
@return if($black < 1, 1 - blue($color) / 255 / (1 - $black), 0);
}
@function cmyk_lighten($color, $amount) {
$black: cmyk_black($color);
$new-black: max(0, min(1, $black + $amount));
$red: (1 - cmyk_cyan($color)) * (1 - $new-black) * 255;
$green: (1 - cmyk_magenta($color)) * (1 - $new-black) * 255;
$blue: (1 - cmyk_yellow($color)) * (1 - $new-black) * 255;
@return rgba($red, $green, $blue, alpha($color));
}
@function cmyk_darken($color, $amount) {
@return cmyk_lighten($color, -$amount);
}
@function cmyk($cyan, $magenta, $yellow, $black) {
$red: (1 - $cyan) * (1 - $black) * 255;
$green: (1 - $magenta) * (1 - $black) * 255;
$blue: (1 - $yellow) * (1 - $black) * 255;
@return rgb($red, $green, $blue);
}
@function cmyka($cyan, $magenta, $yellow, $black, $alpha) {
@return rgba(cmyk($cyan, $magenta, $yellow, $black), $alpha);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment