sassy-math 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sassy-math.rb +9 -0
- data/sassy-math.gemspec +24 -0
- data/stylesheets/_math.scss +271 -0
- metadata +81 -0
    
        data/lib/sassy-math.rb
    ADDED
    
    
    
        data/sassy-math.gemspec
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Gem::Specification.new do |s|
         | 
| 4 | 
            +
              s.name = %q{sassy-math}
         | 
| 5 | 
            +
              s.version = "0.1.0"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5")
         | 
| 8 | 
            +
              s.authors = ["Sam Richard", "Mario Valencia", "Scott Kellum"]
         | 
| 9 | 
            +
              s.date = %q{2012-01-19}
         | 
| 10 | 
            +
              s.description = %q{Use advanced mathematical functions in Compass.}
         | 
| 11 | 
            +
              s.email = %w{scott@scottkellum.com}
         | 
| 12 | 
            +
              s.has_rdoc = false
         | 
| 13 | 
            +
              s.files = [
         | 
| 14 | 
            +
                "sassy-math.gemspec",
         | 
| 15 | 
            +
                "lib/sassy-math.rb",
         | 
| 16 | 
            +
                "stylesheets/_math.scss"
         | 
| 17 | 
            +
              ]
         | 
| 18 | 
            +
              s.homepage = %q{https://github.com/scottkellum/Sassy-math}
         | 
| 19 | 
            +
              s.require_paths = ["lib"]
         | 
| 20 | 
            +
              s.rubyforge_project = %q{sassy-math}
         | 
| 21 | 
            +
              s.rubygems_version = %q{0.1.0}
         | 
| 22 | 
            +
              s.summary = %q{Use advanced mathematical functions in Compass.}
         | 
| 23 | 
            +
              s.add_dependency(%q<compass>, ["~> 0.11"])
         | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,271 @@ | |
| 1 | 
            +
            // SASSY MATH
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            @charset "UTF-8";
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            //////////////////////////////
         | 
| 6 | 
            +
            // Variables
         | 
| 7 | 
            +
            //////////////////////////////
         | 
| 8 | 
            +
            $pi: pi();
         | 
| 9 | 
            +
            $π: pi();
         | 
| 10 | 
            +
            $e: 2.71828182845904523536028747135266249775724709369995;
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            $iter: 50;
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            //////////////////////////////
         | 
| 15 | 
            +
            // Random Number
         | 
| 16 | 
            +
            //   Working from http://xkcd.com/221/
         | 
| 17 | 
            +
            //    Chosen by fair dice roll.
         | 
| 18 | 
            +
            //    Guarenteed to be random.
         | 
| 19 | 
            +
            //////////////////////////////
         | 
| 20 | 
            +
            @function rand() {
         | 
| 21 | 
            +
              @return 4;
         | 
| 22 | 
            +
            }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            //////////////////////////////
         | 
| 25 | 
            +
            // Percent
         | 
| 26 | 
            +
            //////////////////////////////
         | 
| 27 | 
            +
            @function percent($number) {
         | 
| 28 | 
            +
              @return $number * 0.01; 
         | 
| 29 | 
            +
            }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            //////////////////////////////
         | 
| 32 | 
            +
            // Exponent
         | 
| 33 | 
            +
            //////////////////////////////
         | 
| 34 | 
            +
            @function exponent($base, $exponent) {
         | 
| 35 | 
            +
              // reset value
         | 
| 36 | 
            +
              $value: $base;
         | 
| 37 | 
            +
              // positive intergers get multiplied
         | 
| 38 | 
            +
              @if $exponent > 1 {
         | 
| 39 | 
            +
                @for $i from 2 through $exponent {
         | 
| 40 | 
            +
                  $value: $value * $base; } }
         | 
| 41 | 
            +
              // negitive intergers get divided. A number divided by itself is 1
         | 
| 42 | 
            +
              @if $exponent < 1 {
         | 
| 43 | 
            +
                @for $i from 0 through -$exponent {
         | 
| 44 | 
            +
                  $value: $value / $base; } }
         | 
| 45 | 
            +
              // return the last value written
         | 
| 46 | 
            +
              @return $value; 
         | 
| 47 | 
            +
            }
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            @function pow($base, $exponent) {
         | 
| 50 | 
            +
              @return exponent($base, $exponent);
         | 
| 51 | 
            +
            }
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            //////////////////////////////
         | 
| 54 | 
            +
            // Factorial
         | 
| 55 | 
            +
            //////////////////////////////
         | 
| 56 | 
            +
            @function factorial($number) {
         | 
| 57 | 
            +
              // reset value
         | 
| 58 | 
            +
              $value: 1;
         | 
| 59 | 
            +
              // positive intergers get multiplied
         | 
| 60 | 
            +
              @if $number > 0 {
         | 
| 61 | 
            +
                @for $i from 1 through $number {
         | 
| 62 | 
            +
                  $value: $value * $i; 
         | 
| 63 | 
            +
                } 
         | 
| 64 | 
            +
              }
         | 
| 65 | 
            +
              @return $value;
         | 
| 66 | 
            +
            }
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            @function fact($number) {
         | 
| 69 | 
            +
              @return factorial($number); 
         | 
| 70 | 
            +
            }
         | 
| 71 | 
            +
             | 
| 72 | 
            +
             | 
| 73 | 
            +
            //////////////////////////////
         | 
| 74 | 
            +
            // Polynomial Approximation
         | 
| 75 | 
            +
            //////////////////////////////
         | 
| 76 | 
            +
            // Maclaurin series can be used to estimate Sine and Consine
         | 
| 77 | 
            +
            @function maclaurin($start, $key, $number) {
         | 
| 78 | 
            +
              $value: $start;
         | 
| 79 | 
            +
              $add: 0;
         | 
| 80 | 
            +
              
         | 
| 81 | 
            +
              @for $i from 1 through $iter {
         | 
| 82 | 
            +
                @if $add == 0 {
         | 
| 83 | 
            +
                  $value: $value - ( exponent($number, $key) / factorial($key) );
         | 
| 84 | 
            +
                  $add: 1;
         | 
| 85 | 
            +
                }
         | 
| 86 | 
            +
                @else {
         | 
| 87 | 
            +
                  $value: $value + ( exponent($number, $key) / factorial($key) );
         | 
| 88 | 
            +
                  $add: 0;
         | 
| 89 | 
            +
                }
         | 
| 90 | 
            +
                
         | 
| 91 | 
            +
                $key: $key + 2;
         | 
| 92 | 
            +
              }
         | 
| 93 | 
            +
              
         | 
| 94 | 
            +
              @return $value;
         | 
| 95 | 
            +
            }
         | 
| 96 | 
            +
            // Taylor series can be used to estiamte ln
         | 
| 97 | 
            +
            @function taylor($number) {
         | 
| 98 | 
            +
              @return taylor;
         | 
| 99 | 
            +
            }
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            //////////////////////////////
         | 
| 102 | 
            +
            // Basic Trig Functions
         | 
| 103 | 
            +
            //////////////////////////////
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            // BUILT INTO COMPASS :: http://compass-style.org/reference/compass/helpers/trig/
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            //@function sin($number, $unit: 'deg') {
         | 
| 108 | 
            +
            //  @if $unit == 'deg' {
         | 
| 109 | 
            +
            //    $number: deg-to-rad($number);
         | 
| 110 | 
            +
            //  }
         | 
| 111 | 
            +
            //  @return maclaurin($number, 3, $number);
         | 
| 112 | 
            +
            //}
         | 
| 113 | 
            +
            //
         | 
| 114 | 
            +
            //@function cos($number, $unit: 'deg') {
         | 
| 115 | 
            +
            //  @if $unit == 'deg' {
         | 
| 116 | 
            +
            //    $number: deg-to-rad($number);
         | 
| 117 | 
            +
            //  }
         | 
| 118 | 
            +
            //  @return maclaurin(1, 2, $number);
         | 
| 119 | 
            +
            //}
         | 
| 120 | 
            +
            //
         | 
| 121 | 
            +
            // Trig Identity: Tangent = Sine divided by Cosine.
         | 
| 122 | 
            +
            //@function tan($number, $unit: 'deg') {
         | 
| 123 | 
            +
            //  @if $unit == 'deg' {
         | 
| 124 | 
            +
            //    $number: deg-to-rad($number);
         | 
| 125 | 
            +
            //  }
         | 
| 126 | 
            +
            //  @return sin($number) / cos($number); 
         | 
| 127 | 
            +
            //}
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            //////////////////////////////
         | 
| 130 | 
            +
            // Reciprocal Trig Functions
         | 
| 131 | 
            +
            //////////////////////////////
         | 
| 132 | 
            +
            @function csc($number, $unit: 'deg') {
         | 
| 133 | 
            +
              @if $unit == 'deg' {
         | 
| 134 | 
            +
                $number: deg-to-rad($number);
         | 
| 135 | 
            +
              }
         | 
| 136 | 
            +
              @return 1 / sin($number);
         | 
| 137 | 
            +
            }
         | 
| 138 | 
            +
             | 
| 139 | 
            +
            @function scs($number, $unit: 'deg') {
         | 
| 140 | 
            +
              @if $unit == 'deg' {
         | 
| 141 | 
            +
                $number: deg-to-rad($number);
         | 
| 142 | 
            +
              }
         | 
| 143 | 
            +
              @return 1 / cos($number);
         | 
| 144 | 
            +
            }
         | 
| 145 | 
            +
             | 
| 146 | 
            +
            @function cot($number, $unit: 'deg') {
         | 
| 147 | 
            +
              @if $unit == 'deg' {
         | 
| 148 | 
            +
                $number: deg-to-rad($number);
         | 
| 149 | 
            +
              }
         | 
| 150 | 
            +
              @return 1 / tan($number);
         | 
| 151 | 
            +
            }
         | 
| 152 | 
            +
             | 
| 153 | 
            +
            //////////////////////////////
         | 
| 154 | 
            +
            // Hyperbolic Functions
         | 
| 155 | 
            +
            //////////////////////////////
         | 
| 156 | 
            +
            @function sinh($number) {
         | 
| 157 | 
            +
              $top: exponent($e, (2 * $number)) - 1;
         | 
| 158 | 
            +
              $bottom: 2 * exponent($e, $number);
         | 
| 159 | 
            +
              @return  $top / $bottom;
         | 
| 160 | 
            +
            }
         | 
| 161 | 
            +
             | 
| 162 | 
            +
            @function cosh($number) {
         | 
| 163 | 
            +
              $top: exponent($e, (2 * $number)) + 1;
         | 
| 164 | 
            +
              $bottom: 2 * exponent($e, $number);
         | 
| 165 | 
            +
              @return  $top / $bottom;
         | 
| 166 | 
            +
            }
         | 
| 167 | 
            +
             | 
| 168 | 
            +
            @function tanh($number) {
         | 
| 169 | 
            +
              $top: exponent($e, (2 * $number)) - 1;
         | 
| 170 | 
            +
              $bottom: exponent($e, (2 * $number)) + 1;
         | 
| 171 | 
            +
              @return  $top / $bottom;
         | 
| 172 | 
            +
            }
         | 
| 173 | 
            +
             | 
| 174 | 
            +
            //////////////////////////////
         | 
| 175 | 
            +
            // Reciprocal Hyperbolic Functions
         | 
| 176 | 
            +
            //////////////////////////////
         | 
| 177 | 
            +
            @function csch($number) {
         | 
| 178 | 
            +
              @return 1 / sinh($number);
         | 
| 179 | 
            +
            }
         | 
| 180 | 
            +
             | 
| 181 | 
            +
            @function sech($number) {
         | 
| 182 | 
            +
              @return 1 / cosh($number);
         | 
| 183 | 
            +
            }
         | 
| 184 | 
            +
             | 
| 185 | 
            +
            @function coth($number) {
         | 
| 186 | 
            +
              @return 1/ tanh($number);
         | 
| 187 | 
            +
            }
         | 
| 188 | 
            +
             | 
| 189 | 
            +
             | 
| 190 | 
            +
            @function log($number) {
         | 
| 191 | 
            +
              @return $number; 
         | 
| 192 | 
            +
            }
         | 
| 193 | 
            +
             | 
| 194 | 
            +
            @function ln($number) {
         | 
| 195 | 
            +
              @if $number > 0 and $number < 1 {
         | 
| 196 | 
            +
                $value: 0;
         | 
| 197 | 
            +
                @for $i from 1 through $iter {
         | 
| 198 | 
            +
                  $value: $value + ( pow(-1, $i) * pow(-1 * (1 - $number), $i)) / $i;
         | 
| 199 | 
            +
                }
         | 
| 200 | 
            +
                $value: -1 * $value;
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                @return $value;
         | 
| 203 | 
            +
              }
         | 
| 204 | 
            +
              @else if $number == 1 {
         | 
| 205 | 
            +
                @return 0;
         | 
| 206 | 
            +
              }
         | 
| 207 | 
            +
              @else {
         | 
| 208 | 
            +
                @return ERROR;
         | 
| 209 | 
            +
                @warn ln input must be greater than zero and less than or equal to 1; 
         | 
| 210 | 
            +
              }
         | 
| 211 | 
            +
            }
         | 
| 212 | 
            +
             | 
| 213 | 
            +
             | 
| 214 | 
            +
            //////////////////////////////
         | 
| 215 | 
            +
            // Degree/Radian Conversion
         | 
| 216 | 
            +
            //////////////////////////////
         | 
| 217 | 
            +
            @function deg-to-rad($number) {
         | 
| 218 | 
            +
              @return $number * $pi / 180deg; 
         | 
| 219 | 
            +
            }
         | 
| 220 | 
            +
             | 
| 221 | 
            +
            @function rad-to-deg($number) {
         | 
| 222 | 
            +
              @return $number * 180deg / $pi; 
         | 
| 223 | 
            +
            }
         | 
| 224 | 
            +
             | 
| 225 | 
            +
            //////////////////////////////
         | 
| 226 | 
            +
            // Root Functions
         | 
| 227 | 
            +
            //////////////////////////////
         | 
| 228 | 
            +
            // Basic General-Purpose Root Function
         | 
| 229 | 
            +
            @function n-root($number, $n) {
         | 
| 230 | 
            +
              @if $number < 1 {
         | 
| 231 | 
            +
                @return ERROR;
         | 
| 232 | 
            +
                @warn ROOT ERROR; 
         | 
| 233 | 
            +
              }
         | 
| 234 | 
            +
              // If a whole number, generate it quickly
         | 
| 235 | 
            +
              @for $i from 1 through $number {
         | 
| 236 | 
            +
                @if exponent($i, $n) == $number {
         | 
| 237 | 
            +
                  @return $i; 
         | 
| 238 | 
            +
                } 
         | 
| 239 | 
            +
              }
         | 
| 240 | 
            +
              // Else, run through other options
         | 
| 241 | 
            +
              @for $i from 1 through $number * 1000 / 2 {
         | 
| 242 | 
            +
                @if round(exponent($i / 1000, $n) * 100) == round($number * 100) {
         | 
| 243 | 
            +
                  @return $i / 1000; 
         | 
| 244 | 
            +
                } 
         | 
| 245 | 
            +
              } 
         | 
| 246 | 
            +
            }
         | 
| 247 | 
            +
             | 
| 248 | 
            +
            // Square Roots
         | 
| 249 | 
            +
            @function √($number) {
         | 
| 250 | 
            +
              @return n-root($number, 2); 
         | 
| 251 | 
            +
            }
         | 
| 252 | 
            +
             | 
| 253 | 
            +
            @function sqrt($number) {
         | 
| 254 | 
            +
              @return n-root($number, 2); 
         | 
| 255 | 
            +
            }
         | 
| 256 | 
            +
             | 
| 257 | 
            +
            //////////////////////////////
         | 
| 258 | 
            +
            // Export Test
         | 
| 259 | 
            +
            //////////////////////////////
         | 
| 260 | 
            +
            .foo {
         | 
| 261 | 
            +
              width: √(9);
         | 
| 262 | 
            +
              width: √(9) * √(9);
         | 
| 263 | 
            +
              width: deg-to-rad(90deg);
         | 
| 264 | 
            +
              width: factorial(9);
         | 
| 265 | 
            +
              -webkit-transform: rotate(rad-to-deg($pi / 2));
         | 
| 266 | 
            +
              width: sin($pi / 4, 'rad'); 
         | 
| 267 | 
            +
              width: sin(10deg);
         | 
| 268 | 
            +
              width: cos($pi / 2, 'rad'); 
         | 
| 269 | 
            +
              width: cos(10deg);
         | 
| 270 | 
            +
              width: ln(.1);
         | 
| 271 | 
            +
            }
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,81 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: sassy-math
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              prerelease: false
         | 
| 5 | 
            +
              segments: 
         | 
| 6 | 
            +
              - 0
         | 
| 7 | 
            +
              - 1
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              version: 0.1.0
         | 
| 10 | 
            +
            platform: ruby
         | 
| 11 | 
            +
            authors: 
         | 
| 12 | 
            +
            - Sam Richard
         | 
| 13 | 
            +
            - Mario Valencia
         | 
| 14 | 
            +
            - Scott Kellum
         | 
| 15 | 
            +
            autorequire: 
         | 
| 16 | 
            +
            bindir: bin
         | 
| 17 | 
            +
            cert_chain: []
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            date: 2012-01-19 00:00:00 -05:00
         | 
| 20 | 
            +
            default_executable: 
         | 
| 21 | 
            +
            dependencies: 
         | 
| 22 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 23 | 
            +
              name: compass
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 26 | 
            +
                requirements: 
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            +
                    segments: 
         | 
| 30 | 
            +
                    - 0
         | 
| 31 | 
            +
                    - 11
         | 
| 32 | 
            +
                    version: "0.11"
         | 
| 33 | 
            +
              type: :runtime
         | 
| 34 | 
            +
              version_requirements: *id001
         | 
| 35 | 
            +
            description: Use advanced mathematical functions in Compass.
         | 
| 36 | 
            +
            email: 
         | 
| 37 | 
            +
            - scott@scottkellum.com
         | 
| 38 | 
            +
            executables: []
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            extensions: []
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            extra_rdoc_files: []
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            files: 
         | 
| 45 | 
            +
            - sassy-math.gemspec
         | 
| 46 | 
            +
            - lib/sassy-math.rb
         | 
| 47 | 
            +
            - stylesheets/_math.scss
         | 
| 48 | 
            +
            has_rdoc: true
         | 
| 49 | 
            +
            homepage: https://github.com/scottkellum/Sassy-math
         | 
| 50 | 
            +
            licenses: []
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            post_install_message: 
         | 
| 53 | 
            +
            rdoc_options: []
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            require_paths: 
         | 
| 56 | 
            +
            - lib
         | 
| 57 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 58 | 
            +
              requirements: 
         | 
| 59 | 
            +
              - - ">="
         | 
| 60 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 61 | 
            +
                  segments: 
         | 
| 62 | 
            +
                  - 0
         | 
| 63 | 
            +
                  version: "0"
         | 
| 64 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 65 | 
            +
              requirements: 
         | 
| 66 | 
            +
              - - ">="
         | 
| 67 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 68 | 
            +
                  segments: 
         | 
| 69 | 
            +
                  - 1
         | 
| 70 | 
            +
                  - 3
         | 
| 71 | 
            +
                  - 5
         | 
| 72 | 
            +
                  version: 1.3.5
         | 
| 73 | 
            +
            requirements: []
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            rubyforge_project: sassy-math
         | 
| 76 | 
            +
            rubygems_version: 1.3.6
         | 
| 77 | 
            +
            signing_key: 
         | 
| 78 | 
            +
            specification_version: 3
         | 
| 79 | 
            +
            summary: Use advanced mathematical functions in Compass.
         | 
| 80 | 
            +
            test_files: []
         | 
| 81 | 
            +
             |