Other pages: Bio/Geo/CS250, MainModelingWiki
Make a turtle unable to walk into a red cell
ask turtles [
right random 360
forward 1
if pcolor-of patch-here = red [
right 180
forward 1
]
]
So, how does this work? Every time a turtle moves onto a red patch, it immediately turns around and exits it. You can use this to make turtles actually avoid impassable cells. If at least one neighbor is red, make current cell red
ask patches [if any neighbors with [pcolor = red] [set next_pcolor red]] ask patches [set pcolor next_pcolor]If exactly three neighbors are red, make current cell red
ask patches [if (count neighbors with [pcolor = red] = 3) [set next_pcolor red]] ask patches [set pcolor next_pcolor]Why do you have to use the user-defined patches-own variable next_color, instead of just setting pcolor to red? It's because you don't want the patches actually to change color until all the other cells have made their decisions whether to change color. You want each cell to make its decision before the whole simulation moves to the next time step. If you have some cells changing pcolor early, then its neighbor cells will make their decisions on the basis of that cell's next-time-step state. You'd be mixing time steps. Try it both ways. Try having cells choose their next color and update pcolor right away, and then try having them update some other variable, maybe called next-_pcolor, and then setting pcolor to the value of next_pcolor all at once in a later command. You should notice very different behavior.
Randomized space
ask patches [ifelse (random 100) < (red-probability * 100) [set pcolor red][set pcolor black]]
Interesting spaces
Graph-paper:
ask patches [ifelse (pxcor mod 2 = 0 and pycor mod 2 = 0) [set pcolor red][set pcolor black]]Checkerboard:
ask patches [ifelse ((screen-edge-x + pxcor) mod 2 = (screen-edge-y + pycor) mod 2) [set pcolor red][set pcolor black]]Anisotropic graph-paper:
ask patches [ifelse (pycor mod 2 = 0 or pxcor mod 10 = 0) [set pcolor red][set pcolor black]]
