问题
I am new to Netlogo. I used the code of "Traffic grid" to draw square grid. From this code, how can I control square size in the grid from square area (e.g. one square = 100km²) instead of horizontal and vertical road number ? In my Netlogo world, one patch = 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
Thanks in advance for your help. Pierre
回答1:
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
来源:https://stackoverflow.com/questions/22107677/how-to-control-square-size-in-a-grid-from-square-area