

%------------------------------------
%function to draw  quadratic Julia sets

function    julia(a,b)
    tic;
    depth=1000;
    x1=-2;
    x2=2;
    y1=-2;
    y2=2;
    delta=4/1000;
       x=x1:delta:x2;
       y=y2:-delta:y1;
       Lx=length(x);
       Ly=length(y);
       [X,Y] = meshgrid(x,y);
       z0=X+i*Y;
       size(z0);
       z=z0;
       c=zeros(Ly,Lx);
       for k=1:depth
          z=z.^2+(a+i*b);
          c(abs(z)<2)=k;
       end
       m=min(min(c))
       M=max(max(c))
       d=c;  %(M/(M-m))*(c-m);
       figure; hold on;
       title(['Julia set',num2str(a),'+i',num2str(b)]);
       image(d)
    
       % choose how to label axes
       axistype=1;
       switch axistype
          case 0   % no labels
             axis off
          case 1   % label with planar coordinates
             horz=x1:(x2-x1)/4:x2;
             for k=1:length(horz)
                xlabels{k}=num2str(horz(k));
             end
             Lx;
             xt=[[1:Lx/4:Lx],Lx];
             xticks(xt)
             xticklabels(xlabels)
             vert=y2:(y1-y2)/4:y1;
             for k=1:length(vert)
                ylabels{k}=num2str(vert(k));
             end
             Ly;
             yt=[[1:Ly/4:Ly],Ly];
             yticks(yt)
             yticklabels(ylabels)
          case 2  % label with matrix coordiates
             axis image
       end % switch

       % set colors to use
       setc=flipud(jet(depth));
       %colormap(jet(depth))
       %colormap(hsv(depth))
       %colormap(gray(depth))
       %colormap(flipud(winter(depth)))
       s=size(setc,1)
       setc(s,:)=zeros(1,3);
       colormap(setc)
       % add a legend saying how colors give iterates
       colorbar
       toc;
  return 