%****************************************************
%       Copyright (C) 2008 Nasser Abbasi
%  Free to use and modify for academic and research only
%***************************************************

%script to test the function nma_makeDisk(N,r,cx,cy)
%a little simulation of a disk moving in 4 different configurations
%Nasser Abbasi

close all; clear all;

radius =25;
N=256;
A=nma_makeDisk(N,radius,0,0,0,255);

radius=25;   %in pixels radius of disk
N=256;       %size of overall image in pixels

cx1=-N/2:N/2-1; cy1=-N/2:N/2-1; %move it along the diagonal
cx2=20;         cy2=-N/2:N/2-1; %move it up and down, off center

angle=linspace(0,2*pi,N); %move it in a circle around center
rho=ones(1,N)*radius*3;
[cx3,cy3] = pol2cart(angle,rho);
cx3=round(cx3);
cy3=round(cy3);

%move it in a circle off center
cx4=10+cx3;  cy4=10+cy3;

h=figure(1);
set(h,'DoubleBuffer','on');
colormap(gray);

figure;
N=256;
radius=10;
CX=20;         CY=-N/2:N/2-1; %move it up and down, off center
CX2=-20;
for i=1:N
    A=nma_makeDisk(N,radius,CX,CY(i),0,255);
    B=nma_makeDisk(N,radius,CX2,CY(i),0,255);
    imshow(A+B,[]);
    drawnow;
end

for i=1:N
    subplot(2,2,1);
    imshow(nma_makeDisk(N,radius,cx1(i),cy1(i)),[]);
    line([1,N],[N/2,N/2],'Color','white');
    line([N/2,N/2],[1,N],'Color','white');
    line([1,N],[N,1],'Color','white','LineStyle',':');
    title('along the diagonal');

    subplot(2,2,2);
    imshow(nma_makeDisk(N,radius,cx2,cy2(i)),[]);
    line([1,N],[N/2,N/2],'Color','white');
    line([N/2,N/2],[1,N],'Color','white');
    line([cx2+N/2,cx2+N/2],[N,1],'Color','white','LineStyle',':');
    title('vertical off center');

    subplot(2,2,3);
    imshow(nma_makeDisk(N,radius,cx3(i),cy3(i)),[]);
    line([1,N],[N/2,N/2],'Color','white');
    line([N/2,N/2],[1,N],'Color','white');
    %plot(cx3,cy3,'Color','white','LineStyle',':');
    title('circle centered at center');

    subplot(2,2,4);
    imshow(nma_makeDisk(N,radius,cx4(i),cy4(i)),[]);
    line([1,N],[N/2,N/2],'Color','white');
    line([N/2,N/2],[1,N],'Color','white');
    %plot(cx4,cy4,'Color','white','LineStyle',':');
    title('circle centered off center');

    drawnow;
end

