Advertisement
Matthen

Diffusion limited aggregation

Jun 3rd, 2013
1,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. size = 200;
  2. Clear[sticky];
  3. Tmax = 1000;
  4. n = 10000;
  5. sticky[x_, y_] := False;
  6. sticky[Floor[size]/2, Floor[size]/2] = True;
  7. free = RandomReal[{0, size}, {n, 2}];
  8. f[{x_, y_}] := {Clip[Round[x], {1, size}],
  9. Clip[Round[y], {1, size}]};
  10. frames = {};
  11. stuck = {};
  12. Do[
  13. newfree = {};
  14. Do[
  15. {x, y} = f[free[[i]]];
  16. If[sticky[x, y],
  17. Table[
  18. sticky[x + xshift, y + yshift] = True;, {xshift, -1,
  19. 1}, {yshift, -1, 1}];
  20. AppendTo[stuck, {x, y}];
  21. ,
  22. AppendTo[newfree, free[[i]]];
  23. ];
  24. , {i, Length@free}];
  25. newfree += RandomReal[{-1, 1}, {Length@newfree, 2}];
  26. free = newfree;
  27. AppendTo[frames, {newfree, stuck}];
  28. , {t, Tmax}];
  29. Manipulate[
  30. With[{free = frames[[i, 1]], stuck = frames[[i, 2]]},
  31. Graphics[{PointSize[Small], Opacity[0.3], Point[free], Opacity[1],
  32. Table[{ColorData["FallColors"][1 - i/Length@stuck],
  33. Disk[stuck[[i]], 1]}, {i, Length@stuck}]
  34. },
  35. PlotRange -> {{0, size}, {0, size}}, ImageSize -> 250
  36. ]
  37. ],
  38. {i, 1, Tmax, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement