Skip to content

Instantly share code, notes, and snippets.

@magicznyleszek
Created March 29, 2014 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magicznyleszek/9852224 to your computer and use it in GitHub Desktop.
Save magicznyleszek/9852224 to your computer and use it in GitHub Desktop.
Typographic scale creator
// 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