Skip to content

Compass Dependancy  #1

@DarbyBrown

Description

@DarbyBrown

It was brought to my attention that sin and cos are functions of Compass not Sass.
So if you don't use Compass here is a an alternative function for sin and cos.
I haven't tested it yet but will report back when I do.

Created by Jelmer Borst - https://twitter.com/japborst

$pi: 3.14159265359;

@function pow($base,$exp){
    $value: $base;
    @if $exp > 1{
        @for $i from 2 through $exp{
            $value: $value * $base;
        }
    }
    @if $exp < 1{
        @for $i from 0 through -$exp{
            $value: $value / $base;
        }
    }
    @return $value;
}
@function fact($val){
    $value: 1;
    @if $val > 0{
        @for $i from 1 through $number{
            $value: $value * $i;
        }
    }
}

@function sin($angle, $degrees: false){
    $sin: 0
    @if $degrees{
        $degrees: $degrees / 180 * $pi;
    }
    @for $n from 1 through 10{
        $sin: $sin + ( pow(-1,n) / fact(2n+1) ) * pow($angle,(2n+1));
    }
    @return $sin;
}
@function cos($angle, $degrees: false){
    $cos: 0
    @if $degrees{
        $degrees: $degrees / 180 * $pi;
    }
    @for $n from 1 through 10{
        $cos: $cos + ( pow(-1,n) / fact(2n) ) * pow($angle,2n);
    }
    @return $cos;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions