Line of Sight Example

Line of Sight Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 582 times • Downloaded 95 times • Run 0 times
Download the 'Line of Sight 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

breed [walkers walker]
breed [markers marker]
patches-own [elevation]

to setup
  clear-all
  set-default-shape markers "dot"
  ;; setup the terrain
  ask patches [ set elevation random 10000 ]
  repeat 2 [ diffuse elevation 1 ]
  ask patches [ set pcolor scale-color green elevation 1000 9000 ]

  create-walkers 6 [
    set size 1.5
    setxy random-xcor random-ycor
    set color item who [orange blue magenta violet brown yellow]
    mark-line-of-sight
  ]
  reset-ticks
end 

to go
  ;; get rid of all the old markers
  ask markers [ die ]
  ;; move the walkers
  ask walkers [
    rt random 10
    lt random 10
    fd 1
    mark-line-of-sight
  ]
  tick
end 

to mark-line-of-sight  ;; walker procedure
  let dist 1
  let a1 0
  let c color
  let last-patch patch-here
  ;; iterate through all the patches
  ;; starting at the patch directly ahead
  ;; going through MAXIMUM-VISIBILITY
  while [dist <= maximum-visibility] [
    let p patch-ahead dist
    ;; if we are looking diagonally across
    ;; a patch it is possible we'll get the
    ;; same patch for distance x and x + 1
    ;; but we don't need to check again.
    if p != last-patch [
      ;; find the angle between the turtle's position
      ;; and the top of the patch.
      let a2 atan dist (elevation - [elevation] of p)
      ;; if that angle is less than the angle toward the
      ;; last visible patch there is no direct line from the turtle
      ;; to the patch in question that is not obstructed by another
      ;; patch.
      if a1 < a2
        [ ask p [ sprout-markers 1 [ set color c ] ]
          set a1 a2 ]
      set last-patch p
    ]
    set dist dist + 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.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Line of Sight Example Download this version
Uri Wilensky over 14 years ago Line of Sight Example Download this version

Attached files

File Type Description Last updated
Line of Sight Example.png preview Preview for 'Line of Sight Example' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.