- /
-
Isle of Thunderstorms
on 13 Oct 2024
- 35
- 448
- 0
- 5
- 1573
Cite your audio source here (if applicable):
Edited locally to match frames
drawframe(43);
Write your drawframe function below
function drawframe(f)
% Inspired by: https://blogs.mathworks.com/matlab/2023/11/29/creating-natural-textures-with-power-law-noise-clouds-terrains-and-more/
persistent fig S R L
% Create 2D power-law noise
rng(0,'twister')
k = 400;
m = randn(k); % k-by-k matrix
mf = fftshift(fft2(m));
% Filter1 (terrain & local storm conditions)
a = 2; % 1/fᵅ exponent - Brownian noise
d = ((1:k)-(k/2)-1).^2;
dd = sqrt(d(:) + d(:)');
filt = dd .^ -a; % frequency filter
filt(isinf(filt))=1; % replace +/-inf at DC or zero-frequency component
ff1 = mf .* filt;
% Filter2 (swell)
a = 3;
filt = dd .^ -a;
filt(isinf(filt))=1;
ff2 = mf .* filt;
% Construct the island
island = rescale(circshift(circshift(ifft2(ifftshift(ff1)),-k/8),-k/8,2),-1,1);
x = linspace(-5,5,width(island));
y = linspace(-5,5,height(island));
% Construct the wavefield (propagate waves, blend swell & local storm)
waves = rescale(circshift(circshift(ifft2(ifftshift(ff1)),-round(k*f/96)),round(k*f/96),2)+circshift(circshift(ifft2(ifftshift(ff2)),round(k*f/96)),round(k*f/96),2)*.75,-.2,.2);
% Add coastline fluctuations
island(island<waves-.15) = NaN;
% Add wave breaking effect
whitecap = waves;
whitecap(whitecap<=.15) = NaN;
% % Add mist (the wind blows towards the prevalent wave direction)
% mist = rescale(circshift(circshift(ifft2(ifftshift(ff1)),-round(k*2*f/96)-k/8),round(k*f/96)+k/8,2),0,.8);
% Add rain
rng(f)
r = (-1+2*rand(3,500)).*[5;5;2];
addRain = @(x) plot3([x(1,:);x(1,:)+.5],[x(2,:);x(2,:)+.5],[x(3,:);x(3,:)-1.5],'Color',[.8,.8,.8],'LineWidth',2);
if isempty(fig) || ~isgraphics(fig)
fig = figure;
hold on
S.I = surf(x*.8,y*.8,island,'EdgeColor','n');
S.W = surf(x,y,waves,'FaceColor','b','EdgeColor','n','FaceAlpha',.8,'FaceLighting','gouraud');
S.WC = surf(x,y,whitecap,'EdgeColor','n','FaceColor','w');
% S.MI = surf(x*.8,y*.8,island+.01,'EdgeColor','n','FaceColor','w','AlphaData',mist,'FaceAlpha','interp','FaceLighting','n');
% S.MW=surf(x,y,waves+.01,'EdgeColor','n','FaceColor','w','AlphaData',mist,'FaceAlpha','interp','FaceLighting','n');
R = addRain(r);
material dull
material(S.W,'shiny')
% Add lightning & background effect
L(1) = light('style','local','Position',[0,0,2],'Visible','off');
L(2) = patch(x([1,end,end,1]),y([1,1,end,end]),[1,1,1,1]+.02,'w','Visible','off','EdgeColor','n','FaceLighting','n','FaceAlpha',.3);
% Add light sources
arrayfun(@(x) light('style','local','Position',[x,7,1]),-3:3:3)
demcmap(0)
view(0,35)
camva(3)
axis('equal','off')
xlim(x([1,end]))
ylim(y([1,end]))
zlim([-.2,1.2])
else
if mod(f,4)==0 % Reduce graphics generation frames
S.I.ZData = island;
S.W.ZData = waves;
S.WC.ZData = whitecap;
% S.MI.ZData = island+.01;
% S.MI.AlphaData = mist;
% S.MW.ZData = waves+.01;
% S.MW.AlphaData = mist;
R.delete
R = addRain(r);
end
set(L,'Visible',ismember(f,[0:2:4,6:10]-5+96/2));
end
end