如何让乌龟围绕一个点旋转

时间:2018-04-29 17:00:09

标签: rotation netlogo

所以我的乌龟必须围绕一点。我最初的方法是让它们每个刻度旋转垂直于它们必须旋转的点,并使它们向前移动。然而,这导致它们倾向于具有固定半径的相同圆。那么如何处理这个问题?

1 个答案:

答案 0 :(得分:1)

; 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