function kdemo(n)

% function kdemo(n)
% simple demo of the phase of spins as a function of k
% n is the number of spins per axis
% there is not graceful exit yet

n2 = round(n/2);
N = 2 * n2;
n21 = n2+1;

figure;

kx = 0;
ky = 0;

[x,y] = meshgrid(-n2:(n2/1),-n2:(n2/1));

keeplooping = 1;
while keeplooping
    hold off;
    c = exp(j*(pi/n2)*(kx*x+ky*y));
    quiver(x,y,real(c),imag(c),0.5);
    hold on;
    axis equal;
    plot(x,y,'r.');
    axis ([-n21 n21 -n21 n21]);
    plot([0 kx],[0 ky],'ro-');
    plot(0,0,'go');
    [kx,ky,button] = ginput(1);
    kx = max(kx,-n2);
    kx = min(kx,n2);
    ky = max(ky,-n2);
    ky = min(ky,n2);
    if button ~= 1
        keeplooping = 0;
    end
end

