%Mandelbrot and Burning Ship Combined with avi

clf
clear

aviobj = avifile('ship3.avi','fps',5);
fig=figure;

xmin = 3;
xmax = -3;
ymin = 2;
ymax =-2;

nPoints = 405;

zmax = 1e10;


for fac=0:.02:1
for i=1:nPoints
    for j=1:nPoints 
        
        x(i) = ((xmax-xmin)/nPoints*(nPoints-(nPoints-i+1))+xmin);

        y(j) = ((ymax-ymin)/nPoints*(nPoints-(nPoints-j+1))+ymin);

        c = complex(x(i),y(j));
        z = complex(0,0);   
        
        it_max = 75;           
        for n = 1:it_max
            a=real(z);
            b=imag(z);
            d=abs(a);
            e=abs(b);
            z1 = (complex(d,e))^2+c;
            z2= z^2+c;
            z=(1-fac)*z1+fac*z2;
            if (abs(z)>=zmax)
                break
            end
        end
        if (abs(z)<=zmax) ZZ(j,i)=0;  
        else ZZ(j,i)=n;               
        end

    end
    fprintf('i= %d of %d points in X direction: x= %f\n',i,nPoints,x(i));
end

imagesc(-x,y,ZZ); 
colormap(hot)
F = getframe(fig);
aviobj = addframe(aviobj,F);
end

close(fig);
aviobj = close(aviobj);



   