patches-own [ firing? ;; white cells refractory? ;; red cells firing-neighbors ;; counts how many neighboring cells are firing ] 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 ;; patch procedure set firing? true set refractory? false set pcolor white end to cell-aging ;; patch procedure set firing? false set refractory? true set pcolor red end to cell-death ;; patch procedure set firing? false set refractory? false set pcolor black end to go if mouse-down? [ stop ] ;; wait for user to stop drawing ask patches [ set firing-neighbors count neighbors with [firing?] ] ;; 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 firing? [ cell-aging ] [ ifelse refractory? [ cell-death ] [ if firing-neighbors = 2 [ cell-birth ] ] ] ] end to add-cells [white?] if mouse-down? [ ask patch-at mouse-xcor mouse-ycor [ ifelse white? [ cell-birth ] [ cell-aging ] ] ] 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: ; 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. ; ; Copyright 2002 by Uri Wilensky. Updated 2002. 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. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (2002). NetLogo Brian's Brain model. ; http://ccl.northwestern.edu/netlogo/models/BriansBrain. ; 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/BriansBrain ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 290 10 606 491 25 37 6.0 1 10 1 1 1 CC-WINDOW 4 351 286 492 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 37 136 115 169 go-once go NIL 1 T OBSERVER T BUTTON 126 136 217 169 go-forever go T 1 T OBSERVER T BUTTON 17 42 119 75 NIL setup-blank NIL 1 T OBSERVER T TEXTBOX 152 210 280 309 When one of these buttons is down, you can add or remove cells by holding down the mouse button and "drawing". BUTTON 17 195 140 228 add white cells add-cells true T 1 T OBSERVER NIL BUTTON 17 265 140 298 NIL remove-cells T 1 T OBSERVER NIL BUTTON 17 230 140 263 add red cells add-cells false T 1 T OBSERVER NIL @#$#@#$#@ WHAT IS IT? ----------- This program is an example of a two-dimensional cellular automaton. If you are not already familiar with 2D CA, see the model "Life" for a basic discussion. Typical CAs use two cell states (live and dead), but Brian's Brian uses three: firing (white), refractory (red), and dead (black). This CA is especially interesting to watch because it has many configurations that move steadily across the grid (as opposed to Life, which has only relatively few such configurations). HOW IT WORKS ------------ Firing (white) cells always become refractory (red) at the next time step. Refractory (red) cells always die (turn black) at the next time step. A new firing (white) cell is born in any black cell that has exactly two firing (white) neighbors (of its eight surrounding cells). HOW TO USE IT ------------- The INITIAL-DENSITY slider determines the initial density of cells that are firing. SETUP-RANDOM places these cells. GO-FOREVER runs the rule forever. GO-ONCE runs the rule once. If you want to draw an initial pattern yourself, or add or remove cells in the middle of a run, turn on the ADD WHITE CELLS, ADD RED CELLS, and REMOVE CELLS buttons, then "draw" with the mouse in the graphics window. THINGS TO NOTICE ---------------- Lots of patterns stay stable and move steadily across the grid. Such patterns are often referred to as "gliders". How many different types of gliders do you see? Why does this happen? How do the rules of the CA result in this behavior? THINGS TO TRY ------------- Are there any stable shapes that don't move? Are there any "glider guns" (objects that emit a steady stream of gliders)? On a small enough grid, usually the CA reaches a steady state where there may be movement but nothing new happens. In Brian's Brain, a square grid usually reaches a steady state more quickly than a rectangular grid (try it!). Why? EXTENDING THE MODEL ------------------- Many other interesting 3-state 2D automata exist. Experiment with variations on the rules in this model. RELATED MODELS -------------- See all of the other models in the "Cellular Automata" subsection of the "Computer Science" section of the NetLogo Models Library. CREDITS AND REFERENCES ---------------------- Brian's Brain was invented by Brian Silverman. To refer to this NetLogo model in academic publications, please use: Wilensky, U. (2002). NetLogo Brian's Brain model. http://ccl.northwestern.edu/netlogo/models/BriansBrain. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 2002 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/BriansBrain 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 67 [ go ] @#$#@#$#@ @#$#@#$#@