Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- m = zeros(200,20,2);
- m(200,10,1) = 10;
- m(200,11,1) = 10;
- m(200,9,1) = 10;
- %m(19,100,1) = 10;
- m(199,11,1) = 10;
- m(199,9,1) = 10;
- m(200,10,2) = -2;
- m(200,11,2) = -2;
- m(200,9,2) = -2;
- m(199,10,2) = -2;
- m(199,11,2) = -2;
- m(199,9,2) = -2;
- MAXPHER = 90;
- DEPOSIT = 30;
- T = 600;
- M = zeros(202,22,2);
- M(2:201,2:21,1:2) = m;
- EVAP = 20;
- mapANT = [1 1 1;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;0 0 0;1 0 0;0.4 0 0.5];
- %mapPHER = [1 1 1;0 0 0.1;0 0 0.2;0 0 0.3;0 0 0.4;0 0 0.5;0 0 0.6;0 0 0.7;0 0 0.8;0 0 0.9;0 0 1];
- for i =1:202
- for j=1:22
- if i == 1 || i == 202 ||j == 1 || j == 22;
- M(i,j,1) = 11;
- M(i,j,2) = -2;
- end
- end
- end
- % colormap(mapANT)
- % image(M(:,:,1)+1)
- % axis off
- % axis equal
- for t=1:T
- if M(200,11,1) == 0 && mod(t,3) == 0;
- M(200,11,1) = 5;
- end
- Mt = M;
- for i=2:201
- for j=2:21
- if M(i,j,1) ~= 0 && M(i,j,1) ~= 10;
- %SENSE
- if M(i,j,2) <= 30;
- tmove = 3;
- elseif M(i,j,2) <= 60;
- tmove = 2;
- elseif M(i,j,2) <= 90;
- tmove = 1;
- end
- if mod(t,tmove) == 0;
- lst = [M(i-1,j,:),M(i-1,j+1,:),M(i,j+1,:),M(i+1,j+1,:),M(i+1,j,:),M(i+1,j-1,:),M(i,j-1,:),M(i-1,j-1,:)];
- if M(i,j,1) ~= 9;
- lst(1,M(i,j,1),2) = -2;
- end
- for k=1:8
- if lst(1,k,1) > 0
- lst(1,k,2) = -2;
- end
- end
- mx = max(lst(1,:,2));
- if mx < 0;
- Mt(i,j,1) = 9;
- else
- if mx == 0
- n = 0;
- if lst(1,2,1) == 0 || lst(1,8,1) == 0;
- lstt = [lst(1,2,1) lst(1,8,1)];
- arah = [2 8];
- ft = find(lstt == 0);
- if length(ft) == 2;
- r = randi([1 length(ft)],1);
- else
- r = ft;
- end
- Mt(i,j,1) = arah(r);
- end
- else
- f = find(lst(:,:,2) == mx);
- rndPos = randi([1 length(f)],1);
- Mt(i,j,1) = f(rndPos);
- end
- end
- end
- end
- end
- end
- M = Mt;
- %WALK
- for i=2:201
- for j=2:21
- if M(i,j,2) <= 30;
- tmove = 3;
- elseif M(i,j,2) <= 60;
- tmove = 2;
- elseif M(i,j,2) <= 90;
- tmove = 1;
- end
- if mod(t,tmove) == 0;
- if M(i,j,1) == 0;
- Mt(i,j,2) = M(i,j,2) - EVAP;
- if Mt(i,j,2) < 0;
- Mt(i,j,2) = 0;
- end
- elseif M(i,j,1) == 1;
- if M(i-1,j) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i-1,j,1) = 5;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 2;
- if M(i-1,j+1) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i-1,j+1,1) = 6;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 3;
- if M(i,j+1) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i,j+1,1) = 7;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 4;
- if M(i+1,j+1) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i+1,j+1,1) = 8;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 5;
- if M(i+1,j) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i+1,j,1) = 1;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 6;
- if M(i+1,j-1) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i+1,j-1,1) = 2;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 7;
- if M(i,j-1) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i,j-1,1) = 3;
- else
- Mt(i,j,1) = 9;
- end
- elseif M(i,j,1) == 8;
- if M(i-1,j-1) == 0;
- if M(i,j,2) < MAXPHER;
- Mt(i,j,2) = M(i,j,2) + DEPOSIT;
- if Mt(i,j,2) > MAXPHER;
- Mt(i,j,2) = MAXPHER;
- end
- end
- Mt(i,j,1) = 0;
- Mt(i-1,j-1,1) = 4;
- else
- Mt(i,j,1) = 9;
- end
- end
- end
- end
- end
- M = Mt;
- % colormap(gray(101));
- % image(-1.*M(:,:,2)+101)
- % axis off
- % axis equal
- % ANIM(t) = getframe;
- % hold on
- colormap(mapANT);
- image(M(:,:,1)+1)
- axis off
- axis equal
- ANIM(t) = getframe;
- end
- movie(ANIM, 1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement