Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda