gpt4 book ai didi

netlogo - 如何从正方形区域控制网格中的正方形大小?

转载 作者:行者123 更新时间:2023-12-02 16:12:46 25 4
gpt4 key购买 nike

我是 Netlogo 新手。我使用“交通网格”的代码来绘制方形网格。从这段代码中,我如何从正方形面积(例如一平方= 100km²)而不是水平和垂直道路数量来控制网格中的正方形大小?在我的 Netlogo 世界中,一 block = 10 平方公里。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com