globals [buttons] ; Global variables turtles-own [group] ; Each turtle has "group" as a variable to setup ; Initializes model for new run. set-default-shape turtles "circle" ; Turtles are circles clear-all ; Reset turtles and patches set buttons 500 ; Set number of buttons to 500 create-turtles (buttons) ; Create "buttons" number of turtles ask turtles [setup-turtles] ; Initialize each turtle end to setup-turtles ; Called for each turtle during setup set group who ; Initialize "group" ins var to ID built-in setxy random screen-size-x random screen-size-y ; Set our x,y randomly end to go ; Step the model once locals [g1 g2] ; This procedure has some temp local variables set g1 group-of turtle random buttons ; g1 & g2 are two group values set g2 group-of turtle random buttons ; chosen from two random turtles ask turtles [joinClusters g1 g2] ; Merge group g1 with group g2 end to joinClusters [g1 g2] ; Convert group g1 turtles into g2 turtles if (group = g1) [set group g2 set color color-of turtle g2] end