谁能给出一些提示(或完整的解决方案!)如何将模型库代码示例“鼠标拖动多个示例”转换为非包装世界。我的尝试破坏了选择矩形(矩形的边在边缘堆积 - 因为每个部分都是单独处理的)。同样,选定的海龟只是堆积在边缘。谢谢你。
Here's the main procedure from the model - it gives a runtime error on the second setxy when the side of the selection rectangle gets to the edge of the non-wrapping world:
to handle-drag
;; remember where the mouse pointer was located when
;; the user pressed the mouse button
let old-x mouse-xcor
let old-y mouse-ycor
if selected? old-x old-y [ ;; selected? is a reporter defined below
while [mouse-down?] [
let new-x mouse-xcor
let new-y mouse-ycor
;; we need to move both the selected turtles and the sides
;; of the selection rectangle by the same amount that the
;; mouse has moved. we do this by subtracting the current
;; mouse coordinates from the previous mouse coordinates
;; and adding the results to the coordinates of the turtles
;; and sides.
ask selected
[ setxy xcor + new-x - old-x
ycor + new-y - old-y ]
ask sides
[ setxy xcor + new-x - old-x
ycor + new-y - old-y ]
set old-x new-x
set old-y new-y
;; update the view, otherwise the user can't see
;; what's going on
display
]
]
end