当前位置:网站首页>Matlab draws a cute fat doll
Matlab draws a cute fat doll
2022-07-05 22:04:00 【slandarer】
1 Program description
This program uses a series of ellipses , Round rectangle and heart shape are put together , The following describes how each part is generated :
ellipse :
Ellipse is to use the following ellipse data generation function to generate data points , After that fill Function , among Mu Is the center point of the ellipse ,Sigma It's a covariance matrix ,S Is the square of radius ,pntNum Is the number of generated data points :
% Elliptic data calculation function , Input covariance matrix 、 Center point 、 Radius generates ellipse data
function [X,Y]=getEllipse(Mu,Sigma,S,pntNum)
% (X-Mu)*inv(Sigma)*(X-Mu)=S
invSig=inv(Sigma);
[V,D]=eig(invSig);
aa=sqrt(S/D(1));
bb=sqrt(S/D(4));
t=linspace(0,2*pi,pntNum);
XY=V*[aa*cos(t);bb*sin(t)];
X=(XY(1,:)+Mu(1))';
Y=(XY(2,:)+Mu(2))';
end
Rounded rectangle :
Use MATLAB The built-in fillet matrix generation function , For details, please go to MATHWORKS Official website view :
rectangle(‘Position’,pos,‘Curvature’,cur)
heart-shaped :
Use the following cardioid function :
x = 16 ( sin t ) 3 y = 13 cos t − 5 cos ( 2 t ) − 2 cos ( 3 t ) − cos ( 4 t ) \begin{aligned} &x=16(\sin t)^{3} \\ &y=13 \cos t-5 \cos (2 t)-2 \cos (3 t)-\cos (4 t) \end{aligned} x=16(sint)3y=13cost−5cos(2t)−2cos(3t)−cos(4t)
t=linspace(-2.9,2.9,1000);
X=16.*(sin(t)).^3;
Y=13.*cos(t)-5.*cos(2.*t)-2.*cos(3.*t)-cos(4.*t);
fill(X,Y,[180,39,45]./255,'EdgeColor',[180,39,45]./255,'LineWidth',2)

