var n = 8;
var l = 5;
var angle = 120 * Math.PI / 180;
c.translate(300, 200);
terdragon(n);
function terdragon(n) {
if (n <= 1) {
drawLine(l);
} else {
terdragon(n-1);
c.rotate(angle);
terdragon(n-1);
c.rotate(-angle);
terdragon(n-1);
}
}
function drawLine(l) {
c.beginPath();
c.moveTo(0, 0);
c.lineTo(l, 0);
c.stroke();
// Finish at the end of the line we drew
c.translate(l, 0);
}
I don't understand how does it draw the lines as it does, when variable n is 8. As it is stated that if n <= 1 then call the drawLine function, until then it does nothing but calls itself and subtracts 1 each time and changes angle, but I can't see how does it draw, when it doesn't equal to 1.
The code is from Crunchzilla Code Maven. Chapter 40 - Fractals