如何在世界中设置规则的海龟格子
How to set a regular lattice of turtles in the world
我想设置一个规则的海龟网格。在下面的示例中,我已经在 x 维度上等距分布了 reader 个代理,但是我无法设置每行的最大代理数并将 reader 的以下行放在世界.
breed [readers reader]
globals [ reader-ycor ]
to setup
clear-all
setup-globals
setup-readers
end
to setup-globals
set-default-shape readers "square 2"
set reader-ycor (min-pycor + 1)
end
to setup-readers
let horizontal-interval (world-width / number-of-readers)
create-readers number-of-readers [
set color green
setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who)) reader-ycor
set size 3
set label ""
]
end
to go
setup
end
全局number-of-readers
表示readers
的总数,max-number-per-row
是一个变量设置为10(每行最大reader个数) .
我不知道如何告诉 x 坐标在一行有 10 readers 时停止,以及如何告诉 Netlogo 在 [=] 时添加新的一行 readers reader 的 14=] 大于 10.
此致
我认为与其使用 who
数字(不推荐),不如手动计算坐标,然后根据计算值生成海龟。使用此设置:
breed [ readers reader ]
to setup
ca
spawn-by-row
reset-ticks
end
每行读者和读者数量的这些滑块:
此代码将从最低的 x/y 值构建阅读器(评论中的详细信息):
to spawn-by-row
; get the intervals
let h-int world-width / readers-per-row
let v-int world-height / readers-per-row
; Get a range of horizontal and vertical coordinates, starting at half
; of the interval value from the minimum x coordinate
let h-vals ( range ( min-pxcor + h-int / 2 ) max-pxcor h-int )
let v-vals ( range ( min-pycor + v-int / 2 ) max-pycor v-int )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach v-vals [
v ->
set possible-coords ( sentence possible-coords map [ i -> (list i v) ] h-vals )
]
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let use-coords sublist possible-coords 0 number-of-readers
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "square 2"
]
]
end
如果 number-of-readers
多于 readers-per-row
所能容纳的数量,您将抛出一个错误,但这很容易修复。
编辑 2:
在上面的界面中添加distance-var
的滑块,试试这个spawn-by-row
的修改版本
to spawn-by-row
; Get a range of coordinate values
let half-step 0.5 * distance-var
let d-vals ( range ( min-pxcor + half-step ) ( max-pxcor ) distance-var )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach d-vals [
d ->
set possible-coords ( sentence possible-coords map [ i -> (list i d) ] d-vals )
]
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let max-positions length possible-coords
if max-positions > number-of-readers [ set max-positions number-of-readers ]
let use-coords sublist possible-coords 0 max-positions
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "dot"
set color white
]
]
end
我已经找到了解决方案,但使用了可避免的 who
数字。
breed [readers reader]
undirected-link-breed [ rris rri ]
globals [ reader-ycor ]
to setup
clear-all
ask patches [ set pcolor blue - 3 ]
setup-globals
setup-readers
end
to setup-globals
set-default-shape readers "square 2"
set separation-distance-ratio 10 ; should be > 10
set number-of-readers 24
set interf-rri-radius 110
end
to setup-readers
let horizontal-interval (world-width / separation-distance-ratio )
let vertical-interval (world-height / separation-distance-ratio )
create-readers number-of-readers [
setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who mod 10 ))
(min-pycor - 0.5 + vertical-interval * (0.5 + floor (who / 10) ) )
set size 2.5
set color green
]
ask readers [ create-rris-with other readers in-radius interf-rri-radius ]
end
to go
setup
end
我想设置一个规则的海龟网格。在下面的示例中,我已经在 x 维度上等距分布了 reader 个代理,但是我无法设置每行的最大代理数并将 reader 的以下行放在世界.
breed [readers reader]
globals [ reader-ycor ]
to setup
clear-all
setup-globals
setup-readers
end
to setup-globals
set-default-shape readers "square 2"
set reader-ycor (min-pycor + 1)
end
to setup-readers
let horizontal-interval (world-width / number-of-readers)
create-readers number-of-readers [
set color green
setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who)) reader-ycor
set size 3
set label ""
]
end
to go
setup
end
全局number-of-readers
表示readers
的总数,max-number-per-row
是一个变量设置为10(每行最大reader个数) .
我不知道如何告诉 x 坐标在一行有 10 readers 时停止,以及如何告诉 Netlogo 在 [=] 时添加新的一行 readers reader 的 14=] 大于 10.
此致
我认为与其使用 who
数字(不推荐),不如手动计算坐标,然后根据计算值生成海龟。使用此设置:
breed [ readers reader ]
to setup
ca
spawn-by-row
reset-ticks
end
每行读者和读者数量的这些滑块:
此代码将从最低的 x/y 值构建阅读器(评论中的详细信息):
to spawn-by-row
; get the intervals
let h-int world-width / readers-per-row
let v-int world-height / readers-per-row
; Get a range of horizontal and vertical coordinates, starting at half
; of the interval value from the minimum x coordinate
let h-vals ( range ( min-pxcor + h-int / 2 ) max-pxcor h-int )
let v-vals ( range ( min-pycor + v-int / 2 ) max-pycor v-int )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach v-vals [
v ->
set possible-coords ( sentence possible-coords map [ i -> (list i v) ] h-vals )
]
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let use-coords sublist possible-coords 0 number-of-readers
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "square 2"
]
]
end
如果 number-of-readers
多于 readers-per-row
所能容纳的数量,您将抛出一个错误,但这很容易修复。
编辑 2:
在上面的界面中添加distance-var
的滑块,试试这个spawn-by-row
to spawn-by-row
; Get a range of coordinate values
let half-step 0.5 * distance-var
let d-vals ( range ( min-pxcor + half-step ) ( max-pxcor ) distance-var )
; Create an empty list to build into
let possible-coords []
; For each possible vertical value, map all horizontal values in order and
; combine these into an ordered list starting at the lowest px and py coords
foreach d-vals [
d ->
set possible-coords ( sentence possible-coords map [ i -> (list i d) ] d-vals )
]
; Use the number of readers to sublist the possible coordinates, and
; create a turtle at each of the coordinate combinations left.
let max-positions length possible-coords
if max-positions > number-of-readers [ set max-positions number-of-readers ]
let use-coords sublist possible-coords 0 max-positions
foreach use-coords [
coords ->
create-readers 1 [
setxy item 0 coords item 1 coords
set shape "dot"
set color white
]
]
end
我已经找到了解决方案,但使用了可避免的 who
数字。
breed [readers reader]
undirected-link-breed [ rris rri ]
globals [ reader-ycor ]
to setup
clear-all
ask patches [ set pcolor blue - 3 ]
setup-globals
setup-readers
end
to setup-globals
set-default-shape readers "square 2"
set separation-distance-ratio 10 ; should be > 10
set number-of-readers 24
set interf-rri-radius 110
end
to setup-readers
let horizontal-interval (world-width / separation-distance-ratio )
let vertical-interval (world-height / separation-distance-ratio )
create-readers number-of-readers [
setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who mod 10 ))
(min-pycor - 0.5 + vertical-interval * (0.5 + floor (who / 10) ) )
set size 2.5
set color green
]
ask readers [ create-rris-with other readers in-radius interf-rri-radius ]
end
to go
setup
end