• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 15
  • 52
  • 0
  • 2
  • 1131
drawframe(1);
Write your drawframe function below
function drawframe(f)
global NGonSet rotateMat NGonHdl
if f==1
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:20
NGonHdl{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{:});
else
% 旋转
n=f
NGonSet=rotateMat*NGonSet;
for i=1:20
NGonHdl{i}.XData=NGonSet(i*2-1,:)+cos((i-1)*pi/10)*2;
NGonHdl{i}.YData=NGonSet(i*2,:)+sin((i-1)*pi/10)*2;
end
end
end
Animation
Remix Tree