%{
Zadanie 3 z listy 4. Animacja zmian sfery jednostkowej S_p, dla p zmieniaj¹cego
siê od 1 do nieskonczonosci. n=3.
%}


X=zeros(101);
X_p=X;
Y=zeros(101);
Y_p=Y;
Z=zeros(101);
Z_p=Z;
for k=1:101
  for l=1:101
    X(k,l)=cos(2*pi*(k-1)/100)*sin(pi*(l-1)/100);
    Y(k,l)=sin(2*pi*(k-1)/100)*sin(pi*(l-1)/100);
    Z(k,l)=cos(pi*(l-1)/100);
  end;
end;
for i=1:200			%iloœæ klatek animacji
  p=1/(1-(i-1)/200);
  for k=1:101
    for l=1:101
      norma=(abs(X(k,l))^p+abs(Y(k,l))^p+abs(Z(k,l))^p)^(1/p);
      X_p(k,l)=X(k,l)/norma;
      Y_p(k,l)=Y(k,l)/norma;
      Z_p(k,l)=Z(k,l)/norma;
    end;
  end;
  surf(X_p,Y_p,Z_p,'FaceColor','interp','EdgeColor','none','FaceLighting','phong');
  axis([-1.2 1.2 -1.2 1.2 -1.2 1.2]);
  axis square;
  M(i)=getframe;
end;
for k=1:101			%ostatnia klatka dla p=nieskoñczonoœæ
  for l=1:101
    if abs(X(k,l))>abs(Y(k,l))
      if abs(X(k,l))>abs(Z(k,l))
        norma=abs(X(k,l));
      else
        norma=abs(Z(k,l));
      end;
    else
      if abs(Z(k,l))>abs(Y(k,l))
        norma=abs(Z(k,l));
      else
        norma=abs(Y(k,l));
      end;
    end;
    X_p(k,l)=X(k,l)/norma;
    Y_p(k,l)=Y(k,l)/norma;
    Z_p(k,l)=Z(k,l)/norma;
  end;
end;
surf(X_p,Y_p,Z_p,'FaceColor','interp','EdgeColor','none','FaceLighting','phong');
axis([-1.2 1.2 -1.2 1.2 -1.2 1.2]);
axis square;
M(201)=getframe;
movie(M,-1);