Mouse Recording Example
Model was written in NetLogo 5.0.4
•
Viewed 283 times
•
Downloaded 57 times
•
Run 0 times
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.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Mouse Recording Example.png | preview | Preview for 'Mouse Recording Example' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.