RADAR
Model was written in NetLogo 6.2.2
•
Viewed 175 times
•
Downloaded 12 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
; add model procedures here globals [ main-antenna ; refers to the turtle acting as the emitter and receiver antenna-x antenna-y ; the x/y coordinates of the antenna antenna-heading ; the heading of the antenna, in terms ; of -180 to +180 degrees. antenna-direction ; the direction of rotation of the antenna main-scope ; refers to the turtles acting as the display scope scope-x scope-y ; holds the x/y coordinates of the display scope scope-radius ; holds the radius of the display scope horizon ; the lowest that a UFO can fly envelope ; the highest that a UFO can fly old-rf-setting ] breed [ waves wave] breed [ reflected-waves reflected-wave ] breed [ antennas an-antenna] breed [ ufos ufo] breed [ scopes scopex] breed [ scope-markers scope-marker] waves-own [ pips ; used to measure the travel of the wave bounced? ; helps the wave remember that is has bounced off something ; used to prevent our simplified waves ; from bouncing multiple times wave-move ] reflected-waves-own [ pips ; used to measure the travel of the wave bounced? ; helps the wave remember that is has bounced off something ; used to prevent our simplified waves ; from bouncing multiple times wave-move ] ufos-own [ goal-x goal-y ; where the ufo is heading speed ; relative speed of the ufo ] scope-markers-own [ pips ] to setup ;; (for this model to work with NetLogo's new plotting features, ;; __clear-all-and-reset-pips should be replaced with clear-all at ;; the beginning of your setup procedure and reset-pips at the end ;; of the procedure.) clear-all set-default-shape waves "wave" set-default-shape antennas "antenna" set-default-shape ufos "ufo" set-default-shape scope-markers "phosphor" antenna-setup scope-setup set envelope max-pycor set horizon antenna-y + .5 + 1 create-ufos 3 [ UFO-setup ] end to antenna-setup create-antennas 1 [ set main-antenna self set antenna-direction 1 set antenna-x 0 set antenna-y 1 setxy antenna-x antenna-y set size 2 set heading 0 ] end to ufo-setup ; start on left or right edge set xcor plus-or-minus ( max-pxcor ) ; start somewhere between horizon and upper limit of sky set ycor envelope - random-float ( envelope - horizon ) ; head for opposite edge set goal-x (- xcor) ; at some other altitude set goal-y envelope - random-float ( envelope - horizon ) ; point towards the goal set heading towardsxy goal-x goal-y ;set the size set size 1 ; set the speed and color set speed (.5 + random-float 1) / patch-size set color random 13 * 10 + 15 end to-report plus-or-minus [ value ] ; randomly reports either +value or -value report value * (((random 2) * 2) - 1) ; explanation of "(((random 2) * 2) - 1)" ; Operation: Yields: ; random 2 -> 0 or 1 ; * 2 -> 0 * 2 = 0 or 1 * 2 = 2 ; - 1 -> 0 - 1 = -1 or 2 - 1 = 1 ; thus, returns -1 or +1 end to scope-setup set scope-x 0 set scope-y 0 + min-pycor - .5 set scope-radius max-pycor + antenna-y ; - .5 create-scopes 1 [ set main-scope self set shape "scope" set size scope-radius * 2 setxy scope-x scope-y set heading 0 set color green ] end to go every (1 / 20) [ ufo-move ] every ((.5 * sweep-speed) / 60) [ antenna-sweep antenna-emit-pulse wave-propigate ] every (1 / 20) [ scope-fade ] end to-report wave-in report [ -> set pips pips + 1 if pycor + dy < (antenna-y - 1) [ die ] jump (wave-length / patch-size) if ycor <= [ ycor ] of one-of antennas [ scope-activate ] ] end to-report wave-out report [ -> ; advance clock timing the pulse set pips pips + 1 ; pulses are considered lost if they do not return in a certain time. ; but for display purposes, we will destroy pulses that leave the screen, ; or are below the antenna let res wave-length / patch-size ifelse not can-move? res [ die ] [ ; wave moves forward jump res ; if wave has not yet hit something and there's a UFO in the way... if any? ufos with [ distance myself <= .25 ] [ wave-bounce ] ] ] end to wave-propigate if rf-visible? or rf-visible? != old-rf-setting [ clear-drawing set old-rf-setting rf-visible? ] while [ any? waves ] [ ask waves [ run wave-move if rf-visible? [ stamp ] ] ] if rf-visible? [ display ] end to antenna-sweep set antenna-heading antenna-heading + 5 * antenna-direction ifelse reciprocate? [ if abs antenna-heading > 90 [ set antenna-heading 90 * antenna-direction set antenna-direction antenna-direction * -1 ] ] [ if abs antenna-heading >= 180 [ set antenna-heading -180 * antenna-direction + antenna-direction ] ] ; antenna-dir 0 - antenna-dir ask main-scope [ set heading antenna-heading ] ask main-antenna [ set heading antenna-heading ] end to antenna-emit-pulse if abs antenna-heading < 90 [ create-waves 1 [ set shape "wave" set size wave-length / patch-size set heading antenna-heading setxy antenna-x antenna-y set bounced? false set pips 0 set color white set hidden? not rf-visible? set wave-move wave-out ] ] end to scope-activate ; converts the incoming wave to mark the scope ; marks the scope based on the travel-time of the wave let detected-distance 0 hide-turtle set breed scope-markers set shape "phosphor" set size 1 ; move to center of scope setxy scope-x scope-y set color green + 1 ; reverse heading set heading ( heading + 180 ) ; calulate distance, and scale for scope viewing. set detected-distance pips * wave-length / patch-size / 2.5 if detected-distance > scope-radius [ set detected-distance scope-radius ] jump detected-distance show-turtle end to scope-fade ask scope-markers [ ifelse size > (1 / patch-size) [ set size size * .96 ] [ die ] ] end to ufo-move ask ufos [ ifelse ( can-move? (speed ) ) [ jump speed ] [ ufo-setup ] ;; ask (waves in-radius size) with [ not bounced? ] [ wave-bounce ] ] end to wave-bounce set wave-move wave-in set heading heading + 180 set color yellow set shape "wave-return" set bounced? true end
There is only one version of this model, created almost 3 years ago by James Steiner.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
RADAR.png | preview | Preview for 'RADAR' | almost 3 years ago, by James Steiner | Download |
This model does not have any ancestors.
This model does not have any descendants.