1. Start Netlogo.
-
If you're running a Linux machine in Park 230 or Park 232, open the Terminal and enter netlogo. (The Terminal window can be found by clicking The Red Hat -> "System Tools" -> "Terminal")
-
If you're running a Mac or Windows machine (and you know Netlogo is installed), double-click the Netlogo icon.
-
If you need to install Netlogo, go to the
Netlogo site and download it. It's free.
-
Netlogo starts by opening a new, blank model. All you have to do is fill in what you want.
2. Set up the interface.
-
The large black square is the lattice. It's fine as it is.
-
We need three buttons.
-
Click once on the Button icon. Click somplace in the white space to the left of the lattice. The button will appear, and so will a dialogue box.
-
In the Code box, type initialize
-
In the Display Name box, type Initialize
-
Do not check the Forever box, and don't change the Ask box.
-
Make a second button.
-
The Code is go-once
-
The Display Name is Go
-
It's not a forever button, and we're still asking the observer.
-
Make a third button.
-
The Code is also go-once
-
The Display Name is Continue
-
This one is a forever button. We're still asking the observer.
-
Make a monitor.
-
The Reporter is time
-
The Display Name is time
-
We need only zero decimal places.
-
All the interface labels are red to remind you that you still haven't defined the procedures (initialize and go-once) and variable (time to which they refer.
3. Write the code
Click the Procedures tab.3.1. Define the variables
-
All we need is a global variable to keep track of the time. Write:
globals [time]
-
We also need each patch to keep track of what its color will be in the next time step. So write this also:
patches-own [next-color]
3.2. Write the interface code
-
Write this:
to interface end
-
Now we'll fill in the space between to interface and end.
-
First we have to set the color of all the patches to black, which we'll use as the off state. The first command in the interface procedure is
ask patches [set pcolor black]
-
Now set just one patch -- the center one (at x=0, y=0) -- yellow:
ask patch 0 0 [set pcolor yellow]
-
And finally, set the global variable time to 0:
set time 0
3.3. Write the code for go-once
-
Write this:
to go-once A end
-
We want to ask all patches to do the same thing. So replace A with this ask block:
ask patches [
B
]
-
What do we ask the patches to do? We're asking them to do one of two things, depending on whether the number of neighbors that are on is odd or even. So we need an ifelse statement. We'll do it something like this: if EVEN-ON-NEIGHBORS [MAKE NEXT COLOR YELLOW][MAKE NEXT COLOR BLACK].
-
Replace B with this:
ifelse (C) [D] [E]
-
Now, some number x is odd if x mod 2 = 1, and it's even if x mod 2 = 0. In this case, x is the number of von Neumann neighbors that are on. We can get the number of agents in an agentset using count, and we can specify the agents with some property by using with [TEST]. So we can replace C with this:
(count neighbors4 with [pcolor = yellow]) mod 2 = 1
-
If that test is true, then the number of on neighbors is odd and we want the next state to be on. Replace D with this:
set next-color yellow
-
Replace E with the code that sets the next color to black.
-
After that initial ask block, set up a new ask block to update all patches' colors:
ask patches [set pcolor next-color]
-
Update time, so that the monitor displays the right number:
set time (time + 1)
