Skip to content

Instantly share code, notes, and snippets.

@balzer82
Created April 2, 2015 06:27
Show Gist options
  • Save balzer82/53e0e21903a56674d52f to your computer and use it in GitHub Desktop.
Save balzer82/53e0e21903a56674d52f to your computer and use it in GitHub Desktop.
Create a .gif of a rotating 3D Pyramide with Matlab
l=1;
ecken = {'Geld', 'Zeit', 'Kind', 'Ruhm+Ehre'};
%% Base
%
x=0;
y=1;
z=l;
for a = 0:120:360
xn = sind(a)*l;
yn = cosd(a)*l;
line([x xn], [y yn],[0 0], 'linewidth', 10)
hold on
line([xn 0], [yn 0], [0 z], 'linewidth', 10)
x=xn;
y=yn;
if a==360
text(0,0,z+0.1, ecken{a/120+1}, 'Fontsize', 20, 'HorizontalAlignment', 'center')
else
text(x-0.1,y,-0.1, ecken{a/120+1}, 'Fontsize', 20, 'HorizontalAlignment', 'center')
end
end
axis equal;
axis off;
%set(gcf,'color','w');
title('Magische Pyramide des Lebens','Fontsize', 30)
view(155,15)
set(gcf,'renderer','painters')
print(gcf, 'Pyramide.png', '-dpng', '-r150')
%% Create GIF
mygif = 'Pyramide.gif';
f = getframe(gcf);
[im,map]=rgb2ind(f.cdata,256,'nodither');
imwrite(im,map,mygif,'Delaytime',0.1,'Loopcount',inf)
for n = 157:2:365+153
view(n, 15)
drawnow
f = getframe(gcf);
[im,map]=rgb2ind(f.cdata,256,'nodither');
imwrite(im,map,mygif,'writemode','append','Delaytime',0.1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment