Created
December 30, 2011 14:53
-
-
Save binarymax/1540192 to your computer and use it in GitHub Desktop.
Scales the fibonacci sequence
This file contains hidden or 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
#!/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