Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Recursion function called terdragon in Code Maven is ununderstandable
   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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!