to patch-draw if mouse-down? ;; reports true or false to indicate whether mouse button is down [ ;; mouse-xcor and mouse-ycor report the position of the mouse -- ;; note that they report the precise position of the mouse, ;; so you might get a decimal number like 12.3, but patch-at ;; automatically rounds to the nearest patch ask patch-at mouse-xcor mouse-ycor [ set pcolor red ] ] end to turtle-draw ifelse mouse-down? [ ;; first make sure there's a turtle (if the user just pressed ;; the mouse button, there won't be yet) if not any? turtles [ ask patch-at mouse-xcor mouse-ycor [ sprout 1 [ pen-down ] ] ] ;; now that we're sure we have a turtle, we ask it to move ;; towards the mouse ask turtles [ if distancexy mouse-xcor mouse-ycor > 0 [ set heading towardsxy mouse-xcor mouse-ycor fd 0.4 ] ] ] ;; 0.4 gives nice smooth lines ;; once the user releases the mouse button, we don't need the ;; turtle anymore [ clear-turtles ] end @#$#@#$#@ GRAPHICS-WINDOW 288 10 622 365 40 40 4.0 0 10 1 1 1 CC-WINDOW 288 367 612 504 Command Center MONITOR 138 265 226 314 NIL mouse-ycor 3 1 MONITOR 49 265 137 314 NIL mouse-xcor 3 1 MONITOR 83 215 188 264 NIL mouse-down? 3 1 BUTTON 150 42 258 75 NIL turtle-draw T 1 T OBSERVER NIL TEXTBOX 40 84 265 163 Press "patch draw" or "turtle draw", then move the mouse over the graphics window, hold down the mouse button, and move the mouse to draw. BUTTON 36 42 145 75 NIL patch-draw T 1 T OBSERVER NIL BUTTON 87 168 185 201 NIL clear-patches NIL 1 T OBSERVER T @#$#@#$#@ WHAT IS IT? ------------ This demo shows how to use the MOUSE-DOWN?, MOUSE-XCOR, and MOUSE-YCOR reporters to make a model that the user can interact with using the mouse. It also demonstrates the difference between using patches and turtles to achieve a desired effect. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 circle-shape true 0 Circle -7566196 true true 10 10 283 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@