这篇文章主要介绍了Matlab怎么实现动态表白图的绘制的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Matlab怎么实现动态表白图的绘制文章都会有所收获,下面我们一起来看看吧。
提前祝女朋友节日快乐
1 展现
这里没上传视频图,放最后一张成品:
2 代码
漂亮的颜色随你挑:
clearclctic%% 构造体积方程和坐标轴[X,Y,Z] = meshgrid(linspace(-3,3,101));%% 3D心型图方程F = -X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;%% 展开画布hFigure=figure;sz= get(hFigure, 'Position');set(hFigure, 'Position', [sz(1)-0.15*sz(3) sz(2) 1.3*sz(3) sz(4)]);%设置画布大小set(hFigure,'color','w', 'menu','none')%隐藏菜单,颜色做白hAxes = axes('Parent',hFigure,...?'DataAspectRatio',[1 1 1],...? ??'XLim',[30 120], 'YLim',[35 65], 'ZLim',[30 75]);view([-39 30]); %视角axis off %关闭坐标轴 %hidden on %% 制作出动态的隐形效果p = patch(isosurface(F,0)); set(p,'FaceColor','none','EdgeColor','none'); %心形线和面隐藏alpha(0); %使其为0透明度以便显示文字text(45,50,60,'WLZ','fontweight','bold','fontsize',25,'color','m');%显示出文字pause(2)hold on %% 描出Y-Z平面的心形轮廓for iX = 35:1:67plane = reshape(F(:,iX,:),101,101);cData = contourc(plane,[0 0]);xData = iX.*ones(1,cData(2,1));plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'r');pause(0.1), drawnowend%% 描出X-Z平面的心形轮廓for iY = 41:2:61 plane = reshape(F(iY,:,:),101,101); cData = contourc(plane,[0 0]); yData = iY.*ones(1,cData(2,1)); plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'r'); pause(.5), drawnow end%% 描出X-Y平面的心形轮廓for iZ = 36:1:71 plane = F(:,:,iZ); cData = contourc(plane,[0 0]); startIndex = 1; if size(cData,2) > (cData(2,1)+1) startIndex = cData(2,1)+2;zData = iZ.*ones(1,cData(2,1)); plot3(hAxes,cData(1,2:(startIndex-1)),...? ???? cData(2,2:(startIndex-1)),zData,'r'); end zData = iZ.*ones(1,cData(2,startIndex)); plot3(hAxes,cData(1,(startIndex+1):end),...?????? cData(2,(startIndex+1):end),zData,'r');pause(.1), drawnowend %% 给三维心着色补光alpha(1) %恢复透明度set(p,'facecolor','m','edgecolor','none');camlight %补光lighting gouraudpause(.2) %做线line([20 80],[50 50],[52.5 2.5], 'color','r')line([50 50],[20 80],[52.5 52.5], 'color','r')line([50 50],[50 50],[30 80], 'color','r')pause(0.5) %文字部分;text(0,50,107,'好好疼你,陪你长大\heartsuit','fontweight','bold','fontsize',25,'color','r');pause(2)text(7,100,70,['WLZ\heartsuit'], 'fontWeight','bold','FontAngle','italic','FontName','Trebuchet?MS','fontsize',45,'Color','c');pause(.5)text(80,50,43,'YOU', 'fontWeight','bold','FontAngle','italic','FontName','Trebuchet?MS','fontsize',60,'Color','k');pause(.2)text(75,5,40,'超级爱你\heartsuit', 'fontWeight','bold','FontAngle','italic','FontName','Trebuchet?MS','fontsize',20,'Color','g');pause(.2)text(120,0,20,'xys\heartsuit', 'fontWeight','bold','FontAngle','italic','FontName','Trebuchet?MS','fontsize',10,'Color','r');pause(.2)uicontrol(hFigure,'Style','Edit','Units','normalized','Position',[0,0.8,1,0.12],... 'Backgroundcolor','[0,1,1]','String','520快乐','Fontsize',40,'Foregroundcolor','[1,0,1]');pause(.5)uicontrol(hFigure,'Style','Edit','Units','normalized','Position',[0,0.8,1,0.12],... 'Backgroundcolor','[0.3,0.75,0.93]','String','520快乐','Fontsize',40,'Foregroundcolor','[1,0,1]');pause(.5)uicontrol(hFigure,'Style','Edit','Units','normalized','Position',[0,0.8,1,0.12],... 'Backgroundcolor','[1,0.5,0]','String','520快乐','Fontsize',40,'Foregroundcolor','[1,0,1]');pause(.5)uicontrol(hFigure,'Style','Edit','Units','normalized','Position',[0,0.8,1,0.12],... 'Backgroundcolor','[1,1,1]','String','520快乐','Fontsize',40,'Foregroundcolor','[1,1,1]');pause(.5)uicontrol(hFigure,'Style','Edit','Units','normalized','Position',[0,0.8,1,0.12],... 'Backgroundcolor','[1,1,0]','String','520快乐','Fontsize',40,'Foregroundcolor','[1,1,1]');toc
关于“Matlab怎么实现动态表白图的绘制”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Matlab怎么实现动态表白图的绘制”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网行业资讯频道。