Matlab Laberinto

Páginas: 2 (258 palabras) Publicado: 5 de noviembre de 2012
clear
clc
N= 30;
aa=2*N+1;
A = zeros(aa,aa);
A(3:aa,1)=1; %margen izquierdoaa
A(1,1:aa)=1; %margen superior
A(aa,1:aa)=1; %margen inferiorA(1:aa-2,aa)=1; %margen derecho
for i = 1:1000000
x=fix(rand*(N+1)); %de 0 a N
xx = 2*x+1; %impar de 1 a 2N+1
y=fix(rand*(N+1));%de 0 a N
yy = 2*y+1; %impar de 1 a 2N+1
%A(yy,xx)= 4;
if A(yy,xx)==1
z1 = fix(rand*2); %0 o 1
z2 =fix(rand*2); %0 o 1 <>
if z1==0 && z2==0 %horizontal izq
if xx > 1
if A(yy,xx-2)==0;A(yy,xx-2:xx-1)=1;
end
end
end
if z1==0 && z2==1 %horizontal der
if xx< aa
if A(yy,xx+2)==0;
A(yy,xx+1:xx+2)=1;
end
end
end
ifz1==1 && z2==0 %vertica izq
if yy > 1
if A(yy-2,xx)==0;
A(yy-2:yy-1,xx)=1;end
end
end
if z1==1 && z2==1 %vertical aba
if yy < aa
ifA(yy+2,xx)==0;
A(yy+1:yy+2,xx)=1;
end
end
end

end
end
B=ones(aa,aa,3);
fori=1:aa
for j=1:aa
if A(j,i)==1
B ( j, i, 1:3)=0;

end
end
end


imwrite (B,'lab002.png')
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • matlab
  • matlab
  • Matlab
  • Matlab
  • matlab
  • MATLAB
  • MATLAB
  • Matlab

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS