% draws a 3D sphere at 0,0,0
% c - colour (c=0 gives earth colour, otherwise it's yellow and red)
%
% Initial version: Magnus Billvik, Swedish Institute of Space Physics, Uppsala,Oct 2005


function sphere(r,c)

k = 5;
n = 2^k-1;
theta = pi*(-n:2:n)/n;
phi = (pi/2)*(-n:2:n)'/n;
X = r*cos(phi)*cos(theta);
Y = r*cos(phi)*sin(theta);
Z = r*sin(phi)*ones(size(theta));
if c==0
    M=[0 1 0;0 0 1];
else
    M=[1 0 0;1 1 0];
end
colormap(M);

C = hadamard(2^k);
surf(X,Y,Z,C)
axis square