function puzzle(larg,haut,pash,pasv,style,epaisseur,couleur)
if nargin<5
    error('arguments manquent')
end
if nargin==5
    epaisseur=1;
    couleur='b';
end

swapUn=0;
swapDeux=0;

h=plot(0,0);
hold on
delete(h)
axis equal
axis off

for j=2:haut
    swapDeux=~swapDeux;
    if rem(haut,2)
        swapUn=~swapDeux;
    else
        swapUn=swapDeux;
    end
    
    for i=1:larg
        xc(i)=i*pash;
        yc(i)=j*pasv;
        xm(i)=xc(i)+(pash/2);
        if swapUn
            ym(i)=yc(i)-pasv/4;
            yl(i)=yc(i)+has(15)*(pasv/2);;
        else
            ym(i)=yc(i)+pasv/4;
            yl(i)=yc(i)-has(15)*(pasv/2);
        end
        xl(i)=xc(i)+has(85)*(pash/2);
        
        xr(i)=xm(i)+has(15)*(pash/2);
        yr(i)=yl(i);
        xll(i)=xc(i)+has(75)*(pash/2);
        yll(i)=yc(i)+(ym(i)-yc(i))/2;
        xrr(i)=xm(i)+has(25)*(pash/2);
        yrr(i)=yll(i);
        x=[xc(i) xc(i)+.1*pash xl(i) xll(i) xm(i) xrr(i) xr(i) xc(i)+.9*pash xc(i)+pash];
        y=[yc(i) yc(i) yl(i) yll(i) ym(i) yrr(i) yr(i) yc(i) yc(i)];
        t=1:length(x);
        tt=linspace(1,length(x),200);
        xx=spline(t,[0 x 0],tt)-pash;
        yy=spline(t,[0 y 0],tt)-pasv;
        if style=='h'
            h=plot(xx,yy,'-'); set(h,'linewidth',epaisseur,'color',couleur)
        else
            h=plot(yy,xx,'-'); set(h,'linewidth',epaisseur,'color',couleur)
        end
    end
end

% cadre
if style=='h'
    h=plot([0 larg*pash larg*pash 0 0],[0 0 haut*pasv haut*pasv 0],'-');
    set(h,'linewidth',epaisseur,'color',couleur)
end
hold off

function nbo=has(nbi)
nbo=fix(rand*10+nbi)/100;

