Created
March 4, 2016 02:33
-
-
Save mishelen/ee3486838405af2a73dd to your computer and use it in GitHub Desktop.
математика в SCSS
возведение в степень, факториал, тригонометрия
This file contains hidden or 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 fact($number) { | |
| $value: 1; | |
| @if $number > 0 { | |
| @for $i from 1 through $number { | |
| $value: $value * $i; | |
| } | |
| } | |
| @return $value; | |
| } |
This file contains hidden or 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 pow($number, $exp) { | |
| $value: 1; | |
| @if $exp > 0 { | |
| @for $i from 1 through $exp { | |
| $value: $value * $number; | |
| } | |
| } | |
| @else if $exp < 0 { | |
| @for $i from 1 through -$exp { | |
| $value: $value / $number; | |
| } | |
| } | |
| @return $value; | |
| } |
This file contains hidden or 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 pi() { | |
| @return 3.14159265359; | |
| } | |
| @function rad($angle) { | |
| $unit: unit($angle); | |
| $unitless: $angle / ($angle * 0 + 1); | |
| // If the angle has 'deg' as unit, convert to radians. | |
| @if $unit == deg { | |
| $unitless: $unitless / 180 * pi(); | |
| } | |
| @return $unitless; | |
| } | |
| @function sin($angle) { | |
| $sin: 0; | |
| $angle: rad($angle); | |
| // Iterate a bunch of times. | |
| @for $i from 0 through 10 { | |
| $sin: $sin + pow(-1, $i) * pow($angle, (2 * $i + 1)) / fact(2 * $i + 1); | |
| } | |
| @return $sin; | |
| } | |
| @function cos($angle) { | |
| $cos: 0; | |
| $angle: rad($angle); | |
| // Iterate a bunch of times. | |
| @for $i from 0 through 10 { | |
| $cos: $cos + pow(-1, $i) * pow($angle, 2 * $i) / fact(2 * $i); | |
| } | |
| @return $cos; | |
| } | |
| @function tan($angle) { | |
| @return sin($angle) / cos($angle); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment