%在MATLAB中运行
%参考https://download.csdn.net/download/windywoody/5485279
%
clear all;
close all;
clc;
%配置函数,建立图形
f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3.*2 - (9./80).*y.^2.*z.^3;%心形的方程
[x,y,z]=meshgrid(-2:0.04:2); %设置网格密度,中间的数字越小,格越密,形状越逼真,但是太密可能导致内存不足而无法运行
val=f(x,y,z);
[p,v]=isosurface(x,y,z,val,0);
%配置显示环境
figure('Color',[0.5 1 1],'Position',[200,100,800,500]);
axes('Color',[0 0 0],'XColor',[1 1 1],'YColor',[1 1 1],'ZColor',[1 1 1],'FontSize',1,'Visible','off');
patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','none','edgecolor','interp');
% 'color' 后面可以是 'r','g','b','c','m','y','w', or 'k',对应不同的颜色,或者[x,y,z],x,y,z是MATLAB中对颜色的表述,具体自行查资料吧
%'facecolor''edgecolor' 可以是 'flat' 'none', or 'interp',亦或者上一条注释
view(3);grid off;axis equal;
%配置显示文本
da=[38472,24425,38686];%标题内容,每个字符都用数值表示,不运行看不出来什么内容,执行 double('字符串') 可以看到“字符串”对应的数值
db=[32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 102,114,111,109,32,90,104,97,110,103,32,77,105,110,103,32,107,97,105];%落款内容,原理同上
msg1=text(0,0.3,2,char(da),'Color','r','FontSize',20,'HorizontalAlignment','center');%显示标题
text(0,0,-1.5,char(db),'Color','r','FontSize',10,'HorizontalAlignment','left');%显示落款
text(0,0.3,1.75,'\heartsuit \^\_\^ \heartsuit','Color','r','FontSize',20,'HorizontalAlignment','center');
h=gca;
axis vis3d
%配置文字闪烁效果/标题交替显示
sl=10;%减速倍数,控制文字闪烁速度
mn=4;%文字闪烁更替出现的颜色数,对应下面的if/elseif次数
%配置滚动字幕
msg2=text(0,0,-1.1,'','Color','r','FontSize',10,'HorizontalAlignment','right');%配置小字号显示属性和位置
msg3=text(0,0,-1.3,'','Color','r','FontSize',14,'HorizontalAlignment','right');%配置大字号显示属性和位置
txtmsg=char([
20320 22909 28418 20142 126 32 32 32 32 32 32 32 32 32 32
% 23453 36125 126 32 32 32 32 32 32 32 32 32 32 32
% 25105 29233 20320 126 126 32 32 32 32 32 32 32 32 32
% 22909 29233 22909 29233 126 126 126 32 32 32 32 32 32 32
% 20040 20040 32 126 32 92 94 32 51 32 92 94 32 126
]);%滚动字幕默认内容,注意,每行字符数必须相同,字数不够的末尾补空格,即32
% txtmsg=char(importdata('msg.txt'));%从外部文件msg.txt加载文本部分,msg.txt要和代码在同一目录下。无msg.txt可注释掉本行,不影响程序执行。
% 一行文字如果太多,图形窗口显示不下,则文字可能显示不出来,所以一行不要写太多。
[msgLength,~]=size(txtmsg);
msgls=100;%减速倍数,控制滚动字幕速度
for i=0:inf
%文字闪烁
j=mod(fix(i/sl),mn);
if j==0
set(msg1,'Color','r');
elseif j==1
set(msg1,'Color','g');
elseif j==2
set(msg1,'Color','y');
elseif j==3
set(msg1,'Color','r');
end
%滚动字幕
msgl=mod(fix(i/msgls),msgLength+2);
if msgl>msgLength
set(msg2,'String','');
elseif msgl~=0
set(msg2,'String',txtmsg(msgl,:));
end
if msgl<msgLength
set(msg3,'String',txtmsg(msgl+1,:));
else
set(msg3,'String','');
end
%自动旋转效果
view(h,i,10);
drawnow;
end
matlab旋转3D心形,表白利器
需积分: 24 72 浏览量
2022-10-31
10:34:55
上传
评论
收藏 4KB RAR 举报
ZMMK369
- 粉丝: 1
- 资源: 9
最新资源
- testedtestedtested
- 目标检测-智能零售柜商品检测数据集-5000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-智能零售柜商品检测数据集-3000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- 目标检测-智能零售柜商品检测数据集-1000张图-+对应VOC-COCO-YOLO三种格式标签+数据集划分脚本
- linux常用命令大全.docx
- c语言文件读写操作代码.docx
- c语言文件读写操作代码.docx
- 什么是python以及学习了解python的意义
- 什么是c语言文件读写操作代码以及学习的意义
- linux常用命令大全.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