matlab⼩游戏程序代码,[转载]Matlab有趣代码⼀、彩蛋
xpbombs; %扫雷
vibes; %振膜
teapotdemo; %茶壶
logo; %Matlab logo
travel; %路线问题
life; %Convay的⼈⽣⼩游戏
makevase; %造花瓶
truss; %弹弹弹
codec; %编码
fifteen; %拼图
xpquad; %超⼆次曲⾯
wrldtrv; %坐飞机
spy; %不加参数就画个狗
earthmap; %地图
cplxdemo; %复杂的XYZ⽴体图形~黎曼曲⾯的平⾯效果
lorenz; %Lorenz吸引⼦动画显⽰
⼆、代码段
% 画爱⼼
[X, Y] = meshgrid(0.01:0.01:1, 0.01:0.01:1);
Zfun =@(x,y)12.5*x.*log10(x).*y.*(y-1)+exp(-((25 ...
*x - 25/exp(1)).^2+(25*y-25/2).^2).^3)./25;
Z = Zfun(X,Y);
figure;
surf(Y,Z,X,'FaceColor',[1 0.75 0.65],'linestyle','none');
hold on
surf(Y+0.98,Z,X,'FaceColor',[1 0.75 0.65],'linestyle','none');
axis equal;
view([116 30]);
camlight;
lighting phong; % 设置光照和光照模式
% matlabspeech('I Love Maple and Matlab')
% matlabspeech('I Love Maple')
% matlabspeech('I Love Matlab')
if ~ispc, error('要求使⽤Microsoft Win32 SAPI .'); end
if ~ischar(txt), error('第⼀个参数是字符串.'); end
SV = actxserver('SAPI.SpVoice');
TK = invoke(SV,'GetVoices');
if nargin > 1
for k = 0:TK.Count-1
if strcmpi(voice,TK.Item(k).GetDescription)
SV.Voice = TK.Item(k);
break;
elseif strcmpi(voice,'list')
disp(TK.Item(k).GetDescription);
end
end
if nargin > 2
if isempty(pace), pace = 0; end
if abs(pace) > 10, pace = sign(pace)*10; end
SV.Rate = pace;
end
vbs小程序代码大全end
if nargin < 4 || ~ismember(fs,[8000,11025,12000,16000,22050,24000,32000,... 44100,48000]), fs = 16000; end
if nargout > 0
MS = actxserver('SAPI.SpMemoryStream');
MS.Format.Type = sprintf('SAFT%dkHz16BitMono',fix(fs/1000));
SV.AudioOutputStream = MS;
end
invoke(SV,'Speak',txt);
if nargout > 0
wav = reshape(double(invoke(MS,'GetData')),2,[])';
delete(MS);
clear MS;
end
delete(SV);
clear SV TK;
pause(0.2);
end
% 最炫民族风
fs = 44100; % sample rate
dt = 1/fs;
T16 = 0.125;
t16 = [0:dt:T16];
[temp k] = size(t16);
t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);
[temp i] = size(t4);
[temp j] = size(t8);
% Modification functions
mod4=(t4.^4).*exp(-30*(t4.^0.5));
mod4=mod4*(1/max(mod4));
mod8=(t8.^4).*exp(-50*(t8.^0.5));
mod8=mod8*(1/max(mod8));
mod16=(t16.^4).*exp(-90*(t16.^0.5));
mod16=mod16*(1/max(mod16));
f0 = 2*146.8; % reference frequency ScaleTable = [2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/
2 5/
3 9/5 15/8 ...
2 9/4 5/2 8/
3 3 10/3 15/
4 4 ...
1/2 9/16 5/8];
% 1/4 notes
do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4); re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4); re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4); mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4); fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4); so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4); la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4); tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4); ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4); do2f = mod4.*cos
(2*pi*ScaleTable(13)*f0*t4); re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4); mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4); fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4); so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4); la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4); ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4); do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4); blkf = zeros(1,i);
% 1/8 notes
do0e = mod8.*cos(2*pi*ScaleTable(21)*f0*t8); re0e = mod8.*cos(2*pi*ScaleTable(22)*f0*t8); mi0e = mod8.*cos(2*pi*ScaleTable(23)*f0*t8); fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8); so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8); la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8); do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8); re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8); mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8); fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8); blke = zeros(1,j);
% 1/16 notes
do0s = mod16.*cos(2*pi*ScaleTable(21)*f0*t16); re0s = mod16.*cos(2*pi*ScaleTable(22)*f0*t16); mi0s = mod16.*cos(2*pi*ScaleTable(23)*f0*t16); fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16); so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16); la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16); do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16); re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16); mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16); fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16); so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16); la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16); tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16); ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16); do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16); re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16); mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16); fa2s = mo
d16.*cos(2*pi*ScaleTable(16)*f0*t16); so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论