Reputation: 21
I'm trying to set pcolor orange for different patches. I want them to be created randomly, but always at a distance of R from each other. In this current code, it creates the patches randomly just fine, but simply removes the orange patch if they are within the radius, resulting in fewer than N orange patches. How can I solve this so that all N patches are created at a distance R instead of just the ones which randomly fall out of radius R of each other?
ask n-of N patches
[
if not any? other patches with [pcolor = orange] in-radius R [
set pcolor orange
]]
Upvotes: 2
Views: 235
Reputation: 971
You are vey close, but asking N
random patches can result in any number of orange patches, maybe one patch will get colored and the other random N-1
patches will be within the radius R
, even if there are lots of patches that still can be colored.
Maybe if you ask all patches you will obtain more consistent results,
ask patches
[
if not any? other patches with [pcolor = orange] in-radius R
and count patches with [pcolor = orange] < N
[
set pcolor orange
]
]
In case that you want all the possible patches colored instead of just N
you can remove (or comment) the whole line and count patches with [pcolor = orange] < N
.
Also note that ask patches
will iterate over the patches randomly, so if you need a reproducible or ordered coloring of the patches this is not the ideal way to do it.
Upvotes: 0