Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. clear all
  2. m = zeros(200,20,2);
  3. m(200,10,1) = 10;
  4. m(200,11,1) = 10;
  5. m(200,9,1) = 10;
  6. %m(19,100,1) = 10;
  7. m(199,11,1) = 10;
  8. m(199,9,1) = 10;
  9. m(200,10,2) = -2;
  10. m(200,11,2) = -2;
  11. m(200,9,2) = -2;
  12. m(199,10,2) = -2;
  13. m(199,11,2) = -2;
  14. m(199,9,2) = -2;
  15. MAXPHER = 100;
  16. DEPOSIT = 10;
  17. T = 1000;
  18. M = zeros(202,22,2);
  19. M(2:201,2:21,1:2) = m;
  20. EVAP = 1;
  21. 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];
  22. %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];
  23.  
  24.  
  25. for i =1:202
  26. for j=1:22
  27. if i == 1 || i == 202 ||j == 1 || j == 22;
  28. M(i,j,1) = 11;
  29. M(i,j,2) = -2;
  30. end
  31. end
  32. end
  33. % colormap(mapANT)
  34. % image(M(:,:,1)+1)
  35. % axis off
  36. % axis equal
  37.  
  38.  
  39.  
  40. for t=1:T
  41. if M(199,10,1) == 0;
  42. M(198,10,1) = 5;
  43. end
  44. Mt = M;
  45. for i=2:201
  46. for j=2:21
  47. if M(i,j,1) ~= 0 && M(i,j,1) ~= 10;
  48. %SENSE
  49. 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)];
  50. if M(i,j,1) ~= 9;
  51. lst(1,M(i,j,1),2) = -2;
  52. end
  53. for k=1:8
  54. if lst(1,k,1) > 0
  55. lst(1,k,2) = -2;
  56. end
  57. end
  58. mx = max(lst(1,:,2));
  59. if mx < 0;
  60. n = 0;
  61. if lst(1,2,1) == 0 || lst(1,8,1) == 0;
  62. lstt = [lst(1,2,1) lst(1,8,1)];
  63. ft = find(lstt == 0);
  64. r = randi([1 length(ft)],1);
  65. Mt(i,j,1) = r;
  66. else
  67. Mt(i,j,1) = 9;
  68. end
  69. else
  70. f = find(lst(:,:,2) == mx);
  71. rndPos = randi([1 length(f)],1);
  72. Mt(i,j,1) = f(rndPos);
  73. end
  74. end
  75. end
  76. end
  77. M = Mt;
  78. %WALK
  79. for i=2:201
  80. for j=2:21
  81. if M(i,j,1) == 0;
  82. Mt(i,j,2) = M(i,j,2) - EVAP;
  83. if Mt(i,j,2) < 0;
  84. Mt(i,j,2) = 0;
  85. end
  86. elseif M(i,j,1) == 1;
  87. if M(i-1,j) == 0;
  88. if M(i,j,2) < MAXPHER;
  89. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  90. if Mt(i,j,2) > MAXPHER;
  91. Mt(i,j,2) = MAXPHER;
  92. end
  93. end
  94. Mt(i,j,1) = 0;
  95. Mt(i-1,j,1) = 5;
  96. else
  97. Mt(i,j,1) = 9;
  98. end
  99. elseif M(i,j,1) == 2;
  100. if M(i-1,j+1) == 0;
  101. if M(i,j,2) < MAXPHER;
  102. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  103. if Mt(i,j,2) > MAXPHER;
  104. Mt(i,j,2) = MAXPHER;
  105. end
  106. end
  107. Mt(i,j,1) = 0;
  108. Mt(i-1,j+1,1) = 6;
  109. else
  110. Mt(i,j,1) = 9;
  111. end
  112. elseif M(i,j,1) == 3;
  113. if M(i,j+1) == 0;
  114. if M(i,j,2) < MAXPHER;
  115. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  116. if Mt(i,j,2) > MAXPHER;
  117. Mt(i,j,2) = MAXPHER;
  118. end
  119. end
  120. Mt(i,j,1) = 0;
  121. Mt(i,j+1,1) = 7;
  122. else
  123. Mt(i,j,1) = 9;
  124. end
  125. elseif M(i,j,1) == 4;
  126. if M(i+1,j+1) == 0;
  127. if M(i,j,2) < MAXPHER;
  128. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  129. if Mt(i,j,2) > MAXPHER;
  130. Mt(i,j,2) = MAXPHER;
  131. end
  132. end
  133. Mt(i,j,1) = 0;
  134. Mt(i+1,j+1,1) = 8;
  135. else
  136. Mt(i,j,1) = 9;
  137. end
  138. elseif M(i,j,1) == 5;
  139. if M(i+1,j) == 0;
  140. if M(i,j,2) < MAXPHER;
  141. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  142. if Mt(i,j,2) > MAXPHER;
  143. Mt(i,j,2) = MAXPHER;
  144. end
  145. end
  146. Mt(i,j,1) = 0;
  147. Mt(i+1,j,1) = 1;
  148. else
  149. Mt(i,j,1) = 9;
  150. end
  151. elseif M(i,j,1) == 6;
  152. if M(i+1,j-1) == 0;
  153. if M(i,j,2) < MAXPHER;
  154. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  155. if Mt(i,j,2) > MAXPHER;
  156. Mt(i,j,2) = MAXPHER;
  157. end
  158. end
  159. Mt(i,j,1) = 0;
  160. Mt(i+1,j-1,1) = 2;
  161. else
  162. Mt(i,j,1) = 9;
  163. end
  164. elseif M(i,j,1) == 7;
  165. if M(i,j-1) == 0;
  166. if M(i,j,2) < MAXPHER;
  167. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  168. if Mt(i,j,2) > MAXPHER;
  169. Mt(i,j,2) = MAXPHER;
  170. end
  171. end
  172. Mt(i,j,1) = 0;
  173. Mt(i,j-1,1) = 3;
  174. else
  175. Mt(i,j,1) = 9;
  176. end
  177. elseif M(i,j,1) == 8;
  178. if M(i-1,j-1) == 0;
  179. if M(i,j,2) < MAXPHER;
  180. Mt(i,j,2) = M(i,j,2) + DEPOSIT;
  181. if Mt(i,j,2) > MAXPHER;
  182. Mt(i,j,2) = MAXPHER;
  183. end
  184. end
  185. Mt(i,j,1) = 0;
  186. Mt(i-1,j-1,1) = 4;
  187. else
  188. Mt(i,j,1) = 9;
  189. end
  190. end
  191. end
  192. end
  193. M = Mt;
  194. % colormap(gray(101));
  195. % image(-1.*M(:,:,2)+101)
  196. % axis off
  197. % axis equal
  198. % ANIM(t) = getframe;
  199. % hold on
  200. colormap(mapANT);
  201. image(M(:,:,1)+1)
  202. axis off
  203. axis equal
  204. ANIM(t) = getframe;
  205. end
  206.  
  207. for i=1:t;
  208. movie(ANIM, 1, 30)
  209. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement