Reputation: 63
So my turtles have to circle around a point. My initial approach was to have them rotate every tick perpendicular to the point they have to rotate around, and make them move forward. This however results in them gravitating to the same circle with a fixed radius. So how would one approach this problem?
Upvotes: 0
Views: 181
Reputation: 9152
; move in a circle
; by
; Jose M Vidal
to setup
clear-all
create-n-turtles num-turtles
reset-ticks
end
to create-n-turtles [n]
crt n [
fd random 20
shake]
end
to update
if (count turtles < num-turtles)[
create-n-turtles num-turtles - count turtles]
while [count turtles > num-turtles][
ask one-of turtles [die]]
ask turtles [move]
tick
end
;
to move
let cx 0
let cy 0
set cx mean [xcor] of turtles
set cy mean [ycor] of turtles
set heading towardsxy cx cy
if (distancexy cx cy < radius) [
set heading heading + 180]
if (abs distancexy cx cy - radius > 1)[
fd speed / 1.414]
set heading towardsxy cx cy
ifelse (clockwise) [
set heading heading - 90]
[
set heading heading + 90]
fd speed / 1.414
end
to shake
set heading heading + (random 10) - 5
set xcor xcor + random 10 - 5
set ycor ycor + random 10 - 5
end
Upvotes: 1