xxxxxxxxxx
42
let fibs = [];
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
colorMode(HSB);
for (let i = 0; i <= 16; i++) {
fibs.push(fib(i));
}
console.log(int(fibs));
}
function draw() {
background(220);
translate(width / 2, height / 2);
for (let i in fibs) {
let fibz = fibs[i];
if (fibz > 360) {
fill(fibz / 2, 100, 50);
} else {
fill(fibz, 100, 50);
}
rect(0, 0, fibz);
translate(fibz, fibz);
rotate(-90);
}
}
//Fibonacci Equations
function fib(n) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return fib(n - 1) + fib(n - 2);
}
}