这是一个心型动画
function [xcar,ycar]=drawcardioid(varargin)
% A demonstration to show the form of the cardioid
error(nargchk(0,3,nargin));
nin = nargin;
if nin==0
cx1=0; cy1=0;
r=1;
elseif nin==1
cx1=0; cy1=0;
r=varargin{1};
elseif nin==2
cx1=0;
cy1= vararin{1};
r = varargin{2};
else
cx1=vararin{1};
cy1=vararin{2};
r=vararin{3};
end
if nargout==0
flag=1;
else
flag=0;
end
theta = linspace(0,2*pi,120);
x0 = r*cos(theta);
y0 = r*sin(theta);
x1 = x0+cx1;
y1 = y0+cy1;
cx2 = 2*x0+cx1;
cy2 = 2*y0+cy1;
x3=x0.*cos(theta)-y0.*sin(theta);
y3=x0.*sin(theta)+y0.*cos(theta);
for k=1:120
x2(k,:) = cx2(k)+x0;
y2(k,:) = cy2(k)+y0;
xx(k)=cx2(k)+x3(k);
yy(k)=cy2(k)+y3(k);
end
xcar = xx;
ycar = yy;
if flag
plot(x1,y1);
axis([cx1-3.2*r cx1+3.2*r cy1-3.2*r cy1+3.2*r]);
axis manual
hold on
daspect([1 1 1]);
set(gcf,'doublebuffer','on');
for k = 1:120
plot(x2(k,:),y2(k,:),'g',xx(k),yy(k),'r*');
pause(0.05);
%plot(x2,y2,'color','w');
end
end