• Remix
  • Share
  • New Entry

  • ME

  • /
  • MATropolis with moving light source (sun) - now with changing sky

on 10 Nov 2023
  • 8
  • 113
  • 4
  • 0
  • 689
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Adjusted version of the MATropolis with lighting and sky colour
% 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 building colormap and display dependent on bar height
cmap = pink();
customCmap = cmap(:,[2,3,1]);
for i=1:numel(b)
set(b(i),'CData',b(i).ZData,'FaceColor','interp')
end
% Define sky colours
skymap=[[linspace(.1,.3,18)' linspace(0,.7,18)' linspace(.3,.9,18)'];[linspace(.3,.1,30)' linspace(.7,0,30)' linspace(.9,.3,30)']];
% Add moving light source
theta = interp1([0 48],[0 2*pi],f);
ht = 4*sin(theta) + 2;
pos = [20*cos(theta) 20*sin(theta) ht];
light(Position = pos)
% Loop through buildings
for i=1:15 % 1:size(h,1)
for j=1:15 % 1:size(h,2)
c=.1:.2:h(i,j)-.2;
d=[c;c];
z=d(:)'+[0;0;.1;.1];
y=i+[-.2,.2]+[-1;1;1;-1]/12;
y=repmat(y,size(c));
if(f>=20 && rand<=(f-20)/28)
patch(z*0+j-.4,y,z,'w')
else
patch(z*0+j-.4,y,z,'k')
end
end
end
% Assign colormap and remove unnecessary tick marks/labels
set(gca,'Colormap',customCmap,'Color',skymap(f,:),'XTick',[],'YTick',[],'ZTick',[])
camva(4)
end
Animation
Remix Tree
Load full remix tree