breeds [nodes edges] edges-own [a b] nodes-own [v] globals [x-max y-max diam init-v-max reinit-v-max filename tick stoptick] to setup ca set diam 4 set init-v-max 3 set reinit-v-max 10 set x-max screen-edge-x - (diam / 2) set y-max screen-edge-y - (diam / 2) set filename "" ; change to collect images .. or use command center after setup set tick 0 set stoptick 0 ; set to some number to stop, generally for image collections set-default-shape nodes "circle" set-default-shape edges "line" ask patches [set pcolor white] ask patches with [pxcor = 0 or pycor = 0][set pcolor gray] cct-nodes balls [ set color yellow set size diam set v random-float init-v-max setxy random-float (x-max) * (2 * (random 2) - 1) random-float (y-max) * (2 * (random 2) - 1) ] if balls > 1 [ask nodes [ connect-edge random-one-of nodes with [self != myself] ]] end to go if filename = 0 [setup] no-display set tick tick + 1 ask nodes [ set v v - gravity ifelse (abs (ycor + v)) <= y-max [ set ycor ycor + v ;set color yellow ] [ set ycor y-max * sign ycor set v (- v) ifelse v >= 0 and v <= gravity [set v random-float reinit-v-max] ; set color red] [set v v - (sign v) * friction] ; set color blue] ] ] ask edges [adjust-edge] display check-movie if stoptick = tick [stop] end to check-movie if length filename > 0 [ export-graphics filename + substring "0000" (int log tick 10) 3 + tick + ".png" ] end to connect-edge [other-node] ; node proc: attach an edge between self and other hatch 1 [ set breed edges set a myself set b other-node set color red adjust-edge ] end to adjust-edge ; edge proc: reattach to a & b nodes setxy xcor-of a ycor-of a set size distance-nowrap b set heading towards-nowrap b jump size / 2 end ;;;; Utilities to-report sign [num] ifelse num < 0 [report -1][report 1] end @#$#@#$#@ GRAPHICS-WINDOW 204 10 565 392 19 19 9.0 1 10 1 1 1 CC-WINDOW 4 417 475 536 Command Center BUTTON 7 69 62 102 NIL setup NIL 1 T OBSERVER T BUTTON 68 70 123 103 NIL go T 1 T OBSERVER NIL BUTTON 129 70 184 103 step go NIL 1 T OBSERVER T SLIDER 6 34 184 67 balls balls 1 20 5 1 1 NIL SLIDER 7 193 183 226 gravity gravity 0 5 1.0 0.25 1 NIL SLIDER 8 235 184 268 friction friction 0 1 0.25 0.25 1 NIL TEXTBOX 11 10 183 31 Setup Parameters and Controls. TEXTBOX 10 154 165 189 Runtime Parameters.\nCan change while running! @#$#@#$#@ WHAT IS IT? ----------- A very simple first graph (edges and nodes) model. HOW IT WORKS ------------ Nodes are randomly created and linked, then are subject to gravity each step of the model. HOW TO USE IT ------------- Change the number of balls slider if you'd prefer a different value. Click "setup" to initialize the nodes and edges. Click "Go" to run the model, or click "Step" to manually run the model one step at a time. THINGS TO NOTICE ---------------- Not much in the model, this is just a programming exercise to try the NetLogo edges and nodes facility. You can read the code fairly easily to see how the graph is managed. THINGS TO TRY ------------- Move the two sliders "friction" and "gravity" while the model is running to see how they change the bouncing balls. Change the code to play with the edges and nodes. EXTENDING THE MODEL ------------------- Have the nodes be attracted to the other nodes they are attracted to so that the nodes move in two directions. NETLOGO FEATURES ---------------- Edges and Nodes! The cool thing is the model NetLogo uses for edges: they are simply agents located at the center of the edge, and long enough to connect the nodes the edge connects. Using floating coordinates lets the graph continuously morph. RELATED MODELS -------------- Check out the "layout" model which is a springs and forces model making the graph untangle itself. CREDITS AND REFERENCES ---------------------- Seth Tisue sent me a very similar model to start out with .. Thanks! @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 circle false 0 Circle -7566196 true true 35 35 230 line true 0 Line -7566196 true 150 0 150 301 @#$#@#$#@ NetLogo 2.0.0 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@