% Cartoon of a magnon wave in 1-D or 2-D

clear; close all;

prompt = '1-D wave (1), or 2-D wave (2)? ';
d12 = input(prompt);

figure('units','pixels','position',[0 0 1920 1080],'ToolBar','none');
vid = VideoWriter('magnon.mp4','MPEG-4');
vid.Quality = 100;
vid.FrameRate = 30;
open(vid);
set(0,'defaultfigurecolor',[1 1 1]);
set(gca,'linewidth',7);
lp = [0.4 -0.4 0.7];
lp2 = [0 0 2];
r = 0.25;
[x,y,z] = sphere(70);
LL = 1.6;
if (d12 == 1)
    kkmax = 0;
else
    kkmax = 23;
end
for jj = 0:0.25:23.75
    hold off;
    for ii = 0:23
        for kk = 0:kkmax
            newplot
            spin = mArrow3([ii kk -1],[ii kk 1.4],'color','r','stemWidth',0.08,'tipWidth',0.14,'facealpha',1);
            rotate(spin,[1 0 0],30,[ii,kk,0]);
            rotate(spin,[0 0 1],(ii+jj+kk)*180/12,[ii,kk,0]);
            hold on
            surf(ii+x*r,kk+y*r,z*r,'FaceColor',[0.28 0.32 0.64],'EdgeColor','none');
        end
    end
    axis equal
    axis off
    xlim([-2 26]);
    if (d12 == 1)
        ylim([-LL LL]);
    else
        ylim([-2 26]);
    end
    zlim([-LL LL]);
    view(25,20);
    light('Position',lp,'Style','infinite');
    light('Position',lp2,'Style','infinite');
    frame = getframe(gcf);
    writeVideo(vid,frame);
end
hold off;
% Output the movie as an mpg file
close(vid);