clear all

MaxX=500;MaxY=500;
global M
M=zeros(MaxX,MaxY);

nv=10000;
set(0,'recursionlimit',nv);

R=0;
while R <3
prompt = 'Number of points? #>3 ';
R=input(prompt);
end

global Filler
Filler=1234;
global lineColor2
lineColor2=23;
color3=301;
lineColor=14;
global Ax
Ax=axes;
image(M');set(Ax,'YDir','normal');



%while 1
[X,Y]=ginput(R);        % points

X=floor(X);
Y=floor(Y);



R1=R-1;
for i = 1:1:R1
    DrawLine(X(i),Y(i),X(i+1),Y(i+1),lineColor);
    image(M'); set(Ax,'YDir','normal');

end

pause(1);

Xfirst=max(X(1),0);
Yfirst=max(Y(1),0);
Xlast=max(X(R),0);
Ylast=max(Y(R),0);

X=[Xfirst;X;Xlast];
Y=[Yfirst;Y;Ylast];

A = [- 1  3 -3 1; 2 -5 4 -1; - 1 0 1 0 ; 0 2 0 0];

image(M');set(Ax,'YDir','normal');

R=R+2;
for j= 2:1:R-2;
    BX= (1/2)* A * [X(j-1);X(j);X(j+1);X(j+2)];
    BY=  (1/2)* A * [Y(j-1);Y(j);Y(j+1);Y(j+2)];
    for i=0:0.0001:1
    xi=floor(BX(1)*i^3+BX(2)*i^2+BX(3)*i+BX(4) );
    yi=floor(BY(1)*i^3+BY(2)*i^2+BY(3)*i+BY(4) );
    M(xi,yi)= Filler;
    image(M');set(Ax,'YDir','normal')
    end;
end;

for i=2:1:R-1
    M(X(i),Y(i))=lineColor2;
end


image(M');
set(Ax,'YDir','normal');


