# 520拿去表白，表白不成功你打我（Matlab代码动态图）

1 幸福和快乐的哲学追问

2 提前祝女朋友节日快乐

2.1 展现

2.2 代码

## 2 提前祝女朋友节日快乐

### 2.2 代码

``````clear
clc
tic
%% 构造体积方程和坐标轴
[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)]);%设置画布大小
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:67
plane = 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), drawnow
end
%% 描出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), drawnow
end

%% 给三维心着色补光
alpha(1)              %恢复透明度
set(p,'facecolor','m','edgecolor','none');
camlight               %补光
lighting gouraud
pause(.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,['WLZheartsuit'], '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,'xysheartsuit', '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
``````

THE END