• Remix
  • Share
  • New Entry

on 30 Nov 2023
  • 5
  • 18
  • 0
  • 0
  • 957
This entry only slightly modifies the code shown in the blog here:
created by Adam Danz.
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent S i nColors
if f == 1
rng(0,'philox')
k = 480;
nColors = k; % number of colors to use for the water
i = 1:3*nColors^2;
mountainHeights = makenoise(k, 2); % mountain noise
figure()
x = linspace(-4, 4, k);
y = linspace(-4, 4, k);
mountainHeights = mountainHeights + 0.3; % raise the mountain
surf(x,y,mountainHeights,EdgeColor='none')
colormap(flipud(sqrt(copper)))
hold on
seaShading = makenoise(k, 1.4); % water color noise
seaColors = parula(nColors*7/6);
seaColors(nColors+1:end,:) = []; % Capture the blue-green end of parula
% convert seaShading (-1:1) to colormap indices (1:500)
seaShadingIdx = round((seaShading+1)*(nColors/2-.5)+1);
% Create mxnx3 matrix of CData
cdata = reshape(seaColors(seaShadingIdx,:),nColors,nColors,3);
S=surf(x*3, y*3, 0*seaShading,CData=cdata,EdgeColor='none');
axis equal off
clim([-0.5, 1.5])
light(Position = [-.8 .1 .75]) % add lighting
material dull
camva(10) % camera viewing angle
campos([-11,37,20]) % camera position
camtarget([.4 .8 .4]) % camera target
end
S.CData(mod(i+10,3*nColors^2)+1) = S.CData(mod(i,3*nColors^2)+1);
i = i+1;
end
function noise = makenoise(k, a)
% Create the noise matrix
% k is the matrix size (scalar)
% a is the positive exponent (scalar)
% noise are noise values with range [-1,1]
m = randn(k);
mf = fftshift(fft2(m));
d = ((1:k)-(k/2)-1).^2;
dd = sqrt(d(:) + d(:)');
filt = dd .^ -a;
filt(isinf(filt))=1;
ff = mf .* filt;
b = ifft2(ifftshift(ff));
noise = rescale(b,-1,1);
end
Animation
Remix Tree