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 [ 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 ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML) ; The project gratefully acknowledges the support of the National Science ; Foundation (Applications of Advanced Technologies Program) -- grant numbers ; RED #9552950 and REC #9632612. ; ; Converted from StarLogoT to NetLogo, 2001 ; Copyright 1999 by Uri Wilensky. All rights reserved. ; ; Permission to use, copy, or modify this software and its documentation for ; educational and research purposes only and without fee is hereby granted, ; provided that this copyright notice and the original authors' names appear ; on all copies and supporting documentation. For any other uses of this ; software, in original or modified form, including but not limited to ; distribution in whole or in part, specific prior permission must be ; obtained from Uri Wilensky. These programs shall not be used, rewritten, or ; adapted as the basis of a commercial software or hardware product without ; first obtaining appropriate licenses from Uri Wilensky. We make no ; representations about the suitability of this software for any purpose. It ; is provided "as is" without express or implied warranty. @#$#@#$#@ GRAPHICS-WINDOW 288 10 612 334 40 40 4.0 0 10 0 0 CC-WINDOW 288 335 612 472 Command Center MONITOR 138 233 226 282 NIL mouse-ycor 3 1 MONITOR 49 233 137 282 NIL mouse-xcor 3 1 MONITOR 83 183 188 232 NIL mouse-down? 3 1 BUTTON 150 10 258 43 NIL turtle-draw T 1 T OBSERVER TEXTBOX 40 52 265 131 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 10 145 43 NIL patch-draw T 1 T OBSERVER BUTTON 87 136 185 169 NIL clear-patches NIL 1 T OBSERVER @#$#@#$#@ 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 a 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 1.1pre1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@