2 Complete code
function bingdundun
ax=gca;
ax.DataAspectRatio=[1 1 1];
ax.XLim=[-5 5];
ax.YLim=[-5 5];
hold(ax,'on')
% =========================================================================
% Draw rock sugar shell
[X,Y]=getEllipse([0,0],[1,0;0,1.3],3.17^2,200);
plot(X,Y,'Color',[57,57,57]./255,'LineWidth',1.8)
%
[X,Y]=getEllipse([1.7,2.6],[1.2,0;0,1.8],.65^2,200);
plot(X,Y,'Color',[57,57,57]./255,'LineWidth',1.8)
plot(-X,Y,'Color',[57,57,57]./255,'LineWidth',1.8)
[X,Y]=getEllipse([1.7,2.6],[1.2,0;0,1.8],.6^2,200);
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
fill(-X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
%
[X,Y]=getEllipse([-3.5,-1],[1.1,.3;.3,1.1],.75^2,200);
plot(X,Y,'Color',[57,57,57]./255,'LineWidth',1.8)
[X,Y]=getEllipse([-3.5,-1],[1.1,.3;.3,1.1],.68^2,200);
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
[X,Y]=getEllipse([3.5,1],[1.1,.3;.3,1.1],.75^2,200);
plot(X,Y,'Color',[57,57,57]./255,'LineWidth',1.8)
[X,Y]=getEllipse([3.5,1],[1.1,.3;.3,1.1],.68^2,200);
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
%
X=[-3.8,-2,-3];
Y=[-.51+.13,1+.13,-1];
plot(X,Y,'Color',[57,57,57]./255,'LineWidth',1.8)
plot(-X,-Y,'Color',[57,57,57]./255,'LineWidth',1.8)
X=[-3.8,-2,-3];
Y=[-.51+.03,1+.03,-1];
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
fill(-X,-Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
%
[X,Y]=getEllipse([0,-.1],[1,0;0,1.6],.9^2,200);
Y(Y<0)=Y(Y<0).*.2;Y=Y-4.2;X=X-1.2;
plot(X,Y,'Color',[57,57,57]./255,'LineWidth',2)
plot(-X,Y,'Color',[57,57,57]./255,'LineWidth',2)
rectangle('Position',[-2.1 -4.2 1.7 3],'Curvature',0.4,...
'FaceColor',[1 1 1],'EdgeColor',[57,57,57]./255,'LineWidth',1.8)
rectangle('Position',[2.1-1.7 -4.2 1.7 3],'Curvature',0.4,...
'FaceColor',[1 1 1],'EdgeColor',[57,57,57]./255,'LineWidth',1.8)
[X,Y]=getEllipse([0,-.1],[1,0;0,1.6],.8^2,200);
Y(Y<0)=Y(Y<0).*.2;Y=Y-4.1;X=X-1.2;
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
fill(-X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
%
[X,Y]=getEllipse([0,0],[1,0;0,1.3],3.1^2,200);
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',1.8)
% =========================================================================
% Ears
[X,Y]=getEllipse([1.7,2.6],[1.2,0;0,1.8],.5^2,200);
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
fill(-X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
% Arm
[X,Y]=getEllipse([-3.5,-1],[1.1,.3;.3,1.1],.6^2,200);
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
[X,Y]=getEllipse([3.5,1],[1.1,.3;.3,1.1],.6^2,200);
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
X=[-3.8,-2,-3];
Y=[-.51,1,-1];
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255)
fill(-X,-Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255)
tt=linspace(-2.9,2.9,1000);
X=16.*(sin(tt)).^3;
Y=13.*cos(tt)-5.*cos(2.*tt)-2.*cos(3.*tt)-cos(4.*tt);
X=X.*.018+3.6;
Y=Y.*.018+1.1;
fill(X,Y,[180,39,45]./255,'EdgeColor',[180,39,45]./255,'LineWidth',2)
% leg
[X,Y]=getEllipse([0,-.1],[1,0;0,1.6],.7^2,200);
Y(Y<0)=Y(Y<0).*.2;Y=Y-4.1;X=X-1.2;
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
fill(-X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
rectangle('Position',[-1.95 -4.3 1.4 3],'Curvature',0.4,...
'FaceColor',[57,57,57]./255,'EdgeColor',[57,57,57]./255)
rectangle('Position',[1.95-1.4 -4.3 1.4 3],'Curvature',0.4,...
'FaceColor',[57,57,57]./255,'EdgeColor',[57,57,57]./255)
% The body
[X,Y]=getEllipse([0,0],[1,0;0,1.3],3^2,200);
fill(X,Y,[1,1,1],'EdgeColor',[57,57,57]./255,'LineWidth',2.5)
% Five rings
cList=[132,199,114;251,184,77;89,120,177;158,48,87;98,205,247];
for i=1:5
[X,Y]=getEllipse([0,0],[1.6,0;0,1.3],(2.05-0.05.*i)^2,200);
Y(Y<0)=Y(Y<0).*.8;Y=Y+.5;
fill(X,Y,[1,1,1],'EdgeColor',cList(i,:)./255,'LineWidth',2.5)
end
% eyes
[X,Y]=getEllipse([1.2,1.2],[1.2,-.5;-.5,1.1],.65^2,200);
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
fill(-X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
[X,Y]=getEllipse([.95,1.3],[1,0;0,1],.35^2,200);
fill(X,Y,[57,57,57]./255,'EdgeColor',[1,1,1],'LineWidth',1.6)
fill(-X,Y,[57,57,57]./255,'EdgeColor',[1,1,1],'LineWidth',1.6)
[X,Y]=getEllipse([.95,1.3],[1,0;0,1],.1^2,200);
fill(X+.18,Y,[1,1,1],'EdgeColor',[57,57,57]./255,'LineWidth',.5)
fill(-X+.18,Y,[1,1,1],'EdgeColor',[57,57,57]./255,'LineWidth',.5)
% mouth
[X,Y]=getEllipse([0.05,.2],[1.2,.15;.15,.8],.69^2,200);
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
[X,Y]=getEllipse([0,.75],[1,0.2;0.2,.3],.4^2,200);
fill(X,Y,[1,1,1],'EdgeColor',[1,1,1],'LineWidth',2)
[X,Y]=getEllipse([0,0],[.8,0;0,.2],.6^2,200);
fill(X,Y,[180,39,45]./255,'EdgeColor',[180,39,45]./255,'LineWidth',2)
% nose
[X,Y]=getEllipse([0,-.1],[1,0;0,1.6],.2^2,200);
Y(Y<0)=Y(Y<0).*.2;Y=-Y+.9;
fill(X,Y,[57,57,57]./255,'EdgeColor',[57,57,57]./255,'LineWidth',2)
% =========================================================================
% The Winter Olympics logo and the five rings
% Five rings
tt=linspace(0,2*pi,100);
X=cos(tt).*.14;
Y=sin(tt).*.14;
plot(X,Y-2.8,'Color',[57,57,57]./255,'LineWidth',1.2)
plot(X-.3,Y-2.8,'Color',[106,201,245]./255,'LineWidth',1.2)
plot(X+.3,Y-2.8,'Color',[155,79,87]./255,'LineWidth',1.2)
plot(X-.15,Y-2.9,'Color',[236,197,107]./255,'LineWidth',1.2)
plot(X+.15,Y-2.9,'Color',[126,159,101]./255,'LineWidth',1.2)
% Text
text(0,-2.4,'BEIJING 2022','HorizontalAlignment','center',...
'FontSize',8,'FontName','Comic Sans MS')
% sign
fill([.1,-.12,-.08],[0,0-0.05,-0.15]-1.5,[98,118,163]./255,'EdgeColor',[98,118,163]./255)
fill([-.08,-.35,.1],[-0.1,-.2,-.1]-1.6,[98,118,163]./255,'EdgeColor',[98,118,163]./255)
fill([-.08,-.08,.1,.1],[-0.1,-0.15,-.2,-.15]-1.5,[192,15,45]./255,'EdgeColor',[192,15,45]./255)
plot([-.35,-.3,-.25,-.2,-.15,-.1,-.05,.1]+.02,...
[0,.02,.04,.06,.04,.02,0,.02]-1.82,'Color',[120,196,219]./255,'LineWidth',1.8)
plot([-.33,.05]+.02,[0,-.08]-1.82,'Color',[190,215,84]./255,'LineWidth',1.8)
plot([.05,-.2]+.02,[-.08,-.15]-1.82,'Color',[32,162,218]./255,'LineWidth',1.8)
plot([-.2,.05]+.02,[-.15,-.2]-1.82,'Color',[99,118,151]./255,'LineWidth',1.8)
% =========================================================================
% Elliptic data calculation function , Input covariance matrix 、 Center point 、 Radius generates ellipse data
function [X,Y]=getEllipse(Mu,Sigma,S,pntNum)
% (X-Mu)*inv(Sigma)*(X-Mu)=S
invSig=inv(Sigma);
[V,D]=eig(invSig);
aa=sqrt(S/D(1));
bb=sqrt(S/D(4));
t=linspace(0,2*pi,pntNum);
XY=V*[aa*cos(t);bb*sin(t)];
X=(XY(1,:)+Mu(1))';
Y=(XY(2,:)+Mu(2))';
end
end
边栏推荐
- Microservice link risk analysis
- Huawei fast game failed to call the login interface, and returned error code -1
- 854. String BFS with similarity K
- K210学习笔记(四) K210同时运行多个模型
- Overview of concurrency control
- Concurrency control of performance tuning methodology
- Common interview questions of redis factory
- 2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
- Ad637 notes d'utilisation
- Official clarification statement of Jihu company
猜你喜欢
Database tuning solution
Livelocks and deadlocks of concurrency control
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Granularity of blocking of concurrency control
Oracle advanced query
A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition
Getting started with microservices (resttemplate, Eureka, Nacos, feign, gateway)
Ad637 notes d'utilisation
[Yugong series] go teaching course in July 2022 004 go code Notes
华为快游戏调用登录接口失败,返回错误码 -1
随机推荐
boundary IoU 的计算方式
CA certificate trampled pit
Installation of VMware Workstation
A trip to Suzhou during the Dragon Boat Festival holiday
poj 3237 Tree(树链拆分)
How to develop and introduce applet plug-ins
装饰器学习01
Codeforces 12D Ball 树形阵列模拟3排序元素
QML reported an error expected token ";", expected a qualified name ID
ICMP 介绍
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
Poj 3237 Tree (Tree Chain Split)
他们主动布局(autolayout)环境的图像编辑器
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
Basic grammar of interview (Part 1)
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
Oracle views the data size of a table
让开发效率提升的跨端方案
Did you brush the real title of the blue bridge cup over the years? Come here and teach you to counter attack!
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~