• Remix
  • Share
  • New Entry

on 13 Nov 2023
  • 12
  • 38
  • 2
  • 0
  • 1042
drawframe(1);
Write your drawframe function below
function drawframe(f)
% function bouncing_bucky_ball(f)
Rx = @(t) [1 0 0 0
0 cosd(t) sind(t) 0
0 -sind(t) cosd(t) 0
0 0 0 1];
Ry = @(t) [cosd(t) 0 sind(t) 0
0 1 0 0
-sind(t) 0 cosd(t) 0
0 0 0 1];
if nargin == 0 || f == 1
% Truncated icosahedron
B = bucky;
P = plot(graph(B), Layout = 'force3');
V = [P.XData.', P.YData.', P.ZData'];
V = V/max(max(abs(V)));
V = V/8;
cla
C = allcycles(graph(B), maxCycleLength = 6);
L = cellfun(@length, C);
F = NaN(height(C), max(L));
for k = 1:height(C)
F(k,1:L(k)) = C{k};
end
colors = [0 0 0.5; 1 1 1];
faceColor = colors((L == max(L))+1, :);
view(2)
axis square
axis([0 1 0 1])
H = hgtransform(Parent = gca);
patch(Parent = H, ...
Faces = F, ...
Vertices = V, ...
EdgeColor = colors(1,:), ...
FaceVertexCData = faceColor, ...
FaceColor = 'flat')
fps = 24;
set(gca,'userdata',[1/2 0 1/fps 1/fps])
end
g = get(gca,'children');
H = g(1);
g = get(gca,'userdata');
x = g(1);
y = g(2);
dx = g(3);
dy = g(4);
x = x + dx;
y = y + dy;
if x < 0 || x > 1
dx = -dx;
end
if y < 0 || y > 1
dy = -dy;
end
beta = 90*(x+y);
M = Ry(beta)*Rx(2*beta);
M(1,4) = x;
M(2,4) = y;
H.Matrix = M;
set(gca,'userdata',[x y dx dy])
end
Animation
Remix Tree