1

モデルライブラリのコード例「Mouse Drag Multiple Example」をラップされていない世界に変換する方法について、誰かがヒント(または完全な解決策!)を与えることができますか?私の試みは選択長方形を破壊します(長方形の側面が端に積み重なっています - 各部分が別々に扱われるためです)。同様に、選択されたタートルは端に積み上げられます。ありがとうございました。

モデルの主な手順は次のとおりです。選択長方形の辺がラップされていないワールドの端に到達すると、2 番目の setxy で実行時エラーが発生します。

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
4

1 に答える 1