Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size = 200;
- Clear[sticky];
- Tmax = 1000;
- n = 10000;
- sticky[x_, y_] := False;
- sticky[Floor[size]/2, Floor[size]/2] = True;
- free = RandomReal[{0, size}, {n, 2}];
- f[{x_, y_}] := {Clip[Round[x], {1, size}],
- Clip[Round[y], {1, size}]};
- frames = {};
- stuck = {};
- Do[
- newfree = {};
- Do[
- {x, y} = f[free[[i]]];
- If[sticky[x, y],
- Table[
- sticky[x + xshift, y + yshift] = True;, {xshift, -1,
- 1}, {yshift, -1, 1}];
- AppendTo[stuck, {x, y}];
- ,
- AppendTo[newfree, free[[i]]];
- ];
- , {i, Length@free}];
- newfree += RandomReal[{-1, 1}, {Length@newfree, 2}];
- free = newfree;
- AppendTo[frames, {newfree, stuck}];
- , {t, Tmax}];
- Manipulate[
- With[{free = frames[[i, 1]], stuck = frames[[i, 2]]},
- Graphics[{PointSize[Small], Opacity[0.3], Point[free], Opacity[1],
- Table[{ColorData["FallColors"][1 - i/Length@stuck],
- Disk[stuck[[i]], 1]}, {i, Length@stuck}]
- },
- PlotRange -> {{0, size}, {0, size}}, ImageSize -> 250
- ]
- ],
- {i, 1, Tmax, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement