• Remix
  • Share
  • New Entry

on 9 Nov 2023
  • 28
  • 220
  • 0
  • 4
  • 1995
drawframe(1);
Write your drawframe function below
function drawframe(n)
global bl1 bl2 bl3 ml X1 X2 M
L=1600;H=1400;S=1000;R=400;F=550;
x1=@(x)x.*80+F+40.*(rand(1)-.5);
x2=@(x)x.*60+F+200+40.*(rand(1)-.5);
l=@linspace;
f=@fill;
if n==1
rng(12)
ax=gca;
ax.XColor='none';
ax.YColor='none';
ax.XLim=[0,L];
ax.YLim=[0,H];
ax.DataAspectRatio=[1 1 1];
hold on;
rgb=@(C)hsv2rgb(C./[360,100,100]);
cF=[225 35 70]; % 远山的颜色
cM=[210 70 10]; % 近山的颜色
cC=[250 26 43]; % 云的颜色
cS=[215 100 18]; % 天空的颜色
cN=[253,252,222]./255;
% 背景为远山的颜色 ==========================================================
ax.Color=rgb(cM);
% 画出天空颜色渐变效果 ======================================================
bp=rgb(cF)+l(0,1,S)'.*(rgb(cS)-rgb(cF));
ip=(1:S)'.*ones(1,L);
C=ind2rgb(ip,bp);
[X,Y]=meshgrid(1:L,401:H);
surf(X,Y,X.*0,'CData',C,'EdgeColor','none');
% 画出山脉效果 =============================================================
[X,Y]=meshgrid(l(0,1,S));
CLX=(-cos(X.*2.*pi)+1).^.2;
CLY=(-cos(Y.*2.*pi)+1).^.2;
r=(X-.5).^2+(Y-.5).^2;
% 8层山
for i=1:8
% 每次都生成一次二维随机噪声,并取其中一行的数据
h=abs(ifftn(exp(5i*rand(S))./r.^1.05)).*(CLX.*CLY).*24;
nh=(8-i)*30+h(500,:);
if i==1,nh=nh.*.8;end
hm=ceil(max(nh));
C=ones(hm,S);
% 颜色矩阵构造
tcol=cF+(cM-cF)./8.*(i);
tcol=rgb(tcol);
C=ind2rgb(C,tcol);
% 用nan数值框出山的轮廓
a=ones(hm,S);
a((1:hm)'>nh)=nan;
% 绘制山峰
image([-50,L+50],[R,R+hm],C,'AlphaData',a.*0.98);
end
% 绘制月亮和云朵 ===========================================================
t1=l(-pi/2,pi/2,100);
t2=l(pi/2,3*pi/2,100);
X1=cos(t1).*80;Y1=sin(t1).*80;
X2=cos(t2).*80;Y2=sin(t2).*80;
ml=f([X1,X2]+1350,[Y1,Y2]+1200,cN,'EdgeColor','none');
a=abs(ifftn(exp(3i*rand(S))./r.^.8)).*(CLX.*CLY);
a=a./max(a,[],'all');
C=ones(size(a));
C=ind2rgb(C,rgb(cC));
% 越向下、云越透明
dy=(1:S)./S.*0.8+0.2;
image([0,L],[800,H],C,'AlphaData',a.*(dy'));
bp=rgb(cF)+l(0,1,R)'.*(rgb(cM)-rgb(cF));
ip=(1:R)'.*ones(1,L);
C=ind2rgb(ip,bp);
[X,Y]=meshgrid(1:L,0:R);
surf(X,Y,X.*0,'CData',C,'EdgeColor','none');
% 绘制石头桥 ===============================================================
X=l(100,S,100);
Y=sin(l(0,pi,100));
f(X,Y.*150+R,[.1,.1,.1],'EdgeColor','none')
plot(X,Y.*150+R,'Color',[cN,.3],'LineWidth',1)
T=l(0,pi,100);
f(cos(T).*80+F,sin(T).*80+R,cN,'EdgeColor','none');
f(cos(T).*60+F+200,sin(T).*60+R,cN,'EdgeColor','none');
f(cos(T).*60+F-200,sin(T).*60+R,cN,'EdgeColor','none');
for i=1:7
y=(i-1)/6;
x=[-1,1].*sqrt(1-y.^2);
cp={'Color',cN,'LineWidth',1};
bl1(i)=plot(x1(x),R-[y,y].*90,cp{:});
bl2(i)=plot(x2(x),R-[y,y].*60,cp{:});
bl3(i)=plot(x2(x)-R,R-[y,y].*60,cp{:});
end
else
k=l(-1,1,48);
tX2=X2.*k(n);
ml.XData=[X1,tX2]+1350;
for i=1:7
y=(i-1)/6;
x=[-1,1].*sqrt(1-y.^2);
set(bl1(i),'XData',x1(x));
set(bl2(i),'XData',x2(x));
set(bl3(i),'XData',x2(x)-R);
end
end
end
Animation
Remix Tree