• Remix
  • Share
  • New Entry

on 29 Nov 2023
  • 14
  • 23
  • 0
  • 1
  • 1519
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent H
X = [0 0 0 0 0 1; 1 0 1 1 1 1; 1 0 1 1 1 1; 0 0 0 0 0 1];
Y = [0 0 0 0 1 0; 0 1 0 0 1 1; 0 1 1 1 1 1; 0 0 1 1 1 0];
Z = [0 0 1 0 0 0; 0 0 1 0 0 0; 1 1 1 0 1 1; 1 1 1 0 1 1];
C = colororder;
TopCenter=[0,0,5];
TopSize=[5,8,0.1];
BracesCenter=[ 0.0, 3.5, 4.6
0.0,-3.5, 4.6
2.0, 0.0, 4.6
-2.0, 0.0, 4.6
0.0, 3.5, 0.8
0.0,-3.5, 0.8
2.0, 0.0, 0.8
-2.0, 0.0, 0.8];
BracesSize=[ 4.2, 0.1, 0.6
4.2, 0.1, 0.6
0.1, 7.2, 0.6
0.1, 7.2, 0.6
4.2, 0.1, 0.6
4.2, 0.1, 0.6
0.1, 7.2, 0.6
0.1, 7.2, 0.6];
LegsCenter=[ 2.0, 3.5, 2.5
2.0,-3.5, 2.5
-2.0, 3.5, 2.5
-2.0,-3.5, 2.5];
LegsSize=[ 0.4, 0.4, 5
0.4, 0.4, 5
0.4, 0.4, 5
0.4, 0.4, 5];
if(f==1)
set(gcf,'Color','k');
fill3(X,Y,Z,'r'); hold on;% draw cube
arrayfun(@(i)fill3(X,Y,Z,'m'),1:8);
arrayfun(@(i)fill3(X,Y,Z,'g'),1:4);
axis equal off
hold off
elseif(f<30)
scaleddraw(X,Y,Z,TopCenter,TopSize,'r',1,f); hold on;
arrayfun(@(i)scaleddraw(X,Y,Z,BracesCenter,BracesSize,'m',i,f),1:8);
arrayfun(@(i)scaleddraw(X,Y,Z,LegsCenter,LegsSize,'g',i,f),1:4);
axis equal off
hold off
elseif(f==30)
cla;
H=hgtransform('Parent',gca);
scaleddraw(X,Y,Z,TopCenter,TopSize,'r',1,f,H); hold on;
arrayfun(@(i)scaleddraw(X,Y,Z,BracesCenter,BracesSize,'m',i,f,H),1:8);
arrayfun(@(i)scaleddraw(X,Y,Z,LegsCenter,LegsSize,'g',i,f,H),1:4);
axis equal off
hold off
else
set(H,'Matrix',makehgtform('zrotate',(f-30)*pi/36));
end
end
function scaleddraw(X,Y,Z,centers,sizes,clr,i,f,H)
sz=[1,1,1] + (f-1)/29*(sizes(i,:)-[1,1,1]);
cn=(f-1)/29*(centers(i,:));
X = sz(1)*(X-0.5) + cn(1);
Y = sz(2)*(Y-0.5) + cn(2);
Z = sz(3)*(Z-0.5) + cn(3);
if(nargin==9)
fill3(X,Y,Z,clr,Parent=H);
else
fill3(X,Y,Z,clr);
end
end
Animation
Remix Tree