为代理商制造瓶颈障碍
Creating a bottleneck obstacle for agents
我正在尝试创建一个补丁,它将成为海龟必须经过的路径中间的瓶颈结构。
我已经创建了抛物线,但我想添加一个滑块以便可以更改瓶颈的大小,但我不知道如何创建将移动它的代码。
这是代码(我对抛物线的数学很糟糕,所以我得到了上面那个的帮助,我只是手动创建了下面那个)
to setup-road
;; patch procedure
;; colour patches to paint a horizontal road
let bound (max-pycor / 3)
ifelse (pycor < (max-pycor - bound)) and (pycor > (min-pycor + bound))
[ set pcolor red - 3 ]
[ set pcolor green ]
set upper-road-bound (max-pycor - bound - 2 )
set lower-road-bound (min-pycor + bound + 2 )
setup-top-parabola-on-road
setup-down-parabola-on-road
end
;; I want to be able to expand the parabolas so that the opening between them will be wider as well as narrow according a slider.
to setup-top-parabola-on-road
ask patches with
[pxcor > -25 and pxcor < 25] [
if pycor > ((pxcor ^ 2) / 20 + 10)
[ set pcolor green ]
]
end
to setup-down-parabola-on-road
ask patches with [pxcor >= -4 and pxcor <= 4 and pycor = -11][set pcolor green]
ask patches with [pxcor >= -5 and pxcor <= 5 and pycor = -12][set pcolor green]
ask patches with [pxcor >= -6 and pxcor <= 6 and pycor = -13][set pcolor green]
ask patches with [pxcor >= -7 and pxcor <= 7 and pycor = -14][set pcolor green]
ask patches with [pxcor >= -8 and pxcor <= 8 and pycor = -15][set pcolor green]
ask patches with [pxcor >= -9 and pxcor <= 9 and pycor = -16][set pcolor green]
ask patches with [pxcor >= -10 and pxcor <= 10 and pycor = -17][set pcolor green]
ask patches with [pxcor >= -11 and pxcor <= 11 and pycor = -18][set pcolor green]
ask patches with [pxcor >= -12 and pxcor <= 12 and pycor = -19][set pcolor green]
ask patches with [pxcor >= -13 and pxcor <= 13 and pycor = -20][set pcolor green]
ask patches with [pxcor >= -14 and pxcor <= 14 and pycor = -21][set pcolor green]
ask patches with [pxcor >= -15 and pxcor <= 15 and pycor = -22][set pcolor green]
ask patches with [pxcor >= -16 and pxcor <= 16 and pycor = -23][set pcolor green]
ask patches with [pxcor >= -17 and pxcor <= 17 and pycor = -24][set pcolor green]
ask patches with [pxcor >= -18 and pxcor <= 18 and pycor = -25][set pcolor green]
end
有人能帮忙吗?
给你。
这假设您有一个名为设置的按钮
和一个范围从 0 到 11 的可变“宽度”滑块。
我在您设置红色和绿色的顶部附近添加了一个“询问补丁 []”。
to setup
clear-all
setup-road
reset-ticks
end
to setup-road
;; patch procedure
;; colour patches to paint a horizontal road
let bound (max-pycor / 3)
ask patches [
ifelse (pycor < (max-pycor - bound)) and (pycor > (min-pycor + bound))
[ set pcolor red - 3 ]
[ set pcolor green ]
]
let upper-road-bound (max-pycor - bound - 2 )
let lower-road-bound (min-pycor + bound + 2 )
setup-top-parabola-on-road
setup-down-parabola-on-road
end
;; I want to be able to expand the parabolas so that the opening between them will be wider as well as narrow according a slider.
to setup-top-parabola-on-road
ask patches with
[pxcor > -25 and pxcor < 25] [
if pycor > ((pxcor ^ 2) / 20 + width)
[ set pcolor blue ]
]
end
to setup-down-parabola-on-road
ask patches with
[pxcor > -25 and pxcor < 25] [
if pycor < (-1 * (pxcor ^ 2) / 20) - width + 1
[ set pcolor yellow ]
]
end
我正在尝试创建一个补丁,它将成为海龟必须经过的路径中间的瓶颈结构。
我已经创建了抛物线,但我想添加一个滑块以便可以更改瓶颈的大小,但我不知道如何创建将移动它的代码。
这是代码(我对抛物线的数学很糟糕,所以我得到了上面那个的帮助,我只是手动创建了下面那个)
to setup-road
;; patch procedure
;; colour patches to paint a horizontal road
let bound (max-pycor / 3)
ifelse (pycor < (max-pycor - bound)) and (pycor > (min-pycor + bound))
[ set pcolor red - 3 ]
[ set pcolor green ]
set upper-road-bound (max-pycor - bound - 2 )
set lower-road-bound (min-pycor + bound + 2 )
setup-top-parabola-on-road
setup-down-parabola-on-road
end
;; I want to be able to expand the parabolas so that the opening between them will be wider as well as narrow according a slider.
to setup-top-parabola-on-road
ask patches with
[pxcor > -25 and pxcor < 25] [
if pycor > ((pxcor ^ 2) / 20 + 10)
[ set pcolor green ]
]
end
to setup-down-parabola-on-road
ask patches with [pxcor >= -4 and pxcor <= 4 and pycor = -11][set pcolor green]
ask patches with [pxcor >= -5 and pxcor <= 5 and pycor = -12][set pcolor green]
ask patches with [pxcor >= -6 and pxcor <= 6 and pycor = -13][set pcolor green]
ask patches with [pxcor >= -7 and pxcor <= 7 and pycor = -14][set pcolor green]
ask patches with [pxcor >= -8 and pxcor <= 8 and pycor = -15][set pcolor green]
ask patches with [pxcor >= -9 and pxcor <= 9 and pycor = -16][set pcolor green]
ask patches with [pxcor >= -10 and pxcor <= 10 and pycor = -17][set pcolor green]
ask patches with [pxcor >= -11 and pxcor <= 11 and pycor = -18][set pcolor green]
ask patches with [pxcor >= -12 and pxcor <= 12 and pycor = -19][set pcolor green]
ask patches with [pxcor >= -13 and pxcor <= 13 and pycor = -20][set pcolor green]
ask patches with [pxcor >= -14 and pxcor <= 14 and pycor = -21][set pcolor green]
ask patches with [pxcor >= -15 and pxcor <= 15 and pycor = -22][set pcolor green]
ask patches with [pxcor >= -16 and pxcor <= 16 and pycor = -23][set pcolor green]
ask patches with [pxcor >= -17 and pxcor <= 17 and pycor = -24][set pcolor green]
ask patches with [pxcor >= -18 and pxcor <= 18 and pycor = -25][set pcolor green]
end
有人能帮忙吗?
给你。 这假设您有一个名为设置的按钮 和一个范围从 0 到 11 的可变“宽度”滑块。
我在您设置红色和绿色的顶部附近添加了一个“询问补丁 []”。
to setup
clear-all
setup-road
reset-ticks
end
to setup-road
;; patch procedure
;; colour patches to paint a horizontal road
let bound (max-pycor / 3)
ask patches [
ifelse (pycor < (max-pycor - bound)) and (pycor > (min-pycor + bound))
[ set pcolor red - 3 ]
[ set pcolor green ]
]
let upper-road-bound (max-pycor - bound - 2 )
let lower-road-bound (min-pycor + bound + 2 )
setup-top-parabola-on-road
setup-down-parabola-on-road
end
;; I want to be able to expand the parabolas so that the opening between them will be wider as well as narrow according a slider.
to setup-top-parabola-on-road
ask patches with
[pxcor > -25 and pxcor < 25] [
if pycor > ((pxcor ^ 2) / 20 + width)
[ set pcolor blue ]
]
end
to setup-down-parabola-on-road
ask patches with
[pxcor > -25 and pxcor < 25] [
if pycor < (-1 * (pxcor ^ 2) / 20) - width + 1
[ set pcolor yellow ]
]
end