Netlogo 将世界分为上层和下层
Netlogo divide world into upper and lower
大家下午好:
目前我正在 Netlogo 中的一个程序中工作,我想将世界划分为上象限和下象限,并让海龟移动到上象限。我已经从这里回答的上一个问题中找出如何将世界划分为四个象限,但我不知道如何将其划分为两个。
非常感谢您的帮助
ask patches with [ pxcor <= max-pxcor and pxcor > 0 and pycor > 0]
[
set pcolor red
set quadrant 1
]
ask patches with [ pxcor >= min-pxcor and pxcor < 0 and pycor > 0]
[
set pcolor blue
set quadrant 2
]
ask patches with [ pxcor <= max-pxcor and pxcor > 0 and pycor < 0]
[
set pcolor green
set quadrant 3
]
ask patches with [ pxcor >= min-pxcor and pxcor < 0 and pycor < 0]
[
set pcolor yellow
set quadrant 4
]
鉴于您对下象限和上象限感兴趣,您只需要查看 y 坐标。具体情况取决于你的世界原点(即坐标[0;0])在哪里。
如果您的世界原点位于默认位置,即中心,则执行:
patches-own [
quadrant
]
to setup
clear-all
ask patches [
ifelse (pycor > 0)
[set quadrant 1]
[set quadrant 2]
]
end
如果你的世界原点在一个角落里(例如,我假设在这种情况下是左下角),只需这样做:
patches-own [
quadrant
]
to setup
clear-all
ask patches [
ifelse (pycor > max-pycor / 2)
[set quadrant 1]
[set quadrant 2]
]
end
如果您事先不知道您的世界起源在哪里,或者如果您的世界起源与上述两个示例相比不太常见,您可以采用适合任何情况的更通用的方法:
patches-own [
quadrant
]
to setup
clear-all
let y-extent (max-pycor - min-pycor + 1)
ask patches [
ifelse (pycor > y-extent / 2)
[set quadrant 1]
[set quadrant 2]
]
end
大家下午好: 目前我正在 Netlogo 中的一个程序中工作,我想将世界划分为上象限和下象限,并让海龟移动到上象限。我已经从这里回答的上一个问题中找出如何将世界划分为四个象限,但我不知道如何将其划分为两个。
非常感谢您的帮助
ask patches with [ pxcor <= max-pxcor and pxcor > 0 and pycor > 0]
[
set pcolor red
set quadrant 1
]
ask patches with [ pxcor >= min-pxcor and pxcor < 0 and pycor > 0]
[
set pcolor blue
set quadrant 2
]
ask patches with [ pxcor <= max-pxcor and pxcor > 0 and pycor < 0]
[
set pcolor green
set quadrant 3
]
ask patches with [ pxcor >= min-pxcor and pxcor < 0 and pycor < 0]
[
set pcolor yellow
set quadrant 4
]
鉴于您对下象限和上象限感兴趣,您只需要查看 y 坐标。具体情况取决于你的世界原点(即坐标[0;0])在哪里。
如果您的世界原点位于默认位置,即中心,则执行:
patches-own [
quadrant
]
to setup
clear-all
ask patches [
ifelse (pycor > 0)
[set quadrant 1]
[set quadrant 2]
]
end
如果你的世界原点在一个角落里(例如,我假设在这种情况下是左下角),只需这样做:
patches-own [
quadrant
]
to setup
clear-all
ask patches [
ifelse (pycor > max-pycor / 2)
[set quadrant 1]
[set quadrant 2]
]
end
如果您事先不知道您的世界起源在哪里,或者如果您的世界起源与上述两个示例相比不太常见,您可以采用适合任何情况的更通用的方法:
patches-own [
quadrant
]
to setup
clear-all
let y-extent (max-pycor - min-pycor + 1)
ask patches [
ifelse (pycor > y-extent / 2)
[set quadrant 1]
[set quadrant 2]
]
end