Generate rivers with random size and location

て烟熏妆下的殇ゞ 提交于 2020-04-18 05:44:31

问题


I'm working on a smaller project and have one issue I can't find figure out any solutions for.

I want to randomly generate rivers. My plan is to randomly generate a number of rivers with varying sizes and locations. Does anyone know how to generate rivers randomly?

I have tried several things. I did manage to generate this, but I want it to be more like rivers (straight lines) and less 'clustered'.

I used the following code to get the picture above.

; Generating random rivers.
ca
ask patches with [pycor = (random 16) or pxcor = (random 16)]
[
  set pcolor brown
  ask patches in-radius random 3 [set pcolor brown]
]

Thanks for taking your time!

_______________________________________________________________________________

EDIT:

I made some progress, it looks like this. This is the closest I've managed to get to what I want.

to setup   
 ca 
ask n-of 2 patches [
      spread-right
    ]
    ask n-of 2 patches[
      spread-left
    ]
    ask n-of 2 patches[
      spread-down
    ]
    ask n-of 2 patches[
      spread-up
    ]   
end 

to spread-right
   if pxcor < max-pxcor [
    ask n-of 1 neighbors with [ pxcor = [pxcor] of myself + 1] [
      set pcolor brown
      spread-right
    ]
  ]
end
to spread-left   
  if pxcor > min-pxcor [
    ask n-of 1 neighbors with [ pxcor = [pxcor] of myself - 1] [
      set pcolor brown
      spread-left
    ]
  ]
end

to spread-down 
  if pycor > min-pycor [
    ask n-of 1 neighbors with [pycor = [pycor] of myself - 1][
      set pcolor brown
      spread-down
    ]
  ]
end 

to spread-up 
  if pycor > max-pycor [
    ask n-of 1 neighbors with [pycor = [pycor] of myself + 1][
      set pcolor brown
      spread-up
    ]
  ]
end

回答1:


you could simply use a (semi-)random-walk turtle to walk around and color the patches it walks on. Then use your spread-out code to make it thicker in some places.




回答2:


Thanks to @Jumboman suggestion I solved it with this code. Depending on the size of the world and prefered size of the features, it is possible to change the set numbers.

to setup
  ca 
  ;Generating physical features.    
  ask n-of 5 patches[ sprout 1[
    set pcolor brown]
  ]

  let i 0
  while [ i < (max-pycor )][
    ask turtles [
      fd 1
      set pcolor black
      ifelse (random 20 <= 1)
      [
        rt one-of [-90 0 90]      
        forward 1
      ]
            [
        fd 1
        set pcolor brown
        fd 1
        set pcolor brown
      ]
      set pcolor brown
      set i i + 1]
  ]


  ask n-of max-pxcor patches with [pcolor = brown][
    ask patches in-radius 1 with [pcolor = black][
      set pcolor brown]
  ]

  ask turtles [die]
end 


来源:https://stackoverflow.com/questions/60598499/generate-rivers-with-random-size-and-location

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