Mouse Example
      Model was written in NetLogo 5.0.4 
      • 
      Viewed 604 times
      • 
      Downloaded 161 times
      • 
      Run 0 times
    
    
    
      Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
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.
Comments and Questions
  Please start the discussion about this model!
  (You'll first need to log in.)
      
    Click to Run Model
  
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" ;; automatically rounds to the nearest patch ask patch 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 mouse-xcor mouse-ycor [ sprout 1 [ pen-down set pen-size 2 ] ] ] ;; 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 [ facexy 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 ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 10 versions of this model.
Attached files
| File | Type | Description | Last updated | |
|---|---|---|---|---|
| Mouse Example.png | preview | Preview for 'Mouse Example' | over 12 years ago, by Uri Wilensky | Download | 
This model does not have any ancestors.
This model does not have any descendants.
 
  Download this model
Download this model