Chapter 02 - Lesson 06
Color, Depth, and Style
Map recursion depth to color, thickness, and leaves.
Concept explanation
Depth is data. The sketch can use it to choose stroke weight, branch color, and leaf placement so recursion becomes easier to read.
Try it
Map recursion depth to color, thickness, and leaves.
Code fragment
const t = level / maxDepth;
stroke(lerpColor(trunk, leaf, t));
What to observe
- Older branches can be darker and thicker.
- Newer branches can be lighter and thinner.
- Leaves mark base cases visually.
Small challenge
Use high depth and decide whether color or thickness helps more.