% session 3 year 2012
% making graphics


clear all; clf




% a 3D example with streamtubes
n=1000;
th=linspace(0,6*pi,n);
r=th*1.1;
x=r.*cos(th);
y=r.*sin(th);
z=th;

%plot3(x,y,z,'b','linewidth',3);
thickn=7*((cos(40*pi*(r/max(r)))+2)/3);

streamtube({[x',y',z']},{thickn});
shading interp
camlight
lighting gouraud
grid on
box on
axis equal tight

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ù
break

% buttondwon function with clicking on circles
N=50
c=jet(N);
for ind=1:N

    x0=100*randn(1,1);
    y0=100*randn(1,1);
    r0=1*randn(1,1);
    th=linspace(0,4*pi,50);
r=th*1.05;
x=r0*(r.*cos(th))+x0;
y=r0*(r.*sin(th))+y0;
h=plot(x,y,'color',c(ind,:));hold on



mycom=['title(''' num2str(ind) ''');'];

set(h,'buttondownfcn',mycom);


end
hold off
drawnow







%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
break

% example of making a moving zoom

open('spirale.fig')


sched=[
  -300   300  -250   250
  -300   300  -250   250
-7.2948   85.7143  -14.9813   54.3071
-7.2948   85.7143  -14.9813   54.3071
 75.5360  168.5451   67.9616  137.2500
 75.5360  168.5451   67.9616  137.2500
   -300   300  -250   250
   -300   300  -250   250];
tvec=linspace(0,1,8);
ttvec=linspace(0,1,2000);

meth='spline';
x1=interp1(tvec,sched(:,1),ttvec,meth);
x2=interp1(tvec,sched(:,2),ttvec,meth);
x3=interp1(tvec,sched(:,3),ttvec,meth);
x4=interp1(tvec,sched(:,4),ttvec,meth);


for ind=1:length(ttvec);
    axis([x1(ind),x2(ind),x3(ind),x4(ind)]);
    drawnow;

    filename=['mymov' num2str(ind)]
    print(filename,'-dpng');
end



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
break

% example of a surface and adding particles on top
clear all; clf

subplot(1,1,1)
a=jet(64);

n=200;
x=linspace(-3,3,n);
y=linspace(-3,3,n);
[X,Y]=meshgrid(x,y);
f=cos(5*X).*exp(-X.^2-Y.^2);
surf(X,Y,f-10); shading interp
colormap(a)
axis equal tight

hold on

x=rand(2000,1);
y=rand(2000,1);
x=x*6-3;
y=y*6-3;

plot(x,y,'k.');
view(2)
axis([-3,3 -3 3 -12 1])

break


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% examples from year 2011
%
% % graphics
% % session 3
% clear all; clf;
% 
% 
% 
% 
% 
% p1=linspace(0.1,10,10);
% p2=linspace(0.1,10,10);
% [P1,P2]=meshgrid(p1,p2);
% 
% x=linspace(-10,10,100);
% 
% P1=P1(:);P2=P2(:);
% n=length(P1);
% subplot(1,2,1);
% for ind=1:n;
%     h=plot(P1(ind),P2(ind),'k.');
% 
%     
%     st=['subplot(1,2,2);title(''' num2str(P1(ind)) ' ' num2str(P2(ind)) ''')']
% 
%     set(h,'buttondownfcn',st);
% 
%     hold on
% end
% 
% 
% 
% break
% 
% 

% parameterization and zooming

th=linspace(0,2*pi,70);
r=1+0.2*cos(6*th);
x=r.*cos(th);
y=r.*sin(th);
plot(x,y,'k');

nc=100;

coco=jet(nc);

for ind=1:nc
    r=randn(1,1).^2/5;
    plot(x*r+randn(1,1),y*r+randn(1,1),'color',coco(ind,:),'linewidth',2);
hold on
end

sched=[
 -3     4    -3     3
1.3690    2.1253    1.5584    2.2909
   -1.3048   -0.5484   -0.4866    0.2459
   -2.6540    1.4655   -2.6961    0.9195
 -3     4    -3     3];

ni=100;
tvec=linspace(0,1,ni);
tveco=linspace(0,1,size(sched,1));

meth='spline';
g=[interp1(tveco,sched(:,1),tvec,meth)', ...
   interp1(tveco,sched(:,2),tvec,meth)', ...
   interp1(tveco,sched(:,3),tvec,meth)', ...
   interp1(tveco,sched(:,4),tvec,meth)']
    


for ind=1:ni;
    axis(g(ind,:));
    
    filename=['mov' num2str(ind)];
    disp(['printing ' filename]);tic
    print('-djpeg',filename);
    toc
    drawnow;
end



break

%coco=jet(200);
load colo
coco=f;

n=100;
x=linspace(-10,10,n);
y=linspace(-10,10,n);
[X,Y]=meshgrid(x,y);

tvec=linspace(0,4*pi,400);
nt=length(tvec);

for ind=1:nt
t=tvec(ind);
    f=sin(2*X-t).*exp((-X.^2-Y.^2)/10);
surf(X,Y,f);
shading interp
colormap(coco);



zlim([-1,1]);
caxis([-1,1]);
%view(2)
camlight
lighting gouraud
drawnow

end











break




for tre=1:100

n=200;
x=linspace(-10,10,n);

tvec=linspace(0,4*pi,200);
nt=length(tvec);

lwvec=ceil(linspace(1,20,nt));

coco=jet(nt);

for ind=1:nt
    t=tvec(ind);
f=sin(2*x-t).*exp(-x.^2/10);


c=coco(ind,:);
lw=lwvec(ind);
plot(x,f,'color',c,'linewidth',lw);


% text on the image
sel=2:n-1;
l=find(f(sel)>f(sel+1)&f(sel)>f(sel-1))+1;

for gre=1:length(l);
    loc=l(gre);
    xx=x(loc);
    ff=f(loc);
    val=sprintf('%0.2g',ff); 
    text(xx,ff+0.05,val,'fontsize',20,'color',c);
    hold on
end
hold off

ylim([-1,1.2]);
drawnow


end
end


