Last active
March 19, 2018 20:08
-
-
Save mauroreisvieira/ab7f9e9d3c7daa676955ca4d590fa3ce to your computer and use it in GitHub Desktop.
Functions to use in SCSS
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 sqrt($r) { | |
$x0: 1; | |
$x1: $x0; | |
@for $i from 1 through 10 { | |
$x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0); | |
$x0: $x1; | |
} | |
@return $x1; | |
} | |
@function convert-units($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@function strip-unit($number) { | |
@if type-of($number) == "number" and not unitless($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@return $number; | |
} | |
@function get-hsb-b($s-hsl, $l-hsl) { | |
$s-hsl: strip-unit($s-hsl); | |
$l-hsl: strip-unit($l-hsl); | |
@return (($l-hsl/100 * 2) + ($s-hsl/100 * (1 - abs(2 * $l-hsl/100 - 1)))) * 100 / 2; | |
} | |
@function get-hsb-s($s-hsl, $l-hsl) { | |
$b-hsb: get-hsb-b($s-hsl, $l-hsl); | |
@return ((2 * ($b-hsb - $l-hsl)) / $b-hsb) * 100; | |
} | |
@function hsb($h-hsb, $s-hsb, $b-hsb, $a: 1) { | |
@if $b-hsb == 0 { | |
@return hsla(0, 0, 0, $a); | |
} | |
@else { | |
$l-hsl: ($b-hsb/2) * (2 - ($s-hsb/100)); | |
$s-hsl: ($b-hsb * $s-hsb) / if($l-hsl < 50, $l-hsl * 2, 200 - $l-hsl * 2); | |
@return hsla($h-hsb, $s-hsl, $l-hsl, $a); | |
} | |
} | |
@function convert-rem($pixels, $context: $font-size-body) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} | |
@if (unitless($context)) { | |
$context: $context * 1px; | |
} | |
@return $pixels / $context * 1rem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment