PART.0 使用效果
PART.1 程序说明
这个代码主要复刻的Clayton Shonkwiler使用Wolfram绘制的作品(二十个旋转的正九变形),据说其灵感来源于Thomas Davis的一些作品,Clayton Shonkwiler的更多作品可以在这个地址查看
PART.2 完整代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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: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{:}); % 旋转 for n=1:1000 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 pause(.05) drawnow end end |
到此这篇关于利用Matlab绘制好看的旋转九边形的文章就介绍到这了,更多相关Matlab旋转九边形内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://mp.weixin.qq.com/s/L3yN4v4ICU5oOlO-D1a-Tw