Recursively Generated Clouds

I have been having a look at using recursion in Processing to tile things, however, I got a little bit sidetracked.

Going through the online learning basics, there are two recursion examples, “Recursion” and “Recursion 2“. In the first of these, recursion is used to have a circle repeat itself twice at half the original size inside itself, and continue doing this with each smaller circle until the level is no longer greater than 1. The level is basically the amount of times the function will call itself.

The second of these examples builds on the first, but instead of repeating the circle’s inside themselves, it generates random sizes and shades of circles in semi-random x and y co-ordinates around the main circle until the level is no longer greater than 1. The level again basically being how many times the function calls itself.

Experimenting with these two recursive functions, I combined the two to create a cartoonish cloud that slightly resembles a mushroom cloud which can be found online here.

What I have done, is I have taken the second recursive example, and then changed the way it positions the circles along the y axis to be the same as the first recursive example. Thus the circles are all on the same level and appear to be getting bigger, though they are actually getting smaller.

Because I have kept the way the second example generates the circles, there are heaps of circles overlapping each other that weren’t before, creating a more cloud-like appearance.

void setup()
size(500, 500);

void draw()
drawCircle(250, 200, 170, 6);

void drawCircle(float x, float y, int radius, float level)
float tt = 126 * level/4.0;
fill(tt, 153);
ellipse(x, y, radius*2, radius*2);
if(level > 1) {
level = level - 0.5;
int num = int(random(2, 6));
for(int i=0; i<num;>
float a = random(0, TWO_PI);
float nx = x + sin(a) * 6.0 * level;
float ny = y + radius/2;
drawCircle(nx, ny, radius/2, level);

Tags: ,