;;;;; SUMMARY ;; A single table-tennis ball drops. ;;;; ;; Copyright (C) 2005 James Steiner ;; License: Creative Commons 2.0 at-sa-nc ;; ;; ;;;; globals [ ticks friction ;; portion of x-velocity that is lost at impact elastic ;; portion of y-velocity that is retained at impact ] breeds [ 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" set ticks 0 ask patches [ set pcolor 1 + random-float 1 ] ask patches with [ pycor = (- screen-edge-y ) ] [ set pcolor blue - 4 + random-float 2 ] cct-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 set ticks ticks + 1 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 stop? [ stop ] end to-report sex-1/2 report screen-edge-x - .5 end to-report sey-1/2 report screen-edge-y - .5 end to-report -sex+1/2 report (- screen-edge-x) + .5 end to-report -sey+1/2 report (- screen-edge-y) + .5 end @#$#@#$#@ GRAPHICS-WINDOW 260 12 690 463 17 17 12.0 1 10 1 1 1 0 1 1 1 CC-WINDOW 5 477 699 572 Command Center 0 BUTTON 42 335 105 368 NIL setup NIL 1 T OBSERVER T NIL BUTTON 133 335 196 368 NIL drop T 1 T OBSERVER T NIL SLIDER 16 86 188 119 fall-height fall-height 0 1 1.0 0.01 1 NIL SLIDER 16 52 188 85 initial-x-velocity initial-x-velocity 0 1 1.0 0.01 1 NIL SWITCH 17 239 128 272 show-path? show-path? 0 1 -1000 SWITCH 17 274 128 307 stop-motion? stop-motion? 0 1 -1000 SLIDER 130 274 234 307 shutter-delay shutter-delay 1 200 30 1 1 NIL SLIDER 16 131 188 164 gravity gravity 0.01 1 0.96 0.01 1 NIL SLIDER 16 16 218 49 drop-point drop-point -1 1 -1.0 0.5 1 * screen-edge-x BUTTON 194 131 249 164 earth set gravity .96 NIL 1 T OBSERVER T NIL SLIDER 16 182 188 215 movement-scale movement-scale 0.01 1 0.05 0.01 1 NIL @#$#@#$#@ Gravity Demo by James Steiner This model demonstrates some of the new features in NetLogo 3. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 circle false 0 Circle -7500403 true true -1 -1 301 line true 0 Rectangle -7500403 true true 180 0 210 315 Rectangle -1 true false 150 -150 165 150 Rectangle -1 true false 150 150 165 450 mirror true 0 Rectangle -7500403 true true 180 0 210 315 Rectangle -1 true false 150 -150 165 150 Rectangle -1 true false 150 150 165 450 @#$#@#$#@ NetLogo 3.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@