Wall Following Example
Model was written in NetLogo 5.0.4
•
Viewed 239 times
•
Downloaded 36 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 [direction] ;; 1 follows right-hand wall, ;; -1 follows left-hand wall to setup clear-all ;; make some random walls for the turtles to follow. ;; the details aren't important. ask patches [ if random-float 1.0 < 0.04 [ set pcolor brown ] ] ask patches with [pcolor = brown] [ ask patches in-radius random-float 3 [ set pcolor brown ] ] ask patches with [count neighbors4 with [pcolor = brown] = 4] [ set pcolor brown ] ;; now make some turtles. SPROUT puts ;; the turtles on patch centers ask n-of 40 patches with [pcolor = black] [ sprout 1 [ if count neighbors4 with [pcolor = brown] = 4 [ die ] ;; trapped! set size 2 ;; bigger turtles are easier to see set pen-size 2 ;; thicker lines are easier to see face one-of neighbors4 ;; face north, south, east, or west ifelse random 2 = 0 [ set direction 1 ;; follow right hand wall set color blue ] [ set direction -1 ;; follow left hand wall set color green ] ] ] reset-ticks end to go ask turtles [ walk ] tick end to walk ;; turtle procedure ;; turn right if necessary if not wall? (90 * direction) and wall? (135 * direction) [ rt 90 * direction ] ;; turn left if necessary (sometimes more than once) while [wall? 0] [ lt 90 * direction ] ;; move forward fd 1 end to-report wall? [angle] ;; turtle procedure ;; note that angle may be positive or negative. if angle is ;; positive, the turtle looks right. if angle is negative, ;; the turtle looks left. report brown = [pcolor] of patch-right-and-ahead angle 1 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 | |
---|---|---|---|---|
Wall Following Example.png | preview | Preview for 'Wall Following Example' | over 11 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.