Mandelbrot Set

Mathematically, the Mandelbrot set is defined on the plane of complex numbers


//Function
def mandelbrot(wd,ht,mx)
{
	return [Imperative]
	{
		it = [];
		for (rw in 0..ht-1)
		{
		    for (cl in 0..wd-1)
		    {
		        rl = (cl - wd/2.0)*4.0/wd;
		        im = (rw - ht/2.0)*4.0/wd;
		        x = 0;
		        y = 0;
		        n = 0;
		        while (x*x+y*y <= 4 && n < mx)
		        {
		            x1 = x*x - y*y + rl;
		            y = 2*x*y + im;
		            x = x1;
		            n = n + 1;
		        }
		        it[cl][rw] = n;
		    }
		}
		return it;
	}
};
Maximum Iterations: 10
Maximum Iterations: 30

Joni "Let’s draw the Mandelbrot set!", November 17, 2013 <https://jonisalonen.com/2013/lets-draw-the-mandelbrot-set/> January 26, 2021

Last updated