gravity_2009


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


Gravity Demo by James Steiner
This model demonstrated some of the new features in NetLogo 3, such as stamping and drawing in the new drawing layer.

Procedures

NetLogo Version: NetLogo 4.0.4

;;;;; SUMMARY
;; A single table-tennis ball drops.
;;;; 
;;  Copyright (C) 2005 James Steiner
;;  License: Creative Commons 2.0 at-sa-nc
;;
;;
;;;;
globals
[ friction ;; portion of x-velocity that is lost at impact
  elastic  ;; portion of y-velocity that is retained at impact
  
]
breed [ balls ]

balls-own
[ xx yy xv yv
]
patches-own
[ ref-angle 
]

to startup
   setup
end

to setup
   ca
   let threedshapes [ "default" "circle" "dot" "square" "triangle" "cylinder" "line" "line-half" "car" ]
   set-default-shape balls "circle"
   
   ask patches [ set pcolor 1 + random-float 1 ]
   ask patches with [ pycor = min-pycor ] [ set pcolor blue - 4 + random-float 2 ]

   create-balls 1
   [ set color white 
     set xx sex-1/2 * drop-point
     set yy ( sey-1/2 * fall-height )
     set xv initial-x-velocity * movement-scale
     set yv 0
     setxy xx yy
     ifelse show-path? [ pd ] [ pu ]
     if stop-motion? [ stamp ]
    ]
    set friction .05
    set elastic .8
end

to drop
   let stop? false

   ask balls
   [
     set yv yv - gravity * movement-scale
     ;; still on screen, or need to bounce?
     set yy yy + yv * movement-scale
     if yy < (-sey+1/2)
     [ ;; bounce
       set yy yy - yv
       let above-surface (sey-1/2 + yy) ;; 7 + -5  = 2
       let intercept-ratio -1 * above-surface / yv ;; -1 * 2 / (- 4) = .5
       let y-intercept xx + (intercept-ratio * xv)
       setxy y-intercept -sey+1/2
       set yv yv * elastic  * -1
       set xv xv * (1 - friction)
       set yy -sey+1/2 + yv * intercept-ratio * movement-scale
     ]
     ;; bounce (or roll) off screen?
     ifelse abs(xx + xv) > sex-1/2
     [ set xv (- xv) ]
     [ set xx xx + xv ]
     setxy xx yy
     if xv != 0 or yv != 0 [ set heading atan xv (-1 * abs yv) ]
     if stop-motion? and (ticks mod shutter-delay = 0 ) [ stamp ]
     if abs xv < .01 and abs yv < .01 [ set stop? true ]
   ]
   tick
   if stop? [ stop ]
end

to-report sex-1/2 report max-pxcor - .5 end
to-report sey-1/2 report max-pycor - .5 end
to-report -sex+1/2 report min-pxcor + .5 end
to-report -sey+1/2 report min-pycor + .5 end

                    


Download Link

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