Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #175 from jonathanhefner/master
Browse files Browse the repository at this point in the history
Double stranded modular-scale function
  • Loading branch information
Phil LaPier committed Jun 14, 2013
2 parents 0fd16ab + 3f2548b commit eb883dd
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions app/assets/stylesheets/functions/_modular-scale.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
@function modular-scale($value, $increment, $ratio) {
$v1: nth($value, 1);
$v2: nth($value, length($value));
$value: $v1;

// scale $v2 to just above $v1
@while $v2 > $v1 { $v2: ($v2 / $ratio); } // will be off-by-1
@while $v2 < $v1 { $v2: ($v2 * $ratio); } // will fix off-by-1

// check AFTER scaling $v2 to prevent double-counting corner-case
$double-stranded: $v2 > $v1;

@if $increment > 0 {
@for $i from 1 through $increment {
$value: ($value * $ratio);
@if $double-stranded and ($v1 * $ratio) > $v2 {
$value: $v2;
$v2: ($v2 * $ratio);
} @else {
$v1: ($v1 * $ratio);
$value: $v1;
}
}
}

@if $increment < 0 {
$increment: abs($increment);
@for $i from 1 through $increment {
$value: ($value / $ratio);
// adjust $v2 to just below $v1
@if $double-stranded { $v2: ($v2 / $ratio); }

@for $i from $increment through -1 {
@if $double-stranded and ($v1 / $ratio) < $v2 {
$value: $v2;
$v2: ($v2 / $ratio);
} @else {
$v1: ($v1 / $ratio);
$value: $v1;
}
}
}

Expand Down

0 comments on commit eb883dd

Please sign in to comment.