本文介绍了如何从正方形区域控制网格中的正方形大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Netlogo的新手.我使用了交通网格"的代码来绘制正方形网格.从此代码中,如何从正方形区域(例如,一个正方形= 100km²)而不是水平和垂直道路编号控制网格中的正方形大小?在我的Netlogo世界中,一个补丁= 10km².

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

推荐答案

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

这篇关于如何从正方形区域控制网格中的正方形大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 23:59