How to control square size in a grid from square area?

我只是一个虾纸丫 提交于 2020-01-14 14:22:29

问题


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

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