我正在尝试创建一个补丁,这将是海龟必须经过的路径中间的瓶颈结构。
我已经创建了抛物线,但我想添加一个滑块,以便瓶颈的大小可以改变,但我不知道如何创建一个代码来移动它。
下面是代码(我对抛物线的数学很不好,所以我在上面有帮助,我只是手动创建了下面的那个)
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
有人能帮忙吗?
给你。这假定您有一个名为setup的按钮变量"宽度"取值范围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