clear all;
clf;

sphere1=UnitSphere(2);
sphere1.facecolor='white';

cyl1=UnitCylinder(1);
cyl1=translate(scale(cyl1,.1,.1,.75),2.8,0,0);
cyl1.facelighting='flat';
cyl1.facecolor='yellow';

octa1=UnitSphere(1);
octa1.facecolor='red';
octa1.facelighting='flat';
octa1.specularstrength=.7;
octa1=translate(octa1,1.8,0,0);

for time=0:.1:4
   
   level2=combine(...
      rotateX(octa1,time*90), ...
      rotateX(cyl1, time*(-180)) );
   
   level1=combine(...
      level2, ...
      rotateY(level2,90), ...
      rotateY(level2,-90), ...
      rotateY(level2,180), ...
      rotateZ(level2,90), ...
      rotateZ(level2,-90)...
      );
   
   % base=rotateZ([{sphere1} level1],time*45);
   base=rotateZ(combine(sphere1,level1),time*45);
   
   clf
   
   count=renderpatch(base);
   
   axis off;
   grid on
   daspect([1 1 1])
   
   light('position',[10,-10,10])
   %light('position',[10, 10, 10])
   
   %Do a persptective transform
   set(gca,'projection','perspective')
   set(gca,'CameraViewAngle',6)
   
   %The frame background color
   set(gcf,'color', [.6,.8,.8])
   xlabel('x');ylabel('y');zlabel('z'); 
   view(-28,20)
   drawnow;
   
end %for  

rotate3d on
