Created
March 29, 2014 10:46
-
-
Save magicznyleszek/9852224 to your computer and use it in GitHub Desktop.
Typographic scale creator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 16 + 24 @ 1/2 | |
// 15 + 20 @ 1/2 | |
// 16 + 20 @ 1/2 | |
scale = { | |
main: 16, | |
secondary: 20, | |
fraction: 1/2, | |
measurements: [], | |
create: function(greater, lesser) { | |
// default values for greater and lesser numbers amount | |
greater = greater || 8; | |
lesser = lesser || 2; | |
// start subarrays with main and secondary numbers | |
this.measurements = [[this.main], [this.secondary]]; | |
for (a = 0; a < 2; a++) { | |
// make 8 (default) new greater numbers using inverse fraction | |
for (b = 1; b < greater; b++) { | |
this.measurements[a][b] = Math.round(this.measurements[a][b-1] * 1/this.fraction); | |
} | |
// make 2 (default) new lesser numbers using fraction | |
for (c = 0; c < lesser; c++) { | |
this.measurements[a].unshift(Math.round(this.measurements[a][0] * this.fraction)); | |
} | |
} | |
// merge and sort both subarrays | |
this.measurements = this.measurements[0].concat(this.measurements[1]).sort(function (a,b) {return a-b;}); | |
return true; | |
} | |
}; | |
scale.create(); | |
// result scale: | |
// [4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 128, 160, 256, 320, 512, 640, 1024, 1280, 2048, 2560] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment