【发布时间】:2015-08-27 17:56:43
【问题描述】:
我有一个非常具体的问题: 我想制作一个由 3 个滑块定义的网格景观:
- radius - 通过半径值定义聚集块(黄色)的大小
- 网格 - 簇之间的距离
- %_weak - 我希望景观中有多少块黄色的补丁??
我想以交互方式使用所有这 3 个参数。但是,在距离、网格和 %_weak 的某些组合中,我没有获得与滑块 %_weak 定义的相同的 count patches with [pcolor = yellow]。
请问,我怎样才能在不扩大世界大小的情况下保留所有滑块?我不希望将我的世界的维度扩展到超过 601x601。
我的模型在这里可用:http://ulozto.cz/xdSN2ikr/turtles-in-grid3-nlogo,或代码在这里:
globals [
cells-in-cluster ; # of patches in 1 cluster
clusters_number ; # total number of clusters over world
]
to setup
clear-all
setup-patches
end
to setup-patches
ask patches [set pcolor black]
; calculate # of patches in 1 cluster, to calculate how many clusters do I need
ask patch 0 0 [
set pcolor green
ask patches in-radius radius
[set pcolor green]
set cells-in-cluster count patches with [ pcolor = green ]
; calculate # of clusters
set clusters_number round ((world-width * world-height / 100 * %_weak) / cells-in-cluster)
ask patches with [pcolor = green] [set pcolor black] ]
; create grid over world - depends on radius value and clusters-number value
crt 1 [
let $n 0 ; actual number ofturtles on this patch
let $s 0 ; current number of turtles on a side of square pattern - 1
set heading 0
ask patch-here [set pcolor red]
repeat clusters_number ; number of needed turtles
[
hatch 1 jump Grid ; make one turtle and move
set $n $n + 1 ; increment count of curent side
ask patch-here [set pcolor red]
if $n > $s ; if side finished...
[
right 90 set $n 0 ; turn and reset count
ask patch-here [set pcolor red]
if heading mod 180 = 0 [
set $s $s + 1 ; if headed up or down, increment side count
]
]
]
die
]
ask turtles [die] ; ask all turtles to die
; create halo effect around "clusters-numbers" patches with radius value
ask patches with [pcolor = red]
[
ask patches
in-radius radius
[ set pcolor yellow
]
]
end
【问题讨论】:
-
看来你的问题是stackoverflow.com/questions/30345438/…的一个版本
标签: netlogo