Recursion: How to Grow a Tree

Objective

After completing this lesson, you will be able to use a different way of efficiently building custom blocks by calling them inside their definition, an idea called recursion.

Content

Video summary:

The video explains two types of recursion (custom blocks calling themselves in their own block definition): linear (a countdown) and exponential (a fractal tree). It shows how to write recursive blocks with inputs and base cases, how repeated recursive calls produce fractal growth, and tips to speed up and stylize the output.

Key points:

  • Linear (tail) recursion: build a countdown block that says a number, calls itself with number-1, and stops with a base case (number ≤ 0).
  • Exponential recursion: create a tree(level, size) block that draws a stem, then calls itself twice with level-1 and a scaled size to produce branches.
  • Recursion naturally produces fractals and exponential growth; use warp to render deep recursions instantly.
  • Make visuals richer by varying pen size (e.g., set pen size = level) so branches thin out toward the ends.