运行效果
完整代码
function nonagon20% @author:slandarer% axes属性设置ax=gca;hold on;axis equal;ax.Position=[0 0 1 1];ax.XLim=[-6,6];ax.YLim=[-6,6];ax.XColor='none';ax.YColor='none';ax.Color=[0,44,106]./255;% 初始集合构建t=linspace(0,2*pi,9);NGon=[cos(t'),sin(t')].*2;NGonSet=repmat(NGon',[20,1]);rotate18=arrayfun(@(k)[cos(pi/10),-sin(pi/10);sin(pi/10),cos(pi/10)]^k,0:19,'UniformOutput',false);rotate18=blkdiag(rotate18{:});NGonSet=rotate18*NGonSet;% 渐变颜色矩阵创建C1=[237,210,155]./255;C2=[219,90,117]./255;ct=linspace(0,1,11);CList=[interp1([0,1],[C1(1),C2(1)],ct,'linear')',...interp1([0,1],[C1(2),C2(2)],ct,'linear')',...interp1([0,1],[C1(3),C2(3)],ct,'linear')'];CList=[CList;flipud(CList(2:10,:))];CList=[CList(5:end,:);CList(1:4,:)]; % 初始图像绘制NGonHdl{20}=[];for i=1:20NGonHdl{i}=fill(NGonSet(i*2-1,:)+cos((i-1)*pi/10)*2,...NGonSet(i*2,:)+sin((i-1)*pi/10)*2,CList(i,:),...'FaceAlpha',.12,'LineWidth',1.3,'EdgeColor',CList(i,:)); end% 旋转矩阵rotateMat=arrayfun(@(k)[cos(k),-sin(k);sin(k),cos(k)],ones([1,20]).*(2*pi/120),'UniformOutput',false);rotateMat=blkdiag(rotateMat{:});% 旋转for n=1:1000NGonSet=rotateMat*NGonSet;for i=1:20NGonHdl{i}.XData=NGonSet(i*2-1,:)+cos((i-1)*pi/10)*2;NGonHdl{i}.YData=NGonSet(i*2,:)+sin((i-1)*pi/10)*2;endpause(.05)drawnowendend