patches-own [ living? ;; indicates if the cell is living live-neighbors ;; counts how many neighboring cells are alive ] to setup-blank ask patches [ cell-death ] end to setup-random ask patches [ ifelse random-float 1.0 < initial-density [ cell-birth ] [ cell-death ] ] end to cell-birth set living? true set pcolor fgcolor end to cell-death set living? false set pcolor bgcolor end to go if mouse-down? [ stop ] ;; wait for user to stop drawing ask patches [ set live-neighbors count neighbors with [living?] ] ;; Starting a new "ask patches" here ensures that all the patches ;; finish executing the first ask before any of them start executing ;; the second ask. This keeps all the patches in sync with each other, ;; so the births and deaths at each generation all happen in lockstep. ask patches [ ifelse live-neighbors = 3 [ cell-birth ] [ if live-neighbors != 2 [ cell-death ] ] ] end to add-cells if mouse-down? [ ask patch-at mouse-xcor mouse-ycor [ cell-birth ] ] end to remove-cells if mouse-down? [ ask patch-at mouse-xcor mouse-ycor [ cell-death ] ] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Life model. ; http://ccl.northwestern.edu/netlogo/models/Life. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/Life ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 290 10 628 369 20 20 8.0 1 10 1 1 1 CC-WINDOW 289 372 619 503 Command Center SLIDER 126 77 282 110 initial-density initial-density 0.0 1.0 0.3 0.01 1 NIL BUTTON 17 78 119 111 NIL setup-random NIL 1 T OBSERVER T BUTTON 16 218 94 251 go-once go NIL 1 T OBSERVER T BUTTON 105 218 196 251 go-forever go T 1 T OBSERVER T SLIDER 13 379 150 412 fgcolor fgcolor 0.0 139.0 133.0 1.0 1 NIL SLIDER 13 412 150 445 bgcolor bgcolor 0.0 139.0 79.0 1.0 1 NIL BUTTON 157 395 253 428 recolor ifelse living?\n [ set pcolor fgcolor ]\n [ set pcolor bgcolor ] NIL 1 T PATCH T MONITOR 16 273 119 322 current density count patches with\n [living?]\n/ count patches * 100 2 1 BUTTON 17 42 119 75 NIL setup-blank NIL 1 T OBSERVER T TEXTBOX 132 121 285 209 When one of these buttons is down, you can add or remove cells by holding down the mouse button and "drawing". BUTTON 17 117 120 152 NIL add-cells T 1 T OBSERVER NIL BUTTON 17 156 120 194 NIL remove-cells T 1 T OBSERVER NIL @#$#@#$#@ WHAT IS IT? ----------- This program is an example of a two-dimensional cellular automaton. A cellular automaton is a computational machine that performs actions based on certain rules. It can be thought of as a board which is divided into cells (such as square cells of a checkerboard). Each cell can be either on or off. This is called the "state" of the cell. According to specified rules, each cell will be on (alive) or off (dead) at the next time step. This particular cellular automaton is called The Game of Life. The rules of the game are as follows. Each cell checks the state of itself and its eight surrounding neighbors and then sets itself to either on or off, depending upon the rule. The rule is as follows: If there are less than two "on" neighbors, then the cell turns off. If there are more than three "on" neighbors, the cell turns off. If there are 2 "on" neighbors, the cell remains in the state it is in. If there are exactly three "on" neighbors, the cell turns on. This is done in parallel and continues forever. There are certain recurring shapes in Life, for example, the "glider" and the "blinker". The glider is composed of 5 cells which form a small arrow-headed shape, like this: | X | X | XXX This glider will wiggle across the screen, retaining its shape. A blinker is a block of three cells (either up and down or left and right) that rotates between horizontal and vertical orientations. HOW TO USE IT ------------- The INITIAL-DENSITY slider determines the initial density of cells that are alive. SETUP-RANDOM places these cells. GO-FOREVER runs the rule forever. GO-ONCE runs the rule once. The background color and foreground color can be set via the sliders. Just adjust the sliders and click SET-COLORS. It may take some experimentation to find the colors that you want. THINGS TO NOTICE ---------------- Find some objects that are alive, but motionless. Is there a "critical density" - one at which all change and motion stops/eternal motion begins? THINGS TO TRY ------------- Are there any recurring shapes other than gliders and blinkers? Build some objects that don't die (using "add-cells") How much life can the board hold and still remain motionless and unchanging? (use "add-cells") The glider gun is a large conglomeration of cells that repeatedly spits out gliders. Find a "glider gun" (very, very difficult!). EXTENDING THE MODEL ------------------- Give some different rules to life and see what happens. Experiment with using neighbors4 instead of neighbors (see below). LANGUAGE FEATURES ------------------ The neighbors primitive returns the agentset of the patches to the north, south, east, west, northeast, northwest, southeast, and southwest. So "count neighbors with [living?]" counts how many of those eight patches have the living? patch variable set to true. neighbors4 is like neighbors but only uses the patches to the north, south, east, and west. Some cellular automata are defined using the 8-neighbors rule, others the 4-neighbors. RELATED MODELS -------------- CA 1D Elementary - a model that shows all 256 possible simple 1D cellular automata CA 1D Totalistic - a model that shows all 2,187 possible 1D 3-color totalistic cellular automata CA 1D Rule 30 - the basic rule 30 model CA 1D Rule 30 Turtle - the basic rule 30 model implemented using turtles CA 1D Rule 90 - the basic rule 90 model CA 1D Rule 110 - the basic rule 110 model CA 1D Rule 250 - the basic rule 250 model REFERENCES AND CREDITS ------------------- The Game of Life was invented by John Horton Conway. See also: Von Neumann, J. and Burks, A. W., Eds, 1966. Theory of Self-Reproducing Automata. University of Illinois Press, Champaign, IL. "LifeLine: A Quarterly Newsletter for Enthusiasts of John Conway's Game of Life", nos. 1-11, 1971-1973. Martin Gardner, "Mathematical Games: The fantastic combinations of John Conway's new solitaire game `life',", Scientific American, October, 1970, pp. 120-123. Martin Gardner, "Mathematical Games: On cellular automata, self-reproduction, the Garden of Eden, and the game `life',", Scientific American, February, 1971, pp. 112-117. Berlenkamp, Conway, and Guy, Winning Ways for your Mathematical Plays, Academic Press: New York, 1982. William Poundstone, The Recursive Universe, William Morrow: New York, 1985. To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Life model. http://ccl.northwestern.edu/netlogo/models/Life. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Life for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 2.0beta4 @#$#@#$#@ setup-random repeat 20 [ go ] @#$#@#$#@ @#$#@#$#@