NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.
NetLogo Version: NetLogo 4.0.4
;; SUMMARY ;;;; A simulation of RADAR ;; COPYRIGHT & LICENSE ;;;; Copyright (C) 2005 James P. Steiner ;;;; Some Rights Reserved. ;;;; Creative Commons Attribution-NonCommercial-ShareAlike License v. 2.0. ;;;; Visit http://creativecommons.org/licenses/by-nc-sa/2.0/ for more information. ;; APPLET DIMENSIONS (width x height) ;;;; 510 x 400 ;; globals [ 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 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 ] breed [ waves ] breed [ antennas ] breed [ ufos ] breed [ scopes ] breed [ scope-markers ] waves-own [ time ; 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 ] ufos-own [ goal-x goal-y ; where the ufo is heading speed ; relative speed of the ufo ] antennas-own [ clock ] scope-markers-own [ time ] to startup setup end to setup ca set-default-shape waves "wave" set-default-shape antennas "antenna" set-default-shape ufos "ufo side" 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 antenna self set antenna-direction 1 set antenna-x 0 set antenna-y 1 setxy antenna-x antenna-y set size 1 ] end to ufo-setup ; start on left or right edge ; start position is on the left or right edge of the patch, ; not the patch center. This helps reduces the effect of the ; ufos "popping" onto the sky. set xcor plus-or-minus ( max-pxcor + .49 ) ; start somewhere between horizon and upper limit of sky set ycor envelope - random-float ( envelope - horizon ) ; head for opposite edge set goal-x 0 - xcor ; at some other altitude set goal-y envelope - random-float ( envelope - horizon ) ; point towards the goal set heading towardsxy-nowrap goal-x goal-y ;set the size set size 1 ; set the speed and color set speed .005 + random-float .005 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 scope self set size scope-radius * 2 setxy scope-x scope-y set heading 0 set color green set shape "scope-frame" stamp set shape "scope-sweep" ] end to go every (1 / 30) [ ufo-move antenna-sweep emit-pulse repeat world-height * ( 2.0 / resolution ) [ if any? waves [ wave-propigate monitor-receiver ] ] scope-fade tick ] end to wave-propigate ask waves [ ; advance clock timing the pulse set time time + resolution ; pulses are considered lost if they do not return in a certain time. ; but for display purposes, we will destroy pulses that are about to ; leave the screen, or are heading below the antenna ifelse abs ( ycor + dy * resolution ) >= max-pycor + .5 - resolution ;; off the top / bottom or abs ( xcor + dx * resolution ) >= max-pxcor + .5 - resolution ;; off the let / right or abs ( ycor + dy ) <= ( antenna-y - 1 ) ;; below the antenna [ die ] [ ; wave moves forward jump resolution ; if wave has not yet hit something and there's a UFO in the way... if not bounced? and any? ufos with [ distance myself <= .5 ] [ wave-bounce ] ] ] if rf-visible? [ display ] end to antenna-sweep ask antenna [ set clock clock + sweep-angle ifelse reciprocate? [ set antenna-heading -90 * ( sin clock ) ] [ set antenna-heading antenna-heading + sweep-angle if antenna-heading >= 180 [ set antenna-heading antenna-heading - 360 ] ] set heading antenna-heading set [heading] of scope antenna-heading ] end to emit-pulse if abs antenna-heading < 90 [ create-waves 1 [ set heading antenna-heading setxy antenna-x antenna-y set size 1 set bounced? false set time 0 set color white set hidden? not rf-visible? ] ] end to monitor-receiver ask antenna [ ask waves with [ bounced? and distance myself <= .5 ] [ scope-activate ] ] end to scope-activate ; converts the incoming wave to mark the scope ; marks the scope based on the travel-time of the wave let range 0 hide-turtle set breed scope-markers set shape "phosphor" ; move to center of scope setxy scope-x scope-y set color green + 1 ; reverse heading set heading ( heading + 180 ) mod 360 ; calulate distance, and scale for scope viewing. set range time * .5 if range > scope-radius [ set range scope-radius ] jump range show-turtle end to scope-fade ask scope-markers [ ifelse color > green - 4 [ set color (color - resolution * .09) set size size - resolution * .05 ] [ die ] ] end to ufo-move ask ufos [ if abs ( xcor + speed * ufo-speed * dx ) >= abs goal-x [ ufo-setup ] set heading towardsxy-nowrap goal-x goal-y jump speed * ufo-speed ] end to wave-bounce set heading heading + 180 set color yellow set shape "wave-return" set bounced? true end
View or download the complete model file (to download: right-click, save-link-as):
-- Download radar --