Skip to content

Commit

Permalink
update with bower stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkellum committed Feb 13, 2015
1 parent a9832c1 commit b450c6b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "modularscale-js",
"version": "0.0.0",
"homepage": "http://modularscale.com/",
"authors": [
"scottkellum <[email protected]>"
],
"description": "A modular scale calculator written in JavaScript",
"main": "modularscale.js",
"keywords": [
"modularscale",
"modular",
"scale",
"calculator",
"typography",
"type",
"design"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
47 changes: 27 additions & 20 deletions modularscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ var msRatios = (1+ Math.sqrt(5))/2;

// Unique via http://jsfiddle.net/gabrieleromanato/BrLfv/
var msUnique = function(origArr) {
var newArr = [],
origLen = origArr.length,
found, x, y;

for (x = 0; x < origLen; x++) {
found = undefined;
for (y = 0; y < newArr.length; y++) {
if (origArr[x] === newArr[y]) {
found = true;
break;
}
}
if (!found) {
newArr.push(origArr[x]);
}

origArr = origArr.sort(function(a,b) {
var x = a[0];
var y = b[0];
return x-y;
});

newArr = [];
var lastVal = null;

for (var i = 0; i < origArr.length; i++) {
var currentVal = origArr[i][0];
if (currentVal != lastVal) {
newArr.push(origArr[i]);
};

lastVal = currentVal;

}

return newArr;
}

Expand Down Expand Up @@ -53,10 +57,13 @@ function ms(value, bases, ratios) {

// Seed return array
var r = [];
var strand = null;

for (var ratio = 0; ratio < ratios.length; ratio++) {
for (var base = 0; base < bases.length; base++) {

strand = (base + ratio);

// Seed list with an initial value
// r.push(bases[base]);

Expand All @@ -65,37 +72,37 @@ function ms(value, bases, ratios) {
// Find lower values on the scale
var i = 0;
while((Math.pow(ratios[ratio], i) * bases[base]) >= bases[0]) {
r.push(Math.pow(ratios[ratio], i) * bases[base]);
r.push([Math.pow(ratios[ratio], i) * bases[base], strand]);
i--;
}

// Find higher possible values on the scale
var i = 0;
while(Math.pow(ratios[ratio], i) * bases[base] <= Math.pow(ratios[ratio], value + 1) * bases[base]) {
r.push(Math.pow(ratios[ratio], i) * bases[base]);
r.push([Math.pow(ratios[ratio], i) * bases[base], strand]);
i++;
}
} else {
// Find values on a negitve scale
var i = 0;
while((Math.pow(ratios[ratio], i) * bases[base]) <= bases[0]) {
r.push(Math.pow(ratios[ratio], i) * bases[base]);
r.push([Math.pow(ratios[ratio], i) * bases[base], strand]);
i++;
}

// // Find higher possible values on the scale
var i = 0;
while((Math.pow(ratios[ratio], i) * bases[base]) >= (Math.pow(ratios[ratio], value - 1) * bases[base])) {
if (Math.pow(ratios[ratio], i) * bases[base] <= bases[0]) {
r.push(Math.pow(ratios[ratio], i) * bases[base]);
r.push([Math.pow(ratios[ratio], i) * bases[base], strand]);
}
i--;
}
}
}
}

r = msUnique(r.sort(function(a,b) { return a - b;}));
r = msUnique(r);

// reverse array if value is negitive
if(value < 0) {
Expand Down
1 change: 1 addition & 0 deletions modularscale.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added readme.md
Empty file.

0 comments on commit b450c6b

Please sign in to comment.