trampoline


Information

Created with NetLogo version NetLogo 3.1.1
Running with NetLogoLite.jar version 314.


TRAMPOLINE INTO HELL


Procedures

NetLogo Version: NetLogo 3.1.1

;; __extensions[ "sound.jar" ]

globals
[ g
  tick
]

breed [ divers diver ]
breed [ trampolines trampoline ]

divers-own
[ vx vy nx ny last-tramp spin
]

trampolines-own
[ basex basey width period moving?
]

to startup
   setup
end
   
to setup
    ca
    
   set g .02
   set-default-shape trampolines "trampoline"
   set-default-shape divers "diver"
   
   
   ;ask patch (-4) (max-pycor - 6)
   ;[ sprout-trampolines 1
   ;  [ set heading 45 set color blue set size 1.5 set moving? false ]
   ;]
   
   ask patches with [ pxcor = 0 and pycor >= min-pycor + 5 and pycor <= max-pycor - 5  ]
   [ sprout-trampolines 1
     [ set heading 0 set color blue set size 1.5
       set width 5 + random 6 
       set xcor min-pxcor + random (world-width)
       set moving? true;  ((who mod 2) = 0) 
       if moving? 
       [ while [ xcor < min-pxcor + width ] [ set xcor xcor + width ]
         while [ xcor > max-pxcor - width ] [ set xcor xcor - width ]
       ]
       set basex xcor set basey ycor 
       set period 360 / (1 + random-float 10)
       set heading -45 + 22.5 * random 5
     ]
   ]
   make-diver
   ask patches [ set pcolor red - 5 ]
   
   display
end

to fall
  
   if xcor + vx > max-pxcor [ die ]
   if xcor + vx < min-pxcor [ die ]
   if ycor + vy > max-pycor [ die ]
   ifelse ycor + vy < min-pycor 
   [ set ny min-pycor - ( (ycor + vy) - min-pycor) 
     set vy (- vy) * .9 set vx vx * .9
     set pcolor red + 4.9
     ask neighbors [ set pcolor red + 4.9 ]
     set color red
     
   ]
   [ set vy vy - g   
     set ny ycor + vy 
   ]
   set nx xcor + vx
   setxy nx ny
   let tramp collide with [ self != last-tramp-of myself ]
   if not any? tramp [ set tramp other-divers-here ]
   ifelse any? tramp 
   [ set spin spin * -1 * one-of [ 2 .5 ]
     set pcolor red - 5
     ask neighbors [ set pcolor red  ]
     set tramp one-of tramp
     let h heading-of tramp if h > 90 and h < 270 [ set h (h + 180) ] set h h + 180
     set vy vy * cos (h ) - vx * sin (h )  
     set vx vy * sin (- h) - vx * cos (- h)
     if breed-of tramp = trampolines
     [ ask tramp
       [ set color white
         rt 22.5 
         if heading > 90 and heading < 270
         [ set heading heading - 180
         ]
       ]
     ]
     if random 200 = 1 [ set label "Weeee!     " ]
     if is-turtle? last-tramp
     [ if breed-of last-tramp = trampolines
       [ ask last-tramp [ set color blue ]
       ]
     ]
     set last-tramp tramp

     ;; play-note (item int (128 * ((pxcor - min-pxcor) / world-width)) instruments)  (60 + pxcor) (127 * volume) .25
   ]
   [ if is-turtle? last-tramp
     [ if breed-of last-tramp = trampolines
       [ ask last-tramp [ set color blue ] ]
       set last-tramp nobody
     ]
   ]
   if pycor = min-pycor and (vx * vx + vy * vy) < .02 [ set pcolor red die ]

end

to go
   no-display
   every .25 + random-float .25
   [ make-diver
   ]
   every .016666
   [ set tick tick + .02
     ask trampolines with [ moving? ]
     [ move ]
     ask divers
     [ fall 
       rt spin
     ]
     ;ask patches with [ min-pycor = pycor and random 10 = 1 ]
     ;[ set pcolor  (red - 5 + random 9 )
     ;]
     ask patches
     [ let b .99 * mean values-from neighbors [ pcolor mod 10 ]
       set pcolor pcolor - (pcolor mod 10) + b
     ]
     display
   ]
end  

to move
   set xcor basex + width * sin (tick * period)
end   

to-report collide
   let mintx xcor - .5 
   let maxtx xcor + .5 
   let maxty 0
   let minty 0
   ifelse vy < 0
   [ set maxty ycor 
     set minty ycor - .5 + vy
   ]
   [ set maxty ycor + .5 + vy
     set minty ycor  
   ]
   let yes/no? trampolines with [     xcor >= mintx and xcor <= maxtx
                                   and ycor >= minty and ycor <= maxty 
                                 ]
   report yes/no?
end                                   

to make-diver
     ask patch int(7 * sin (tick * 90) ) (max-pycor - 1)
     [ set pcolor orange
       if not any? divers-here
       [ sprout-divers 1
         [ set heading 45
           set vx dx * .15
           set vy dy * .1
           set color one-of (list pink (yellow + 2) brown (orange - 2) (pink - 2) (pink + 2) )
           set spin 5 * (((random 2) * 2) - 1)
         ]
       ]
     ]
end     
 
 
to flame
   set pcolor red + 1
end
     
   

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download trampoline --