- /
 - 
        
MATropolis with moving light source (sun) - now with windows/lights
 
        on 9 Nov 2023
        
        
 
    - 10
 - 47
 - 5
 - 4
 - 556
 
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(0,'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]);
    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) + 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)/8)
                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',customCmap(25,:),'XTick',[],'YTick',[],'ZTick',[])
    camva(4)
end


