% file light2.m

clear all;close all;
p=linspace(0,1,100);
%r=sin(p*pi).*(sin(4*pi*p)+2).*exp(-p/2);
r=(cos(2*pi*p)+2)/6;
[xc,yc,zc]=cylinder(r,100); % 100 points around diameter

if 0
figure(1);
surf(xc,yc,zc);
shading interp;
material shiny;
l=light('pos',[-5 2 1]);
colormap cool
axis equal;
axis square;
end

fvc=surf2patch(xc,yc,zc,zc);
%fvc = 
%              faces: [19980x4 double]
%           vertices: [21000x3 double]
%    facevertexcdata: [21000x1 double]
v=fvc.vertices;
f=fvc.faces;
c=fvc.facevertexcdata;

figure(22);

%Frames = moviein(16);
for i=1:16
    %close(22);
    clf;
    figure(22);
    T1=rot3d_pre((2*pi)/16,2);
    T2=trans_pre(1/16,1/16,1/16);
    T3=scale_pre(0.9,0.9,0.9);
    vsize =size(v);
    vh=[v ones(vsize(1),1)];
    v = T3*T2*T1*vh';
    v(4,:)=[];
    v=v';
    fvc.vertices=v;
    
    patch(fvc)
    
    view(3);
    grid on;
    axis([-1 1 -1 1 -1 1]);
    axis square;
    xlabel('x'),ylabel('y'),zlabel('z');
    shading interp;
    material shiny;
    l=light('pos',[-5 2 1]);
    colormap (cool);
 %   Frames(:,i) = getframe;
 Frames(i) = getframe;
end
 movie(Frames,10)












