• Remix
  • Share
  • New Entry

on 3 Dec 2023
  • 14
  • 81
  • 0
  • 1
  • 1995
drawframe(1);
Write your drawframe function below
function drawframe(n)
persistent u v
if n==1
ax=gca;
ax.XColor='none';
ax.YColor='none';
hold on
ax.Position=[0,0,1,1];
axis([0,6,0,8])
ax.DataAspectRatio=[1 1 1];
ax.Color=[.4,.5,.8];
EN={'EdgeColor','none'};FC={'filled','CData'};
AD='AlphaData';FA='FaceAlpha';
L=@linspace;ir=@ind2rgb;sc=@scatter;g=@image;
a=100;b=(.5:a)'/a;o=ones(a);
c=(-cos(b*2*pi)+1).^.2;
f=b-.5;r=f'.^2+f.^2;
p=abs(ifftn(exp(3i*rand(a))./r.^.8)).*(c*c');
p=p./max((max(p)));
% 越向上、雾气越透明
dy=(100:-1:1)/100*.8+.2;
g([0,6],[2,8],ir(o,[.7,.5,.75]),AD,p.*(dy'));
t=0:pi/99:2*pi;
% 绘制月亮
fill(cos(t)*.3+4.5,sin(t)*.3+7,[.9,.9,1],EN{:})
fill(cos(t)*.4+4.5,sin(t)*.4+7,[.9,.9,1],EN{:},FA,.3)
% 8层山
b=@(p,q)abs(ifftn(exp(p*1i*rand(a))./r.^q)).*(c*c');
for i=1:8
% 每次都生成一次二维柏林式噪声,并取其中一行的数据
h=b(5,1.05).*10;
nh=(8-i)*30+h(50,:)+180;
m=ceil(max(nh));
% 用nan数值框出山的轮廓
alp=ones(m,a);
alp((1:m)'>nh)=nan;
% 绘制山峰
g([-.5,6.5],[0,m]./100,ir(ones([m,100]),hsv2rgb([2/3,1/3,3/4]+[-7e-3,.01,-.02]*i)),AD,alp.*0.98);
end
nh=h(100,:);
fill([L(0,6,a),6,0],[nh./150+1.4,0,0],[218,222,234]./255,EN{:})
% 绘制树干
patch([2.8,3.2,3.2,2.8],[1,1,2,2],ir([1,1,2,2],[.64,.64,.7;.3,.4,.5]),EN{:})
fill([2.8:.01:3.2,3.2,2.8],[1+rand(1,41)/10,1,1],[.8,.85,.9],EN{:})
g([2.8,3.2,],[1,2],ir(o,[.6,.6,.7]),AD,p.*(dy'));
% 绘制树叶
for i=1:34
p=b(3,.8);
p=p./max(max(p));p(p<.5)=0;p(p>=.5)=.7;
for j=(1:i)-i/2
g([2.7,3.3]+j*.06+(rand(1)-.5).*.03,[2,2.6]+4-i*.13+(rand(1)-.5).*.03,ind2rgb(o,[.25,.35,.5]),AD,p);
end
end
% 绘制五角星
t=L(pi/2,2*pi+pi/2,11);
l=ones(1,11);l(2:2:11)=.47;
fill(cos(t)*.26.*l+3,sin(t)*.26.*l+6.4,[.9,.9,.7],EN{:},FA,.9)
% 绘制彩带
SC={'Color',[.8,.5,.6],'LineWidth',1.2};
y=-abs(sin(L(0,2.3*pi,90)))-L(0,2,90);
plot(L(2,4,90),y*.2+3,SC{:})
y=-abs(sin([L(0,pi,50),L(0,pi,40)]))-L(0,-5,90);
plot(L(2.2,3.8,90),y*.2+3.3,SC{:})
y=-abs(sin(L(0,1.2*pi,90)))-L(0,1.6,90);
plot(L(2.6,3.5,90),y*.2+5.2,SC{:})
% 绘制装饰圆球
sc([2.5,3.2,3.2,3.5],[3.2,3.8,4.7,2.4],15,FC{:},[.6,.7,.7]);
sc([2.6,3,3.2,2.4],[5,4.3,5.4,2.4],15,FC{:},[.4,.5,.8]);
% 绘制雪花
r=@()rand([40,1]);
u=sc(r()*8-1,r()*7+2,10,FC{:},[1,1,1],'MarkerFaceAlpha',.3);
v=sc(r()*8-1,r()*7+2,4,FC{:},[1,1,1],'MarkerFaceAlpha',.3);
end
u.YData=u.YData-.1;
u.YData(u.YData<2)=u.YData(u.YData<2)+7;
v.YData=v.YData-.04;
v.YData(v.YData<2)=v.YData(v.YData<2)+7;
end
Animation
Remix Tree