• Remix
  • Share
  • New Entry

on 7 Nov 2023
  • 16
  • 76
  • 0
  • 3
  • 1853
drawframe(1);
Write your drawframe function below
% Author:Eric Ludlam
function drawframe(f)
% Constants
blue=validatecolor("#0076a8");
darkblue=validatecolor("#004b87");
S.vertices = [ 0 2 0; 1 2 0; % top
1 0 0; 2 0 0; % middle
0 -2 0; 1 -2 0; % bottom
];
S.faces = [ 1 2 4 3;
3 4 6 5;
];
S.facevertexcdata = [ 1 ;
1 ];
% Convert our number into different animation stages.
framemax = floor(48/5); % 5 stages
stage = ceil(f/framemax);
f = mod(f-1,framemax)+1; % approx 9 frames per stage
if stage > 5
stage = 5;
f = f + framemax;
framemax = framemax + 4;
end
% Initialize
if f==1 && stage==1
ax = newplot;
set(gcf, 'color','white');
axis(ax, [ -2 6 -5 3 0 1 ])
set(ax, 'position', [ 0 0 1 1], 'visible','off','tag','mh_ax')
daspect(ax,[1 1.5 1]);
clim([1 2]);
colormap(ax,[ blue; darkblue]);
p1 = patch('vertices',[], 'faces', [], 'FaceColor', 'flat', 'EdgeColor', 'none', 'tag', 'chevron1');
p2 = patch('vertices',[], 'faces', [], 'FaceColor', 'flat', 'EdgeColor', 'none', 'tag', 'chevron2');
txt = text(0,0,'', ...
'FontUnits', 'norm', ...
'FontSize', .17, ... % normalized units lets you resize this fig to any old size.
'Color', blue, ...
'VerticalAlignment', 'top',...
'HorizontalAlignment', 'center',...
'tag', 'mh_txt');
else
p1 = findobj('tag','chevron1');
p2 = findobj('tag','chevron2');
txt = findobj('tag','mh_txt');
end
% Animate
switch stage
case 1 % First chevron appears
xrng = linspace(-4,0,framemax);
x = xrng(f);
S.vertices = S.vertices + [ x 0 0 ];
set(p1, S);
set([txt p2], 'visible','off');
case 2 % Flip down
tmp = S.vertices([1 2],:);
yrng = linspace(2,-2,framemax);
tmp(:,2) = yrng(f);
S.vertices = [ S.vertices
tmp ];
S.faces = [ S.faces
3 4 8 7 ];
S.facevertexcdata = [ 1;1;2 ];
set(p1, S);
case 3 % Second chevron appears
xrng = linspace(-4,2,framemax);
x = xrng(f);
S.vertices = S.vertices + [ x 0 0 ];
S.facevertexcdata(2) = 2;
set(p2, S, 'visible','on');
case 4 % Minihack Txt appears
xrng = linspace(-5,2,framemax);
x = xrng(f);
clr = sprintf('\\color[rgb]{%.2f,%.2f,%.2f}', darkblue);
set(txt, 'visible','on', 'Position', [x -2.5], 'String', "Mini \bf" + clr + "Hack");
case 5 % Txt color change
rrng = linspace(darkblue(1),blue(1),framemax);
grng = linspace(darkblue(2),blue(2),framemax);
brng = linspace(darkblue(3),blue(3),framemax);
clr = sprintf('\\color[rgb]{%.2f,%.2f,%.2f}', rrng(f),grng(f),brng(f));
set(txt,'String', "Mini \bf" + clr + "Hack");
end
end
Animation
Remix Tree