clear all rows=100; cols=100; iterations=300; colormap gray Next=zeros(rows,cols); B= rand(rows,cols); for i = 1:rows for j= 1:cols B(i,j)= double(int8(B(i,j)*8)); end end Next=B; for k=1:iterations for i = 1:rows for j= 1:cols if i<2 arriba=0; else arriba=B(i-1,j); end; if i>rows-1 abajo=0; else abajo=B(i+1,j); end; if j<2 izquierda=0; else izquierda=B(i,j-1); end; if j>cols-1 derecha=0; else derecha=B(i,j+1); end; if (i<2 || j<2) ar_iz=0; else ar_iz=B(i-1,j-1); end; if (i<2 || j>cols-1) ar_dr=0; else ar_dr=B(i-1,j+1); end; if (i>rows-1 || j<2) ab_iz=0; else ab_iz=B(i+1,j-1); end; if (i>rows-1 || j>cols-1) ab_dr=0; else ab_dr=B(i+1,j+1); end; suma=arriba+abajo+izquierda+derecha+ar_iz+ar_dr+ab_iz+ab_dr; mierda=double(uint8( (B(i,j)/2))); if (( suma>19 && suma<35)) Next(i,j)=Next(i,j)+1; else Next(i,j)=Next(i,j)-mierda ; end; if Next(i,j)>6.9 Next(i,j)=7; end; if Next(i,j)<1.01 Next(i,j)=0.1; end; end end B=Next; if (k>00) surf(B,'Edgecolor','none'); text(18,5,20,'Unity Analytics LLC (www.unityanalytics.net)','BackgroundColor','black','Color',[1 1 1],'FontWeight','bold') axis off box off view([0 90]) set(gcf,'Renderer','zbuffer','Color',[0 0 0]) M(k)= getframe; pause(0.05) end end movie(M) movie2avi(M,'CellAutomaton.avi','compression','Cinepak')