
% easy function to draw Julia sets of quadratic polynomials
% z^2 + c

function  julia2(c)
  clear d;
  x1=-2;
  x2=2;
  y1=-2;
  y2=2;
  num=100;
  delta=(x2-x1)/num;
  x=[x1:delta:x2];  % x coordinates
  y=[y2:delta:y2];  % y coordinates
  depth=100; % how many iterations to try
  flag=1;
  while flag==1
     Lx=length(x);
     Ly=length(y);
     d=depth*ones(Lx,Ly);
     for k=1:Lx
        for j=1:Ly 
	   z=x(k)+i*y(j);
	   for t=1:depth
              if abs(z) > 4
                d(Ly-j+1,k)=t;
	        break;
              else
                z=z^2+c;
              end  % if
	   end  % for t
        end  % for y
     end   % for x
     image(d); 
     setc=flipud(jet(depth));
     s=size(setc,1);
     setc([s-1,s],:)=zeros(2,3);
     colormap(setc)
     return
     %colorbar
     [a(1),b(1),button]=ginput(1)
     [a(2),b(2)]=ginput(1)
     a=sort(a)
     b=sort(b)
     [x1,x2,y1,y2]
     a2=x(1)+(x2-x1)*a(2)/num
     a1=x(1)+(x2-x1)*a(1)/num
     b1=y(end)-(y2-y1)*b(2)/num
     b2=y(end)-(y2-y1)*b(1)/num
     cx=(a1+a2)/2
     cy=(b1+b2)/2
     hold on
     scatter(cx,cy,'r','o','Filled')
     r=abs(a2-a1)/2
     x1=cx-r
     x2=cx+r
     y1=cy-r
     y2=cy+r
     delta=(x2-x1)/num;
     x=[x1:delta:x2];
     y=[y1:delta:y2];
     [x(1),x(end),y(1),y(end)]
   end % while 


 return


