Chapter 02 - Lesson 03
Recursive Branching
Build from one branch to two branches, then to a full recursive structure.
Concept explanation
After a branch is drawn, the rule moves to its tip and draws two smaller branches. Each child branch repeats the same rule until depth reaches zero.
Try it
Build from one branch to two branches, then to a full recursive structure.
Code fragment
function branch(length, depth) {
if (depth === 0) return;
line(0, 0, 0, -length);
branch(length * 0.67, depth - 1);
}
What to observe
- Depth 1 is just the trunk.
- Each level creates more endpoints.
- The base case prevents endless drawing.
Small challenge
Increase depth one step at a time and estimate how fast the endpoints multiply.