diary-website

Website for diary
git clone https://git.in0rdr.ch/diary-website.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

_modular-scale.scss (1605B)


      1 // Scaling Variables
      2 $golden:           1.618;
      3 $minor-second:     1.067;
      4 $major-second:     1.125;
      5 $minor-third:      1.2;
      6 $major-third:      1.25;
      7 $perfect-fourth:   1.333;
      8 $augmented-fourth: 1.414;
      9 $perfect-fifth:    1.5;
     10 $minor-sixth:      1.6;
     11 $major-sixth:      1.667;
     12 $minor-seventh:    1.778;
     13 $major-seventh:    1.875;
     14 $octave:           2;
     15 $major-tenth:      2.5;
     16 $major-eleventh:   2.667;
     17 $major-twelfth:    3;
     18 $double-octave:    4;
     19 
     20 $modular-scale-ratio: $perfect-fourth !default;
     21 $modular-scale-base: em($em-base) !default;
     22 
     23 @function modular-scale($increment, $value: $modular-scale-base, $ratio: $modular-scale-ratio) {
     24   $v1: nth($value, 1);
     25   $v2: nth($value, length($value));
     26   $value: $v1;
     27 
     28   // scale $v2 to just above $v1
     29   @while $v2 > $v1 {
     30     $v2: ($v2 / $ratio); // will be off-by-1
     31   }
     32   @while $v2 < $v1 {
     33     $v2: ($v2 * $ratio); // will fix off-by-1
     34   }
     35 
     36   // check AFTER scaling $v2 to prevent double-counting corner-case
     37   $double-stranded: $v2 > $v1;
     38 
     39   @if $increment > 0 {
     40     @for $i from 1 through $increment {
     41       @if $double-stranded and ($v1 * $ratio) > $v2 {
     42         $value: $v2;
     43         $v2: ($v2 * $ratio);
     44       } @else {
     45         $v1: ($v1 * $ratio);
     46         $value: $v1;
     47       }
     48     }
     49   }
     50 
     51   @if $increment < 0 {
     52     // adjust $v2 to just below $v1
     53     @if $double-stranded {
     54       $v2: ($v2 / $ratio);
     55     }
     56 
     57     @for $i from $increment through -1 {
     58       @if $double-stranded and ($v1 / $ratio) < $v2 {
     59         $value: $v2;
     60         $v2: ($v2 / $ratio);
     61       } @else {
     62         $v1: ($v1 / $ratio);
     63         $value: $v1;
     64       }
     65     }
     66   }
     67 
     68   @return $value;
     69 }