- /
-
Windy Fall Day
on 19 Oct 2024
- 20
- 95
- 0
- 0
- 1556
Cite your audio source here (if applicable): I couldn't get this to load up if I included audio. :(
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent verts inc LT LTR
t=0:0.01:pi;
nleaf=96;
if f==1
rng(95)
%% Jenny Bosten's cloudy sky, stolen from Adam's 99 luftballoons
Q=0:.646:328;
r=hypot(Q,Q'-90);
s=(285-r)/285;
image(cat(3,s/3+.1,s/2+.2,s/3+.6),AlphaData=5E4*abs(ifft2(r.^-1.7.*cos(6*rand(508)))));
set(gca,'pos',[0 0 1 1],'vis','off');
%% Leaf shorteners
c=@cos;
s=@sin;
% oak shorteners
co=@(f)c(f*t);
so=@(f)s(f*t);
% Maple leaf shorteners
C=@(f,x)c(f*t).^x;
D=@(a,b)(c(a*t).*c(b*t)).^10;
a=@(f)1+C(6,2)+D(6,f)/5;
b=C(30,12)/9; % one of the occurances was /10, but looked close enough /w 9
d=1-C(1,10).*C(3,2);
e=1-C(1,4);
g=1-s(6*t).^10;
%% Wind measurements in a volume
mf = matfile('wind.mat');
% Wind starts on the left (X=80) and fills and the Y/Z plane
% is Y=20->50 Z=0->15
[startX,startY,startZ] = meshgrid(80,20:2:50,0:5:15);
% Compute vertices of "streams" through the wind volume starting
% at the starting coordiates.
cverts = stream3(mf.x,mf.y,mf.z,mf.u,mf.v,mf.w,startX,startY,startZ);
% Convert to array of vertices - we don't care about connectivity
verts = cat(1,cverts{:});
% Streamline can draw lines where our leaves will blow.
% Stream particles can draw dots where leaves will start.
% Useful for debugging.
%streamline(cverts);
%streamparticles(cverts,96)
% Compute where our leaves should go by dividing up the space into 96
% blocks of leaf-flow
inc = size(verts,1)/nleaf;
axes('pos',[0 0 1 1]);
LT = gobjects(0);
LTR = gobjects(0);
for k=1:nleaf
switch mod(k,2)
case 0
% Oak Leaf
x=.01*co(1).^9.*co(5).^10+so(2)/4.*(1-so(10).^2/2).*(1-(co(1).*co(3)).^8);
y=so(1).*(1-so(10).^2/5.*(.5+so(2).^2))-.5;
case 1
% Maple Leaf
x=(a(24)+(C(30,2)/4+b).*g).*s(2*t).*e.*d;
y=-1.05*c(2*t).*(e+D(1,3)/2).*(a(18)+(C(30,4)/4+b).*d.*g);
end
LT(k)=hgtransform;
LTR(k)=hgtransform(LT(k));
if mod(k,4)>1
dir=1;
else
dir=-1;
end
fill(LTR(k),x,dir*y,mod(k,4),Linew=1);
end
daspect([1 1 .4])
set(gca,'clipping','off',...
'cameraviewangle',7,...
'cameraposition',[48 -210.5 52.5]);
axis([80 130 20 50 0 15],'off')
colormap autumn
end
for k=1:nleaf
idx=mod(floor(interp1([1 96],[1 inc*4],f)+(k-1)*inc+1),size(verts,1))+1;
pos=verts(idx,:);
dir=verts(mod(idx+1,size(verts,1)),:)-verts(idx,:);
if sum(dir)>10
% jumping from one side to the other, then get dir by going backward
dir=verts(idx,:)-verts(idx-1,:);
end
%dir = dir+[1 0 1];
rotv = dir/vecnorm(dir,2,2);
sc = [ 3 .5 ];
sc = sc(mod(k,2)+1);
LT(k).Matrix = makehgtform('translate',pos,'scale',[sc sc sc/2]);
LTR(k).Matrix = makehgtform('xrotate',rotv(1),'yrotate',rotv(2),'zrotate',rotv(3));
end
end
Movie
Audio
This submission does not have audio.