问题
I would like to add forest patches in a landscape. To be more precise, the idea is to add patch clusters like "Patch Clusters" example. Contrary to this example, I want to randomly distribute some patch clusters with the same color and not several clusters that fill entirely the landscape. This is a beginning of code :
to create-forests
repeat 30 [
ask one-of patches [
set pcolor green
ask neighbors [ set pcolor green] ] ]
end
With this code, the clusters look like squares and not clusters like "Patch Clusters" example. How can I add forest patch clusters in my landscape ?
Thank you for your help Have a good day Marine
回答1:
How about something like:
to create-forests
ask n-of 10 patches [ set pcolor green ]
repeat 6 [
ask patches with [pcolor = green] [
ask one-of neighbors4 [ set pcolor green ]
]
]
end
The results look like:

回答2:
A fast solution could be using patch-at-heading-and-distance function.
to create-forests
ask patches[set pcolor black]
repeat 5
[
ask one-of patches
[
set pcolor green
repeat 20
[
let a random 360
let b random 2
ask patch-at-heading-and-distance a b
[
ask neighbors4 [ set pcolor green]
set pcolor green
]
]
]
]
end
With this function you can move to another patch neighbor. Playing with the range of the random values of a (angle), b (distance) and the number of times that is repeated this part of code, can be achieved different forest densities.
With neighbors 4 we try to fill possible black patches inside the forest, (Note that the success of this trick will depend of the forest size)
A more sophisticated option could be:
to create-forests2
ask patches[set pcolor black]
repeat 5
[
ask one-of patches
[
let size_f (random 2) + 1
let border 2
let big_area [list pxcor pycor] of patches with [abs pxcor <= size_f + border and abs pycor <= size_f + border]
let forested [list pxcor pycor] of patches with [abs pxcor <= size_f + random border and abs pycor <= size_f + random border]
ask patches at-points forested[set pcolor green]
ask patches at-points big_area with[pcolor != green]
[ if count(neighbors with [pcolor = green]) > 6 [ set pcolor green ] ]
]
]
end
With the help of a list are identified the patches surrounded in 6/8 of forest, thus are converted to forest also
来源:https://stackoverflow.com/questions/19326781/adding-patch-clusters-in-a-landscape