Mouse Example

Mouse Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 352 times • Downloaded 30 times • Run 0 times
Download the 'Mouse Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


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.

Uploaded by When Description Download
Uri Wilensky over 9 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 10 years ago Updated version tag Download this version
Uri Wilensky over 10 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 12 years ago Mouse Example Download this version
Uri Wilensky over 12 years ago Mouse Example Download this version

Attached files

File Type Description Last updated
Mouse Example.png preview Preview for 'Mouse Example' over 9 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.