function siegel();
nx = 480;
ny = 480;
ColorMset = zeros(nx,ny,3);
magc=0.65;
xmin = -1/magc;
xmax = 1/magc;
ymin = -1/magc;
ymax = 1/magc;
maxiter = 1200;
wb = waitbar(0,'Please wait...');
for iy = 1:ny
  cy = ymin + iy*(ymax - ymin)/(ny - 1);
  for ix= 1:nx
    cx = xmin + ix*(xmax - xmin)/(nx - 1);
    [k myfl] = Mlevel(cy,cx,maxiter);
    if myfl==2  
        ColorMset(ix,iy,2) = abs(sin(5*k/10+pi/4));
    else
        if myfl==1
            ColorMset(ix,iy,1) = abs(sin(2*k/10));
        else
            %ColorMset(ix,iy,2) = abs(sin(2*k/10+pi/4));
            ColorMset(ix,iy,3) = abs(cos(2*k/10));
        end
    end
  end
  waitbar(iy/ny,wb)
end
close(wb);
image(ColorMset);
imwrite(ColorMset,'siegel.jpg','jpg','Quality',100);
 
function [potential myfl] = Mlevel(cx,cy,maxiter)
z = complex(cx,cy);
th=pi*(-1+sqrt(5));
d=exp(complex(0,th));
d=d/2-d*d/4;
%e=(1-sqrt(1-4*d))/2;
%e=0;
%a=complex(0,sqrt(3));
%a=sqrt(3);
a=4;
ang=0;
iter = 0;
while (iter < maxiter)&&(abs(z) > 0.001)&&(abs(z)<20)
   h=z;
   %z=d*z*z*(z-a)/(1-a*z);
   z=z*z+d;
     hh=abs(z-h)*(z-h);
     if iter>maxiter/2
       ang=ang+hh;
    end
   iter = iter+1;
end
if iter < maxiter
    potential = iter;
    if abs(z)>=20
        myfl=0;
    else
        myfl=1;
    end
else
    %potential = -(ang-floor(ang));
    potential=abs(ang);
    myfl=2;
end
