Skip to content

Instantly share code, notes, and snippets.

@binarymax
Created December 30, 2011 14:53
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 binarymax/1540192 to your computer and use it in GitHub Desktop.
Save binarymax/1540192 to your computer and use it in GitHub Desktop.
Scales the fibonacci sequence
#!/usr/bin/env node
(function() {
var rnd = function(x) { return Math.round(x*10)/10; };
var tbl = function(a) {
var b=[];
for(var i=0,l=a.length;i<l;i++) {
var n=a[i].toString();
for(var j=0, s=" "; j<(5-n.length);j++) {
s+=" ";
}
b[i]=s+n;
}
return b.join('|');
}
var scaleWidth = 50;
var width = 295; //width of the canvas,in cm)
var depth = 15;
var targ = 232; //10th fibonacci digit
var scale = (width/targ)*(scaleWidth/width); //50cm is scale width;
var fibs = [1,1];
var tran = [rnd(scale),rnd(scale)];
var fsum = [1,2];
var tsum = [rnd(scale),rnd(scale*2)];
for(var i=2;i<depth;i++) {
fibs[i] = fibs[i-1]+fibs[i-2];
fsum[i] = fibs[i] + fsum[i-1];
}
for(var i=2;i<depth;i++) {
tran[i] = rnd(fibs[i] *scale);
tsum[i] = rnd(tran[i] + tsum[i-1]);
}
console.log(tbl(fibs));
console.log(tbl(fsum));
console.log(tbl(tran));
console.log(tbl(tsum));
return;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment