- /
-
MATropolis with moving light source (sun)
on 8 Nov 2023
- 6
- 37
- 7
- 0
- 371
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Adjusted version of the MATropolis with lighting
% Set seed for random number generator (needed to prevent bars changing
% height between steps)
rng(20210214,'twister')
% Generate random bar heights and plot as bar3
h = randg(1,15);
b = bar3(h);
% Define colormap and display dependent on bar height
cmap = pink();
customCmap = cmap(:,[2,3,1]);
view(45,25);
for i=1:numel(b)
set(b(i),'CData',b(i).ZData,'FaceColor','interp')
end
% Add moving light source
theta = interp1([0 48],[0 2*pi],f);
ht = 4*sin(theta) + 4;
pos = [20*cos(theta) 20*sin(theta) ht];
light(Position = pos)
% Assign colormap and remove unnecessary tick marks/labels
set(gca,'Colormap',customCmap,'Color',customCmap(25,:),'XTick',[],'YTick',[],'ZTick',[])
end