Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda