CIRCLE SOURCE CODE

Back to Circle


Turtle Procedures Observer Procedures
turtles-own [next-turtle 
             prev-turtle 
             heading-1 
             dist-1 
             heading-2 
             dist-2 
             repel-turtle] 

to setup 
setc red 
settotal-turtles num 
seth random 360 fd random 25 
setnext-turtle who + 1 
if next-turtle >= total-turtles [setnext-turtle 0] 
setprev-turtle who - 1 
if prev-turtle < 0 [setprev-turtle total-turtles - 1] 
end 

to adjust 
setheading-1 towards xcor-of next-turtle ycor-of next-turtle 
setdist-1 
   (convergence / 100) * 
     ((distance xcor-of next-turtle ycor-of next-turtle)  - desired-distance)

setheading-2 towards xcor-of prev-turtle ycor-of prev-turtle 
setdist-2 
   (convergence / 100) * 
     ((distance xcor-of prev-turtle ycor-of prev-turtle)  - desired-distance) 

seth heading-1 
fd dist-1 
seth heading-2 
fd dist-2 
end 

to repel 
setrepel-turtle random total-turtles 
seth towards xcor-of repel-turtle ycor-of repel-turtle 
bk repel-strength / 100 
end

globals [total-turtles] 

to setup 
ca 
crt num 
ask-turtles [setup] 
end