'Is it possible to change patch color for a range of patches?
Is it possible to change a range of patches color in the code tab? Instead of setting each individual coordinate. This would be done as part of initial model setup. I am essentially trying to "draw" a map for a battle simulation with patch colors. Below is the code I have but its obviously slow going. If i could use a range of coordinates it would be way faster
ask patches at-points[[-16 -16] [-15 -16] [-14 -16] [-13 -16] [-12 -16] [-11 -16] [-10 -16] [-9 -16] [-8 -16] [-7 -16] [-6 -16]] [ set pcolor brown ]
Solution 1:[1]
You can definitely address patches within a range of coordinates values, by using with and remembering that pxcor and pycor are nothing more than patch variables for which each patch holds specific values:
to setup
clear-all
ask patches with [pycor = -16 AND pxcor < -5] [
set pcolor brown
]
end
The code above does the exact same thing as your example.
If instead you have a situation in which there is no particular pattern to follow, but you still want some very specific patches to change color, I am afraid that you will have to hard code it. Doing it with at-points is a way to do it, and I don't think it is particularly inefficient.
Maybe creating an agentset of patches (i.e. a patch-set) and then asking them to change color would be faster? I don't know, you can find it out using the Profiler extension if you want.
If instead for some reason you don't want to have those lines of code in your model, an option would be to create your initial environment once and then use export-world to export it as a file that can be read at later moments using import-world.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
