globals [ time color-sep ;; amount color is changed for patches ] breeds [ balls center-of-mass ] to setup ca set time 0 setup-border setup-balls setup-center set color-sep (13 - (sqrt count balls)) * .1 ;;color-sep is calculated this way to create a value if color-sep < 0.5 ;;that is appropriate given the number of turtles [ set color-sep 2 * color-sep ] end to setup-border ask patches [if (pxcor < 10 - screen-edge-x) [set pcolor blue] if (pxcor > screen-edge-x - 10) [set pcolor blue] if (pycor > screen-edge-y - 10) [set pcolor blue] if (pycor < 10 - screen-edge-y) [set pcolor blue] ] end to setup-balls ;;creates and distributes the green turtles set-default-shape balls "circle" create-custom-balls number [ set color green rt random-float 360 setxy (random-float (2 * (screen-edge-x - 11) ) - (screen-edge-x - 11)) (random-float (2 * (screen-edge-y - 11) ) - (screen-edge-y - 11)) ] end to setup-center create-center-of-mass 1 ask center-of-mass [ set color yellow ] end to go ask balls [ bounce ] ask center-of-mass [ move-center ] if trace-center? [ ask center-of-mass [ draw-center ] ] set time time + 1 end to move-center ;; center-of-mass procedure setxy (sum values-from turtles [xcor] - (xcor-of turtle 0) ) / (count turtles - 1) (sum values-from turtles [ycor] - (ycor-of turtle 0) ) / (count turtles - 1) end ;; increases the brightness of the trace on the current patch to draw-center ;; center-of-mass procedure ifelse (pcolor = black) [ stamp red - (5 - color-sep) ] [ if (pcolor < red + (5 - color-sep - .1)) [ stamp (pcolor + color-sep) ] ] end to bounce ;; balls procedure, balls bounce off the border if ( (round xcor) < (10 - screen-edge-x)) [set heading (- heading)] if ( (round xcor) > (screen-edge-x - 10)) [set heading (- heading)] if ( (round ycor) < (10 - screen-edge-y)) [set heading (180 - heading)] if ( (round ycor) > (screen-edge-y - 10)) [set heading (180 - heading)] fd 1 end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Random Balls model. ; http://ccl.northwestern.edu/netlogo/models/RandomBalls. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/RandomBalls ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 281 18 777 535 40 40 6.0 1 10 1 1 1 CC-WINDOW 3 343 274 457 Command Center BUTTON 49 50 104 83 setup setup NIL 1 T OBSERVER SLIDER 22 107 222 140 number number 2 1000 20 1 1 NIL BUTTON 119 50 174 83 go go T 1 T OBSERVER SWITCH 59 182 191 215 trace-center? trace-center? 0 1 -1000 @#$#@#$#@ WHAT IS IT? ----------- Random Balls simulates a frictionless billiard table. The balls are drawn in green. They move in straight lines and bounce off the walls but not off of each other. The center of mass is drawn in yellow. A continuous trace is optionally made of it in red, with the brightness increasing each time the center of mass is on that patch, which results in the display of its statistical behavior. HOW TO USE IT ------------- Select the number of balls to be used, then push SETUP. Push GO to run the model. THINGS TO NOTICE ---------------- Watch how the center of mass moves for a while. Is there a pattern? Is there a region in the box that it stays within? THINGS TO TRY -------------- Run the model with a lot of turtles, then just a few. What happens to the motion of the center of mass? Why? Let the model run for a while. What do you notice about how much time the center of mass spends at different distances from the origin (its frequency distribution)? Push SETUP, then in the command center, type "ask balls [set heading 60]" and press ENTER. This points all of the turtles in the same direction. What does the center of mass do now? Try other headings. EXTENDING THE MODEL ------------------- Presently the balls don't bounce off each other. If they did, would it make a difference in the behavior of the center of mass? Try it. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Random Balls model. http://ccl.northwestern.edu/netlogo/models/RandomBalls. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/RandomBalls for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 circle true 0 Circle -7566196 true true 35 35 230 @#$#@#$#@ NetLogo 2.0alpha1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@