• Remix
  • Share
  • New Entry

on 8 Nov 2023
  • 13
  • 60
  • 0
  • 3
  • 1303
drawframe(48);
Write your drawframe function below
Animated remix of the MATropolis rooftop (2021)
https://www.mathworks.com/matlabcentral/communitycontests/contests/6/entries/13182
function drawframe(f)
persistent h
if f==1 || isempty(h)
%% plot the city
h = struct(); % store graphics handles.
rng(0) % the scene is customized for seed=0 (twister)
set(gcf,'color','k')
h.ax = axes(Position=[0 0 1 1],colormap=gray,Color='k',Projection='perspective');
hold on
axis equal
h.ax.XTickLabel = '';
h.ax.YTickLabel = '';
h.ax.ZTickLabel = '';
xlim([-27.76, 88.76])
ylim([-4.5, 65.5])
zlim([0,10.7])
h.light = light(po=[-.7 .7 -1]);
campos([1.3,33,7]) % z=buildingHeights(33) % plot3(1.3, 33,7,'r*')
camtarget([40 33 3])
camva(70)
buildingHeights = randg(2,60); % building heights
h.bar = bar3(h.ax,buildingHeights);
set(h.bar,'EdgeColor','k')
% Loop through buildings
h.windows = gobjects([2,size(buildingHeights)]);
floorCount = nan(size(buildingHeights));
for i = 1:height(buildingHeights)
for j = 1:width(buildingHeights)
c = 0.1:0.2:buildingHeights(i,j)-.2;
floorCount(i,j) = numel(c);
d = [c;c];
z = d(:)'+[0;0;.1;.1];
y = i+[-.2,.2]+[-1;1;1;-1]/12;
y = repmat(y,size(c));
ison = logical(rand(1,numel(d))>0.3); % some window lights will be off
yellow = [1,1,.05];
p1 = patch(h.ax,z(:,ison)*0+j-.4,y(:,ison),z(:,ison),yellow);
p2 = patch(h.ax,z(:,~ison)*0+j-.4,y(:,~ison),z(:,~ison),yellow);
if ~isempty(p1)
h.windows(1,i,j) = p1;
end
if ~isempty(p2)
p2.FaceColor = 'none';
h.windows(2,i,j) = p2;
end
end
end
h.ax.XAxis.Visible = 'off';
h.ax.ZTick = 0:5:10;
h.ax.TickLength = [0 0];
grid(h.ax,'on')
h.ax.GridColor = 'm';
h.ax.GridAlpha = 1;
end
%% Animate construction
h.ax.GridAlpha = 1-f/48; % Fade grid
h.ax.CameraPosition(3) = f/48*7+2;
h.ax.CameraPosition(1) = max(40-f/40*38.7,1.3);
h.ax.CameraTarget(3) = 2.2 - f/48*3.9;
camva(50*f/48+30)
end
Animation
Remix Tree