Mouse Recording Example

Mouse Recording 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 197 times • Downloaded 21 times • Run 0 times
Download the 'Mouse Recording 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

turtles-own [ path ]    ;; a list of two-element lists (x and y coordinates)

breed [drawers drawer]  ;; turtles that record the path of the mouse
breed [tracers tracer]  ;; turtles that trace the recorded path

to setup
  clear-all
  reset-ticks
end 

to go
  ifelse mouse-down?
    [ if not any? drawers                 ;; creates a new drawer at the beginning of a stroke
        [ create-drawers 1 [ initialize-drawers ] ]
      ask drawers [ follow-mouse ] ]      ;; updates paths of drawers as long as the mouse button is down
    [ ask drawers [ become-tracer ] ]     ;; completes the stroke and turns drawers into tracers
  ask tracers [ follow-path ]             ;; updates the tracers regardless of mouse state
  tick
end 

;; Breed Initializers

to initialize-drawers
  set size 14
  set pen-size 3
  set xcor mouse-xcor
  set ycor mouse-ycor
  set path []
  pen-down
  ;; cycle colors, just to be more aesthetically pleasing
  set color item (who mod 4) [red green blue yellow]
end 

to become-tracer
  set breed tracers
  set color color + 2.5
  pen-up
  if length path > 1    ;; makes the path into a full loop, including the first and last points only once
     [ set path sentence path (reverse but-first but-last path) ]
end 

;; Mouse Recording and Retracing Procedures

;; a procedure to track and record the movement of the mouse

to follow-mouse
  let x mouse-xcor                    ;; gets the current mouse coordinates
  let y mouse-ycor
  facexy x y
  setxy x y
  set path fput (list x y) path       ;; adds the coordinate pair (x,y) to the front of the path
end 

;; a procedure to iterate through the recorded path

to follow-path
  let x (first first path)             ;; extracts the first coordinate pair from the path then extracts
  let y (first but-first first path)   ;; the first member as the x coord and the second as the y coord
  facexy x y
  setxy x y
  set path but-first path               ;; removes the current coordinate pair from the beginning of the path
  set path lput (list x y) path         ;; adds the coordinate pair back onto the end of the list
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 Recording Example Download this version
Uri Wilensky over 12 years ago Mouse Recording Example Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.