% Plot a 2D shape -- calls MySpline
% function [X,Y] = MySpline(x,y,n);
function [X,Y] = Plot2D(f1,f2,res);

% Create a user-defined spline
if isempty(f1) & isempty(f2)
cla;
axis on;
axis([-1 1 -1 1]);
axis square;
b = 1;
i = 0;

% Read mouse clicks every time the main button is pressed
while (b == 1)
i = i + 1;
[x(i),y(i),b] = ginput(1);
plot(x(i),y(i),'o');
axis([-1 1 -1 1]);
axis square;
hold on;
end

% Plot a spline fit to the chosen points
[X,Y] = MySpline(x,y,res);
cla;
plot(X,Y);
hold off;

% Plot the parametric shape defined by f1, f2
elseif not(isempty(f1)) & not(isempty(f2))
t = linspace(0,2*pi,res);
X = eval(f1);
Y = eval(f2);
plot(X,Y);
axis square;

% User is in the process of changing equations
else
X = '';
Y = '';
end