Thursday, 17 July 2014

The Mandelbrot Set - Simple Addition (or should that be multiplication?)

Yesterday my friend Alana posted some images to Facebook that were reminiscent of fractals, but she actually only used a piece of paper, a pencil and an iPhone. I asked her how she did it is expecting her to answer that she used some sort of computer program. This set me thinking maybe I can do a similar thing, but with C#.

Supposedly the Mandelbrot set is supposed to be really simple, but I don’t like maths (that’s why I got into computer programming (the computer does all the maths, you see?)) and I’m not very good at it. So simple to a mathematician and simple to me, well you would need to come up with another definition of simple.

Anyway, I did my research and tried to program my own Mandelbrot bitmap maker in C#. It was the roughest Mandelbrot set you have ever seen. If you tried to render a Mandelbrot set using only 10 pixels - that is what it looked like.

I’m not alone in trying to do this as there is a lot of cut and pasted code on the Internet. Most computer programmers have edited complex code that they don’t understand. It is surprisingly easy to get such code to work and I suspect it was the case with this.

I found some great code that worked, on this site: in my opinion the code was bit overcomplicated, so I rewrote it, simplified it and switched the way it works around a bit. The code still uses the complex numbers class in C# not that I really get complex numbers yet. After reverse engineering the code I can say that I now understand how the Mandelbrot set is rendered. Here are a few pics:

This first image is what it looks like with more detailed code.

The interesting thing about this algorithm is that the number of times it iterates. The greater the detail. If it is one iteration you get a circle, with three you get this.

And with 10...

In the future I will modify it to do all sorts of things like colours and eventually do something like this:

Here is the code. Just dump it in your visual studio project folder and un-zip.

No comments:

Post a Comment