% Cartoon showing a circular path above a cemetery, highlighting the
% different crystal planes between crosses 

clear; close all;
figure('units','pixels','position',[0 0 1920 1080]);
vid = VideoWriter('cemetery4.mp4','MPEG-4');
vid.Quality = 100;
vid.FrameRate = 30;
open(vid);
set(0,'defaultfigurecolor',[1 1 1]);
set(gca,'linewidth',7);

set(gca, 'Projection','perspective');
set(gca,'View',[0,20]);
campos([50 50 4]);
lp = [-0.7 -0.5 0.5];
light('Position',lp,'Style','infinite');
axis equal
axis off
LL = 25*1.42;
xlim([-LL LL]);
ylim([-LL LL]);
zlim([-0.02 2.1]);
gray = [0.3 0.3 0.3];
%gray = [0.3 0.28 0.55];
lightgray = [0.7 0.7 0.7];

[x,y,z] = sphere;

for theta = 0:0.25:359.75
    hold off
    newplot
    set(gca, 'Projection','perspective');
    %set(gca,'View',[0,20]);
    campos([0 22 3.2]);
    axis equal
    axis off
    
    for i = -25:2:25
        for j = -25:2:25
            
            hold on
            l1 = plot3([i i],[j j],[0 1.4],'LineWidth',4,'Color',gray);
            l2 = plot3([i i],[j+0.002 j+0.002],[0 1.4],'LineWidth',4,'Color',gray);
            l3 = plot3([i i],[j+0.004 j+0.004],[0 1.4],'LineWidth',4,'Color',gray);
            l4 = plot3([i i],[j+0.006 j+0.006],[0 1.4],'LineWidth',4,'Color',gray);
            c1 = plot3([i-0.25 i+0.25],[j j],[1 1],'LineWidth',4,'Color',gray);
            c2 = plot3([i-0.25 i+0.25],[j+0.002 j+0.002],[1 1],'LineWidth',4,'Color',gray);
            c3 = plot3([i-0.25 i+0.25],[j+0.004 j+0.004],[1 1],'LineWidth',4,'Color',gray);
            c4 = plot3([i-0.25 i+0.25],[j+0.006 j+0.006],[1 1],'LineWidth',4,'Color',gray);
            ls = plot3([i i+1],[j j+1],[0 0],'LineWidth',3,'Color',lightgray);
            cs = plot3([i+0.45 i+0.95],[j+0.7 j+0.7],[0 0],'LineWidth',3,'Color',lightgray);
            rotate(l1,[0 0 1],theta,[0,0,0]);
            rotate(l2,[0 0 1],theta,[0,0,0]);
            rotate(l3,[0 0 1],theta,[0,0,0]);
            rotate(l4,[0 0 1],theta,[0,0,0]);
            rotate(c1,[0 0 1],theta,[0,0,0]);
            rotate(c2,[0 0 1],theta,[0,0,0]);
            rotate(c3,[0 0 1],theta,[0,0,0]);
            rotate(c4,[0 0 1],theta,[0,0,0]);
            rotate(ls,[0 0 1],theta,[0,0,0]);
            rotate(cs,[0 0 1],theta,[0,0,0]);
        end
    end
    surf(0.01*x+LL,0.01*y+LL,0.01*z+0.5,'FaceAlpha',0.01,...
        'FaceColor','blue','LineStyle','none');
    surf(0.01*x-LL,0.01*y-LL,0.01*z+0.5,'FaceAlpha',0.01,...
        'FaceColor','blue','LineStyle','none');
    surf(0.01*x+LL,0.01*y-LL,0.01*z+0.5,'FaceAlpha',0.01,...
        'FaceColor','blue','LineStyle','none');
    surf(0.01*x-LL,0.01*y+LL,0.01*z+0.5,'FaceAlpha',0.01,...
        'FaceColor','blue','LineStyle','none');
    light('Position',lp,'Style','infinite');
    theta 
    
    frame = getframe(gcf);
    writeVideo(vid,frame);
    
end
% Output the movie as an mpg file
close(vid);

