function sine_model(B1,B2)
% Filip Piekniewski 2010
% works in Matlab and Octave
% sine and cos-1 coupled oscillatros (phase model)
% B1 - strength of the sine coupling
% B2 - strength of cos-1 coupling
% e.g. sine_model(2,0) - pinwheels
% e.g. sine_model(2,2) - spiral waves
ff=figure;
N=150; % size of the domain
D=rand(N,N)*2*pi;
tau=0.02;
A1=ones(N,N);
A2=ones(N,N);
A3=ones(N,N);
A4=ones(N,N);
A1(1,1:end)=0;
A2(end,1:end)=0;
A3(1:end,1)=0;
A4(1:end,end)=0;

for i=1:5000
    
    D1=circshift(D,[1,0]);
    D2=circshift(D,[-1,0]);
    D3=circshift(D,[0,1]);
    D4=circshift(D,[0,-1]);
    % grid coupling
    C1=B1*(A1.*sin(D1-D)+A2.*sin(D2-D)+A3.*sin(D3-D)+A4.*sin(D4-D));
    C2=B2*(A1.*(cos(D1-D)-1)+A2.*(cos(D2-D)-1)+A3.*(cos(D3-D)-1)+A4.*(cos(D4-D)));
    % torus coupling
    %C1=B1*(sin(D1-D)+sin(D2-D)+sin(D3-D)+sin(D4-D));
    %C2=B2*((cos(D1-D)-1)+(cos(D2-D)-1)+(cos(D3-D)-1)+(cos(D4-D)));
    
    D=mod(D+tau*(1+C1+C2),2*pi);
    if mod(i,10)==0
      imagesc(D);
      %contourf(D);
      colorbar;drawnow;
       % Uncomment to print frames of the animation:
       % print(ff, '-r100', '-dpng', ['sine_model', num2str(i),'.png']);
    end;
end;    
    