Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Percolation

By: Matthen on Jul 9th, 2013  |  syntax: None  |  size: 0.66 KB  |  views: 333  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.  ]
clone this paste RAW Paste Data