Cartoon of a spin flipping between up and down
Matlab code 

clear; close all;

 

figure('units','pixels','ToolBar','none');

vid = VideoWriter('qubit.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]; 

light('Position',lp,'Style','infinite');

 

for ii = 0:pi/30:pi 

    newplot;

    rcomp = (pi-ii)/pi;

    gcomp = 0; 

    bcomp = ii/pi;

    arrowCol = [rcomp gcomp bcomp];

    mArrow3([0 -sin(ii) -cos(ii)],[0 1.4*sin(ii) 1.4*cos(ii)],'color',arrowCol,'stemWidth',0.08,'tipWidth',0.14,'facealpha',1); % Lorentz force 

    r = 0.25;

    hold on;

    [x,y,z] = sphere(70); surf(x*r,y*r,z*r,'FaceColor',[0.28 0.32 0.64],'EdgeColor','none'); 

    axis square;

    axis off;

    light('Position',lp,'Style','infinite');

    LL = 1.6;

    xlim([-LL LL]);

    ylim([-LL LL]);

    zlim([-LL LL]);

    view(35,31);

    frame = getframe(gcf); 

    writeVideo(vid,frame); 

    hold off

end 

for ii = pi:-pi/30:0 

    newplot;

    rcomp = (pi-ii)/pi;

    gcomp = 0; 

    bcomp = ii/pi; 

    arrowCol = [rcomp gcomp bcomp];

    mArrow3([0 -sin(ii) -cos(ii)],[0 1.4*sin(ii) 1.4*cos(ii)],'color',arrowCol,'stemWidth',0.08,'tipWidth',0.14,'facealpha',1); % Lorentz force 

    r = 0.25;

    hold on;

    [x,y,z] = sphere(70); surf(x*r,y*r,z*r,'FaceColor',[0.28 0.32 0.64],'EdgeColor','none'); 

    axis square;

    axis off;

    light('Position',lp,'Style','infinite');

    LL = 1.6;

    xlim([-LL LL]);

    ylim([-LL LL]);

    zlim([-LL LL]);

    view(35,31);

    frame = getframe(gcf); 

    writeVideo(vid,frame); 

    hold off

end 

hold off;

% Output the movie as an mpg file

close(vid);