1/**
2 * Recursion.
3 *
4 * A demonstration of recursion, which means functions call themselves.
5 * Notice how the drawCircle() function calls itself at the end of its block.
6 * It continues to do this until the variable "level" is equal to 1.
7 */
8
9void setup()
10{
11  size(200, 200);
12  noStroke();
13  smooth();
14  noLoop();
15}
16
17void draw()
18{
19  drawCircle(126, 170, 6);
20}
21
22void drawCircle(int x, int radius, int level)
23{
24  float tt = 126 * level/4.0;
25  fill(tt);
26  ellipse(x, 100, radius*2, radius*2);
27  if(level > 1) {
28    level = level - 1;
29    drawCircle(x - radius/2, radius/2, level);
30    drawCircle(x + radius/2, radius/2, level);
31  }
32}
33