% 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             ');
f=input('podaj ksztalt puntku w apostrofie '); 
period=100/((2*n+1)*(2*n+1)*(2*n+1));
whitebg
%----------------------
for i=-n:n
 for j=-n:n
  for k=-n:n
      y0=[i j k]';
   [t,y]=ode23('rowr',t0,tfinal,y0);
   pom=length(y);
   clear t;
   clc;
   if (round(y(pom,:))==A)
    colr='b';
   elseif (round(y(pom,:))==B)
    colr='m';
   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;
   plot3(y(:,1),y(:,2), y(:,3),colr);
   clear y,y0,colr;
   tpom=tpom+period;
   fprintf('%d procent',round(tpom))
   hold on
  %------------------ 
  end
 end
end
%--------------------
legend('b*','[ 0 0 0]','m*','[ 1-1 1]','c*','[-1 1 1]','r*','[-1-1-1]','g*','[ 1 1-1]',-1)
%--------------------
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,'k.');
   plot3(b,a,c,'k.');
   plot3(b,c,a,'k.');
   hold on
%   clear a,b,c;
end
end
end
%--------------------
clear n,t0,tfinal;
k=0;
n=0;
d=30;
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     
%--------------------


