MATLAB|绘制冰墩墩
% 参考 https://m.thepaper.cn/baijiahao_16627631
% 作者:2377389590@qq.com
% 公众号:好玩的MATLAB
% CSND :好玩的MATALB https://blog.csdn.net/zzx2016zzx
% 环境:Win10 Matlab20b
clc;clear;close all figure('name','公众号:好玩的MATLAB','color','w') EllipseAndCircle(0.8,1,-1.55,7.5,[0.96,3.35],0,'plot',[0.7765 0.8863 1]) %右耳朵轮廓 EllipseAndCircle(0.8,1,1.8,7.5,[-0.29,2.2],-0.01,'plot',[0.7765 0.8863 1]) % 头顶轮廓 EllipseAndCircle(3.4,4.5,0.1,4.1,[1.21,1.953],0,'plot',[0.7765 0.8863 1]) %左边耳朵到左手直接的轮廓 EllipseAndCircle(3.4,4.5,0.1,4.1,[2.34,2.94],0,'plot',[0.7765 0.8863 1]) %左手 EllipseAndCircle(0.8,0.6,-3.7,3.8,[2.1,6],0,'plot',[0.7765 0.8863 1]) line([-3.229,-4.1038],[5.014,4.317],'color',[0.7765 0.8863 1],'linewidth',2) %右边耳朵到右手直接的轮廓 EllipseAndCircle(3.4,4.5,0.1,4.1,[0.54,0.80266],0,'plot',[0.7765 0.8863 1]) %右手 pause(0.1) EllipseAndCircle(0.7,0.9,-2.5,6.7,[-0.32,3],0.9,'plot',[0.7765 0.8863 1]) line([3.01621,3.3707],[6.413,6.749],'color',[0.7765 0.8863 1],'linewidth',2) line([3.226,3.885],[4.866,5.426],'color',[0.7765 0.8863 1],'linewidth',2) % 右手到右腿之间的轮廓 pause(0.1) EllipseAndCircle(3.4,4.5,-0.1,5.8,[-0.9,-0.19],0,'plot',[0.7765 0.8863 1]) % 左手到左腿之间的轮廓 pause(0.1) EllipseAndCircle(3.4,4.5,0.02,5.8,[3.65,4.06],0,'plot',[0.7765 0.8863 1]) %左脚 pause(0.1) EllipseAndCircle(1,0.35,-1.23,0.8,[-0.8,0.6],0,'plot',[0.7765 0.8863 1]) EllipseAndCircle(1,0.35,-1.23,0.8,[2.6,4.2],0,'plot',[0.7765 0.8863 1]) line([-1.7455,-0.53329],[0.5,0.548925],'color',[0.7765 0.8863 1],'linewidth',2) line([-2.0484,-2.1026],[2.2285,0.9709],'color',[0.7765 0.8863 1],'linewidth',2) %右脚 pause(0.1) EllipseAndCircle(1,0.35,1.23,0.8,[-0.8,0.6],0,'plot',[0.7765 0.8863 1]) EllipseAndCircle(1,0.35,1.23,0.8,[2.6,4.2],0,'plot',[0.7765 0.8863 1]) line([0.714499,1.92671],[0.5,0.548925],'color',[0.7765 0.8863 1],'linewidth',2) line([2.0652,2.0134],[0.9924,2.275],'color',[0.7765 0.8863 1],'linewidth',2) %裤裆轮廓 pause(0.1) EllipseAndCircle(1,0.35,0,1.7,[4.25,5.16],0,'plot',[0.7765 0.8863 1]) line([-0.446,-0.3948],[1.38675,0.992481],'color',[0.7765 0.8863 1],'linewidth',2) line([0.40525,0.3731],[1.38003,0.980425],'color',[0.7765 0.8863 1],'linewidth',2) %% 内部轮廓 pause(0.1) EllipseAndCircle(3.3,4.3676,0.1,4.1,[0.5,3],0,'plot','k') EllipseAndCircle(0.8,0.2800,0,1.75,[3.8,5.6],0,'plot','k') EllipseAndCircle(3.3,4.3676,-0.1,5.8,[-1,-0.15],0,'plot','k') EllipseAndCircle(3.3,4.3676,0.02,5.8,[3.55,4.2],0,'plot','k') %% 内部填充 % 左耳朵填充 pause(0.1) EllipseAndCircle(0.7,0.8750,-1.55,7.5,[0.94,3.48],0,'fill','k') % 右耳朵填充 pause(0.1) EllipseAndCircle(0.7,0.8750,1.8,7.5,[-0.29,2.2],-0.01,'fill','k') % 左手内部填充 pause(0.1) EllipseAndCircle(0.7,0.5250,-3.7,3.8,[2.1,6],0,'fill','k') fill([-4.05,-3.038,-2.92,-3.139],[4.25,3.65,3.817,4.929],'k','FaceAlpha',0.9,'edgecolor','k') % 右手内部填充 pause(0.1) EllipseAndCircle(0.6, 0.7714,-2.5,6.7,[-0.32,3],0.9,'fill','k') fill([2.95,3.42425,3.8522,3.144],[6.3133,6.6669,5.526,5.004],'k','FaceAlpha',0.9,'edgecolor','k') % 右腿内部填充 pause(0.1) EllipseAndCircle(0.8, 0.3111,1.23,0.8,[-0.8,0.6],0,'fill','k') EllipseAndCircle(0.8, 0.3111,1.23,0.8,[2.6,4.2],0,'fill','k') fill([1.85384,1.89816,1.78737,0.817599,0.544489,0.489486],... [2.28022,0.9971089,0.576831,0.533422,0.960372,1.52853,],'k','FaceAlpha',0.9,'edgecolor','k') % 左腿内部填充 pause(0.1) EllipseAndCircle(0.8, 0.3111,-1.23,0.8,[-0.8,0.6],0,'fill','k') EllipseAndCircle(0.8, 0.3111,-1.23,0.8,[2.6,4.2],0,'fill','k') fill([-0.61,-0.5619,-0.672635,-1.6424,-1.91551,-1.83487],... [1.58,0.971089,0.576831,0.533422,0.960372,2.18764],'k','FaceAlpha',0.9,'edgecolor','k') %% 画脸 pause(0.1) EllipseAndCircle(2.5,2.1429,0.1,5.8,[0,2*pi],0,'plot',[126,198,124]/255) EllipseAndCircle(2.4, 2.0572,0.1,5.8,[0,2*pi],0,'plot',[232,185,105]/255) EllipseAndCircle(2.3,1.9715,0.1,5.8,[0,2*pi],0,'plot',[147,59,97]/255) EllipseAndCircle(2.2,1.8858,0.1,5.8,[0,2*pi],0,'plot',[145,208,239]/255) %画眼睛 %右眼 pause(0.1) EllipseAndCircle(0.9,0.55,-3,5.6,[0,2*pi],0.7,'fill','k') EllipseAndCircle(0.35,0.35,1,6.4,[0,2*pi],0,'fill','w') EllipseAndCircle(0.28,0.28,1,6.4,[0,2*pi],0,'fill','k') EllipseAndCircle(0.08,0.08,1.1,6.4,[0,2*pi],0,'fill','w') %左眼 EllipseAndCircle(0.9,0.55,3.4,5.28,[0,2*pi],-0.75,'fill','k') EllipseAndCircle(0.35,0.35,-0.84,6.3,[0,2*pi],0,'fill','w') EllipseAndCircle(0.28,0.28,-0.84,6.3,[0,2*pi],0,'fill','k') EllipseAndCircle(0.08,0.08,-0.68,6.3,[0,2*pi],0,'fill','w') %鼻子 pause(0.1) EllipseAndCircle(0.5,0.5,0.08,5.522,[1.0472,2.0944],0,'fill','k') EllipseAndCircle(0.265,0.4,0.08,6.1,[3.5,5.92],0,'fill','k') % 嘴巴1 pause(0.1) EllipseAndCircle(0.8,0.6,2.62,4.5,[1.85,6.7],-0.5,'fill','k') EllipseAndCircle(0.8,0.6,3.1,5.3,[3.48,5.1],-0.5,'fill','w') EllipseAndCircle(0.56,0.3,0.08,5,[0,2*pi],0,'fill','r')%舌头 %嘴巴2 % EllipseAndCircle(0.56,0.3,0.08,5.2,[pi,2*pi],0,'plot','k') %% 手上的爱心 pause(0.1) t=0:0.025:2*pi; x=(16*sin(t).^3)/36+3.8; y=(13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t))/36+6.2; % fill(x,y,'r','FaceAlpha',0.8,'edgecolor','r'); fill(x,y,'r','edgecolor','r'); %% 奥运五环 pause(0.1) EllipseAndCircle(0.2,0.2,-0.42,0.2+2,[0,2*pi],0,'plot','b') EllipseAndCircle(0.2,0.2,-0.2,0+2,[0,2*pi],0,'plot','y') EllipseAndCircle(0.2,0.2,0,0.2+2,[0,2*pi],0,'plot','k') EllipseAndCircle(0.2,0.2,0.2,0+2,[0,2*pi],0,'plot','g') EllipseAndCircle(0.2,0.2,0.42,0.2+2,[0,2*pi],0,'plot','r') %% 字标识BEIJING 2020 pause(0.1) text(0,2.62,'BEIJING 2022','HorizontalAlignment','center','FontName','Comic Sans MS','color','k','FontSize',10,'FontWeight','bold') text(4.2,7.5,'健儿加油!','HorizontalAlignment','center','FontName','方正舒体','color','r','FontSize',20,'FontWeight','bold') %% 冬奥会logo pause(0.1) fill([-0.1,-0.1,0.2,0.2],[3.4,3.33,3.28,3.357],[1,0.3,0.3],'edgecolor',[1,0.3,0.3]); hold on fill([0.08,-0.16,-0.1],[3.5,3.45,3.37],[0.1,0.3,0.53],'edgecolor',[0.1,0.3,0.53]); fill([0.162,-0.107,-0.231,-0.366,-0.304,-0.107],[3.3,3.3,3.25,3.21,3.2,3.2],[0.1,0.3,0.53],'edgecolor',[0.1,0.3,0.53]); fill([-0.33,-0.33,-0.2,0,0.4,0.5],[3.1,3.2,3.18,3.17,3.17,3.1],[0.4,0.3,0.53],'edgecolor',[0.4,0.3,0.53]); fill([0.5,-0.33,-0.15,0.5],[3.05,3.1,3,3],[0.4,0.6,0.8],'edgecolor',[0.4,0.6,0.8]); fill([0.04,-0.15,-0.15,0.3],[3,3,2.95,2.9],[0.4,0.3,0.53],'FaceAlpha',0.9,'edgecolor',[0.3,0.3,0.53]) axis equal off;
EllipsAndCircle函数
function EllipsAndCircle(a,b,x,y,Angle,Rotate,PlotType,Color) % a、b 为长短半径 % x,y 圆心坐标 % Angle 开始/结束角度 % Rotate 旋转角度 % PlotType 画的类型 包括 plot 和fill类型 % Color线的颜色 % a=1,b=2,x=0,y=0,Angle=[0,2*pi],Rotate=pi/3,PlotType='plot',Color='r' theta=Angle(1):pi/100:Angle(2); X=x+a*cos(theta); Y=y+b*sin(theta); XY=[X;Y]'*[cos(Rotate),-sin(Rotate);sin(Rotate),cos(Rotate)]; if strcmp(PlotType,'plot' ) plot(XY(:,1),XY(:,2),'-','color',Color,'linewidth',2.5); hold on; axis equal elseif strcmp(PlotType,'fill' ) fill(XY(:,1),XY(:,2),Color,'edgecolor',Color) % fill(XY(:,1),XY(:,2),Color,'FaceAlpha',0.9,'edgecolor',Color) hold on; axis equal else disp('没有此类型作图') end end
posted on 2022-02-10 23:45 好玩的MATLAB 阅读(94) 评论(0) 编辑 收藏 举报 来源