Advertisement
Guest User

Untitled

a guest
Jun 11th, 2010
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. duration = 10;
  3. length = 200;
  4.  
  5. northdensity = 0;
  6. southdensity = 0;
  7. eastdensity = 0;
  8. westdensity = 0;
  9.  
  10. east = 1;
  11. north = 2;
  12. west = 4;
  13. south = 8;
  14.  
  15. northfield = rand(length, length)< northdensity;
  16. southfield = rand(length, length)< southdensity;
  17. eastfield = rand(length, length)< eastdensity;
  18. westfield = rand(length, length)< westdensity;
  19.  
  20. field = northfield * north + southfield * south + westfield * west + eastfield * east;
  21.  
  22.  
  23. lookuptable = [ 0, 1,2,3,4,10,6,7,8,9,5,11,12,13,14,15 ];
  24.  
  25. colormap(gray(5));
  26.  
  27. smallsquare = length / 10
  28. field(length/2 - smallsquare:length/2 + smallsquare,length/2 - smallsquare:length/2 + smallsquare)=15;
  29.  
  30.  
  31. for step=1:duration
  32. # Move all of the particles
  33. eastmovement = bitand(shift(field ,1, 2), east);
  34. northmovement = bitand(shift(field, -1), north);
  35. westmovement = bitand(shift(field, -1, 2), west)';
  36. southmovement = bitand(shift(field, 1), south);
  37.  
  38. density = eastmovement + southmovement + westmovement + northmovement;
  39. field = lookuptable(density+1);
  40.  
  41. image((1+bitand(density, north)+bitand(density, west)+bitand(density, east)+bitand(density, south))>2*5);title(num2str(step));drawnow;
  42. # pause;
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement