我是Netlogo的新手。我使用了“交通网格”的代码来绘制正方形网格。通过此代码,如何从正方形区域(例如,一个正方形= 100km²)而不是水平和垂直道路号控制网格中的正方形大小?在我的Netlogo世界中,一个补丁= 10km²。
to setup
let grid-x-inc world-width / grid-size-x
let grid-y-inc world-height / grid-size-y
ask patches [ set pcolor brown ]
let roads patches with [( floor( (pxcor + max-pxcor - floor(grid-x-inc - 1) ) mod grid-x-inc ) = 0) or ( floor( (pycor + max-pycor) mod grid-y-inc ) = 0)]
ask roads [ set pcolor white ]
end
在此先感谢您的帮助。
皮埃尔
最佳答案
to setup
clear-all
let block-area 100 ; desired area for a grid block in km²
let patch-area 10 ; area represented by a patch in km²
let num-patches-in-block (block-area / patch-area)
let side round sqrt num-patches-in-block
if side != sqrt num-patches-in-block [
user-message (word
"Can't make blocks of " block-area " km², since their "
"sides would have to be " sqrt num-patches-in-block ". "
"Using sides of " side " instead, which will give "
"you blocks of " (side ^ 2 * patch-area) " km².")
]
; the rest of the code is similar, expect both `grid-x-inc`
; and `grid-y-inc` are replaced by `side`
ask patches [ set pcolor brown ]
let roads patches with [
(pxcor mod (side + 1) = 0 ) or
(pycor mod (side + 1) = 0 )
]
ask roads [ set pcolor white ]
ask patches with [ pcolor = brown ] [
; sprout square turtles inside blocks
; just to make their size easier to see
sprout 1 [ set shape "square" set color brown - 2]
]
end
关于netlogo - 如何从正方形区域控制网格中的正方形大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22107677/