The Buddhabrot - That's Some Pretty Maths

Posted by Tom on 2011-01-15 13:34

So I've been messing with fractals. More specifically Buddhabrots, which are an alternative approach to rendering the Mandelbrot set, care of the brain of Melinda Green.

Github repository

There are a few tweakable parameters you can pass in from the command line. Typically, increasing the maximum number of interations increases the level of detail and the amount of 'features' (for want of a better word) in the final image, and increasing the number of samples per pixel makes the final image smoother and less grainy. I probably didn't explain that too well. Your best bet is going to be to download it and have a play around.

The contrast of the final images is defined by some half-arsed finger-in-the-air divined voodoo-method algorithm. I wish I could say some craftiness went into it, but in reality it started from a point arrived at through rational thought and ended up somewhere completely different based on observation, random tweaks and guesswork. Manual genetic programming, I guess.

Since I can write my buffer to a PNG at any point in the process it seemed like a fairly natural progression to animate the whole shebang.

You won't find the animation stuff in the GitHub repository simply because it was unspeakably vile and hacky, but it should be simple enough to work out for yourself. The only change to the algorithm was to change the x loop so that it started at the extremes and ping-ponged back and forth, tending towards the centre of the area. So:

for (x = 0; x < samples; x ++)
{
    for (y = 0; y < samples; y ++)
    {
        /* Do stuff */
    }
}

becomes:

x = 0;
for (w = 0; w < samples; w ++)
{
    for (y = 0; y < samples; y ++)
    {
        /* Do stuff */
    }
    
    if (w % 2 == 0)
        x += (samples - w);
    else
        x -= (samples - w);
}

This just means that the animation has an interesting ending, or you spend the last third watching very little happen as the columns to the far right of the region don't have much of an influence on the final result.