问题描述
我正在做一个较小的项目,有一个问题找不到解决方案.
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!
_______________________________________________________________________________
我取得了一些进展,看起来像此.这是我设法达到的最接近的目标.
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
推荐答案
您可以简单地使用(半)随机行走的乌龟四处走动并为其行走的斑块着色.然后使用您的扩展代码在某些地方使其更粗.
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.
这篇关于生成大小和位置随机的河流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!