Advertisement
Guest User

Untitled

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