MATLAB | 万圣节来画个简单的可爱鬼叭!

万圣节要到啦一起来画个可爱鬼吧~

MATLAB | 万圣节来画个简单的可爱鬼叭!_第1张图片

代码比较的短:

完整代码

figure('Units','normalized','Position',[.2,.1,.52,.72]);
ax=gca;hold on;axis off; 
ax.DataAspectRatio=[1,1,1];
ax.YDir='reverse';
ax.XLim=[0,100];
ax.YLim=[0,100];
[X,Y]=meshgrid(linspace(0,1,200));
Z=sqrt((X-.5).^2+(Y-.5).^2);
image([0,100],[0,100],Z.*420);
colormap(flipud(gray))
% colormap(gray)
% colormap(summer)
% 配色及基础数据 ===========================================================
CList=[255,255,255;  83, 70, 63; 
       158,158,157; 254,201,206; 
       246,213,85 ; 253,247,197]./255;
CircT=linspace(0,2*pi,200);
% 绘制叉子或者星星 =================================================================
plot([85,91.3],[24.8,52.8],'Color',CList(2,:),'LineWidth',18)
% 画叉子的代码
% plot([80,82,92.5,90.7],[28,34.3,31,25.2],'Color',CList(2,:),'LineWidth',18)
% 画星星的代码
StarT=[linspace(0,2*pi,6);linspace(0,2*pi,6)+pi/5];
StarT=StarT(:,1:5);StarT=StarT(:);StarR=[1;cos(pi/5)*2]*ones(1,5);StarR=StarR(:);
fill(cos(StarT).*StarR.*5+85,sin(StarT).*StarR.*5+25,CList(5,:),'LineWidth',2)
fill(cos(StarT).*StarR.*3+85,sin(StarT).*StarR.*3+25,CList(6,:),'EdgeColor','none')
% 绘制身体 =================================================================
fill([19.3,15.1,12.7,10,8.9,9.6,linspace(10,90,200),91.3,92.4,91.3,88.4,84.1,77],...
    [43.4,54.7,63.2,72.6,79,82,-linspace(-1.5,1.5,200).^2+3.*sin(linspace(0,7*pi,200))+85,...
    80.9,76.6,71.5,64.2,54.5,39.2],CList(1,:),'LineWidth',12,'EdgeColor',CList(2,:))
fill([24,cos(CircT(80:200)).*3.5+16],...
     [60,sin(CircT(80:200)).*4.1+46],...
      CList(1,:),'LineWidth',14,'EdgeColor',CList(2,:))
fill([76,cos(CircT([100:200,1:40])).*3.5+82],...
     [55,sin(CircT([100:200,1:40])).*4.5+43.5],...
      CList(1,:),'LineWidth',14,'EdgeColor',CList(2,:))
fill(cos(CircT).*30+49.5,sin(CircT).*30+47.5,CList(1,:),'LineWidth',12,'EdgeColor',CList(1,:))
plot(cos(CircT(100:195)).*30+49.5,sin(CircT(100:195)).*30+47.5,'Color',CList(2,:),'LineWidth',12)
fill([42.8,41.3,40,38.6,37.4,36.8,36],[19,16.6,14.3,13.3,15.1,17.8,20.6],CList(3,:),'LineWidth',12,'EdgeColor','none')
plot([42.8,41.3,40,38.6,37.4,36.8,36],[19,16.6,14.3,13.3,15.1,17.8,20.6],'Color',CList(2,:),'LineWidth',12)
fill([61.7,61.3,60.3,59,57.5,56.1,54.7,52],[20,18.6,16.3,14.3,13.4,15.5,17.2,17.5],CList(3,:),'LineWidth',12,'EdgeColor','none')
plot([61.7,61.3,60.3,59,57.5,56.1,54.7,52],[20,18.6,16.3,14.3,13.4,15.5,17.2,17.5],'Color',CList(2,:),'LineWidth',12)
% 绘制五官 =================================================================
fill(cos(CircT).*6.2+33.7,sin(CircT).*5.9+42.5,CList(4,:),'EdgeColor','none')
fill(cos(CircT).*6.2+62.1,sin(CircT).*5.9+39.7,CList(4,:),'EdgeColor','none')
fill(cos(CircT).*2.2+39.1,sin(CircT).*2.8+37.8,CList(2,:),'EdgeColor','none')
fill(cos(CircT).*2.2+56.3,sin(CircT).*2.8+35.9,CList(2,:),'EdgeColor','none')
fill(cos(CircT).*1.1+51,sin(CircT).*1.2+39.3,CList(2,:),'EdgeColor','none')
plot([43.7,45.7,48,50,51.7],[39.1,39.7,39.5,38.8,38.1],'Color',CList(2,:),'LineWidth',6)

关于背景色

背景色是通过这里来设置的:

[X,Y]=meshgrid(linspace(0,1,200));
Z=sqrt((X-.5).^2+(Y-.5).^2);
image([0,100],[0,100],Z.*420);
colormap(flipud(gray))
% colormap(gray)
% colormap(summer)

更换colormap可以试试不同的背景色:

MATLAB | 万圣节来画个简单的可爱鬼叭!_第2张图片

MATLAB | 万圣节来画个简单的可爱鬼叭!_第3张图片

MATLAB | 万圣节来画个简单的可爱鬼叭!_第4张图片


关于叉子或者星星

绘制叉子或者绘制星星是在这里实现的:

plot([85,91.3],[24.8,52.8],'Color',CList(2,:),'LineWidth',18)
% 画叉子的代码
% plot([80,82,92.5,90.7],[28,34.3,31,25.2],'Color',CList(2,:),'LineWidth',18)
% 画星星的代码
StarT=[linspace(0,2*pi,6);linspace(0,2*pi,6)+pi/5];
StarT=StarT(:,1:5);StarT=StarT(:);StarR=[1;cos(pi/5)*2]*ones(1,5);StarR=StarR(:);
fill(cos(StarT).*StarR.*5+85,sin(StarT).*StarR.*5+25,CList(5,:),'LineWidth',2)
fill(cos(StarT).*StarR.*3+85,sin(StarT).*StarR.*3+25,CList(6,:),'EdgeColor','none')

MATLAB | 万圣节来画个简单的可爱鬼叭!_第5张图片

MATLAB | 万圣节来画个简单的可爱鬼叭!_第6张图片


祝MATLABer万圣节快乐!!
一起画个可爱鬼叭

你可能感兴趣的:(matlab,python,算法,万圣节)