% Define initial conditions.
%clear a,b,c;
t0=0;
n=0;
i=0;
j=0;
k=0;
tfinal = 60; 
tpom=0;

A=[0 0 0];
B=[1 -1 1];
C=[-1 1 1];
D=[-1 -1 -1];
E=[1 1 -1];

n=input('podaj wielkosc kostki             ');
lkrok=input('podaj podzia³kê: 1,2,3...  ');
f=input('podaj ksztalt punktu w apostrofie '); 
gr=input('podaj grubosc punktu: 0...1,2...  ');
period=100/((2*lkrok*n+1)^3);
clf reset
whitebg('w')
krok=1/lkrok
%----------------------
for i=-n:krok:n
 for j=-n:krok:n
  for k=-n:krok:n
      y0=[i j k]';
   [t,y]=ode23('rowr',t0,tfinal,y0);
   pom=length(y);
   clear t;
   
   if (round(y(pom,:))==A)
    colr='k';
   elseif (round(y(pom,:))==B)
    colr='b';
   elseif (round(y(pom,:))==C)
    colr='c';
   elseif (round(y(pom,:))==D)
    colr='r';
   elseif (round(y(pom,:))==E)
    colr='g';
   else 
    colr='k';
   end
  
  %------------------    
   colr(2)=f;
   hndl=plot3(y(:,1),y(:,2), y(:,3),colr);
   set(hndl,'LineWidth',gr); 
   set(hndl,'MarkerSize',gr);
   
   clear y,colr;
   tpom=tpom+period;
   clc
   fprintf(1,'\n%3.1f%%',tpom)
   hold on
   clear y0;
   
  %------------------ 
  end
 end
end
%--------------------
legend('k*','[ 0 0 0]','b*','[ 1-1 1]','c*','[-1 1 1]','r*','[-1-1-1]','g*','[ 1 1-1]',-1)
%--------------------
%               Drukuje linie
for i=-n:n;
 for j=-n:n;
  for k=-n:n;
   a=linspace(0,k);
   b=linspace(j,j);
   c=linspace(i,i);
   plot3(a,b,c,'m.');
   plot3(b,a,c,'m.');
   plot3(b,c,a,'m.');
   hold on
%   clear a,b,c;
end
end
end
%--------------------
clear n,t0,tfinal;
k=0;
n=0;
d=30;           % k¹t obrotu
while (k~=5)
 k=menu('kierunek','w lewo','w prawo','w gore','w dol','wyjscie');
 if (k==2)
  n=n-d;
  view(n,d)
 elseif (k==1)
  n=n+d;
  view(n,d)
 elseif (k==4)
  t0=t0+d;
  view(n,t0)
 elseif (k==3)
  t0=t0-d;
  view(n,t0) 
 end
end
whitebg
clf 
close    
clear all
%--------------------
