Advertisement
Matthen

Percolation

Jul 9th, 2013
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. RandomLattice[p_, n_] := Module[{g, img0, img1, topcolors},
  2. g = Flatten[Table[
  3. Table[
  4. If[RandomReal[] < p,
  5. {{i, j} -> pt},
  6. {}
  7. ],
  8. {pt, {{i + 1, j}, {i, j + 1}}}
  9. ],
  10. {i, n}, {j, n}
  11. ]];
  12. img0 =
  13. GraphPlot[g,
  14. VertexCoordinateRules -> (Flatten[
  15. Table[{i, j} -> {i, -j}, {i, n + 1}, {j, n + 1}]]),
  16. VertexRenderingFunction -> ({} &),
  17. PlotStyle -> Directive[Black]];
  18. img1 = ImageData[Binarize[ImageCrop[img0]]];
  19. Colorize[MorphologicalComponents[Binarize[ImageCrop[img0]]]]
  20. ];
  21. Manipulate[
  22. RandomLattice[p, n],
  23. {{n, 50}, 0, 100, 1},
  24. {{p, 0.5}, 0, 1}
  25. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement