Skip to content

Instantly share code, notes, and snippets.

@jakob-e
Last active December 24, 2015 07:29
Show Gist options
  • Save jakob-e/6763993 to your computer and use it in GitHub Desktop.
Save jakob-e/6763993 to your computer and use it in GitHub Desktop.
ModularSCSScale - A mixin for making modular scales a la ModuularScales.com
// Config
$base-font-size:16 !default; // Ideal font size
$sign-font-size:16 !default; // Significant font size
$MS_MINOR_SECOND: 1.067;
$MS_MAJOR_SECOND: 1.125;
$MS_MINOR_THIRD: 1.200;
$MS_MAJOR_THIRD: 1.250;
$MS_PERFECT_FOURTH:1.333;
$MS_PERFECT_FIFTH: 1.500;
$MS_MINOR_SIXTH: 1.600;
$MS_MAJOR_SIXTH: 1.667;
$MS_MINOR_SEVENTH: 1.778;
$MS_MAJOR_SEVENTH: 1.875;
$MS_OCTAVE: 2.000;
$MS_MAJOR_TENTH: 2.500;
$MS_MAJOR_ELEVENTH:2.667;
$MS_MAJOR_TWELFTH: 3.000;
$MS_DOUBLE_OCTAVE: 4.000;
$MS_GOLDEN_RATIO: 1.618;
$MS_ARGUMENTED_FOURTH:1.414;
$MS_DEMINISHED_FIFTH:$MS_ARGUMENTED_FOURTH;
$__modular-scales:();
//
@mixin ModularScale($scale,$base-font-size:16,$sign-font-size:16){
$list:();
$scale:1/$scale;
$b:$base-font-size;
$s:$sign-font-size;
$p:$b; @while($p < 2560){ $list:append($list,round($p/$b*1000)/1000); $p:$p/$scale; }
$p:$b; @while($p >=1){ $list:append($list,round($p/$b*1000)/1000); $p:$p*$scale; }
$p:$s; @while($p < 2560){ $list:append($list,round($p/$b*1000)/1000); $p:$p/$scale; }
$p:$s; @while($p >=1){ $list:append($list,round($p/$b*1000)/1000); $p:$p*$scale; }
$ms:();
$temp:$list;
$min:0;
@for $i from 1 through length($list){
@if(length($temp)>0){
$min:min($temp...); // Find lowest value
$ms:append($ms,$min); // Add lowest value
$temp:(); // Clear temp for next comparison
}
// Re-populate temp ( > removes dublicate entries)
@for $k from 1 through length($list){
@if(nth($list,$k) > $min){ $temp:append($temp,nth($list, $k)); }
}
}
$__modular-scales:$ms;
.scales { list:$ms;}
}
@function ms($size){
$index:index($__modular-scales,1) + $size - 1 ;
@return nth($__modular-scales,$index);
}
@include ModularScale($MS_GOLDEN_RATIO,16,16);
* {line-height:120%; margin:0;padding:0;font-weight:normal;}
h1 { font-size:ms(4) * 1em; }
h2 { font-size:ms(3) * 1em; }
h3 { font-size:ms(2) * 1em; }
p { font-size:ms(1) * 1em; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment