function molle(tn,un)
%  molle(tn,un)
%   rappresentazione grafica del sistema
%   parete - molla - massa - molla - massa.
%
%     uso: molle(tn,un)
% 
%     Input: tn= vettore dei tempi
%            un= array con almeno due vettori colonna (o riga)
%                contenenti le posizioni delle 2 masse ai tempi tn. 
%
[n1,n2]=size(un);
if n1>n2
    un=un';
end

% preparo le variabili 
xmin=min(min(un(1:2,:)));xmax=max(max(un(1:2,:))); xr=(xmax-xmin)/5;
ymin=-1;ymax=1; yr=0;
xmin=xmin-xr; xmax=xmax+xr;
ymin=ymin-yr; ymax=ymax+yr;

    figNumber=figure( ...
        'Name','Doppia Molla', ...
        'Visible','on');
    colordef(figNumber,'white');
    axes( ...
        'Units','normalized', ...
        'Visible','on');

    axis([-1 1 -1 1]);
    axHndl=gca;
    figNumber=gcf;
    set(axHndl, ...
        'XLim',[xmin xmax],'YLim',[ymin ymax], ...
        'Drawmode','fast', ...
        'Visible','on', ...
        'NextPlot','add', ...
        'View',[0,90]);
    tempo=text('position',[3,0.6,0],...
            'String',[],...
            'Fontsize',14);
        molla1=line( ...
            'color','g', ...
            'Linewidth',2,...
            'erase','normal', ...
            'xdata',[],'ydata',[]);
        molla2=line( ...
            'color','g', ...
            'Linewidth',2,...
            'erase','normal', ...
            'xdata',[],'ydata',[]);
        parete=line( ...
            'color','k', ...
            'Linewidth',3,...
            'erase','none', ...
            'xdata',[],'ydata',[]);
        massa1 = line( ...
            'color','r', ...
            'Marker','s', ...
            'markersize',9, ...
            'markerfacecolor','r', ...
            'markeredgecolor','r', ...
            'erase','normal', ...
            'xdata',[],'ydata',[]);
        massa2 = line( ...
            'color','b', ...
            'Marker','s', ...
            'markersize',9, ...
            'markerfacecolor','b', ...
            'markeredgecolor','b', ...
            'erase','normal', ...
            'xdata',[],'ydata',[]);
         
l=length(tn);
for k=1:l
   
    x1=linspace(0,un(1,k),11);
    x2=linspace(un(1,k),un(2,k),11);
    y1=[0,0,.1,-.1,.1,-.1,.1,-.1,.1,0,0];y2=y1;
    set(tempo,'String',['t=',num2str(tn(k))]);
    set(parete,'xdata',[0,0],'ydata',[-0.5,0.5]);
    set(massa1,'xdata',un(1,k),'ydata',0);
    set(massa2,'xdata',un(2,k),'ydata',0);
    set(molla1,'xdata',x1,'ydata',y1);
    set(molla2,'xdata',x2,'ydata',y1);
    drawnow;
end
