Reputation: 21
I am trying to set up patches in Netlogo where I randomly assign a few (4 as of now in my code) to be a set high quality value of 9 (quality is a patches-own variable I created). I have coded this part correctly.
Next, I want to create code so that all the other patches are assigned a quality value that decreases with distance from the high quality patches I already assigned (which I have given the value of 9 currently). I essentially am trying to create mountains (high quality patches) and valleys (lowest quality patches) of patch quality in my netlogo world. So that patch quality changes on a gradient scale. I cannot figure out this part though. Is it even possible? Can anyone provide some helpful code to make this work?
I have added in a green scale color associated with patch quality so that I will visually be able to see the gradient of patch quality. I thought using an "ifelse" code would be a good way to go about this all, but I am unable to finish the code needed if the patch quality value isn't one of the 4 patches already assigned to be 9:
to setup-patches
resize-world (number-of-patches * -1)number-of-patches (number-of-patches * -1)number-of-patches
ask n-of 4 patches
[ set quality 9
set pcolor scale-color green quality 1 10
ask patches
[ ifelse quality = 9
[ set quality 9
set pcolor scale-color green quality 1 10 ]
[ set quality 9 - distance ;;This is the part I have no idea what to code to achieve my goal. I want it to code distance from the patches that are set at a quality of 9, but I don't know how to do that
set pcolor scale-color green quality 1 10]]
Upvotes: 2
Views: 177
Reputation: 17678
Your idea of distances will work, you just need min-one-of
to look around for the closest patch with quality of 9. Try this:
to setup-patches
ask n-of 4 patches [ set quality 9 ]
ask patches with [quality != 9]
[ let closest min-one-of patches with [quality = 9] [distance myself]
set quality 9 - distance closest
if quality < 1 [ set quality 1]
]
ask patches [set pcolor scale-color green quality 12 0]
end
Another way to do this is with the diffuse
primitive, repeated a few times.
Upvotes: 2