Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RandomLattice[p_, n_] := Module[{g, img0, img1, topcolors},
- g = Flatten[Table[
- Table[
- If[RandomReal[] < p,
- {{i, j} -> pt},
- {}
- ],
- {pt, {{i + 1, j}, {i, j + 1}}}
- ],
- {i, n}, {j, n}
- ]];
- img0 =
- GraphPlot[g,
- VertexCoordinateRules -> (Flatten[
- Table[{i, j} -> {i, -j}, {i, n + 1}, {j, n + 1}]]),
- VertexRenderingFunction -> ({} &),
- PlotStyle -> Directive[Black]];
- img1 = ImageData[Binarize[ImageCrop[img0]]];
- Colorize[MorphologicalComponents[Binarize[ImageCrop[img0]]]]
- ];
- Manipulate[
- RandomLattice[p, n],
- {{n, 50}, 0, 100, 1},
- {{p, 0.5}, 0, 1}
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement