• Remix
  • Share
  • New Entry

  • ME

  • /
  • Happy 40th MATLAB

on 21 Nov 2023
  • 12
  • 89
  • 0
  • 3
  • 1932
drawframe(1);
CALL TO ACTION! All residents of the MATropolis, let's show off how cool our city is! More MATropolis GIFs!
Write your drawframe function below
function drawframe(f)
persistent S
if f==1 || isempty(S)
% Get MATLAB logo outline
logo
I=getframe(gcf);
muralCData = I.cdata(:,:,3);
clf
% Create buildings
rng(0)
axes(colorm=gray,Color='k')
hold on
h=[2 1; 3 2]; % building heights
bh = bar3(h);
% Set up axes and field of view
axis equal
clim([0,4])
campos([10 -6.7 3.5])
camtarget([1.7 1.3 1.4])
camva(6.8)
% Widen the building that has the billboard
bh(2).YData(bh(2).YData<1) = -.3;
% loop through the buildings to add windows
for i=1:2
for j=1: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));
ison = logical(rand(1,numel(d))>0.5);
pw = patch(z(:,ison)*0+j+.41,y(:,ison),z(:,ison),[.97 .91 .44]); % Lights on
patch(z(:,~ison)*0+j+.41,y(:,~ison),z(:,~ison),[.2 .2 .3]); % Lights off
if i==1 && j==2
% Add more windows to the wide building
pw2 = copyobj(pw,gca);
pw2.YData = pw2.YData-.8;
end
end
end
% Add text to the wall mural to appear as an old advertisement
% Text inspired by a street I used to live on.
% The image is intentionally degraded to make it appear weathered.
muralCData = [muralCData; zeros(50,width(muralCData))];
Itext = insertText(muralCData, [120 270], '', ...
AnchorPoint = "CenterTop", ... % Font = "DejaVuSans-Bold", ...
FontSize = 50, ...
FontColor = 'w', ...
TextBoxColor = "k");
% Plot the mural on the wall
binCdata = flipud(Itext(:,:,1)>10) * 1.2 + 2;
surf([1.7 2.3],[1.58 1.58],[1.2 1.2;1.9 1.9], ...
CData = binCdata, ...
FaceColor = "texturemap", ...
EdgeColor = "none")
% Add billboard on rooftop
[my,mz] = meshgrid(linspace(-.11,1.05,10),linspace(1,1.7,10));
S = surf(zeros(10)+2.3,my,mz,...
CData = zeros(200,371,3), ... % No words yet
FaceColor = "texturemap", ...
EdgeColor = "none", ...
DiffuseStrength = 1);
% Add support to hold up the billboard
plot3([1.9,2.3],(-.08 : .1 : 1.05)'.*[1,1],[1,1.5], '-',LineWidth = 2, Color=.15*[1 1 1]);
end
% Compute neon brightness
pnb = (12:24:48)'; % Controls frequency of flashes
strength = min(abs(pnb-f))/10+.3; % Strength of the neon sign
% Update the billboard
I = zeros(size(S.CData,[1,2]));
Itext = insertText(I, size(I,[2,1])/2, '40th Birthday', ...
AnchorPoint = "Center", ...
Font = "DejaVuSans-Bold", ...
FontSize = 40, ...
FontColor = [strength,0, strength], ...
TextBoxColor = "k");
Itext = insertText(Itext, [1,1], 'Happy', ...
AnchorPoint = "LeftTop", ...
Font = "DejaVuSans-Bold", ...
FontSize = 40, ...
FontColor = [0 strength strength], ...
TextBoxColor = "k");
Itext = insertText(Itext, fliplr(size(I)), 'MATLAB', ...
AnchorPoint = "RightBottom", ...
Font = "DejaVuSans-Bold", ...
FontSize = 40, ...
FontColor = [0 strength strength], ...
TextBoxColor = "k");
% Blur it as it gets brighter
ItextGaus = imgaussfilt(Itext,strength*2);
S.CData = flipud(ItextGaus);
end
Animation
Remix Tree