%f = @(z) (2*z)./(z+1)

%f = @(x,y) (2*(x+i*y)+.01)./(x+i*y + sqrt(2)); 
f = @(x,y) (2*(x+i*y)+.01)./(1); 
n = 200;
a = .5; 
b = 1;

x = linspace(a,b,200);
y = linspace(a,b,200);

[xq,yq]=meshgrid(x,y);
%z = xq+i*yq;
fz = f(xq,yq);

xf = real(fz);
yf = imag(fz);

A = [reshape(xf,1,size(xf,1)*size(xf,2)); reshape(yf,1,size(yf,1)*size(yf,2))];
P = StereographicProj(A,0);

XX = reshape(P(1,:),200,200);
YY = reshape(P(2,:),200,200);
ZZ = reshape(P(3,:),200,200);

% The plot in the plane
%[C,h] =  contour(xf,yf,xf.*yf,'Fill','on');
C=mod(xf.*yf*100,250); 
h1 = surface(xf,yf,zeros(size(xf)),C,'EdgeColor','none');
c=colormap(hot);
cm_length = length(c);

% The projection on the sphere
CS=mod(ZZ*100,50);
h=surface(XX,YY,ZZ,C,'EdgeColor','none')


%surf(XX,YY,ZZ); %'EdgeColor','none','FaceColor','texturemap')
%colormap_index = fix((color_data-cmin)/(cmax-cmin)*cm_length)+1


%zq = xq + i*yq;
%
%X = f(zq);
%
%fx = real(X); fy = imag(X);
%
%patch(fx,fy,'b')

hold on;
view([90 25])

%cmap=colormap(jet);
%X=[zeros(1,n-1);x(1:end-1);x(2:end);zeros(1,n-1)];
%Y=[zeros(1,n-1);y(1:end-1);y(2:end);zeros(1,n-1)];
%C=numel(cmap)*(1:n-1)/n-1;
%%patch(X,Y,C,'EdgeAlpha',0);
%contour3(x,y,fz)
%axis equal;
