当前位置:首页 » 《资源分享》 » 正文

中秋节快到了,一起用MATLAB绘制一款2.5D月饼叭_slandarer的博客

25 人参与  2021年10月28日 07:43  分类 : 《资源分享》  评论

点击全文阅读


转眼中秋节就要到了!!

用MATLAB给大家画个月饼:

同时,在这里

提前祝大家中秋快乐!!!

程序其实非常简单哈,只是用一系列plot和fill绘制线条和各种不规则形状拼接起来就好,说是2.5D,只是依靠降低y轴坐标数值重新绘图模拟阴影效果,显得比平面月饼更有立体感了而已。

程序效果:

在这里插入图片描述

完整代码:

function moonCake
% @author:slandarer
ax=gca;
hold(ax,'on');
axis equal
ax.XLim=[-15,15];
ax.YLim=[-15,15];
CSet=[0.92 0.51 0.11;1 0.7 0.09;0.87 0.41 0.05];


for i=[1:7,9,8]
    if i==1
        tt=linspace(0,-pi/16,100);
    elseif i==9
        tt=linspace(-pi+pi/16,-pi,100);
    else
        tt=linspace(-pi/16-(i-2)*pi/8,-pi/16-(i-1)*pi/8,100);
    end
    xSet=cos(tt).*(10+abs(cos(tt.*8)));
    xMin=find(xSet==min(xSet));tt(xMin)
    xMax=find(xSet==max(xSet));
    t1=min([xMin(1),xMax(1)]);
    t2=max([xMin(1),xMax(1)]);
    xSet=cos(tt(t1:t2)).*(10+abs(cos(tt(t1:t2).*8)));
    ySet=sin(tt(t1:t2)).*(10+abs(cos(tt(t1:t2).*8)))-3;
    fill([xSet(1),xSet,xSet(end)],[ySet(1)+3,ySet,ySet(end)+3],CSet(mod(i,2)+1,:),'EdgeColor','none')
    
    
end
t=linspace(0,2*pi,640);
fill(cos(t).*(10+abs(cos(t.*8))),sin(t).*(10+abs(cos(t.*8))),CSet(1,:),'EdgeColor','none')
plot(cos(t).*(9+abs(cos(t.*8))),sin(t).*(9+abs(cos(t.*8)))-0.3,'Color',CSet(3,:),'LineWidth',6)
plot(cos(t).*8.7,sin(t).*8.7-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(cos(t).*(9+abs(cos(t.*8))),sin(t).*(9+abs(cos(t.*8))),'Color',CSet(2,:),'LineWidth',6)
plot(cos(t).*8.7,sin(t).*8.7,'Color',CSet(2,:),'LineWidth',4)

plot([0 0],[-7 7]-0.3,'Color',CSet(3,:),'LineWidth',4)
plot([-7 7],[0 0]-0.3,'Color',CSet(3,:),'LineWidth',4)
plot([0 0],[-7 7],'Color',CSet(2,:),'LineWidth',4)
plot([-7 7],[0 0],'Color',CSet(2,:),'LineWidth',4)


t4=linspace(0,pi/2,100);
xSet4=[cos(t4).*6+1,1,6,cos(t4(1:end-12)).*5+1,2,4.8,cos(t4(17:end-40)).*3.9+1];
ySet4=[sin(t4).*6+1,1,1,sin(t4(1:end-12)).*5+1,2,2,sin(t4(17:end-40)).*3.9+1];

plot(xSet4,ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(-xSet4,ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(xSet4,-ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(-xSet4,-ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(xSet4,ySet4,'Color',CSet(2,:),'LineWidth',4)
plot(-xSet4,ySet4,'Color',CSet(2,:),'LineWidth',4)
plot(xSet4,-ySet4,'Color',CSet(2,:),'LineWidth',4)
plot(-xSet4,-ySet4,'Color',CSet(2,:),'LineWidth',4)
end

当然,大家也可以尝试其它颜色:
在这里插入图片描述
颜色列表如下:

CSet1=[0.92 0.51 0.11;1 0.7 0.09;0.87 0.41 0.05];
CSet2=[0.43 0.68 0.44;0.62 0.8 0.44;0.28 0.47 0.28];
CSet3=[0.44 0.25 0.38;0.54 0.37 0.51;0.23 0.16 0.21];
CSet4=[0.94 0.83 0.55;0.98 0.89 0.68;0.83 0.67 0.4];
CSet5=[0.79 0.46 0.44;0.9 0.61 0.58;0.73 0.38 0.38];
CSet6=[0.89 0.7 0.23;0.97 0.85 0.37;0.91 0.68 0.2];
CSet7=[0.54 0.38 0.27;0.64 0.42 0.27;0.25 0.1 0.03];
CSet8=[ 0.62 0.53 0.6;0.7 0.7 0.81;0.44 0.39 0.45];
CSet9=[0.73 0.78 0.65;0.75 0.84 0.77;0.59 0.58 0.48];

再次祝愿大家中秋快乐

阖家团圆幸福!


点击全文阅读


本文链接:http://zhangshiyu.com/post/30193.html

月饼  中秋  颜色  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1