function flowers(a,b,r,mode,N,gifname)
%万花尺程序
%input -a 大圆半径 -b 小圆半径 -r 画笔距小圆圆心的距离
% -mode :非0 表示小圆沿大圆内侧转动
% 0 表示小圆沿大圆外侧转动
% a = 4;b = 1.2;mode =1;r = b;%10花尺
% a = 4;b = 2;mode =1;r = 3;%2花尺
% a = 4;b = 1;mode =1;r = b;%4花尺
% a = 4;b = 1.5;mode =1;r = b;%8花尺
% a = 4;b = 0.75;mode =1;r = b;%16花尺
% a = 4;b = 8/3;mode =1;r = b;%6花尺
% a = 4;b = 8/9;mode =1;r = b;%9花尺
% a = 4;b = 4/3;mode =1;r = b/2;%3花尺
% a = 4;b = 1;mode =1;r = b/2;%4花尺
% a = 4;b = 2;mode =1;r = b;%2花尺
if nargin < 3,r = b;end
if nargin < 4 || mode,mode = -1;else mode = 1;end
if nargin < 5,N = 10;end
if nargin < 6,gifname = 'flowers.gif';end
[k,m] = cylnumber(a,b,N);
t = 0:pi/200:2*k*pi;
tt = 0:pi/200:2*pi;
x1 = a+mode*b;
xx = a*cos(tt); yy = a*sin(tt);
plot(xx,yy);
xm = a+abs(r+mode*b);
axis equal off
title([num2str(m),'花尺'])
%设置颜色、标记、标记尺寸、擦除模式
h = line('Color','k','Marker','*',...
'MarkerSize',1,'EraseMode','xor');
h2 = line('Color','k','Marker','.',...
'MarkerSize',8,'EraseMode','xor');
h1 = line('Color','r','Marker','.',...
'MarkerSize',20,'EraseMode','xor');
n = length(t);
if mode == -1,nk = n:-1:1;else nk = 1:n;end
for k = 1:n
x = x1*cos(t(k))+r*cos(x1/b*t(nk(k)));
y = x1*sin(t(k))+r*sin(x1/b*t(nk(k)));
x2 = x1*cos(t); y2 = x1*sin(t);
x3 = x2(k)+b*cos(tt); y3 = y2(k)+b*sin(tt);
hold on
set(h,'xdata',x3,'ydata',y3); %画图、画线设置
plot(x,y,'r.');
set(h2,'xdata',[x x2(k)],'ydata',[y y2(k)]);
set(h1,'xdata',[x x],'ydata',[y y]);
axis([-xm,xm,-xm,xm]);
try
f = getframe;
imind = frame2im(f); %将单帧图像转化为RGB图像
[imind,cm] = rgb2ind(imind,256);
if k ~= 1
imwrite(imind,cm,gifname,'gif','WriteMode','append','DelayTime',.05)
else
imwrite(imind,cm,gifname,'gif','Loopcount',inf,'DelayTime',.05)
end
end
pause(0.00001)
end
function [k,m] = cylnumber(a,b,N)
k = 1;
m = a/b;
while rem(m,1) && k < N
k = k + 1;
m = k*a/b;
end