Adding patch clusters in a landscape

落花浮王杯 提交于 2019-11-28 14:17:49

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:

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!