forked from mathworks/awesome-matlab-students
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bucky_Ball.m
54 lines (51 loc) · 1.47 KB
/
Bucky_Ball.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
animateFrames();
function animateFrames()
animFilename = 'Bucky_Ball.gif'; % Output file name
firstFrame = true;
framesPerSecond = 24;
delayTime = 1/framesPerSecond;
% Create the gif
for frame = 1:48
drawframe(frame);
fig = gcf();
fig.Units = 'pixels';
fig.Position(3:4) = [300,300];
im = getframe(fig);
[A,map] = rgb2ind(im.cdata,256);
if firstFrame
firstFrame = false;
imwrite(A,map,animFilename, 'LoopCount', Inf, 'DelayTime', delayTime);
else
imwrite(A,map,animFilename, 'WriteMode', 'append', 'DelayTime', delayTime);
end
end
end
function drawframe(f)
% Truncated icosahedron
B = bucky;
P = plot(graph(B), Layout = 'force3');
V = [P.XData.', P.YData.', P.ZData.'];
V = V/max(max(abs(V)));
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(3)
axis square
if nargin > 0
t = (f-1)*180/24;
R = [cosd(t) sind(t) 0; -sind(t) cosd(t) 0; 0 0 1];
V = V*R;
end
patch( ...
Faces = F, ...
Vertices = V, ...
EdgeColor = colors(1,:), ...
FaceVertexCData = faceColor, ...
FaceColor = 'flat')
end