MatLab中畫雪人

思路

  1. 畫出左右手:可以用線段表示
  2. 畫頭、身體:用圓表示
  3. 畫眼睛:用小圓表示
  4. 畫嘴巴:用小小的二次曲線表示
  5. 畫鼻子:用尖尖的三角形表示
  6. 畫帽子:用四邊形表示
  7. 添加其他想要的文字

具體代碼

<code>clc;close all;
figure;
patch([-12 -12 7 7],[-12 3 3 -12],[ 0.5843 0.8157 0.9882]);
axis equal;
axis([-12 7 -12 3]);
hold on;
t=0:0.01:2*pi;
%left hand
plot([-1.8 -4],[-2.9 -1],'r','linewidth',4);
%right hand
plot([1.8 4],[-2.9 -1],'r','linewidth',4);
%upper circle
x=cos(t);y=sin(t);
fill(x,y,'w');
%middle circle
x=2*cos(t);y=-2.8+2*sin(t);
fill(x,y,'w');
%lower circle
x=3*cos(t);y=-7.5+3*sin(t);
fill(x,y,'w');
%botam
x=0.25*cos(t);y=-2+0.25*sin(t);
fill(x,y,'k');
x=0.25*cos(t);y=-4+0.25*sin(t);
fill(x,y,'k');
x=0.25*cos(t);y=-7+0.25*sin(t);
fill(x,y,'k');
x=0.25*cos(t);y=-9+0.25*sin(t);
fill(x,y,'k');
%eyes
x=-0.5+0.25*cos(t);y=0.4+0.25*sin(t);
fill(x,y,'k');
x=0.5+0.2*cos(t);y=0.4+0.2*sin(t);
fill(x,y,'k');
%mouth
t=-0.3:0.1:0.3;
y=t.^2-0.5;
plot(t,y,'k','linewidth',2);
%hat
plot([-1 1],[0.8 0.8],'k','linewidth',5);
fill([-0.6 -0.6 0.6 0.6],[0.8 2 2 0.8],'k');
%nose
patch([-0.15 -0.15 1.5],[0.1 -0.2 -0.3],[1 0.5 0]);
text(-10,2,'HAPPY CHRISTMAS','Color','black','FontSize',30)/<code>

結果展示


MatLab中畫雪人

MatLab中畫雪人


分享到:


相關文章: