home *** CD-ROM | disk | FTP | other *** search
-
- (*: Summary: This package gives an example of an impementation of a
- two-dimensional Game of Life.
- *)
-
- LifeRule[list_] :=
- Module[{ t },
- t = Count[list, 1, {2}] ;
- If[(list[[2, 2]] == 1 && t == 4) || t == 3, 1, 0]
- ]
-
- LifeUpdate[list_] :=
- Map[LifeRule, Partition[
- Wrap[ Map[Wrap, list]], {3, 3}, {1, 1}], {2}]
-
- Wrap = Join[{Last[#]}, #, {First[#]}]&
-
- AddObject[list_, {i_, j_}, template_] :=
- ReplacePart[list, 1, Table[{i, j}, {Length[template]}] + template]
-
- Glider = {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {0, 1}}
-
- LifeBlock = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}
-
-
- LifeEvolve[init_, t_] := NestList[LifeUpdate, init, t]
-
- ShowLife[tarray_] := Show[Graphics3D[ Cuboid[-Reverse[#], -Reverse[#] + 0.5]&
- /@ Position[tarray, 1] ], ViewPoint -> {1, 2, 10}]
-
-
-